コード例 #1
0
 def __init__(self, model, position, orientation, scale):
     self.model = model
     self.position = position
     self.orientation = orientation
     self.scale = scale      
     
     self.transform = Matrix44.translation_vec3(position) * Matrix44.scale(scale) * orientation
コード例 #2
0
    def __init__(self, model, position, orientation, scale):
        self.model = model
        self.position = position
        self.orientation = orientation
        self.scale = scale

        self.transform = Matrix44.translation(position.x, position.y, position.z) * Matrix44.scale(scale) * orientation
        self.bounds_radius = model.bounds_radius * scale # the bounds radius should also change
        self.bounds_center = self.transform.transform_vec3(model.bounds_center)
コード例 #3
0
def handle_arcball():
    global last_click_pos
    global model_mod
    global model
    global view_mod
    global view

    # LMB = rotate arcball
    if (pygame.mouse.get_pressed()[0]):
        if (last_click_pos[0] == (-1, -1)):
            last_click_pos[0] = pygame.mouse.get_pos()

        v_new = screen_to_arcball(pygame.mouse.get_pos())
        v_old = screen_to_arcball(last_click_pos[0])

        angle = math.acos(min(1.0, v_new.dot(v_old)))
        axis = (v_new.cross(v_old)).normalize()
        model_mod = Matrix44.rotation_about_axis(axis, angle)
    else:
        if (last_click_pos[0] != (-1, -1)):
            last_click_pos[0] = (-1, -1)
            model = model_mod * model
            model_mod = Matrix44.identity()

    # MMB = translate arcball
    if (pygame.mouse.get_pressed()[1]):
        if (last_click_pos[1] == (-1, -1)):
            last_click_pos[1] = pygame.mouse.get_pos()

        dx = (pygame.mouse.get_pos()[0] - last_click_pos[1][0]) / float(res[0])
        dy = (pygame.mouse.get_pos()[1] - last_click_pos[1][1]) / float(res[1])

        view_mod = Matrix44.translation(-dx, -dy, 0)
    else:
        if (last_click_pos[1] != (-1, -1)):
            last_click_pos[1] = (-1, -1)
            view = view_mod * view
            view_mod = Matrix44.identity()

    # RMB = scale arcball (based on RMB delta y)
    if (pygame.mouse.get_pressed()[2]):
        if (last_click_pos[2] == (-1, -1)):
            last_click_pos[2] = pygame.mouse.get_pos()

        dy = (pygame.mouse.get_pos()[1] - last_click_pos[2][1]) / float(res[1])
        model_mod = Matrix44.scale(max(-dy + 1.0, 0.01))
    else:
        if (last_click_pos[2] != (-1, -1)):
            last_click_pos[2] = (-1, -1)
            model = model_mod * model
            model_mod = Matrix44.identity()