Example #1
0
 def rotate_absolute(self,axis,angle):
     # rotate the object
     self.makeCurrent()
     glMatrixMode(GL_MODELVIEW)
     glLoadIdentity()
     t = [self._modelview_matrix[3][0], self._modelview_matrix[3][1], self._modelview_matrix[3][2]]
     glTranslatef(t[0], t[1], t[2])
     glRotated(angle, axis[0], axis[1], axis[2])
     glTranslatef(-t[0], -t[1], -t[2])
     matrix = glGetDoublev(GL_MODELVIEW_MATRIX)
     matrix[3][0], matrix[3][1],matrix[3][2] = t
     glLoadMatrixd(matrix)
     # update _modelview_matrix
     self._modelview_matrix = glGetDoublev(GL_MODELVIEW_MATRIX)
Example #2
0
 def load_view_matrix(self,view_matrix):
     self.makeCurrent()
     glMatrixMode(GL_MODELVIEW)
     glLoadIdentity()
     glLoadMatrixd(view_matrix)
     self._modelview_matrix = glGetDoublev(GL_MODELVIEW_MATRIX)
Example #3
0
 def paintGL(self):
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     glMatrixMode(GL_MODELVIEW)
     glLoadMatrixd(self._modelview_matrix)
Example #4
0
 def reset_rotation(self):
     self._modelview_matrix[0] = [1.0, 0.0, 0.0, 0.0]
     self._modelview_matrix[1] = [0.0, 1.0, 0.0, 0.0]
     self._modelview_matrix[2] = [0.0, 0.0, 1.0, 0.0]
     glMatrixMode(GL_MODELVIEW)
     glLoadMatrixd(self._modelview_matrix)
Example #5
0
def start():
    pygame.init()
    screen = pygame.display.set_mode(SCREEN_SIZE, pygame.HWSURFACE|pygame.OPENGL|pygame.DOUBLEBUF)
    resize(*SCREEN_SIZE)
    init()

    clock = pygame.time.Clock()

    # This object renders the 'map'
    map = Map()

    # Camera transform matrix
    cam_matrix = Matrix44()
    cam_matrix.translate = (10.0, 0.6, 10.0)

    # Initialize speeds and directions
    rotation_direction = Vector3()
    rotation_speed = radians(90.0)
    movement_direction = Vector3()
    movement_speed = 5.0

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE:
                pygame.quit()
                quit()
        # Clear the screen, and z-buffer
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        time_passed = clock.tick()
        time_passed_seconds = time_passed / 1000.0

        pressed_keys = pygame.key.get_pressed()

        # Reset rotation and movement directions
        rotation_direction.set(0.0, 0.0, 0.0)
        movement_direction.set(0.0, 0.0, 0.0)

        # Modify direction vectors for key presses
        if pressed_keys[pygame.K_LEFT]:
            rotation_direction.y = +1.0
        elif pressed_keys[pygame.K_RIGHT]:
            rotation_direction.y = -1.0
        if pressed_keys[pygame.K_UP]:
            rotation_direction.x = -1.0
        elif pressed_keys[pygame.K_DOWN]:
            rotation_direction.x = +1.0
        if pressed_keys[pygame.K_z]:
            rotation_direction.z = -1.0
        elif pressed_keys[pygame.K_x]:
            rotation_direction.z = +1.0
        if pressed_keys[pygame.K_q]:
            movement_direction.z = -1.0
        elif pressed_keys[pygame.K_a]:
            movement_direction.z = +1.0

        # Calculate rotation matrix and multiply by camera matrix
        rotation = rotation_direction * rotation_speed * time_passed_seconds
        rotation_matrix = Matrix44.xyz_rotation(*rotation)
        cam_matrix *= rotation_matrix

        # Calcluate movment and add it to camera matrix translate
        heading = Vector3(cam_matrix.forward)
        movement = heading * movement_direction.z * movement_speed
        cam_matrix.translate += movement * time_passed_seconds

        # Upload the inverse camera matrix to OpenGL
        glLoadMatrixd(cam_matrix.get_inverse().to_opengl())

        # Light must be transformed as well
        glLight(GL_LIGHT0, GL_POSITION, (0, 1.5, 1, 0))

        map.render()

        pygame.display.flip()
Example #6
0
 def reset_rotation(self):
     self._modelview_matrix[0] = [1.0, 0.0, 0.0, 0.0]
     self._modelview_matrix[1] = [0.0, 1.0, 0.0, 0.0]
     self._modelview_matrix[2] = [0.0, 0.0, 1.0, 0.0]
     glMatrixMode(GL_MODELVIEW)
     glLoadMatrixd(self._modelview_matrix)
Example #7
0
 def paintGL(self):
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     glMatrixMode(GL_MODELVIEW)
     glLoadMatrixd(self._modelview_matrix)
Example #8
0
 def load_hardware(self) :
   ''' Load the current matrix instance as the, display, MODELVIEW matrix. '''
   
   glMatrixMode(GL_MODELVIEW)
   glLoadMatrixd(self.main_matrix)