def rotateCam(self, axis, dtheta): rotation_mat = matrix44.create_from_axis_rotation(axis, dtheta) self.camLookAt -= self.camPos newvec = Vector4.from_vector3(self.camLookAt, 1.0) newvec = rotation_mat.dot(newvec) self.camLookAt = Vector3.from_vector4(newvec)[0] self.camLookAt += self.camPos
def calculateMouseRay(self, projectionMatrix, viewMAtrix, screenX, screenY, mouse_x, mouse_y): x = (2.0 * mouse_x) / screenX - 1.0 y = 1.0 - (2.0 * mouse_y) / screenY z = -1.0 D_view = Vector4.from_vector3(Vector3([x, y, z]), w=1.0) ray_eye = projectionMatrix.inverse * D_view ray_eye = Vector4([ray_eye.x, ray_eye.y, -1.0, 0.0]) ray_wor = ((viewMAtrix.inverse) * ray_eye).xyz return Vector3(ray_wor)
def test_conversions(self): from pyrr import Quaternion, Matrix33, Matrix44, Vector3, Vector4 v3 = Vector3([1.,0.,0.]) v4 = Vector4.from_vector3(v3, w=1.0) v3, w = Vector3.from_vector4(v4) m44 = Matrix44() q = Quaternion(m44) m33 = Matrix33(q) m33 = Matrix44().matrix33 m44 = Matrix33().matrix44 q = Matrix44().quaternion q = Matrix33().quaternion m33 = Quaternion().matrix33 m44 = Quaternion().matrix44
def test_conversions(self): from pyrr import Quaternion, Matrix33, Matrix44, Vector3, Vector4 v3 = Vector3([1., 0., 0.]) v4 = Vector4.from_vector3(v3, w=1.0) v3, w = Vector3.from_vector4(v4) m44 = Matrix44() q = Quaternion(m44) m33 = Matrix33(q) m33 = Matrix44().matrix33 m44 = Matrix33().matrix44 q = Matrix44().quaternion q = Matrix33().quaternion m33 = Quaternion().matrix33 m44 = Quaternion().matrix44
def project_to_img_frame(self, vector, viewMatrix): clip_space_vector = self.projection * ( viewMatrix * Vector4.from_vector3(vector, w=1.0)) if clip_space_vector.w != 0: nds_vector = Vector3(clip_space_vector.xyz) / clip_space_vector.w else: # Clipped nds_vector = clip_space_vector.xyz if nds_vector.z >= 1: return [-1, -1] viewOffset = 0 image_frame_vector =\ ((np.array(nds_vector.xy) + 1.0) / 2.0) * np.array([self.width, self.height]) + viewOffset # Translate from bottom-left to top-left image_frame_vector[1] = self.height - image_frame_vector[1] return image_frame_vector