Exemplo n.º 1
0
    def on_key_press(self, event):
        if event.key.name == 'Q':
            self.phi += 1
        elif event.key.name == 'A':
            self.phi -= 1
        elif event.key.name == 'W':
            self.theta += 1
        elif event.key.name == 'S':
            self.theta -= 1
        elif event.key.name == 'E':
            self.eta += 1
        elif event.key.name == 'D':
            self.eta -= 1
        elif event.key.name == "Right":
            self.translate_x += 10
        elif event.key.name == "Left":
            self.translate_x += -10
        elif event.key.name == "Up":
            self.translate_y += 10
        elif event.key.name == "Down":
            self.translate_y += -10

        self.view = translate(
            (self.translate_x, self.translate_y, -self.translate))
        self.model = np.dot(
            rotate(self.theta, (1, 0, 0)),
            np.dot(rotate(self.phi, (0, 0, 1)), rotate(self.eta, (0, 1, 0))))
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view
        self.update()
Exemplo n.º 2
0
	def on_key_press(self, event):
		if event.text == 'k':
			self.model = np.dot(rotate(0.5, (0, 1, 0)), self.model)
			self.program['u_model'] = self.model

		if event.text == 'h' :
			self.theta -= .5
			self.model = np.dot(rotate(-0.5, (0, 1, 0)), self.model)
			self.program['u_model'] = self.model

		if event.text == 'u' :
			self.phi += .5
			self.model = np.dot(rotate(0.5, (1, 0, 0)), self.model)
			self.program['u_model'] = self.model

		if event.text == 'j' :
			self.phi -= .5
			self.model = np.dot(rotate(-0.5, (1, 0, 0)), self.model)
			self.program['u_model'] = self.model

		if event.text == 'r':
			self.phi = 0
			self.theta = 0
			self.model = np.eye(4, dtype=np.float32)
			self.program['u_model'] = self.model

		self.camera.onKeyPress(event)
		self.camera.update()
Exemplo n.º 3
0
def test_transforms():
    """Test basic transforms"""
    xfm = np.random.randn(4, 4).astype(np.float32)

    # Do a series of rotations that should end up into the same orientation
    # again, to ensure the order of computation is all correct
    # i.e. if rotated would return the transposed matrix this would not work
    # out (the translation part would be incorrect)
    new_xfm = xfm.dot(rotate(180, (1, 0, 0)).dot(rotate(-90, (0, 1, 0))))
    new_xfm = new_xfm.dot(rotate(90, (0, 0, 1)).dot(rotate(90, (0, 1, 0))))
    new_xfm = new_xfm.dot(rotate(90, (1, 0, 0)))
    assert_allclose(xfm, new_xfm)

    new_xfm = translate((1, -1, 1)).dot(translate((-1, 1, -1))).dot(xfm)
    assert_allclose(xfm, new_xfm)

    new_xfm = scale((1, 2, 3)).dot(scale((1, 1. / 2., 1. / 3.))).dot(xfm)
    assert_allclose(xfm, new_xfm)

    # These could be more complex...
    xfm = ortho(-1, 1, -1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))

    xfm = frustum(-1, 1, -1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))

    xfm = perspective(1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))
Exemplo n.º 4
0
Arquivo: brain.py Projeto: ringw/vispy
 def update_matrices(self):
     self.view = translate((0, 0, -self.translate))
     self.model = np.dot(rotate(self.theta, (1, 0, 0)), rotate(self.phi, (0, 1, 0)))
     self.projection = np.eye(4, dtype=np.float32)
     self.program["u_model"] = self.model
     self.program["u_view"] = self.view
     self.program["u_normal"] = np.linalg.inv(np.dot(self.view, self.model)).T
Exemplo n.º 5
0
    def on_mouse_move(self, event):
        dx = event.pos[0] - self.prevMouseEventCoord[0]
        dy = event.pos[1] - self.prevMouseEventCoord[1]
        if (event.button==1):
            self.translateX += dx/100.0
            self.translateY += -dy/100.0
            # print(dx,dy)
            self.view = translate((self.translateX, self.translateY, -self.translateZ))
            self.program['u_view'] = self.view
            self.program_e['u_view'] = self.view
            # self.print_mouse_event(event, 'Mouse release')
        elif (event.button==2):
            self.phi += dx/10.0
            self.psi += dy/10.0
            # print(dx,dy)
            self.model = np.dot(rotate(self.theta, (0, 0, 1)), np.dot(rotate(self.phi, (0, 1, 0)),rotate(self.psi, (1, 0, 0))))
            self.program['u_model'] = self.model
            self.program_e['u_model'] = self.model
            # self.print_mouse_event(event, 'Mouse release')
        elif (event.button==3):
            self.theta += dx/10.0
            # print(dx,dy)
            self.model = np.dot(rotate(self.theta, (0, 0, 1)), np.dot(rotate(self.phi, (0, 1, 0)),rotate(self.psi, (1, 0, 0))))
            self.program['u_model'] = self.model
            self.program_e['u_model'] = self.model
            # self.print_mouse_event(event, 'Mouse release')

        self.update()
        self.prevMouseEventCoord = event.pos
