python - python中的Opengl和glut呈现不正确的结果,有什么建议吗?
问题描述
参考阅读源码所在的OpenGL Superbible的SMB格式文件,在一些帮助下创建了一个程序。现在我将结果与我实际得到的结果进行比较。
关于为什么输出不正确的任何建议?在这一点上我很难过。谢谢。
解决方案
圆环被投影的近平面剪裁。
改变投影矩阵:
proj_matrix = m3dPerspective(m3dDegToRad(60.0), float(self.width) / float(self.height), 0.1, 100.0);
和视图矩阵:
mv_matrix = (GLfloat * 16)(*identityMatrix)
m3dRotationMatrix44(mv_matrix, currentTime * m3dDegToRad(45.0), 1.0, 0.0, 0.0)
m3dTranslateMatrix44(mv_matrix, 0.0, 0.0, -3.0)
如果要连接不同的矩阵,则必须实现矩阵“乘法”:
def m3dMultiply(A, B):
C = (GLfloat * 16)(*identityMatrix)
for k in range(0, 4):
for j in range(0, 4):
C[k*4+j] = A[0*4+j] * B[k*4+0] + A[1*4+j] * B[k*4+1] + \
A[2*4+j] * B[k*4+2] + A[3*4+j] * B[k*4+3]
return C
例如连接一个平移矩阵和围绕 x 和 y 轴的旋转矩阵:
T = (GLfloat * 16)(*identityMatrix)
m3dTranslateMatrix44(T, 0, 0, -4)
RX = (GLfloat * 16)(*identityMatrix)
m3dRotationMatrix44(RX, currentTime * m3dDegToRad(17.0), 1.0, 0.0, 0.0)
RY = (GLfloat * 16)(*identityMatrix)
m3dRotationMatrix44(RY, currentTime * m3dDegToRad(13.0), 0.0, 1.0, 0.0)
mv_matrix = m3dMultiply(T, m3dMultiply(RY, RX))
请注意,如果您想使用numpy.matmul
而不是m3dMultiply
,那么您必须.reshape
将 16 元素数组转换为 2 维 4x4 数组。例如:
R = np.matmul(np.array(RX).reshape(4,4), np.array(RY).reshape(4,4))
mv_matrix = np.matmul(R, np.array(T).reshape(4,4))
或numpy.matrix
-*
运算符:
mv_matrix = np.matrix(RX).reshape(4,4) * np.matrix(RY).reshape(4,4) * np.matrix(T).reshape(4,4)
推荐阅读
- c++ - 使用 Mxnet C++ API 输出值
- arduino - Arduino:if else 语句,如果所有数字都在范围内,如果至少一个不在范围内?
- apache-zeppelin - 如何从同一本地计算机上的另一个笔记本运行 Apache Zeppelin 笔记本?
- assembly - MIPS 程序不工作错误:在表中找不到符号出口
- javascript - 如何防止表单在 Jquery 提交事件中被重新提交?
- php - Shopify 使用 laravel 自定义店面
- r - 如何根据 2 个标准生成第 6 个最差值并将结果插入单独的列?
- visual-studio-code - 在 VS Code 中打开项目时启动应用程序?
- laravel - 如何使用 Laravel/Valet/Xdebug 测试 PhpStorm 的 Web 服务器调试验证?
- excel - 从 Excel 运行 Word 宏