gpt4 book ai didi

c - 绕 Y 轴旋转 gluLookAt

转载 作者:太空宇宙 更新时间:2023-11-04 02:23:13 27 4
gpt4 key购买 nike

我正在尝试围绕 y 轴旋转查看器。我有一个名为 tranform_eye() 的函数,它将计算 eyexeyeyeyez 的下一个位置更新。

谁能帮我弄清楚如何计算 eyexeyeyeyez 的值?

我的代码:

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.
}

最佳答案

应用来自例如this answer给我们:

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;
}

关于c - 绕 Y 轴旋转 gluLookAt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54857183/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com