Exemplo n.º 6
0
def test_transforms():
    """Test basic transforms"""
    xfm = np.random.randn(4, 4).astype(np.float32)

    for rot in [xrotate, yrotate, zrotate]:
        new_xfm = rot(rot(xfm, 90), -90)
        assert_allclose(xfm, new_xfm)

    new_xfm = rotate(rotate(xfm, 90, 1, 0, 0), 90, -1, 0, 0)
    assert_allclose(xfm, new_xfm)

    new_xfm = translate(translate(xfm, 1, -1), 1, -1, 1)
    assert_allclose(xfm, new_xfm)

    new_xfm = scale(scale(xfm, 1, 2, 3), 1, 1. / 2., 1. / 3.)
    assert_allclose(xfm, new_xfm)

    # These could be more complex...
    xfm = ortho(-1, 1, -1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))

    xfm = frustum(-1, 1, -1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))

    xfm = perspective(1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))
Exemplo n.º 7
0
 def view(self, z=5, theta=0.0, phi=0.0):
     """ change the zoom factor and view point """
     self.program['u_view'] = translate((0, 0, -self.z))
     model = np.dot(rotate(self.theta, (0, 1, 0)),
                    rotate(self.phi, (0, 0, 1)))
     self.program['u_model'] = model
     self.update()
Exemplo n.º 8
0
 def update_transforms(self, event):
     self.theta += .5
     self.phi += .5
     self.model = np.dot(rotate(self.theta, (0, 0, 1)),
                         rotate(self.phi, (0, 1, 0)))
     self.program['u_model'] = self.model
     self.update()
Exemplo n.º 9
0
    def render(self, model, view, projection, mode="color", block_rotation=0, element_transform=np.eye(4, dtype=np.float32), uvlock=False):
        element_rotation = np.eye(4, dtype=np.float32)
        if self.rotation:
            rotationdef = self.rotation
            axis = {"x" : [1, 0, 0],
                    "y" : [0, 1, 0],
                    "z" : [0, 0, 1]}[rotationdef["axis"]]
            origin = (np.array(rotationdef.get("origin", [8, 8, 8]), dtype=np.float32) - 8.0) / 16.0 * 2.0
            element_rotation = np.dot(transforms.translate(-origin), np.dot(transforms.rotate(rotationdef["angle"], axis), transforms.translate(origin)))

        program = Element.get_program(mode)
        self.current_program = program

        # add rotation of block and element to element transformation
        block_rotation = transforms.rotate(-90 * block_rotation, (0, 1, 0))
        element_transform = np.dot(element_rotation, np.dot(element_transform, block_rotation))
        complete_model = np.dot(element_transform, model)
        program["u_model"] = complete_model
        program["u_view"] = view
        program["u_projection"] = projection
        #program["u_normal"] = np.array(np.matrix(np.dot(view, complete_model)).I.T)

        for i, (texture, uvs) in enumerate(self.faces):
            if texture is None:
                continue
            self.render_face(i, texture, uvs, complete_model, view, projection, element_rotation=element_rotation, element_transform=element_transform, uvlock=uvlock or mode == "uv")
Exemplo n.º 10
0
def create_transform_ortho(aspect=1.0, view="isometric", fake_ortho=True):
    model = np.eye(4, dtype=np.float32)

    if view == "isometric":
        if fake_ortho:
            # 0.816479 = 0.5 * sqrt(3) * x = 0.5 * sqrt(2)
            # scale of y-axis to make sides and top of same height: (1.0, 0.81649, 1.0)
            # scale to get block completely into viewport (-1;1): (1.0 / math.sqrt(2), ..., ...)
            model = np.dot(model, transforms.scale((1.0 / math.sqrt(2), 0.816479 / math.sqrt(2), 1.0 / math.sqrt(2))))
        else:
            # this scale factor is just for nicely viewing the block image manually
            model = np.dot(model, transforms.scale((0.5, 0.5, 0.5)))

        # and do that nice tilt
        model = np.dot(model, np.dot(transforms.rotate(45, (0, 1, 0)), transforms.rotate(30, (1, 0, 0))))
    elif view == "topdown":
        model = np.dot(model, transforms.rotate(90, (1, 0, 0)))
    elif view == "side":
        # same thing with scaling factor as with isometric view
        #f = 1.0 / math.sqrt(2)
        f = 0.5 / math.cos(math.radians(45))
        model = np.dot(model, transforms.scale((f / math.cos(math.radians(45)), f, f)))
        model = np.dot(model, transforms.rotate(45, (1, 0, 0)))
    elif view == "default":
        pass
    else:
        assert False, "Invalid view '%s'!" % view

    view = transforms.translate((0, 0, -5))
    projection = transforms.ortho(-aspect, aspect, -1, 1, 2.0, 50.0)
    return model, view, projection
