controlling multiple objects - help

Hi, I am really new at this, and I am struggling with some basics, maybe because I have a CAD background. I want to write an app that has a terrain object and multiple vehicles (100 or so) that move independantly from each other. I can grasp the Push/Pop for 2 objects, but how do you manage 100? I am a little lost. How can I select a previously created/displayed object and translate/rotate it when I am not tracking which matrix put it there originally?

Any assistance would be very much appreciated

The push/pop is the same as if for 2 or 1000 objects.

Use array varaibles to store your objects position.

create a object processing routine in your display routine

example

for (i = 0; i < total_objects, i++)
{
glPushMatrix();
glTranslatef(obj[i].x,obj[i].y ,obj[i].z);
glRotatef(obj[i].angle_x, 1, 0, 0);
glRotatef(obj[i].angle_y, 0, 1, 0);
glRotatef(obj[i].angle_z, 0, 0, 1);

draw_obj(obj[i].type); // number to tell what object to draw, 0 = car, 1 = plane, 2 = house, etc

glPopMatrix();
}
// the for loop process’s drawing all of our objects

Hope this helps

Originally posted by Kim Adil:
[b]Hi, I am really new at this, and I am struggling with some basics, maybe because I have a CAD background. I want to write an app that has a terrain object and multiple vehicles (100 or so) that move independantly from each other. I can grasp the Push/Pop for 2 objects, but how do you manage 100? I am a little lost. How can I select a previously created/displayed object and translate/rotate it when I am not tracking which matrix put it there originally?

Any assistance would be very much appreciated[/b]

Thanks, I’ll give it a try. The underlying problem that I had, was knowing exactly goes in the display routine. My terrain object will involve a huge number of polygons.I have GPS coordinates (with elevation)for a patch of land 70000meters long and 10000 meters wide with elevations at 1 meter resolution. After drawing it once, I was hoping that I would not have to load all polygons each time the display function is called. I expect it could really slow things down. A lot of the polygons will be out of the depth of view area. Should I code to filter distant polygons out, or is that what openGL is optimised for?

Regards,
Kim

You only load in the area of the map that you can see. I don’t think you will see 70000 meters at one time.

now push/pop is not for every part of your map. Just objects.
The map it self is handled as one big object, and there is a method for doing it in sections.

Maybe someone else will post on that.

Originally posted by Kim Adil:
[b]Thanks, I’ll give it a try. The underlying problem that I had, was knowing exactly goes in the display routine. My terrain object will involve a huge number of polygons.I have GPS coordinates (with elevation)for a patch of land 70000meters long and 10000 meters wide with elevations at 1 meter resolution. After drawing it once, I was hoping that I would not have to load all polygons each time the display function is called. I expect it could really slow things down. A lot of the polygons will be out of the depth of view area. Should I code to filter distant polygons out, or is that what openGL is optimised for?

Regards,
Kim[/b]

If you can, try breaking the terrain down in to small sections.

In my case this was easy because my terrain was stored in a number of different files. When loading I just took the max and min values for X Y and Z and created a bounding box from these.

Check to see if each section should be shown (is it in the view area (called frustum)) and draw it if it is.
You have to check if any of the 8 points of the bounding box is in the frustum (itself made up of 5 planes)

The check should be quicker than actually drawing the section (if its done correctly).

Examples can be found on Hehe

hope this helps.

Many thanks! I am now confident enough in my new approach that I can get on with it. I am interested in the others experiences with this sort of application, but I really do have a head full of ideas and no experience. Time write a program now. Thanks again.

Kim