6DOF Camera

I’m curious if anyone out there has some example code they wouldn’t mine sharing of a 6 DOF camera as used in a flight / space sim, or more appropriately a game like Descent.

Most of the examples I’m finding simply use base.camera.setHpr() to control the camera, but as I understand it, for a true 6 DOF camera you shouldn’t be using Euler angles, you should be multiplying Quaternions to get your new camera rotation.

Does anyone have any examples of this?

Found a similar example here:

[url]Need help with controling my vehicle's flight with the mouse]

I can’t believe how easy this is. I just got started with panda, and I only have a basic understanding of quaternions and vector math, and I got it working with the task below.

def update_player(self, task):
        """ handles player movement"""
        pointer = base.win.getPointer(0)
        x = pointer.getX()
        y = pointer.getY()
        #Reset pointer position
        if base.win.movePointer(0, 300, 300):
            #get amount cursor moved
            x = x - 300 
            y = y - 300 
            quat = base.camera.getQuat()
            upQ = copy.copy(quat)
            rightQ = copy.copy(quat)
            #forwardQ = copy.copy(quat)
            up = quat.getUp()
            right = quat.getRight()
            forward = quat.getForward()
            upQ.setFromAxisAngle((x * self.MOUSESENSITIVITY * -1), up)
            rightQ.setFromAxisAngle(y * self.MOUSESENSITIVITY, right)
            #forwardQ.setFromAxisAngle(45, right)
        return task.cont

I’m really loving this engine.

maybe a silly question… but wouldnt it work for you to rotate the camera relative to itself?


base.camera.setH(base.camera, x * self.MOUSESENSITIVITY * -1)
base.camera.setP(base.camera, y * self.MOUSESENSITIVITY )

if not, glad you know your way with quaternion :slight_smile:
in most cases lookAt and setHpr will be able to do pretty much everything.

As I understand it if you do your rotation like that you get what’s called Gimbal Lock. It’s the difference between rotating with 3 fixed points (HPR) and rotating freely in 3d space.

For a regular FPS, the 3 gimbals are good enough, because your horizon is always fixed.