Jump to content
  • Advertisement
Sign in to follow this  

Please help with a special function - it involves rotation and new x y z coordinates

This topic is 4453 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

OpenGL I need to make a function in OpenGL that will rotate some objects around a point and after the rotation the new coordinates(x y z) of the objects to be the one where they were rotated Maybe what i have done bellow will explain better: rotation of 180 degree object(x1 y1 z1) x(point) same object(new x2 y2 z2) Also i need the object (in the new location) to be rotated (180 degres -> upside down) Thank!

Share this post

Link to post
Share on other sites
It is not clear what you are trying to do. Here is how you rotate around a point:
    GLfloat px, py, pz; // the point you want to rotate around (the "pivot")
Glfloat angle; // the angle of rotation
GLfloat ax, ay, az; // the axis of rotation

glTranslate( px, py, pz );
glRotate( angle, ax, ay, az );
glTranslate( -px, -py, -pz );

Share this post

Link to post
Share on other sites
do you want your game object's coordinates to be changed when doing e.g a glRotatef? if so you can do this:

/*this will store the transformations*/
Glfloat Matrix[16];

/*reset current matrix*/

/*begin doing some transformations*/

glTranslatef(x, y, z);
glRotatef(angle, x, y, z);


/*copy OpenGL's MODELVIEW_MATRIX to your own Matrix*/
glFloatv(GL_MODELVIEW_MATRIX, Matrix);

/*write a similar function that will multiply Matrix with all your object's coordiantes to get the transformed coordinates*/


OpenGL's matrix is 4x4 and it is stored transposed.

you can also use glIntergerv or glDoublev with Matrix being of type GLint or GLdouble.

hope this was helpful if that's what you are trying to do.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!