コード例 #1
0
ファイル: transform.py プロジェクト: freneticmonkey/Epsilon
    def look_at(self, eye, to, up):
        if not self.position == eye or (self._look_at_position is not None and not self._look_at_position == to):
            mat = Matrix4.new_look_at(eye, to, up)
            r = Quaternion.new_rotate_matrix(mat)

            self.rotate(r, Space.WORLD)
            self.position = eye
            self._look_at_position = to

            self._need_update()
コード例 #2
0
ファイル: transform.py プロジェクト: freneticmonkey/Epsilon
    def _update_from_parent(self):
        
        if self._parent:
            
            # update rotation
            parent_rotation = self._parent.rotation
            if self._inherit_rotation:
                # Combine rotation with parent rotation
                self._world_rotation = parent_rotation * self._local_rotation
            else:
                self._world_rotation = self._local_rotation
            
            # update scale
            parent_scale = self._parent.local_scale
            if self._inherit_scale:
                # Scale own position by parent scale
                self._local_scale = parent_scale * self._local_scale
            else:
                self._local_scale = self._local_scale
            
            # Change position vector based on parent's rotation and scale
            self._world_position = parent_rotation * (parent_scale * self._local_position)
            
            # Add altered position vector to parent's position
            self._world_position += self._parent.position

        else:
            # This is the root node.
            self._world_position = self._local_position
            self._world_rotation = self._local_rotation
            self._world_scale    = self._local_scale

        # Create a new world matrix
        rot_matrix = self._world_rotation.get_matrix()
        scale_matrix = Matrix4.new_scale(self._local_scale)
        res = rot_matrix * scale_matrix

        self._world_matrix = Matrix4()
        for i in range(3):
            self._world_matrix[ 4 * i ]     = res[ 4 * i ]
            self._world_matrix[ 4 * i  + 1] = res[ 4 * i + 1]
            self._world_matrix[ 4 * i  + 2] = res[ 4 * i + 2]
            self._world_matrix[ 4 * i  + 3] = 0
        
        tm = Matrix4()
        tm[3] = self._world_position.x
        tm[7] = self._world_position.y
        tm[11] = self._world_position.z

        self._world_matrix = tm * self._world_matrix
            
        self._need_parent_update = False
コード例 #3
0
ファイル: frustum.py プロジェクト: freneticmonkey/Epsilon
 def update_projection_matrix(self):
     #print self
     self._projection_matrix = Matrix4.new_perspective(self._fov, self._aspect, self._near_dist, self._far_dist)