Skip to content

Commit

Permalink
Reapply #308 but return np.array instead of list (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyaointl authored Aug 21, 2021
1 parent f29280e commit 508b8d5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions p5/sketch/Vispy2DRenderer/openglrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,5 +351,10 @@ def cleanup(self):
self.fbuffer.delete()

def _transform_vertices(self, vertices, local_matrix, global_matrix):
return np.dot(np.dot(vertices, local_matrix.T), global_matrix.T)[:, :3]

"""Applies `local_matrix` then `global_matrix` to `vertices`
"""
product = np.dot(np.dot(vertices, local_matrix.T), global_matrix.T)
# dehomogenize coordinates
# need np.newaxis to broadcast the vector because each row represents a vertex
dehomogenized = product / product[:,3][:,np.newaxis]
return dehomogenized[:,:3] # Return the first three rows of the result

0 comments on commit 508b8d5

Please sign in to comment.