Notes for OpenGL - 2

 

1.  glRotatef(glRotated) 顾名思义是用来旋转的。在旋转前,我们必须要有一个确定好视角的3D世界。然后我们便可以调用glRotatef来旋转合适的角度来“观看”这个世界,然后再在这个世界的正常坐标内画出图形。我们要建立一个观念,便是,移动的是“镜头”而非图形或者是“世界”。如同这个世界我们无法改变,但是我们可以改变观看世界的角度。3D世界也是一个“世界”,在这个世界内的事物是固定的,变化的只是viewer的视角而已。

 

函数原型:void glRotated(GLdouble angle,
               GLdouble x,
               GLdouble y,
               GLdouble z)

 

        X Axis - You're working on a table saw. The bar going through the center of the blade runs left to right (just like the x axis in OpenGL). The sharp teeth spin around the x axis (bar running through the center of the blade), and appear to be cutting towards or away from you depending on which way the blade is being spun. When we spin something on the x axis in OpenGL it will spin the same way. 

Y Axis - Imagine that you are standing in the middle of a field. There is a huge tornado coming straight at you. The center of a tornado runs from the sky to the ground (up and down, just like the y axis in OpenGL). The dirt and debris in the tornado spins around the y axis (center of the tornado) from left to right or right to left. When you spin something on the y axis in OpenGL it will spin the same way. 

Z Axis - You are looking at the front of a fan. The center of the fan points towards you and away from you (just like the z axis in OpenGL). The blades of the fan spin around the z axis (center of the fan) in a clockwise or counterclockwise direction. When You spin something on the z axis in OpenGL it will spin the same way.

 

It's important to note that rotations are done in degrees. If rtri had a value of 10, we would be rotating 10 degrees on the y-axis.

 

 

下面是一些图解。 

 

话说这个图看不懂….

 

 

这个是glRotatef 的原理,是绕着z轴转30°的公式。不过么…公式没理解…


这个嘛,就是先Rotate 还是先Translate 所产生的不同的效果。

这个地方有些问题。我自己测试的时候,先Rotate 的话图形不会呆在原来的位置,而是会绕着某个点(我专门测试过发现他会绕着屏幕中心的那个原点旋转,因为我们必须先调用glLoadIdentity来重置世界坐标);而如果我们先Translate的话只会在原地打转。

后来我发现,还是那个3D的思想,世界还是那个世界,不管怎么样变,世界里的事物是不会改变的,改变的依旧只是我们的视角。我们先Rotate的时候,是以原来的原点为中心旋转的,我们都知道Translate在移动的时候是不会影响角度的,因此我们可以在旋转后再移动的时候在没有改变的视口(其实旋转就是改变视口,但窗口毕竟是不变的,因此我们在这里姑且这么认为)中发现移动后的原点位置是新原点移动后绕着旧原点旋转后的位置,并且方向也是旋转了的。

而先Translate的话,前面说过了,Rotate是绕着原点转动的,移动后原点会改变,而旋转又是绕着新的原点转动的,因此在我们的视口中会出现原地打转的效果。

呃,其实说来说去最后总结为一句话:先Rotate的话图形会绕着旧原点旋转,而先Translate的话图形会绕着新原点旋转。

因此么,上图是有问题的哦~~

 

 

//下面是我的测试代码

    glLoadIdentity();

    glRotatef( qAngle = qAngle >= 360 ? 2 : qAngle + 2, 0, 0, 1 );

    glTranslatef(1.0f,0.0f,-6.0f);

    glBegin(GL_QUADS);

    {

        glColor3f( 0, 1, 0 );

        glVertex3f(-1.0f, 1.0f, 0.0f);

        glColor3f( 1, 0, 0 );

        glVertex3f( 1.0f, 1.0f, 0.0f);

        glColor3f( 0, 0, 1 );

        glVertex3f( 1.0f,-1.0f, 0.0f);

        glColor3f( 1, 1, 1 );

        glVertex3f(-1.0f,-1.0f, 0.0f);

    }

    glEnd();

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值