Rotation about a single axis

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

Recommended Posts

Not particularly sure if the title of this thread is correct...but what i a want to achieve is to be able to rotate the object about the x, y or z axis .

i already got the models rotating in all the axis but the point is they tend to move away from their original position when rotating, what i want is for them to stay in the same position while i rotate them in any angle i want
 GLfloat rotMast[3]; void Draw(){ ........... glPushMatrix(); glRotatef(rotMast[0], 1.0f, 0.0f, 0.0f); glRotatef(rotMast[1], 0.0f, 1.0f, 0.0f); glRotatef(rotMast[2], 0.0f, 0.0f, 1.0f); glTranslatef(positions[0].x, positions[0].y, positions[0].z); drawMast(); glPopMatrix(); .......... } void OnKey(unsigned char key, int x, int y) { switch(key){ case 'k': case 'K': if (selected_index==0){ rotMast[0]+= amount; } } } 
please your ideas and possibly a short snippet would be very helpful....

thanks

Share on other sites
[font=arial, verdana, tahoma, sans-serif][size=2]Try rotating before you translate. I believe the problem is that you're translating first and then rotating around the axes of the original position.[/font]

Share on other sites

[font="arial, verdana, tahoma, sans-serif"]Try rotating before you translate. I believe the problem is that you're translating first and then rotating around the axes of the original position.[/font]

i made the adjustments ...it still travels when rotating.....i just want it to rotate about itself and not have to move from its original position

Share on other sites

[quote name='DigitalDisciple' timestamp='1311101806' post='4837560']
[font="arial, verdana, tahoma, sans-serif"]Try rotating before you translate. I believe the problem is that you're translating first and then rotating around the axes of the original position.[/font]

i made the adjustments ...it still travels when rotating.....i just want it to rotate about itself and not have to move from its original position
[/quote]

it works thank you...i basically just did this

translate[positionx.positiony,positionz]

translate[originx,originy,originz]
rotate[x....]
rotate[y....]
rotate[z....]
translate[-originx,-originy,-originz]

origin being the center coodinate of the model