changeset 411:2428296cccab

Remove indirect access to Matrix values.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 12 Jun 2013 16:07:22 +0200
parents 9d790ca73c13
children 5fe6cd6ceb48
files pytouhou/ui/renderer.pyx pytouhou/utils/matrix.pyx
diffstat 2 files changed, 17 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/ui/renderer.pyx
+++ b/pytouhou/ui/renderer.pyx
@@ -176,11 +176,12 @@ cdef class Renderer:
 
     cpdef ortho_2d(self, left, right, bottom, top):
         mat = Matrix()
-        mat[0][0] = 2 / (right - left)
-        mat[1][1] = 2 / (top - bottom)
-        mat[2][2] = -1
-        mat[3][0] = -(right + left) / (right - left)
-        mat[3][1] = -(top + bottom) / (top - bottom)
+        data = mat.data
+        data[0][0] = 2 / (right - left)
+        data[1][1] = 2 / (top - bottom)
+        data[2][2] = -1
+        data[3][0] = -(right + left) / (right - left)
+        data[3][1] = -(top + bottom) / (top - bottom)
         return mat
 
 
@@ -207,12 +208,13 @@ cdef class Renderer:
         right = top * aspect
 
         mat = Matrix()
-        mat[0][0] = (2 * z_near) / (right - left)
-        mat[1][1] = (2 * z_near) / (top - bottom)
-        mat[2][2] = -(z_far + z_near) / (z_far - z_near)
-        mat[2][3] = -1
-        mat[3][2] = -(2 * z_far * z_near) / (z_far - z_near)
-        mat[3][3] = 0
+        data = mat.data
+        data[0][0] = (2 * z_near) / (right - left)
+        data[1][1] = (2 * z_near) / (top - bottom)
+        data[2][2] = -(z_far + z_near) / (z_far - z_near)
+        data[2][3] = -1
+        data[3][2] = -(2 * z_far * z_near) / (z_far - z_near)
+        data[3][3] = 0
         return mat
 
 
--- a/pytouhou/utils/matrix.pyx
+++ b/pytouhou/utils/matrix.pyx
@@ -24,15 +24,14 @@ cdef class Matrix:
                              [0, 0, 0, 1]]
 
 
-    def __getitem__(Matrix self, key):
-        return self.data[key]
-
-
     def __mul__(Matrix self, Matrix other):
         out = Matrix()
+        d1 = self.data
+        d2 = other.data
+        d3 = out.data
         for i in xrange(4):
             for j in xrange(4):
-                out[i][j] = sum(self[i][k] * other[k][j] for k in xrange(4))
+                d3[i][j] = sum(d1[i][k] * d2[k][j] for k in xrange(4))
         return out