So I created a struct here in my model.h file:
typedef struct
{
float* vertexBuffer;
float* Faces_Triangles;
float* normals;
long TotalConnectedTriangles;
} model;
under this 'model' struct, I have a model.c
I have this inserting my data into the struct, plus the return:
So In my main, I want to call this struct or return, but how...
like if I say it directly like printf(newModel); it won't work, it says its undeclared I want to access the variables within the previous function. How do I do so.
These lines do nothing. Absolutely nothing. What are you trying to do here?
call this struct or return, but how...
You can't call a struct. You can only call functions. A struct is just another kind of variable you can create. What is your question? Are you asking how to create and use structs of type model?
Of course they will. All a getter does is return some value. All a setter does is set some value. C code is chock full of setting values and reading them. However, since in C a struct does not have functions, you'd have to have stand-alone getter and setter functions, and since getter and setter functions exist to allow you to control access, it's pretty pointless in C as there is no concept of public or private.
A big part of the problem here is that you are thinking in terms of programming concepts that don't exist in C. You're clearly trying to create objects, with member functions, which C just doesn't do in nearly so neat a way as a programming language built with that in mind.
Well what I'm trying to do is this:
I'm reading in model data through my model.c
I want it to store the data in that model.c file so that I can call it in other functions.
I want it to store its vertexBuffer, Faces_triangles, normals and TotalConnectedTriangles.
So, lets say I load 3 different models. I want it to store the data uniquely for those three seperate models, and I want to be able to pull the data out of each one as I see fit.
like, for example, I have a drawing function that will draw the model that is loaded, but it needs the data that came from my model.c file. More specifically my model function.
I have my model data stored in my model function as vertexBuffer, Faces_triangles, normals and TotalConnectedTriangles. It DOES store the data, but I can pass it onto anything, or have it accessible.
The thing is, I have the arrays loaded in, after the file has been read and split up in my function in model.c I just want to figure out a way that I can access this information (be it whatever technique it is, enums, structs, return values).
Like for example. I load up box.obj in my model.c class
it splits it up into vertexBuffer, Faces_triangles, normals and TotalConnectedTriangles.
what can *I* do to access these variables within this load function somewhere else, like lets say in main.c
I may not even need to use a struct, I just threw the struct in there because I thought I could store data in this struct and access it elsewhere.
what can *I* do to access these variables within this load function somewhere else, like lets say in main.c
Create the struct model variables in your main function (stop thinking about main.c - main.c does not exist once the program has been compiled). Pass them by pointer to whichever functions you have that read the data and fill them up, and then you can pass the filled-in struct around wherever you like from the main function.
I load up box.obj in my model.c class
No, you don't, because this in C, and C has no meaningful class type, and even if it did, model.c is a text file - not a class. If you're going to code in C, think in C. If you're thinking in classes, you'll go wrong.
I believe that's what I did. I had my struct set up as mentioned earlier
and in my function to load, I create this:
model* newModel = (model*)malloc( sizeof(model) );
This creates a new model with the struct variables, correct?
If this is the case, then I can just push the data into it (once it has been read in and processed) like so:
So, wouldn't this fill the struct with the post-processed data?
I understand its called 'newModel' so if I were to call this function and load 3 different models, it would be just create newModel and overwrite it 3 times, correct?
I'm sorry if I'm being difficult, return values and getting data is something that's a little over my head in C, so I'm just trying to clear it up. The only reason why I mention different classe is to help people see where its being called from. It's a segmented system such as:
model.c
light.c
camera.c
...
all with their appropriate .h files as well
and a main.c
I understand its just a text file, but I just want to show where they are being put together. I don't want to write everything monolithically in one file.
does nothing. Absolutely nothing. What are you trying to do here? Assign values? Call functions? Whatever you're trying, it's not working. This does nothing.
I understand its called 'newModel' so if I were to call this function and load 3 different models, it would be just create newModel and overwrite it 3 times, correct?
No. If you load three different models, for example by giving them different names, when you assign values to one of them, the other two will not be overwritten. Here, look at this:
1 2 3 4 5 6
int a;
int b;
int c;
a=7;
b=8;
c=9;
See how I made three differentint values, and then gave them values? When I gave a value to c, it did not overwrite the value given to a or b.