OpenGL“相机”在错误的轴上偏航(OpenGL “camera” Yaw on wrong axis)

编程入门 行业动态 更新时间:2024-10-18 08:36:59
OpenGL“相机”在错误的轴上偏航(OpenGL “camera” Yaw on wrong axis)

我正在使用gluLookAt()来设置“相机”的位置和方向

GLU.gluLookAt(xPosition, yPosition, zPosition, xPosition + lx, yPosition, zPosition + lz 0, 1, 0);

我的lz和lx变量代表我的前向矢量

lz = Math.cos(angle); lx = -Math.sin(angle);

当在3D世界中转身时,看起来我在一个总是在我面前的轴上旋转

我知道这是因为我的xPosition和yPosition变量保持不变,但是当我接近它并且转向时,我似乎旋转了一个对象。

我知道我在这里使用的数学没有问题,因为我尝试使用过去项目中的代码已经正常工作但问题仍然存在。

这就是我在渲染循环中所做的

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //draw scene from user perspective glLoadIdentity(); GLU.gluLookAt(camera.getxPos(), camera.getyPos(), camera.getzPos(), camera.getxPos()+camera.getLx(), camera.getyPos(), camera.getzPos()+p1.getLz(), 0, 1, 0); glBegin(GL_QUADS); glVertex3f(-dim, dim, 0); glVertex3f(dim, dim, 0); glVertex3f(dim, 0, 0); glVertex3f(-dim, 0, 0); glEnd(); pollInput(); camera.update();

我试过渲染一个玩家坐标的框,我得到了这个结果。 相机似乎从玩家坐标后面看。 现在使用类比它就像第三人称游戏,它应该看起来像第一人称游戏

这里的小盒子在相机坐标中渲染,以提供更大的盒子在前面的一些视角。

I am using gluLookAt() to set the "camera" position and orientation

GLU.gluLookAt(xPosition, yPosition, zPosition, xPosition + lx, yPosition, zPosition + lz 0, 1, 0);

my lz and lx variables represent my forward vector

lz = Math.cos(angle); lx = -Math.sin(angle);

When turn around in the 3D world, it appears that I am rotating around an axis that is always infront of me

I know this because my xPosition and yPosition variables stay the same, but I appear to spin around an object when im close to it and I turn.

I know there is not a problem with the maths that I have used here, because I have tried using code from past projects that have worked properly but the problem still remains.

This is what I am doing in the rendering loop

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //draw scene from user perspective glLoadIdentity(); GLU.gluLookAt(camera.getxPos(), camera.getyPos(), camera.getzPos(), camera.getxPos()+camera.getLx(), camera.getyPos(), camera.getzPos()+p1.getLz(), 0, 1, 0); glBegin(GL_QUADS); glVertex3f(-dim, dim, 0); glVertex3f(dim, dim, 0); glVertex3f(dim, 0, 0); glVertex3f(-dim, 0, 0); glEnd(); pollInput(); camera.update();

I have tried rendering a box where the player coordinates are and I got this result. The camera appears to be looking from behind the player coordinates. To use an analogy right now its like a 3rd Person game and It should look like a first person game

The small box here is rendered in the camera coordinates, to give some perspective the bigger box is infront.

最满意答案

解决了!

问题是我最初调用gluLookAt()而矩阵模式设置为GL_PROJECTION。

我删除了该行并将其移动到我将矩阵模式设置为GL_MODELVIEW并解决了问题之后。

Solved!

The problem was that I was initially calling gluLookAt() while the matrix mode was set to GL_PROJECTION.

I removed that line and moved it to just after I had set the matrix mode to GL_MODELVIEW and that solved the problem.

更多推荐

本文发布于:2023-04-29 03:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1334507.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   相机   偏航   OpenGL   axis

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!