Python OpenGL glrotatef-寻找正确的乘数

发布于 2025-02-04 20:58:29 字数 656 浏览 2 评论 0原文

我正在将glulookat与坐标为XCAM,YCAM和ZCAM的相机。相机正在查看的对象的坐标是XPOS,YPO和ZPO。有一些名为Mouseturnx和Mouseturny的变量,它们测量了小鼠与X轴和Y轴中屏幕中间的偏差。变量camdist描述了相机与它所看到的对象之间的距离。

摄像头的代码是这样的:

xCam = sin(mouseturnX)*camdist+xPos
yCam = mouseturnY+yPos
zCam = cos(mouseturnX)*camdist+zPos

我现在制作了一个多边形对象,我旋转了:

glRotatef(mouseturnX,0,1,0)

通常它只能显示对象的背面,相机的位置都无关紧要。但是现在它无法正确转动。我使用其他旋转轴进行尝试,在那里工作正常,但是使用Y轴,它只是不想工作。我尝试将camdist从正变为负,glrotatef函数中的Mouseturnx从正到负,再到阳性。它只是不起作用。在旋转命令之前,我使用 glpushmatrix ,之后 glpopmatrix 。旋转命令之前的一条线我使用翻译函数为多边形设置固定点。

编辑:多边形实际上是旋转的,但没有适当的数量。似乎我必须将多边形的旋转乘以东西。

I am using gluLookAt with a camera whose coordinates are xCam, yCam and zCam. The coordinates of the object the camera is looking at are xPos, yPos, and zPos. There are variables named mouseturnX and mouseturnY, which measure the deviation of the mouse from the middle of the screen in the x-axis and the y-axis. The variable camdist describes the distance between camera and the object it looks at.

The code of the cameraposition is this:

xCam = sin(mouseturnX)*camdist+xPos
yCam = mouseturnY+yPos
zCam = cos(mouseturnX)*camdist+zPos

I now made a polygon object, which I rotate with:

glRotatef(mouseturnX,0,1,0)

Usually it should only show me the backside of the object, it does not matter which position the camera has. But now it does not turn correctly. I tried it with other rotation-axises, there it works fine, but with the y-axis it just does not want to work. I tried changing the camdist from positive to negative, the mouseturnX in the glRotatef function from positive to negative and back to positive again. It just does not work. I used glPushMatrix before the rotation command and glPopMatrix after it. One line before the rotation command I used the translate function to set a fixpoint for the polygon.

Edit: The polygon actually spins, but not in the right amount. It seems like I have to multiply the rotation of the polygon with something.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

無心 2025-02-11 20:58:29

我通过尝试找到了乘数。是56.5。它不是完美的,但可以起作用。

I found the multiplicator by trying. It is 56.5. It is not perfect, but it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文