Python: How To Get Cube To Spin And Move In Opengl Superbible Example
For some reason, the cube does not move around the screen, though it spins. This is with the use of the functions m3dTranslateMatrix44 and m3dRotationMatrix44 though there seems
Solution 1:
The expression form the question:
mv_matrix = np.array(A * B * C * D)
performs a component-wise multiplication of the elements of the numpy.array
.
A concatenation of matrices can be performed by numpy.matmul
.
The operation
C = A * B
can be expressed as
C = np.matmul(B, A)
So concatenate 4 matrices A * B * C * D
is:
mv_matrix = np.matmul(D, np.matmul(C, np.matmul(B, A)))
Note, if you use numpy.matrix
rather than numpy.array
, then the *
-operator proceeds a matrix multiplication.
Side note: The identity matrix can be set by numpy.identity
ident4x4 = np.identity(4, np.float32)
since the data-type of the output defaults to float, this can be simplified further:
ident4x4 = np.identity(4)
e.g. Use the functions translate
and rotation_matrix
to concatenate a translation and rotations around the x and y axis:
T = np.matrix(translate(0.0, 0.0, -4.0)).reshape(4,4)
RX = np.matrix(rotation_matrix( [1.0, 0.0, 0.0], currentTime * m3dDegToRad(17.0)))
RY = np.matrix(rotation_matrix( [0.0, 1.0, 0.0], currentTime * m3dDegToRad(13.0)))
mv_matrix = RX * RY * T
Post a Comment for "Python: How To Get Cube To Spin And Move In Opengl Superbible Example"