Skip to main content
gamedev.net
🔒 Locked

rotating objects

Started by penetrator 3 replies 800+ views
Original Post
penetrator
penetrator
using glRotatef I''m able to rotate an object, but how do I modify the rotation point ? thanks !
baldurk
baldurk
penetrator, what do you mean? you just need to do gltranslatef to where your object is, then do glrotatef. Or do you mean something else?
penetrator
penetrator
Sorry, I''ll try to explain better. If I have an object and I use glRotatef(), yes I do rotate it, but around which point ? The center of te object of course. But how do I rotate it around another point, i.e. a vertex ?
Hope I can explain myself, my english is not good enough, sigh !

davepermen
davepermen
you always rotate your (0,0,0)-Point..

when you translate-- you move your 0-Point around, at rotating you rotate then your things around it and and and..

rotating around a vertex.. hm

perhaps:

you vertex has (x,y,z)

glTranslatef(-x,-y,-z);
glRotatef(howyouwant);
glTranslatef(x,y,z);

i dont know.. my visual c has troubles currently..

we wanna play, not watch the pictures

If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
baldurk
baldurk
I think probably the easiest way to do it is to gltranslatef() to where the object''s 0,0,0 point is, then glrotatef() whatever you want then gltranslatef() away a bit to where you want the vertex to be, understand?

to sum up, say you had a cube, which you want to rotate around its right side, around the y axis.

you would move to where ever it is:

e.g gltranslatef(1.0f,0.0f,0.0f) // 1 along the x axis right

then you would spin it around the y axis however much:

e.g glrotatef(speed,0.0f,1.0f,0.0f) // spin it ''speed'' around the y axis

draw it, then move out half the length and carry on drawing the scene and (hopefully) it will look like you spun it round the right side:

e.g gltranslatef(0.3f,0.0f,0.0f) // move half of the length right

I haven''t tested it but it seems OK.

hope that helps

Baldur K

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.