Python OpenGL - 如何在变换后找到一个点的当前世界坐标?
Python OpenGL - How to find the current world coordinate of a point after transformation?
在C++中,我可以这样找到一个点的当前位置:
glm::vec3 somePoint(x,y,z); //x,y,z are some float values
glm::mat4 translationMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(xTrans, yTrans, zTrans));
glm::vec4 currentPointPosition = translationMatrix*glm::vec4(somePoint,1);
如何在 Python 中进行相同的计算以获得 curretPointPosition
?我可以使用 Python 的 pyrr 吗?
在 PyOpenGL 中,我有以下代码:
somePoint = [x,y,z]
translationMatrix= pyrr.matrix44.create_from_translation(pyrr.Vector3([xTrans, yTrans, zTrans]))
currentPointPosition = ?
您可以将 OpenGL 数学 (GLM) 库用于 Python (PyGLM)
somePoint = glm.vec3(x, y, z)
tranaltionVec = glm.vec3(xTrans, yTrans, zTrans)
translationMatrix = glm.translate(glm.mat4(1), tranaltionVec)
currentPointPosition = translationMatrix * glm.vec4(somePoint, 1)
Pyrr Maths Library 的语法略有不同。
somePoint = pyrr.Vector3((x, y, z))
tranaltionVec = pyrr.Vector3((xTrans, yTrans, zTrans))
translationMatrix = pyrr.matrix44.create_from_translation(tranaltionVec)
currentPointPosition = pyrr.Vector4.from_vector3(somePoint, 1) @ translationMatrix
在C++中,我可以这样找到一个点的当前位置:
glm::vec3 somePoint(x,y,z); //x,y,z are some float values
glm::mat4 translationMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(xTrans, yTrans, zTrans));
glm::vec4 currentPointPosition = translationMatrix*glm::vec4(somePoint,1);
如何在 Python 中进行相同的计算以获得 curretPointPosition
?我可以使用 Python 的 pyrr 吗?
在 PyOpenGL 中,我有以下代码:
somePoint = [x,y,z]
translationMatrix= pyrr.matrix44.create_from_translation(pyrr.Vector3([xTrans, yTrans, zTrans]))
currentPointPosition = ?
您可以将 OpenGL 数学 (GLM) 库用于 Python (PyGLM)
somePoint = glm.vec3(x, y, z)
tranaltionVec = glm.vec3(xTrans, yTrans, zTrans)
translationMatrix = glm.translate(glm.mat4(1), tranaltionVec)
currentPointPosition = translationMatrix * glm.vec4(somePoint, 1)
Pyrr Maths Library 的语法略有不同。
somePoint = pyrr.Vector3((x, y, z))
tranaltionVec = pyrr.Vector3((xTrans, yTrans, zTrans))
translationMatrix = pyrr.matrix44.create_from_translation(tranaltionVec)
currentPointPosition = pyrr.Vector4.from_vector3(somePoint, 1) @ translationMatrix