Public Group

# 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.

## 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 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 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);

/*end*/

/*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*/
apply_matrix_to_object(Matrix);

draw_object();

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 on other sites
Thank you - this was exactly what i was looking for - both of you helped me alot

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632997
• Total Posts
3009799
• ### Who's Online (See full list)

There are no registered users currently online

×