[英]Rotate about Y-Axis gluLookAt
我正在尝试围绕y轴旋转查看器。 我有一个名为tranform_eye()
的函数, eyez
在每次更新后计算eyex
, eyey
和eyez
的下一个位置。
谁能帮我找出如何计算eyex
, eyey
和eyez
的值?
我的代码:
float eyex = 5;
float eyey = 5;
float eyez = 5;
void display() {
transform_eye();
glMatrixMode(GL_PROJECTION); // To operate on model-view matrix
glLoadIdentity();
gluPerspective(40.0, 1.0, 1.0, 10000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyex, eyey, eyez,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers
drawTriangles();
glutSwapBuffers(); // Swap the front and back frame buffers (double buffering)
}
void transform(){
/// calculate new eyex, y z.
}
从这个答案中应用数学可以得出:
void transform()
{
float theta = 0.01; //angle in radians to rotate every frame
float cosTheta = cos(theta);
float sinTheta = sin(theta);
float newX = cosTheta * eyeX + sinTheta * eyeZ;
eyeZ = -sinTheta * eyeX + cosTheta * eyeZ;
eyeX = newX;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.