开发者

Rotation in opengl

开发者 https://www.devze.com 2023-03-14 03:12 出处:网络
I have a plane and I want to rotate it around the y axis. The planes coordinates are in: Vec4f(-1,-1, -5, 1),

I have a plane and I want to rotate it around the y axis. The planes coordinates are in:

Vec4f(-1,-1, -5, 1),
Vec4f( 1,-1, -5, 1),
Vec4f( 1, 1, -5, 1),
Vec4f(-1, 1, -5, 1),

I just want the plane to rotate, not go arou开发者_StackOverflow社区nd in circles, so I translate it back to origin a then do the rotation:

glTranslatef(0,0,-5);
glRotatef(50.0*t, 0, 1, 0);

draw(plane);

But the plane still makes a circle around the origin. What am I doing wrong?


Transformations apply in the opposite order in which you multiply them, also you might want to translate back to where it came from. So change it like this:

translation = -5;
if(translate_back) glTranslatef(0,0,-translation);
glRotatef(50.0*t, 0, 1, 0);
glTranslatef(0,0,+translation);
0

精彩评论

暂无评论...
验证码 换一张
取 消