Beispiel #1
0
def key_event(window, key, scancode, action, mode):
    global eye

    if action == glfw.PRESS and key == glfw.KEY_RIGHT:
        rot = 5
        rot = mat3.create_from_axis_rotation(vec3([0.0, 1.0, 0.0]), np.radians(rot))
        eye = rot.dot(eye)
    elif action == glfw.PRESS and key == glfw.KEY_LEFT:
        rot = -5
        rot = mat3.create_from_axis_rotation(vec3([0.0, 1.0, 0.0]), np.radians(rot))
        eye = rot.dot(eye)

    if action == glfw.PRESS and key == glfw.KEY_UP:
        rot = 5
        right = np.cross(center - eye, up)
        rot = mat3.create_from_axis_rotation(vec3(right), np.radians(rot))
        eye = rot.dot(eye)
    elif action == glfw.PRESS and key == glfw.KEY_DOWN:
        rot = -5
        right = np.cross(center - eye, up)
        rot = mat3.create_from_axis_rotation(vec3(right), np.radians(rot))
        eye = rot.dot(eye)

    if action == glfw.PRESS and key == glfw.KEY_S:
        eye = 1.01 * eye
    elif action == glfw.PRESS and key == glfw.KEY_W:
        eye = 0.99 * eye

    if action == glfw.PRESS and key == glfw.KEY_SPACE:
        create_pes()
Beispiel #2
0
    def behave(self, params):
        if params.mouse.left_pressed:
            if self._start is None:
                self._start = params.mouse.location
                self._origin = params.scene.camera_target
                self._camera_pos = params.scene.camera_position
                cam_dir = vector.normalize(self._camera_pos - self._origin)
                self._right = np.cross(params.scene.up_vector, cam_dir)
                self._up = np.cross(cam_dir, self._right)
            else:
                size = params.scene.size
                end = params.mouse.location
                deltaX = float(end[0] - self._start[0]) / size[0]
                deltaY = float(end[1] - self._start[1]) / size[1]

                Rx = matrix33.create_from_axis_rotation(
                    self._up, deltaX * 2 * np.pi)
                Ry = matrix33.create_from_axis_rotation(
                    self._right, deltaY * 2 * np.pi)
                R = Ry.dot(Rx)
                newpos = self._origin + R.dot(self._camera_pos - self._origin)
                newup = R.dot(self._up)

                params.scene.camera_position = newpos
                params.scene.up_vector = newup
                params.refresh = True
        else:
            self._start = None
Beispiel #3
0
def rot33(magnitude, direction) -> numpy.float32:
    """Return the 3x3 matrix of float32 which rotates
    by the given magnitude and direction.
    """
    return matrix33.create_from_axis_rotation(AXIS.dot(
        matrix33.create_from_z_rotation(direction)),
                                              magnitude,
                                              dtype=numpy.float32)
Beispiel #4
0
 def test_create_from_axis_rotation_non_normalised(self):
     result = matrix33.create_from_axis_rotation([1., 1., 1.], np.pi)
     np.testing.assert_almost_equal(result,
                                    matrix33.create_from_quaternion([
                                        5.77350000e-01, 5.77350000e-01,
                                        5.77350000e-01, 6.12323400e-17
                                    ]),
                                    decimal=3)
     self.assertTrue(result.dtype == np.float)
Beispiel #5
0
 def test_create_from_axis_rotation(self):
     # wolfram alpha can be awesome sometimes
     result = matrix33.create_from_axis_rotation(
         [0.57735, 0.57735, 0.57735], np.pi)
     np.testing.assert_almost_equal(result,
                                    matrix33.create_from_quaternion([
                                        5.77350000e-01, 5.77350000e-01,
                                        5.77350000e-01, 6.12323400e-17
                                    ]),
                                    decimal=3)
     self.assertTrue(result.dtype == np.float)
Beispiel #6
0
    def _set_velocity_for_speed_and_direction(self, speed: float, direction: float):
        # get the heading
        dx = self.model.target_x - self.model.ball.x
        dy = self.model.target_y - self.model.ball.y

        # direction is meaningless if we're already at the target
        if (dx != 0) or (dy != 0):

            # set the magnitude
            vel = vector.set_length([dx, dy, 0.0], speed)

            # rotate by direction around Z-axis at ball position
            rot = matrix33.create_from_axis_rotation([0.0, 0.0, 1.0], direction)
            vel = matrix33.apply_to_vector(rot, vel)

            # unpack into ball velocity
            self.model.ball_vel.x = vel[0]
            self.model.ball_vel.y = vel[1]
            self.model.ball_vel.z = vel[2]
Beispiel #7
0
 def angle(self, theta):
     assert isinstance(theta, (int, float))
     self._rot = matrix33.create_from_axis_rotation(Z, theta, dtype='f4')
     self._angle = theta
     self._set_dirty()
def m3MatrixRotation(axis, radian):
    return m3.create_from_axis_rotation(np.array(axis)*1.0, radian).transpose()
Beispiel #9
0
 def get_value(self, t):
     R = matrix33.create_from_axis_rotation(self._normal, 2 * t * np.pi)
     return self._center + R.dot(self._point - self._center)
Beispiel #10
0
 def test_create_from_axis_rotation(self):
     # wolfram alpha can be awesome sometimes
     result = matrix33.create_from_axis_rotation([0.57735, 0.57735, 0.57735],np.pi)
     np.testing.assert_almost_equal(result, matrix33.create_from_quaternion([5.77350000e-01, 5.77350000e-01, 5.77350000e-01, 6.12323400e-17]), decimal=3)
     self.assertTrue(result.dtype == np.float)
Beispiel #11
0
 def test_create_from_axis_rotation_non_normalised(self):
     result = matrix33.create_from_axis_rotation([1.,1.,1.], np.pi)
     np.testing.assert_almost_equal(result, matrix33.create_from_quaternion([5.77350000e-01, 5.77350000e-01, 5.77350000e-01, 6.12323400e-17]), decimal=3)
     self.assertTrue(result.dtype == np.float)