围绕点旋转顶点 [英] Rotating vertices about point

查看:40
本文介绍了围绕点旋转顶点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对游戏的关卡地图进行逆向工程.关卡中的每个对象都有 3 个浮点用于定位 (x,y,z) 和 3 个浮点用于旋转 (x,y,z).

I'm reverse engineering a level map for a game. Each object within the level has 3 floats for positioning (x,y,z) and 3 floats for rotation (x,y,z).

许多对象,当被拉入 3D 程序时,轴位于 0,0,0(世界轴)并且对象从该点被拉开,而不是被拉入并以世界轴为中心.

A lot of the objects, when pulled into a 3D Program, axis sit at 0,0,0 (world axis) and the object is drawn away from that point rather than being pulled in and centered at the world axis.

这是我的意思的二维示例:

Here is 2D example of what I mean:

你有一个有 4 个顶点 (5,5),(5,10),(10,10),(10,5) 的正方形,它的中心是 (7.5,7,5)

You have a square with 4 vertex's (5,5),(5,10),(10,10),(10,5) and its center is (7.5,7,5)

我需要将 4 个顶点旋转到 0,0 而不是它的中心 (7.5,7.5)

I need the 4 vertex's to be rotated around 0,0 and not its center (7.5,7.5)

我一直在使用以下 python 代码旋转对象:

I've been rotating the objects using the following python code:

#vX,vY,vZ is the vector coords
#rx,rY,rZ is the rotation angles in degrees
#Xrotation
xX = vX
xY = vY * math.cos(rX) - vZ * math.sin(rX)
xZ = vY * math.sin(rX) + vZ * math.cos(rX)
#Yrotation
yX = xZ * math.sin(rY) + xX * math.cos(rY)
yY = xY
yZ = xZ * math.cos(rY) - xX * math.sin(rY)
#Zrotation
zX = yX * math.cos(rZ) - yY * math.sin(rZ)
zY = yX * math.sin(rZ) + yY * math.cos(rZ)
zZ = yZ
#zX,zY,zZ is what gets outputted

上面的代码是围绕它的中心而不是世界轴 0,0,0 旋转对象.我不知道如何修改上述计算以绕世界轴旋转对象.

The above code rotates the objects around its center rather than the world axis of 0,0,0. I'm at a loss of how to modify the above calculations to rotate the object around the world axis.

我一直在查看这里和其他地方的许多其他类似问题,我的大脑即将爆炸成一堆希腊符号.

I've been looking over a lot of other similar questions on here and other places and my brain is about to explode into a pool of greek symbols.

非常感谢任何帮助或指导!

Any help or direction would be very much appreciated!

推荐答案

您是否尝试过将对象中心平移到世界轴,应用旋转,然后以相反的量平移回来?

Have you tried translating the object center to the world axis, applying your rotation, and then translating back by the opposite amount?

在您的 2D 示例中,您将对 (-7.5,-7.5) 进行平移,应用旋转,然后按 (7.5,7.5) 进行平移.

In your 2D example you would do a translation of (-7.5,-7.5), apply your rotation, and then translate by (7.5,7.5).

这篇关于围绕点旋转顶点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