Exemplo n.º 11
0
def test_transforms():
    """Test basic transforms"""
    xfm = np.random.randn(4, 4).astype(np.float32)

    # Do a series of rotations that should end up into the same orientation
    # again, to ensure the order of computation is all correct
    # i.e. if rotated would return the transposed matrix this would not work
    # out (the translation part would be incorrect)
    new_xfm = xfm.dot(rotate(180, (1, 0, 0)).dot(rotate(-90, (0, 1, 0))))
    new_xfm = new_xfm.dot(rotate(90, (0, 0, 1)).dot(rotate(90, (0, 1, 0))))
    new_xfm = new_xfm.dot(rotate(90, (1, 0, 0)))
    assert_allclose(xfm, new_xfm)

    new_xfm = translate((1, -1, 1)).dot(translate((-1, 1, -1))).dot(xfm)
    assert_allclose(xfm, new_xfm)

    new_xfm = scale((1, 2, 3)).dot(scale((1, 1. / 2., 1. / 3.))).dot(xfm)
    assert_allclose(xfm, new_xfm)

    # These could be more complex...
    xfm = ortho(-1, 1, -1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))

    xfm = frustum(-1, 1, -1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))

    xfm = perspective(1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))
Exemplo n.º 12
0
 def on_timer(self, event):
     self.theta += .005
     self.phi += .005
     self.model = rotate(self.phi, (0, 1, 0)) * rotate(self.theta, (0, 0, 1))
     
     self.program['u_model'] = self.model
     self.update()
Exemplo n.º 13
0
    def on_key_press(self, event):
        if event.text == 'k':
            self.model = np.dot(rotate(0.5, (0, 1, 0)), self.model)
            self.program['u_model'] = self.model

        if event.text == 'h':
            self.theta -= .5
            self.model = np.dot(rotate(-0.5, (0, 1, 0)), self.model)
            self.program['u_model'] = self.model

        if event.text == 'u':
            self.phi += .5
            self.model = np.dot(rotate(0.5, (1, 0, 0)), self.model)
            self.program['u_model'] = self.model

        if event.text == 'j':
            self.phi -= .5
            self.model = np.dot(rotate(-0.5, (1, 0, 0)), self.model)
            self.program['u_model'] = self.model

        if event.text == 'r':
            self.phi = 0
            self.theta = 0
            self.model = np.eye(4, dtype=np.float32)
            self.program['u_model'] = self.model

        self.camera.onKeyPress(event)
        self.camera.update()
Exemplo n.º 14
0
 def view(self, z=5, theta=0.0, phi=0.0):
     """ change the zoom factor and view point """
     self.program['u_view'] = translate((0, 0, -self.z))
     model = np.dot(rotate(self.theta, (0, 1, 0)),
                    rotate(self.phi, (0, 0, 1)))
     self.program['u_model'] = model
     self.update()
Exemplo n.º 15
0
 def update_transforms(self, event):
     self.theta += .5
     self.phi += .5
     self.model = np.dot(rotate(self.theta, (0, 0, 1)),
                         rotate(self.phi, (0, 1, 0)))
     self.program['u_model'] = self.model
     self.update()
Exemplo n.º 16
0
 def on_timer(self, event):
     self.theta += .11
     self.phi += .13
     self.model = np.dot(rotate(self.theta, (0, 0, 1)),
                         rotate(self.phi, (0, 1, 0)))
     self.program['u_model'] = self.model
     self.update()
def test_transforms():
    """Test basic transforms"""
    xfm = np.random.randn(4, 4).astype(np.float32)

    for rot in [xrotate, yrotate, zrotate]:
        new_xfm = rot(rot(xfm, 90), -90)
        assert_allclose(xfm, new_xfm)

    new_xfm = rotate(rotate(xfm, 90, 1, 0, 0), 90, -1, 0, 0)
    assert_allclose(xfm, new_xfm)

    new_xfm = translate(translate(xfm, 1, -1), 1, -1, 1)
    assert_allclose(xfm, new_xfm)

    new_xfm = scale(scale(xfm, 1, 2, 3), 1, 1. / 2., 1. / 3.)
    assert_allclose(xfm, new_xfm)

    # These could be more complex...
    xfm = ortho(-1, 1, -1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))

    xfm = frustum(-1, 1, -1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))

    xfm = perspective(1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))
Exemplo n.º 18
0
 def on_timer(self, event):
     self.theta += .5
     self.phi += .5
     self.model = np.dot(rotate(self.theta, (0, 0, 1)),
                         rotate(self.phi, (0, 1, 0)))
     self.program['u_model'] = self.model
     self.update()
Exemplo n.º 19
0
 def on_timer(self, event):
     self.theta += .5
     self.phi += .5
     self.model = np.eye(4, dtype=np.float32)
     rotate(self.model, self.theta, 0, 0, 1)
     rotate(self.model, self.phi, 0, 1, 0)
     self.program['u_model'] = self.model
     self.update()
Exemplo n.º 20
0
 def affine_transform(self) -> ndarray:
     r = rotate(self.rx,
                (1, 0, 0)) @ rotate(self.ry,
                                    (0, 1, 0)) @ rotate(self.rz, (0, 0, 1))
     t = translate((self.x, self.y, self.z))
     matrix = (r @ t).T
     assert matrix.shape == (4, 4)
     return matrix
