Skip to content

Commit 9846e86

Browse files
committed
Fix rotation
1 parent e1ffc0d commit 9846e86

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

transutils.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ def transMatrix(x, y, z):
2121
T = [ [1.,0.,0.,0.], [0.,1.,0.,0.], [0.,0.,1.,0.], [x,y,z,1] ]
2222
return T
2323

24-
def rotMatrix(x, y, z, angDeg):
24+
def rotMatrix(angDeg, x, y, z):
2525

2626
#Based on https://github.com/freedreno/mesa/blob/383558c56427b0e8b4e56cce8737771ad053f753/src/mesa/math/m_matrix.c
2727
M = identityMatrix()
28-
s = math.sin(math.radians(angDeg))
29-
c = math.cos(math.radians(angDeg))
28+
angRad = math.radians(angDeg)
29+
s = math.sin(-angRad)
30+
c = math.cos(-angRad)
3031
mag = math.sqrt(x * x + y * y + z * z)
3132

3233
if mag <= 1.0e-4:
@@ -105,27 +106,27 @@ def rotMatrix(x, y, z, angDeg):
105106
row0[0] = (one_c * xx) + c;
106107
row0[1] = (one_c * xy) - zs;
107108
row0[2] = (one_c * zx) + ys;
108-
# row0[3] = 0.0F;
109+
# row0[3] = 0.0;
109110

110111
row1 = M[1]
111112
row1[0] = (one_c * xy) + zs;
112113
row1[1] = (one_c * yy) + c;
113114
row1[2] = (one_c * yz) - xs;
114-
# row1[3] = 0.0F;
115+
# row1[3] = 0.0;
115116

116117
row2 = M[2]
117118
row2[0] = (one_c * zx) - ys;
118119
row2[1] = (one_c * yz) + xs;
119120
row2[2] = (one_c * zz) + c;
120-
# row2[3] = 0.0F;
121+
# row2[3] = 0.0;
121122

122123
# row3 = M[3]
123-
# row3[0] = 0.0F;
124-
# row3[1] = 0.0F;
125-
# row3[2] = 0.0F;
126-
# row3[3] = 1.0F;
124+
# row3[0] = 0.0;
125+
# row3[1] = 0.0;
126+
# row3[2] = 0.0;
127+
# row3[3] = 1.0;
127128

128-
return M
129+
return np.array(M)
129130

130131

131132
if __name__ == "__main__":
@@ -155,17 +156,15 @@ def rotMatrix(x, y, z, angDeg):
155156
trans = np.array(transMatrix(*vec))
156157
mat = np.dot(trans, mat)
157158
print "predicted 1", mat
158-
gl.glLoadMatrixf(list(mat.reshape(mat.size)))
159-
159+
160160
vec = list(4. * np.random.random((1,3))[0] - 2.)
161161
ang = 4. * math.pi * np.random.random() - 2
162-
print vec, ang
163-
gl.glRotated(vec[0], vec[1], vec[2], ang)
162+
gl.glRotated(ang, vec[0], vec[1], vec[2])
164163
correct = gl.glGetFloatv(gl.GL_MODELVIEW_MATRIX)
165164
print "correct 2", correct
166165

167-
rot = np.array(rotMatrix(vec[0], vec[1], vec[2], ang))
166+
rot = np.array(rotMatrix(ang, vec[0], vec[1], vec[2]))
168167
mat = np.dot(rot, mat)
169168
print "predicted 2", mat
170-
gl.glLoadMatrixf(list(mat.reshape(mat.size)))
169+
171170

0 commit comments

Comments
 (0)