Skip to main content
gamedev.net
🔒 Locked

Displaying several objects....

Started by trondb Mar 10, 2003 at 9:03 AM 0 replies 300+ views
Original Post
trondb
trondb
Hi, I am just getting into OGL, and haven''t found a way to display several objects at once... For now, I am simply using the predefined models in the glut library like glutSolidTorus and glutSolidSphere. Lets say I''d wanna display a torus and a sphere, and be able to move/rotate them around as one object - how would I draw the two objects as one? Thanks dudes,
"That's Tron. He fights for the users."
Expendable
Expendable
You want to rotate and translate the model view matrix before drawing the 2 objects. That will keep them together. If you want the torus and the sphere to rotate and move separately, then you would want to rotate, translate, and draw the first ojbect. Then you would reset the model view matrix back to the "beginning state", and rotate, translate, and draw the second object.

You want:

glLoadIdentity(); // Reset to starting matrix
glRotatef(270.0f, 1.0f, 0.0f, 0.0f); // Rotate 270 degrees on X -Axis
glRotatef(180.0f, 0.0f, 1.0f, 0.0f); // Rotate 180 degrees on y -axis
glTranslatef(x, y, z); // Move by x, y, z units
// Draw first object here
// Draw second object here


versus:


glLoadIdentity(); // Reset to starting matrix
glRotatef(270.0f, 1.0f, 0.0f, 0.0f); // Rotate 270 degrees on X -Axis
glRotatef(180.0f, 0.0f, 1.0f, 0.0f); // Rotate 180 degrees on y -axis
glTranslatef(x, y, z); // Move by x, y, z units
// Draw first object here

glLoadIdentity(); // Reset to starting matrix
glRotatef(90.0f, 1.0f, 0.0f, 0.0f); // Rotate 90 degrees on X -Axis
glRotatef(-180.0f, 0.0f, 1.0f, 0.0f); // Rotate -180 degrees on y -axis
glTranslatef(x, y, z); // Move by x, y, z units
// Draw second object here

E-x-p-e-n-d-a-b-l-e

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.