python 中的 Opengl 和 glut 渲染不正确的结果,有什么建议吗?
Opengl in python and glut rendering incorrect results, any suggestions why?
参考源代码所在的的阅读,我在一些帮助下创建了一个程序。现在我将结果与实际得到的结果进行比较。
我得到的是:
结果应该是这样的:
关于为什么输出不正确有什么建议吗?我在这一点上感到难过。谢谢
环面被投影的近平面剪裁。
改变投影矩阵:
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)
如果你想连接不同的矩阵,那么你必须实现一个矩阵 "multiplication":
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
instead of m3dMultiply
, then you've to .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)
另见
参考源代码所在的
我得到的是:
结果应该是这样的:
关于为什么输出不正确有什么建议吗?我在这一点上感到难过。谢谢
环面被投影的近平面剪裁。
改变投影矩阵:
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)
如果你想连接不同的矩阵,那么你必须实现一个矩阵 "multiplication":
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
instead of m3dMultiply
, then you've to .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)
另见