Sign in to follow this  
OgbobeBuko

Rotation about a single axis

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
[code]


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;

}
}
}
[/code]
please your ideas and possibly a short snippet would be very helpful....

thanks

Share this post


Link to post
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.[/size][/font]

Share this post


Link to post
Share on other sites
[quote name='DigitalDisciple' timestamp='1311101806' post='4837560']
[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.[/size][/font]
[/quote]
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='GottiJay' timestamp='1311160539' post='4837889']
[quote name='DigitalDisciple' timestamp='1311101806' post='4837560']
[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.[/size][/font]
[/quote]
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this