Finding a point
How would you find the location of a cube after several transformations?
Before each time the cube is drawn it is rotated by a value depeding on if the user was holding down a key, and then translated based on the same thing. How would I then find the location of that cube so I can draw another object in that same place?
I''m trying to make it so that when the user pushes space, another object emenates from the center of the cube, wherever on the screen it may be by that point, then travels off in a given heading.
I''ve tried doing a glPushMatix() after the cube was positioned, and then calling glPopMatrix() before drawing the next object, but that doesnt seem to be working???
Maybe i misunderstood you here but ill give it a shot.
glPushMatrix(); //pushes the current matrix to the stack, ie. it stores the current values
glPopMatrix(); //Pops the last Pushed matrix back from the stack, ie. it restores the values that you pushed with the above command
glTranslatef(0.0f,2.0f,0.0f); //
glPushMatrix(); // Now you store the CURRENT values in the stack
//now we move around, rotate and scale.
glTranslate(0.04324f,2.23f,0.33f);
glRotatef(tilt,1.0f,0.0f,0.0f);
glScalef(blablabla you get the point);
glPopMatrix(); // Now you restore them to what they where before you pushed them.
Gah i suck at explaining. maybe a good idea for me would be NOT to try!
glPushMatrix(); //pushes the current matrix to the stack, ie. it stores the current values
glPopMatrix(); //Pops the last Pushed matrix back from the stack, ie. it restores the values that you pushed with the above command
glTranslatef(0.0f,2.0f,0.0f); //
glPushMatrix(); // Now you store the CURRENT values in the stack
//now we move around, rotate and scale.
glTranslate(0.04324f,2.23f,0.33f);
glRotatef(tilt,1.0f,0.0f,0.0f);
glScalef(blablabla you get the point);
glPopMatrix(); // Now you restore them to what they where before you pushed them.
Gah i suck at explaining. maybe a good idea for me would be NOT to try!
June 13, 2000 01:42 AM
Avoid incremental rotations (and translations for that matter). Instead, have an array of the objects translations in the x y and z directions, and an array of the objects rotations in the x y and z directions. When the user presses a key, it increments the relevent area of each array. Then each frame, do a glLoadIdentity(), and then something like:
glRotatef(rotate[0], 1.0, 0.0, 0.0)
glRotatef(rotate[1], 0.0, 1.0, 0.0)
glRotatef(rotate[2], 0.0, 0.0, 1.0)
glTranslatef(translate[0], translate[1], translate[2]);
then to find the position of that object, simply rotate and translate another object by the same arrays.. wallah!
hope this helps
glRotatef(rotate[0], 1.0, 0.0, 0.0)
glRotatef(rotate[1], 0.0, 1.0, 0.0)
glRotatef(rotate[2], 0.0, 0.0, 1.0)
glTranslatef(translate[0], translate[1], translate[2]);
then to find the position of that object, simply rotate and translate another object by the same arrays.. wallah!
hope this helps
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement