python - Python OpenGL - 如何在转换后找到一个点的当前世界坐标?
问题描述
在 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 = ?
解决方案
您可以使用 Python 的 OpenGL 数学 (GLM) 库 ( 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 数学库的语法略有不同。
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
推荐阅读
- javascript - 在 React-Table 单元格中呈现动态数据列表
- prolog - 为什么有些 DCG 测试用例使用断言(Rest == [])?
- python - 当此代码打印时,它有一个 0。没有它我如何让它打印?
- docker - Docker Alpine 镜像是否包含 npm?
- vba - 循环工作表,并将工作表范围的命名范围分配给工作表名称
- aspnetboilerplate - 如何登录非现有用户?如何让模拟(虚拟)用户登录没有连接字符串的 Web.Mvc(UI)项目?
- python-3.x - ModuleNotFoundError: No module named 'rasterio' even 它是从 cmd 安装的
- python - 如何在 SPOJ 问题硬币中接受 Python 输入?
- r - 如何使用 github_document 作为输出的 R Markdown 主题?
- elasticsearch - 如何查询存储在elasticsearch中的metricbeat系统cpu和内存数据