Exemplo n.º 21
0
 def on_timer(self, event):
     self.theta = event.elapsed * 30
     self.phi = 0
     self.program['model'] = np.dot(
         rotate(self.phi, [1, 0, 0]),
         rotate(self.theta, [0, 1, 0]),
     )
     self.update()
Exemplo n.º 22
0
 def on_timer(self, event):
     self.theta += .017
     self.phi += .013
     self.model = np.eye(4, dtype=np.float32)
     rotate(self.model, self.theta, 0, 0, 1)
     rotate(self.model, self.phi, 0, 1, 0)
     self.program['u_model'] = self.model
     self.update()
Exemplo n.º 23
0
 def on_timer(self, event):
     self.theta += .5
     self.phi += .5
     model = np.eye(4, dtype=np.float32)
     rotate(model, self.theta, 0, 0, 1)
     rotate(model, self.phi, 0, 1, 0)
     self.cube['model'] = model
     self.update()
Exemplo n.º 24
0
	def on_mouse_move(self, event):
		if event.is_dragging and event.button==1:
			delta = .2*(event.pos - event.last_event.pos)
			self.model = numpy.dot(self.model, rotate(delta[0], (0, 1, 0)))
			self.model = numpy.dot(self.model, rotate(delta[1], (1, 0, 0)))

			self.program['u_model'] = self.model
			self.update()
Exemplo n.º 25
0
 def on_timer(self, event):
     self.theta += .5
     self.phi += .5
     model = np.eye(4, dtype=np.float32)
     rotate(model, self.theta, 0, 0, 1)
     rotate(model, self.phi, 0, 1, 0)
     self.cube['model'] = model
     self.update()
Exemplo n.º 26
0
    def update_transforms(self, event):
        self.theta += .5
        self.phi += .5
        self.model = np.eye(4, dtype=np.float32)
        rotate(self.model, self.theta, 0, 0, 1)
        rotate(self.model, self.phi, 0, 1, 0)

        self.update()
Exemplo n.º 27
0
 def update_transforms(self, event):
     self.theta += 0.5
     self.phi += 0.5
     self.model = np.eye(4, dtype=np.float32)
     rotate(self.model, self.theta, 0, 0, 1)
     rotate(self.model, self.phi, 0, 1, 0)
     self.program["u_model"] = self.model
     self.update()
Exemplo n.º 28
0
    def __init__(self):
        '''Map drawable - contains the goddamn map
        '''
        self.projection = np.eye(4)
        self.view = np.eye(4)

        self.model = scale(np.eye(4), 0.6)
        orientation_vector = (0, 1, 0)
        unit_orientation_angle = np.array(orientation_vector) / np.linalg.norm(orientation_vector)
        rotate(self.model, -30, *unit_orientation_angle)
        translate(self.model, -2.2, -2.4, -9)
        
        height, width = 5.0, 5.0  # Meters

        # Add texture coordinates
        # Rectangle of height height
        self.vertices = np.array([
            [-width / 2, -height / 2, 0],
            [ width / 2, -height / 2, 0],
            [ width / 2,  height / 2, 0],
            [-width / 2,  height / 2, 0],
        ], dtype=np.float32)

        self.tex_coords = np.array([
            [0, 1],
            [1, 1],
            [1, 0],
            [0, 0],
        ], dtype=np.float32)

        self.indices = IndexBuffer([
            0, 1, 2,
            2, 3, 0,
        ])

        ###### TESTING
        self.position_lla = self.ecef2llh((738575.65, -5498374.10, 3136355.42))
        ###### TESTING

        self.map, self.ranges = self.cache_map(self.position_lla[:2])
        self.map, self.ranges = self.get_map(self.position_lla[:2])
        self.program = Program(self.frame_vertex_shader, self.frame_frag_shader)

        default_map_transform = np.eye(4)

        self.program['vertex_position'] = self.vertices
        self.program['default_texcoord'] = self.tex_coords
        self.program['zoom'] = 1
        self.program['view'] = self.view
        self.program['model'] = self.model
        self.program['projection'] = self.projection

        self.program['map_transform'] = default_map_transform
        self.program['map_center'] = self.position_lla[:2]
        self.program['map_texture'] = self.map
        self.program['corners'] = self.ranges
        self.program['user_position'] = self.position_lla[:2]
        self.program['hide'] = 0
Exemplo n.º 29
0
    def on_timer(self, event):
        self.phi += np.clip(self.delta_phi, -1, 1)
        self.theta += np.clip(self.delta_theta, -1, 1)
        self.model = np.dot(rotate(self.theta, (0, 0, 1)),
                            rotate(self.phi, (0, 1, 0)))
        for program in self.programs:
            program['u_model'] = self.model

        self.update()
