Exemplo n.º 1
0
    def tumble(self, hdelta, vdelta):
        """
        This is equivalent of rotating the camera around it's target point while maintaining the direction vector; to reflect the change in view the camera will be rotated by the additive inverse of the deltas.

        @param hdelta The horizontal delta (the up vector rotation)
        @param vdelta The vertical delta (the right vector rotation)

        @see Maya Rotation defintions (http://download.autodesk.com/global/docs/maya2013/en_us/index.html?url=files/Viewing_the_scene_Tumble_track_dolly_or_tilt_the_view.htm,topicNumber=d30e15213)
        @see Rotation algorithm (http://gamedev.stackexchange.com/questions/20758/how-can-i-orbit-a-camera-about-its-target-point)
        """
        # Get the current look at vector (e.g inverse direction)
        idirection = self._position - self._target

        # Rotate the y-axis (aka 'up' vector) which is the plane normal coming out of the x-z plane.
        # The x-z plane is typically the horizontal plane and the yaw angle is measured by the horizontal delta parameter.
        hrotation  = - hdelta * self._pixelradians
        M          = Matrix4x4.rotation( hrotation, self.__camera_upvector__ )
        idirection = M * idirection
        self._up   = M * self._up
        right      = (self._up ^ idirection).normalized()

        # Now rotate the x-axis (aka 'right' vector) which is the plane normal coming out of the y-z plane.
        # The y-z plane is typically the vertical plane and the pitch angle is measured by the vertical delta parameter.
        vrotation  = - vdelta * self._pixelradians
        M          = Matrix4x4.rotation( vrotation, right )
        idirection = M * idirection
        self._up   = M * self._up

        # Update the camera's position
        self._position = self._target + idirection
        
        self._updateProjectionMatrix()
Exemplo n.º 2
0
    def _generateMatrix(self):
        """
        Generates a transformation matrix from internal data.

        @returns A Matrix4x4 representation of the transformation component.
        """
        radians = math.radians(self.angle)
        return Matrix4x4.rotation(radians, self.__axis, self.__point)
Exemplo n.º 3
0
    def _generateMatrix(self):
        """
        Generates a transformation matrix from internal data.

        @returns A Matrix4x4 representation of the transformation component.
        """
        radians = math.radians(self.angle)
        return Matrix4x4.rotation(radians, self.__axis, self.__point)
Exemplo n.º 4
0
    def paint_enter(self):
        """
        Implements the GLNodeAdapter's paint_enter method for an OpenGL Render operation.
        """
        GL.glPushAttrib(GL.GL_ENABLE_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_LINE_BIT | GL.GL_CURRENT_BIT)
        GL.glPushClientAttrib(GL.GL_CLIENT_VERTEX_ARRAY_BIT)
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        GL.glMultMatrixf(self._node.matrix().data())
        GL.glColor(self._node.color.getRgbF())
        
        # The positive Z-axis is the default direction for Cylinder Quadrics in OpenGL.
        # If our vector is not parallel to the z-axis, e.g. (0, 0, Z), then rotate it.
        #   1) Get a normal from the z-v plane
        #   2) Get the angle inbetween z-v on the plane (see vector dot product)
        #   3) Rotate the normal by that angle.
        v = self._node.axis
        m = Matrix4x4.identity()
        if v.x != 0 or v.y != 0:
            zaxis  = Vector3D(0,0,1)
            angle  = zaxis.angle(v)
            normal = zaxis.crossproduct(v, True)
            m *= Matrix4x4.rotation(angle, normal)

        # The positive Z-axis is the default direction fo Cylinder Quadrics in OpenGL.
        # If our z is negative, we need to flip the cylinder
        if v.z < 0:
            yaxis  = Vector3D(1,0,0)
            m *= Matrix4x4.rotation(math.radians(180), yaxis)       
        GL.glMultMatrixf(m.data())

        q = self.__quadric
        r = self._node.radius
        h = self._node.length
        sl = self._node.slices
        st = self._node.stacks
        lp = self._node.loops
        GLU.gluQuadricDrawStyle (q, GLU.GLU_FILL)
        GLU.gluQuadricNormals (q, GLU.GLU_SMOOTH)
        GLU.gluQuadricOrientation(q, GLU.GLU_OUTSIDE)
        self._glcylinder(q, r, h, sl, st, lp)
Exemplo n.º 5
0
    def roll(self, delta):
        """
        Executes a rotation operation around the z-axis

        This is equivalent of rotating the camera around it's z-axis; to reflect the change in view the camera will be rotated by the additive inverse of the delta.

        @param delta The rotation delta (the change in rotating around the direction vector)
        """
        # Get the current look at vector (e.g inverse direction)
        direction = self._target - self._position

        # Rotate the z-axis (aka 'look at' vector) which is the plane normal coming out of the x-y plane.
        # Since we're rotating the x-y plane, the concept of vertical or horizontal delta doesn't apply; it's
        # a straight up spin of the look at vector
        rotation = - delta * self._pixelradians
        M        = Matrix4x4.rotation( rotation, direction )
        self._up = M * self._up
        
        self._updateProjectionMatrix()