PDA

View Full Version : view transformation



edwong
11-01-2003, 02:44 PM
Hi,
I have created several models in opengl. if i want to press the left and right arrow key for spinning models in horizontal direction, and press the up and down key for spinning models in vertical direction, how can i set up?

thank you
Ed

fuxifuxi
11-01-2003, 03:05 PM
You rotate objects with glRotatef(angle, xdir, ydir, zdir);

Angle is in degrees, not in radians. If you want to rotate "in horizontal direction", then you want to rotate in the XOZ plane, hence rotate by glRotatef(angle, 0, 1, 0);
(the OY axis). For the other case rotate around the OX axis, hence glRotatef(angle, 1, 0, 0);

cwc36
11-03-2003, 12:44 AM
Hi,

void display()
{
glClear(...);
glPushMatrix();
glRotatef(rotx,1,0,0); //rot in vert
glRotatef(roty,0,1,0); //rot in horz
DrawObjects();
glPopMatrix();
glutSwapBuffers();
}

void Keyboard(unsigned char key, int , int )
{
switch(key)
{
case VK_UP:
rotx++;
break;
case VK_DOWN:
rotx--;
break;
case VK_LEFT:
roty++;
break;
case VK_RIGHT:
roty--;
break;

}
}
Hope it can help. Thanks.