Exemplo n.º 30
0
 def update_matrix(self):
     rotation_matrix = rotate(self.alpha, [0, 1, 0]) @ rotate(
         self.theta, [1, 0, 0])
     self.program["rotation"] = rotation_matrix
     self.program["view"] = self.view
     depth = (self.vertices @ rotation_matrix)[:, 2]
     self.program["dmin"] = np.min(depth)
     self.program["dmax"] = np.max(depth)
     self.update()
Exemplo n.º 31
0
 def on_timer(self, event):
     self.theta += .5
     self.phi += .5
     model = np.dot(rotate(self.theta, (0, 0, 1)),
                    rotate(self.phi, (0, 1, 0)))
     normal = np.linalg.inv(np.dot(self.view, model)).T
     self.program['u_model'] = model
     self.program['u_normal'] = normal
     self.update()
Exemplo n.º 32
0
 def on_timer(self, event):
     self.counter += 1
     print("on_timer", self.counter)
     self.theta += .5
     self.phi += .5
     self.program['model'] = np.dot(rotate(self.theta, (0, 1, 0)),
                                    rotate(self.phi, (0, 1, 0)))
     # self.program['texture'] = im if self.counter % 200 else checkerboard()
     self.update()
Exemplo n.º 33
0
 def on_timer(self, event):
     self.theta += .5
     self.phi += .5
     model = np.dot(rotate(self.theta, (0, 0, 1)),
                    rotate(self.phi, (0, 1, 0)))
     normal = np.linalg.inv(np.dot(self.view, model)).T
     self.program['u_model'] = model
     self.program['u_normal'] = normal
     self.update()
Exemplo n.º 34
0
 def on_midi(self, event):
     self.theta += 3.5
     self.phi += 3.5
     self.model = np.dot(rotate(self.theta, (0, 1, 0)),
                         rotate(self.phi, (0, 0, 1)))
     self.program['u_model'] = self.model
     if event.message[1] < 60:
         self.transparency = np.random.uniform(0.5, 1)
     self.update()
Exemplo n.º 35
0
 def rotate_graph(self):
     self.theta += 2
     self.phi += 2
     self.model = np.dot(rotate(self.theta, (0, 0, 1)),
                         rotate(self.phi, (0, 1, 0)))
     self.program['u_model'] = self.model
     self.program_e['u_model'] = self.model
     self.program_p['u_model'] = self.model
     self.update()
Exemplo n.º 36
0
 def on_timer(self, event):
     self.timer_t += self.timer_dt  # keep track on the current time
     self.theta += self.rotate_theta_speed
     self.phi += self.rotate_phi_speed
     self.model = np.eye(4, dtype=np.float32)
     rotate(self.model, self.theta, 0, 0, 1)
     rotate(self.model, self.phi, 0, 1, 0)
     self.program['u_model'] = self.model
     self.update()
Exemplo n.º 37
0
 def on_timer(self, event):
     if not self.stop_rotation:
         self.theta += .02
         self.phi += .02
         self.model = rotate(self.phi, (0, 1, 0)) * rotate(self.theta, (0, 0, 1))
         self.program['u_model'] = self.model
     self.clock += np.pi / 1000
     self.program['u_clock'] = self.clock
     self.update()
Exemplo n.º 38
0
 def update_matrices(self):
     self.view = translate((0, 0, -self.translate))
     self.model = np.dot(rotate(self.theta, (1, 0, 0)),
                         rotate(self.phi, (0, 1, 0)))
     self.projection = np.eye(4, dtype=np.float32)
     self.program['u_model'] = self.model
     self.program['u_view'] = self.view
     self.program['u_normal'] = np.linalg.inv(np.dot(self.view,
                                                     self.model)).T
Exemplo n.º 39
0
 def on_timer(self,event):
     self.timer_t += self.timer_dt # keep track on the current time
     self.theta += self.rotate_theta_speed
     self.phi += self.rotate_phi_speed
     self.model = np.eye(4, dtype=np.float32)
     rotate(self.model, self.theta, 0,0,1)
     rotate(self.model, self.phi,   0,1,0)
     self.program['u_model'] = self.model
     self.update()
Exemplo n.º 40
0
    def adjust_rotate(self, event):
        """Adjust rotation of rendered data."""
        sign = {'Up':-1, 'Left':-1, ']':-1, '}':-1}.get(event.key, 1)

        print 'adjust_rotate %s' % event

        if event.key == 'S':
            # stop auto-rotate
            self.auto_rotate_X_angle = 0.0
            self.auto_rotate_Y_angle = 0.0
            self.auto_rotate_Z_angle = 0.0
            self.auto_rotate_X_speed = 0
            self.auto_rotate_Y_speed = 0
            self.auto_rotate_Z_speed = 0

            if self._timer is not None:
                self._timer.stop()
                self._timer = None

        elif 'Shift' in event.modifiers:
            # adjust auto-rotation speed in small increments
            if event.key in ('Right', 'Left'):
                self.auto_rotate_Y_speed += sign
            elif event.key in ('Up', 'Down'):
                self.auto_rotate_X_speed += sign
            elif event.key in ('[', ']', '{', '}'):
                self.auto_rotate_Z_speed += sign

            if self.auto_rotate_Z_speed != 0.0 \
                    or self.auto_rotate_Y_speed != 0.0 \
                    or self.auto_rotate_X_speed != 0.0:
                if self._timer is None:
                    print 'starting timer'
                    self._timer = app.Timer('auto', connect=self.on_timer, start=True)
            else:
                if self._timer is not None:
                    print 'stopping timer'
                    self._timer.stop()
                    self._timer = None
        else:
            # just apply a single small rotation increment
            axis = {
                'Up': (1, 0, 0), 
                'Down': (1, 0, 0), 
                'Left': (0, 1, 0),
                'Right': (0, 1, 0),
                '[': (0, 0, 1),
                ']': (0, 0, 1)
                }[event.key]

            angle = 2 * sign

            rotate(*(self.rotation, angle) + axis)
            rotate(*(self.anti_rotation, -angle) + axis)

            self.update_view()
