Esempio n. 1
0
    def move(self, forward_amount: float = 0.0, right_amount: float = 0.0, up_amount: float = 0.0):
        """Offsets the camera's position incrementally.

        :param forward_amount: distance to move along the camera's current forward heading.
        :param right_amount: distance to move along a right angle to the camera's current forward heading.
        :param up_amount: distance to move along the camera's up vector.
        """
        self._look_at += self._up * up_amount

        # Move forward/back and left/right
        pitch = self._pitch
        yaw = self._yaw
        camera_offset = util.Vector3(math.cos(yaw), math.sin(yaw), math.sin(pitch))

        heading = math.atan2(camera_offset.y, camera_offset.x)
        half_pi = math.pi * 0.5

        self._look_at += util.Vector3(
            right_amount * math.cos(heading + half_pi),
            right_amount * math.sin(heading + half_pi),
            0.0)

        self._look_at += util.Vector3(
            forward_amount * math.cos(heading),
            forward_amount * math.sin(heading),
            0.0)
Esempio n. 2
0
 def __init__(self, look_at: util.Vector3, up: util.Vector3, distance: float, pitch: float, yaw: float):
     # Camera position and orientation defined by a look-at positions
     # and a pitch/and yaw to rotate around that along with a distance
     self._look_at = look_at
     self._pitch = pitch
     self._yaw = yaw
     self._distance = distance
     self._pos = util.Vector3(0, 0, 0)
     self._up = up
     self._update_pos()
Esempio n. 3
0
    def _update_pos(self):
        """Calculate camera position based on look-at, distance and angles."""
        cos_pitch = math.cos(self._pitch)
        sin_pitch = math.sin(self._pitch)
        cos_yaw = math.cos(self._yaw)
        sin_yaw = math.sin(self._yaw)
        cam_distance = self._distance
        cam_look_at = self._look_at

        self._pos = util.Vector3(
            cam_look_at.x + (cam_distance * cos_pitch * cos_yaw),
            cam_look_at.y + (cam_distance * cos_pitch * sin_yaw),
            cam_look_at.z + (cam_distance * sin_pitch))
#: A default window resolution provided for OpenGL Vector programs
#: 800x600 is large enough to see detail, while fitting on the smaller
#: end of modern monitors.
default_resolution = [800, 600]

#: A default projector configurate provided for OpenGL Vector programs
#: A Field of View of 45 degrees is common for 3d applications,
#: and a viewable distance range of 1.0 to 1000.0 will provide a
#: visible space comparable with most physical Vector environments.
default_projector = opengl.Projector(fov=45.0,
                                     near_clip_plane=1.0,
                                     far_clip_plane=1000.0)

#: A default camera object provided for OpenGL Vector programs.
#: Starts close to and looking at the charger.
default_camera = opengl.Camera(look_at=util.Vector3(100.0, -25.0, 0.0),
                               up=util.Vector3(0.0, 0.0, 1.0),
                               distance=500.0,
                               pitch=math.radians(40),
                               yaw=math.radians(270))

#: A default light group provided for OpenGL Vector programs.
#: Contains one light near the origin.
default_lights = [
    opengl.Light(ambient_color=[1.0, 1.0, 1.0, 1.0],
                 diffuse_color=[1.0, 1.0, 1.0, 1.0],
                 specular_color=[1.0, 1.0, 1.0, 1.0],
                 position=util.Vector3(0, 32, 20))
]

# Global viewer instance.  Stored to make sure multiple viewers are not