【发布时间】:2014-10-30 12:14:50
【问题描述】:
我正在对游戏的关卡地图进行逆向工程。关卡中的每个对象都有 3 个用于定位的浮动 (x,y,z) 和 3 个用于旋转的浮动 (x,y,z)。
很多对象,当被拉入 3D 程序时,轴位于 0,0,0(世界轴),并且对象被拉离该点,而不是被拉入并以世界轴为中心。
这是我的意思的 2D 示例:
你有一个正方形,有 4 个顶点 (5,5),(5,10),(10,10),(10,5),它的中心是 (7.5,7,5)
我需要将 4 个顶点围绕 0,0 而不是其中心 (7.5,7.5) 旋转
我一直在使用以下 python 代码旋转对象:
#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 旋转对象。我不知道如何修改上述计算以围绕世界轴旋转对象。
我一直在这里和其他地方查看很多其他类似的问题,我的大脑即将爆炸成一堆希腊符号。
非常感谢任何帮助或指导!
【问题讨论】:
标签: python 3d rotation reverse-engineering vertex