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:

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()
up.normalize()
right.normalize()
forward.normalize()

upQ.setFromAxisAngle((x * self.MOUSESENSITIVITY * -1), up)
rightQ.setFromAxisAngle(y * self.MOUSESENSITIVITY, right)
#forwardQ.setFromAxisAngle(45, right)

base.camera.setQuat(quat.multiply(upQ.multiply(rightQ)))

I’m really loving this engine.

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

like:

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