Exemplo n.º 41
0
def timer(fps):
    global theta, phi
    theta += .5
    phi += .5
    model = np.eye(4, dtype=np.float32)
    rotate(model, theta, 0, 0, 1)
    rotate(model, phi, 0, 1, 0)
    program['model'] = model
    glut.glutTimerFunc(1000 / fps, timer, fps)
    glut.glutPostRedisplay()
Exemplo n.º 42
0
 def on_timer(self, event):
     self.theta += 0.5
     self.phi += 0.5
     model = np.eye(4, dtype=np.float32)
     rotate(model, self.theta, 0, 0, 1)
     rotate(model, self.phi, 0, 1, 0)
     normal = np.array(np.matrix(np.dot(self.view, model)).I.T)
     self.program["u_model"] = model
     self.program["u_normal"] = normal
     self.update()
Exemplo n.º 43
0
    def update_matrices(self):
        self.view = translate((0, 0, -self.translate))
        self.model = rotate(self.phi, (0,1,0)) * rotate(self.theta, (0, 0, 1))
        self.projection = np.eye(4, dtype=np.float32)

        
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view
        self.program['u_normal'] = np.array(np.matrix(np.dot(self.view, 
                                                             self.model)).I.T)
Exemplo n.º 44
0
 def on_timer(self, event):
     if not self.stop_rotation:
         self.theta += .5
         self.phi += .5
         self.model = np.dot(rotate(self.theta, (0, 0, 1)),
                             rotate(self.phi, (0, 1, 0)))
         self.program['u_model'] = self.model
     self.clock += np.pi / 1000
     self.program['u_clock'] = self.clock
     self.update()
Exemplo n.º 45
0
def timer(fps):
    global theta, phi
    theta += 0.5
    phi += 0.5
    model = np.eye(4, dtype=np.float32)
    rotate(model, theta, 0, 0, 1)
    rotate(model, phi, 0, 1, 0)
    program["model"] = model
    glut.glutTimerFunc(1000 / fps, timer, fps)
    glut.glutPostRedisplay()
Exemplo n.º 46
0
 def on_timer(self, event):
     self.theta += .5
     self.phi += .5
     model = np.eye(4, dtype=np.float32)
     rotate(model, self.theta, 0, 0, 1)
     rotate(model, self.phi, 0, 1, 0)
     normal = np.array(np.matrix(np.dot(self.view, model)).I.T)
     self.program['u_model'] = model
     self.program['u_normal'] = normal
     self.update()
Exemplo n.º 47
0
    def on_key_press(self, event):
        """Controls -
        a(A) - move left
        d(D) - move right
        w(W) - move up
        s(S) - move down
        x/X - rotate about x-axis cw/anti-cw
        y/Y - rotate about y-axis cw/anti-cw
        z/Z - rotate about z-axis cw/anti-cw
        space - reset view
        p(P) - print current view
        i(I) - zoom in
        o(O) - zoom out
        """
        self.translate = [0, 0, 0]
        self.rotate = [0, 0, 0]

        if event.text == "p" or event.text == "P":
            print(self.view)
        elif event.text == "d" or event.text == "D":
            self.translate[0] = 0.3
        elif event.text == "a" or event.text == "A":
            self.translate[0] = -0.3
        elif event.text == "w" or event.text == "W":
            self.translate[1] = 0.3
        elif event.text == "s" or event.text == "S":
            self.translate[1] = -0.3
        elif event.text == "o" or event.text == "O":
            self.translate[2] = 0.3
        elif event.text == "i" or event.text == "I":
            self.translate[2] = -0.3
        elif event.text == "x":
            self.rotate = [1, 0, 0]
        elif event.text == "X":
            self.rotate = [-1, 0, 0]
        elif event.text == "y":
            self.rotate = [0, 1, 0]
        elif event.text == "Y":
            self.rotate = [0, -1, 0]
        elif event.text == "z":
            self.rotate = [0, 0, 1]
        elif event.text == "Z":
            self.rotate = [0, 0, -1]
        elif event.text == " ":
            self.view = self.default_view

        self.view = self.view.dot(
            translate(-np.array(self.translate)).dot(
                rotate(self.rotate[0], (1, 0, 0)).dot(
                    rotate(self.rotate[1], (0, 1, 0)).dot(rotate(self.rotate[2], (0, 0, 1)))
                )
            )
        )
        self.program["u_view"] = self.view
        self.update()
