This isn’t specifically OGL related, but I think it’s relavent. I’d sure appreciate some help. I’ve been out of C/C++ coding for a while, and the pointer/reference stuff is still a little fuzzy.
Here’s my problem: I have defined a structure to hold an “object” in my virtual world. Then, in my main() function, I define a dynamic array to hold these objects (so I can define at runtime how many objects there are). Next, I want to pass my whole dynamic array (well, a pointer to it) to another function so that I can process the whole list of objects (like initializing the world or drawing the scene).
Here’s a simplified version of my code to illustrate where I’m having the problems (where you see the question marks), I’d really apprecieate it if someone could look it over and give me some guidance:
typedef struct Object_typ {
GLfloat matrixArray[16];
int objectID;
int state;
} Object, *Object_ptr; // ??? Should I use the “*Object_ptr” type, or is this confusing (in general)?Object* controlledObject; // Pointer to the Object our control inputs affect
Object* cameraObject; // Pointer to the Object that is the current “camera”
void initWorldData(???What do I put here??? worldObjects)
{
int totalObjects = 3;
delete worldObjects; //??? is this correct? can I do this beofer worldObjects has been allocated w/ new???
worldObjects = new Object_ptr[totalObjects]; // pointer to dynamic array of pointers to objectsglMatrixMode(GL_MODELVIEW);
glLoadIdentity();
for (int index = 0; index < totalObjects; index++){
// ??? is this the correct syntax to reference the object’s matrixArray???
glGetFloatv(GL_MODELVIEW_MATRIX, worldObjects[0]->matrixArray);
}cameraObject = worldObjects[0]; // Pointer to the Object that is the current “camera”
controlledObject = worldObjects[1]; // Pointer to the Object our control inputs affect
}int WINAPI WinMain() {
//??? which of the following two lines should I use???
Object* (*objects); // pointer to dynamic array of pointers to objects
Object_ptr (*objects); // pointer to dynamic array of pointers to objectsinitWorldData(objects); // ??? is this the correct way to pass a dynamic array of structs???
}
Thanks a bunch!
-BradlyP
[This message has been edited by BradlyP (edited 12-03-2000).]