-
struct pointers
Hi!
I was wondering how it would be done to point to struct, like this
you have two dif structs
Code:
typedef struct {
float face1,face2,face3;
char name[200];
int num_objs;
} object_list;
typedef struct {
scene_name
}scenes;
object_list obj[50];
scenes scene[50];
where scene would be 1 element, and pointing to several objects with in the
(this is pseudo and what i want todo)
scene[0].obj[0].numobj;
result with how many objects there are in scene 0, right now i add the start object and the end object into the scene struct so, when drawing the 3d object, i do
this more or less.
Code:
for (counter=startobj;counter<endobj;counter++)
anyone could elaborate how i could do this?
Any help are appricated! :)
- seidel
-
If you're asking how to iterate through a series of structs, you have at least two options. Here they are in somewhat-pseudo-code:
As an array
Code:
my_type objects[50];
int length = 50;
...
for(i = 0; i < length; i++) {
// Do some stuff with objects[i]
}
As a linked list (i.e. the struct contains a pointer that is used to point to the next instance in the series)
Code:
struct my_type {
int data[50];
struct my_type * next;
} current;
...
for(current = start; current.next != NULL; current = current.net) {
// Do some stuff with current
}
-
For one thing, struct scene DOES NOT contain an 'obj', so your 'scene[0].obj[0].numobj;' is completely bogus.
To do what you want to do, you would have to include the structure 'object_list' INSIDE your scene struct.
Code:
typedef struct {
float face1,face2,face3;
char name[200];
int num_objs;
} object_list;
typedef struct {
scene_name
struct object_list[50];
}scenes;