Exemplo n.º 48
0
 def on_timer(self, event):
     if not self.stop_rotation:
         self.theta += .05
         self.phi += .05
         self.model = np.eye(4, dtype=np.float32)
         rotate(self.model, self.theta, 0, 0, 1)
         rotate(self.model, self.phi, 0, 1, 0)
         self.program['u_model'] = self.model
     self.clock += np.pi / 100
     self.program['u_clock'] = self.clock
     self.update()
Exemplo n.º 49
0
Arquivo: donut.py Projeto: LiloD/vispy
 def on_timer(self, event):
     if not self.stop_rotation:
         self.theta += .5
         self.phi += .5
         self.model = np.eye(4, dtype=np.float32)
         rotate(self.model, self.theta, 0, 0, 1)
         rotate(self.model, self.phi, 0, 1, 0)
         self.program['u_model'] = self.model
     self.clock += np.pi / 1000
     self.program['u_clock'] = self.clock
     self.update()
Exemplo n.º 50
0
 def on_timer(self, event):
     self.data1['a_position'] = 0.45 * np.random.randn(self.n, 3)
     self.data1['a_normal'] = 0
     self.data1['a_color'] = 0, 0, 0, 1
     
     self.theta += .5
     self.phi += .5
     self.model = np.dot(rotate(self.theta, (0, 0, 1)),
                         rotate(self.phi, (0, 1, 0)))
     self.program['u_model'] = self.model
     self.update()
Exemplo n.º 51
0
    def on_key_press(self, event):
        """Controls -
        a(A) - move left
        d(D) - move right
        w(W) - move up
        s(S) - move down
        x/X - rotate about x-axis cw/anti-cw
        y/Y - rotate about y-axis cw/anti-cw
        z/Z - rotate about z-axis cw/anti-cw
        space - reset view
        p(P) - print current view
        i(I) - zoom in
        o(O) - zoom out
        """
        self.translate = [0, 0, 0]
        self.rotate = [0, 0, 0]

        if(event.text == 'p' or event.text == 'P'):
            print(self.view)
        elif(event.text == 'd' or event.text == 'D'):
            self.translate[0] = 0.3
        elif(event.text == 'a' or event.text == 'A'):
            self.translate[0] = -0.3
        elif(event.text == 'w' or event.text == 'W'):
            self.translate[1] = 0.3
        elif(event.text == 's' or event.text == 'S'):
            self.translate[1] = -0.3
        elif(event.text == 'o' or event.text == 'O'):
            self.translate[2] = 0.3
        elif(event.text == 'i' or event.text == 'I'):
            self.translate[2] = -0.3
        elif(event.text == 'x'):
            self.rotate = [1, 0, 0]
        elif(event.text == 'X'):
            self.rotate = [-1, 0, 0]
        elif(event.text == 'y'):
            self.rotate = [0, 1, 0]
        elif(event.text == 'Y'):
            self.rotate = [0, -1, 0]
        elif(event.text == 'z'):
            self.rotate = [0, 0, 1]
        elif(event.text == 'Z'):
            self.rotate = [0, 0, -1]
        elif(event.text == ' '):
            self.view = self.default_view

        self.view = self.view.dot(
            translate(-np.array(self.translate)).dot(
                rotate(self.rotate[0], (1, 0, 0)).dot(
                    rotate(self.rotate[1], (0, 1, 0)).dot(
                        rotate(self.rotate[2], (0, 0, 1))))))
        self.program['u_view'] = self.view
        self.update()
Exemplo n.º 52
0
 def update_matrices(self):
     self.view = np.eye(4, dtype=np.float32)
     self.model = np.eye(4, dtype=np.float32)
     self.projection = np.eye(4, dtype=np.float32)
     
     rotate(self.model, self.theta, 1, 0, 0)
     rotate(self.model, self.phi, 0, 1, 0)
     
     translate(self.view, 0, 0, -self.translate)
     
     self.program['u_model'] = self.model
     self.program['u_view'] = self.view
Exemplo n.º 53
0
def timer(fps):
    global theta, phi
    theta += .5
    phi += .5
    model = np.eye(4, dtype=np.float32)
    rotate(model, theta, 0, 0, 1)
    rotate(model, phi, 0, 1, 0)
    normal = np.array(np.matrix(np.dot(view, model)).I.T)
    program['u_model'] = model
    program['u_normal'] = normal
    glut.glutTimerFunc(1000 / fps, timer, fps)
    glut.glutPostRedisplay()
Exemplo n.º 54
0
 def on_timer(self, event):
     """ canvas time-out callback """
     self.theta += .5
     self.phi += .5
     # note the convention is, theta is applied first and then phi
     # see vispy.utils.transforms,
     # python is row-major and opengl is column major,
     # so the rotate function transposes the output.
     model = np.dot(rotate(self.theta, (0, 1, 0)),
                    rotate(self.phi, (0, 0, 1)))
     self.program['u_model'] = model
     self.update()
