Exemple #1
0
    def __init__(self, pos=DEFAULT_POS, vpn=DEFAULT_VPN, up=DEFAULT_UP, \
                 moveSpeed=DEFAULT_MOVESPEED, rotateSpeed=DEFAULT_ROTATESPEED):
        # Cacheable: keep track of observers
        self.__dict__['observers'] = []

        self.pos = pos
        self.vpn = normalize3D(vpn)
        self.up = normalize3D(up)
        self.moveSpeed = moveSpeed
        self.rotateSpeed = rotateSpeed

        # Tracking parameters that are used when drawing
        self.trackPosOffset = None
        self.trackRotMatrix = None
Exemple #2
0
    def __getattr__(self, name):
        """dynamic attributes:
           - Camera.yz: the vector mutually perpendicular to up and vpn
           - Camera.lookAt: world-space point the camera looks at"""
        # cross product lifted from
        # http://www.physics.uoguelph.ca/tutorials/torque/Q.torque.cross.html
        if name == 'yz':
            yz = (  # Cx = AyBz - AzBy
                    self.vpn[Y_AXIS] * self.up[Z_AXIS] - \
                    self.vpn[Z_AXIS] * self.up[Y_AXIS],  # Cy = AzBx - AxBz
                    self.vpn[Z_AXIS] * self.up[X_AXIS] - \
                    self.vpn[X_AXIS] * self.up[Z_AXIS],  #Cz = AxBy - AyBx:
                    self.vpn[X_AXIS] * self.up[Y_AXIS] - \
                    self.vpn[Y_AXIS] * self.up[X_AXIS])
            return normalize3D(yz)
        elif name == 'lookAt':
            # Add the vpn to the current world-space position
            return (self.pos[0] + self.vpn[0],
                    self.pos[1] + self.vpn[1],
                    self.pos[2] + self.vpn[2])

        raise AttributeError, "Camera object has no attribute '%s'" % (name)
Exemple #3
0
#!/usr/bin/python2.3

from math import tan, atan, atan2, cos, acos, sin, asin, sqrt, pi
from utilities import diff3D, dist3D, add3D, normalize3D, rotate3D, dot_product
import sys

try:
    from twisted.spread import pb
except ImportError:
    from fakepb import pb

DEFAULT_POS = (0.0, 0.0, 40.0)
DEFAULT_TAIL = normalize3D((-2.0, -2.0, 0.0))
DEFAULT_ROT = (1.0, 0.0, 0.0, 0.0,
               0.0, 1.0, 0.0, 0.0,
               0.0, 0.0, 1.0, 0.0,
               0.0, 0.0, 0.0, 1.0)
DEFAULT_COLOR = (0.6, 0.6, 0.9)
DEFAULT_ALPHA = 1.0


class Cursor(pb.Cacheable):
    """
    A 3D active cursor, designed to be controlled by
    an active 3D input device.
    Important to note - the cursor's native position is relative to
    the camera and is in camera coordinates (i.e. +Z is away from the
    camera, +X is on camera's left)
    """

    def __init__(self, pos=DEFAULT_POS, rot=DEFAULT_ROT, color=DEFAULT_COLOR, alpha=DEFAULT_ALPHA):