Advertisement

Specify the location of many cylinders

Started by July 22, 2002 02:15 PM
3 comments, last by laura_steph1 22 years, 7 months ago
Hi, I need help figuring out how to place 5 cylinders in specific locations. For instance, if I need the base of one cylinder to be located at x-axis = 1, y-axis = 6, and z-axis = -1.5, how would I write that? thanks, Laura --> laura stephens
laura stephens
TRY GLTRANSLATE

glPushMatrix();
glLoadIdentity ();
glTranslatef(X, Y, Z);
// RENDER CYLINDER

glPopMatrix();


[edited by - BGCJR on July 22, 2002 10:04:25 PM]
Game Core
Advertisement
Okay, I think I tried doing something similar but didn''t put the pushmatrix and popmatrix in the right place. If I had five different cylinders would it look like this:

glPushMatrix();
glLoadIdentity ();
glTranslatef(X, Y, Z);
// RENDER CYLINDER #1
glPopMatrix();

glPushMatrix();
glLoadIdentity ();
glTranslatef(X, Y, Z);
// RENDER CYLINDER #2
glPopMatrix();

etc...
or
glPushMatrix();
glLoadIdentity ();
glTranslatef(X, Y, Z);
// RENDER CYLINDER #1
// RENDER CYLINDER #2
// RENDER CYLINDER #ETC...
glPopMatrix();

Thanks,
Laura
laura stephens
You don't actually have to call LoadIdentity for each transform... a better way to do it is to call LoadIdentity once at the beginning of the frame, then apply your viewing translation/rotations (ie position the "camera"), then Push/Translate/Draw/Pop for each object in your scene.

Also, you can't draw all your objects withing the one Push/Pop, as they will simply be drawn over the top of each other... you have not specified a different position (translation) for each of them. The first example you gave is the right way.

Just for clarity, an example of the code variety:

  glLoadIdentity();// glTranslate/glRotate here if you wish to move the viewpoint //  around in the scenefor(int j = 0; j < 5; j++){  glPushMatrix();    glTranslatef(object[j].x, object[j].y, object[j].z);    DrawFunkyCylinderBaby();  glPopMatrix();}  



Hope that helps



[edited by - Bad Monkey on July 23, 2002 1:17:09 AM]
Oh that helps alot!

Thanks, I''ll try it that way.


-Laura -->
laura stephens

This topic is closed to new replies.

Advertisement