Jump to content
  • Advertisement
Sign in to follow this  
OgbobeBuko

Rotation about a single axis

This topic is 2555 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

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 this post


Link to post
Share on other sites
Advertisement
[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 this post


Link to post
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]

thanks DigitalDisciple for your reply


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 this post


Link to post
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]

thanks DigitalDisciple for your reply


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





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!