Exemplo n.º 55
0
    def on_key_press(self, event):
        """Controls -
        a(A) - move left
        d(D) - move right
        w(W) - move up
        s(S) - move down
        x/X - rotate about x-axis cw/anti-cw
        y/Y - rotate about y-axis cw/anti-cw
        z/Z - rotate about z-axis cw/anti-cw
        space - reset view
        p(P) - print current view
        i(I) - zoom in
        o(O) - zoom out
        """
        self.translate = [0, 0, 0]
        self.rotate = [0, 0, 0]

        if(event.text == 'p' or event.text == 'P'):
            print(self.view)
        elif(event.text == 'd' or event.text == 'D'):
            self.translate[0] = 0.3
        elif(event.text == 'a' or event.text == 'A'):
            self.translate[0] = -0.3
        elif(event.text == 'w' or event.text == 'W'):
            self.translate[1] = 0.3
        elif(event.text == 's' or event.text == 'S'):
            self.translate[1] = -0.3
        elif(event.text == 'o' or event.text == 'O'):
            self.translate[2] = 0.3
        elif(event.text == 'i' or event.text == 'I'):
            self.translate[2] = -0.3
        elif(event.text == 'x'):
            self.rotate = [1, 0, 0]
        elif(event.text == 'X'):
            self.rotate = [-1, 0, 0]
        elif(event.text == 'y'):
            self.rotate = [0, 1, 0]
        elif(event.text == 'Y'):
            self.rotate = [0, -1, 0]
        elif(event.text == 'z'):
            self.rotate = [0, 0, 1]
        elif(event.text == 'Z'):
            self.rotate = [0, 0, -1]
        elif(event.text == ' '):
            self.view = self.default_view

        self.view = self.view.dot(
            translate(-np.array(self.translate)).dot(
                rotate(self.rotate[0], (1, 0, 0)).dot(
                    rotate(self.rotate[1], (0, 1, 0)).dot(
                        rotate(self.rotate[2], (0, 0, 1))))))
        self.program['u_view'] = self.view
        self.update()
Exemplo n.º 56
0
    def on_timer(self, event):
        self.theta += 0.0
        self.phi += 0.0
        self.model = np.eye(4, dtype=np.float32)

        rotate(self.model, self.theta, 0, 0, 1)
        rotate(self.model, self.phi, 0, 1, 0)

        self.coords = self.get_coordinates()
        self.load_data()
        self.program['u_model'] = self.model
        self.update()
Exemplo n.º 57
0
    def _mouse_drag_rotation(self, distance, delta):
        prev_rot = self.drag_rotation

        self.drag_rotation = np.eye(4, dtype=np.float32)
        rotate(self.drag_rotation, distance * 180, delta[1], delta[0], 0)

        self.drag_anti_rotation = np.eye(4, dtype=np.float32)
        rotate(self.drag_anti_rotation, - distance * 180, delta[1], delta[0], 0)

        if prev_rot is None \
                or(self.drag_rotation != prev_rot).any():
            self.update_view()
            self.update()
Exemplo n.º 58
0
 def on_draw(self, event):
     """ refresh canvas """
     gloo.clear()
     view = translate((0, 0, -self.z))
     model = np.dot(rotate(self.theta, (0, 1, 0)),
                    rotate(self.phi, (0, 0, 1)))
     # note the convention is, theta is applied first and then phi
     # see vispy.utils.transforms,
     # python is row-major and opengl is column major,
     # so the rotate function transposes the output.
     self.program['u_model'] = model
     self.program['u_view'] = view
     self.program.draw('line_strip')
Exemplo n.º 59
0
    def on_key_press(self, event):
        if event.text == "x":
            self.theta += 0.5
            self.phi += 0.5
            self.model = np.dot(rotate(self.theta, (0, 0, 1)), rotate(self.phi, (0, 1, 0)))
            self.program["u_model"] = self.model
            self.update()
        elif event.text == "z":
            self.theta += 0.5
            self.phi += 0.5
            self.model = np.dot(rotate(-self.theta, (0, 0, 1)), rotate(self.phi, (0, 1, 0)))
            self.program["u_model"] = self.model
            self.update()
        elif event.text == "w":
            self.wireframe = not self.wireframe

        self.update()
Exemplo n.º 60
0
    def on_mouse_move(self, event):
        if event.is_dragging:
            self.is_dragging = True
            w, h = self.size
            x, y = event.pos
            dx = x-self.prev_cursor_x
            dy = y-self.prev_cursor_y
            dphi = float(dx)/x*180
            dtheta = float(dy)/y*180
            dt = self.timer_t - self.prev_timer_t
            if dt > 0 or True:
                self.phi += float(dx)/x*180
                self.theta += float(dy)/y*180

                rotate(self.model, self.theta, 0,0,1)
                rotate(self.model, self.phi,   0,1,0)
                self.prev_cursor_x, self.prev_cursor_y = event.pos
                self.prev_timer_t = self.timer_t