Skip to content

Commit

Permalink
some tweaks to get pypy working
Browse files Browse the repository at this point in the history
  • Loading branch information
paddywwoof committed Dec 3, 2013
1 parent 3908148 commit ce5febc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pi3d/Buffer.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ def __init__(self, shape, pts, texcoords, faces, normals=None, smooth=True):
if len(texcoords) != n_verts: if len(texcoords) != n_verts:
if len(normals) != n_verts: if len(normals) != n_verts:
self.N_BYTES = 12 # only use pts self.N_BYTES = 12 # only use pts
self.array_buffer = c_floats(pts.reshape(-1)) self.array_buffer = c_floats(pts.reshape(-1).tolist())
else: else:
self.N_BYTES = 24 # use pts and normals self.N_BYTES = 24 # use pts and normals
self.array_buffer = c_floats(np.concatenate((pts, normals), self.array_buffer = c_floats(np.concatenate((pts, normals),
axis=1).reshape(-1)) axis=1).reshape(-1).tolist())
else: else:
self.N_BYTES = 32 # use all three NB doesn't check that normals are there self.N_BYTES = 32 # use all three NB doesn't check that normals are there
self.array_buffer = c_floats(np.concatenate((pts, normals, texcoords), self.array_buffer = c_floats(np.concatenate((pts, normals, texcoords),
axis=1).reshape(-1)) axis=1).reshape(-1).tolist())


self.ntris = len(faces) self.ntris = len(faces)
self.element_array_buffer = c_shorts(faces.reshape(-1)) self.element_array_buffer = c_shorts(faces.reshape(-1))
Expand Down
8 changes: 4 additions & 4 deletions pi3d/Camera.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, at=(0, 0, 0), eye=(0, 0, -0.1), lens=None,
self.projection = _OrthographicMatrix(scale=scale) self.projection = _OrthographicMatrix(scale=scale)
self.model_view = dot(self.view, self.projection) self.model_view = dot(self.view, self.projection)
# Apply transform/rotation first, then shift into perspective space. # Apply transform/rotation first, then shift into perspective space.
self.mtrx = copy(self.model_view) self.mtrx = array(self.model_view, copy=True)
# self.L_reflect = _LookAtMatrix(at,eye,[0,1,0],reflect=True) # self.L_reflect = _LookAtMatrix(at,eye,[0,1,0],reflect=True)
self.rtn = [0.0, 0.0, 0.0] self.rtn = [0.0, 0.0, 0.0]


Expand Down Expand Up @@ -204,7 +204,7 @@ def _LookAtMatrix(at, eye, up=[0, 1, 0], reflect=False):
zaxis.append(-vec_dot(zaxis, eye)) zaxis.append(-vec_dot(zaxis, eye))
z = [0, 0, 0, 1.0] z = [0, 0, 0, 1.0]
return array([[xaxis[a], yaxis[a], zaxis[a], z[a]] for a in range(4)], return array([[xaxis[a], yaxis[a], zaxis[a], z[a]] for a in range(4)],
dtype=ctypes.c_float) dtype=float)


def _ProjectionMatrix(near, far, fov, aspectRatio): def _ProjectionMatrix(near, far, fov, aspectRatio):
"""Set up perspective projection matrix """Set up perspective projection matrix
Expand All @@ -228,7 +228,7 @@ def _ProjectionMatrix(near, far, fov, aspectRatio):
M[2][2] = (far + near) / (far - near) M[2][2] = (far + near) / (far - near)
M[2][3] = 1 M[2][3] = 1
M[3][2] = -(2 * far * near)/(far - near) M[3][2] = -(2 * far * near)/(far - near)
return array(M, dtype=ctypes.c_float) return array(M, dtype=float)


def _OrthographicMatrix(scale=1.0): def _OrthographicMatrix(scale=1.0):
"""Set up orthographic projection matrix """Set up orthographic projection matrix
Expand All @@ -246,5 +246,5 @@ def _OrthographicMatrix(scale=1.0):
M[2][2] = 2.0 / 10000.0 M[2][2] = 2.0 / 10000.0
M[3][2] = -1 M[3][2] = -1
M[3][3] = 1 M[3][3] = 1
return array(M, dtype=ctypes.c_float) return array(M, dtype=float)


3 changes: 3 additions & 0 deletions pi3d/Shape.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pi3d.Buffer import Buffer from pi3d.Buffer import Buffer
from pi3d.Light import Light from pi3d.Light import Light
from pi3d.util import Utility from pi3d.util import Utility
from pi3d.util.Ctypes import c_floats


from pi3d.util.Loadable import Loadable from pi3d.util.Loadable import Loadable


Expand Down Expand Up @@ -146,7 +147,9 @@ def draw(self, shader=None, txtrs=None, ntl=None, shny=None, camera=None):
dot(self.rox, dot(self.rox,
dot(self.roz, self.tr1))))) dot(self.roz, self.tr1)))))
self.M[0:16] = self.MRaw.ravel() self.M[0:16] = self.MRaw.ravel()
#self.M[0:16] = c_floats(self.MRaw.reshape(-1).tolist()) #pypy version
self.M[16:32] = dot(self.MRaw, camera.mtrx).ravel() self.M[16:32] = dot(self.MRaw, camera.mtrx).ravel()
#self.M[16:32] = c_floats(dot(self.MRaw, camera.mtrx).reshape(-1).tolist()) #pypy
self.MFlg = False self.MFlg = False


elif camera.was_moved: elif camera.was_moved:
Expand Down

0 comments on commit ce5febc

Please sign in to comment.