Camera following ship in space (6 Degrees of Freedom)

This is the type of camera I want to achieve - http://youtu.be/3P5rkSh2jJE#t=1m50s - when it stops being first person and follows behind the submarine, though in my demo it will be a space ship. I figured that I should start simple and make one for a racing type of demo, where the camera doesn’t need to roll according to the vehicle’s orientation, but definitely chases it. Here’s an example - https://www.youtube.com/watch?v=4qUMQ04xuCI - notice how the vehicle turns first and then the camera chases it to stay behind.

So far I’ve done this:

if (FOLLOW_BEHIND):
			wantPos = render.getRelativePoint(self.fighter, Point3(0, DISTANCE, 0))
		else:
			wantPos = render.getRelativePoint(self.fighter, Point3(0, -DISTANCE, 0))
		lerpPos = base.camera.getPos() + (wantPos - base.camera.getPos()) * globalClock.getDt() * DAMPING
		base.camera.setPos(lerpPos)
		
		base.camera.lookAt(self.fighter)

And it works for the racing demo, but what if I wanted to make it follow a ship in space, how would I make the rotation of the camera follow the ship’s rotation? Because the control is like this:

if base.win.movePointer(0, base.win.getXSize()/2, base.win.getYSize()/2):
			if (self.keyMap["roll-left"] != 0):
				self.lookVec.setZ(self.lookVec.getZ() + 1)
			if (self.keyMap["roll-right"] != 0):
				self.lookVec.setZ(self.lookVec.getZ() - 1)
				
			self.lookVec = Vec3((x - base.win.getXSize()/2) * -0.1, (y - base.win.getYSize()/2) * 0.1, self.lookVec.getZ())
			self.movQuat.setHpr(self.lookVec)
			self.fighter.setQuat(self.fighter, self.movQuat)

I may be missing something–I’m a little dozy today–but the only problems that I see offhand are the use of a hard-coded “up” vector in the call to “getRelativePoint” and no indication of an “up” vector for the camera in the call to “lookAt”.

In “getRelativePoint”, I think that you might be able to simply use “self.fighter.getQuat().getUp()”; in fact, thinking about it, you should be able to dispense with “getRelativePoint” entirely and just use “wantPos = self.fighter.getQuat(render).getUp()”. (Note, however: if you find that this gives you the wrong direction, try other directions–that is, “getRight” and “getForward”–and the negations of these, as your model’s orientation may not be as expected.)

With regards to “lookAt”, I see that there is a version that takes an “up” vector, but “headsUp” might be a better bet.

Thanks, I made some adjustments according to your explanation and got this:

if (FOLLOW_BEHIND):
			wantVec = self.fighter.getQuat(render).getForward()
			wantPos = self.fighter.getPos() + wantVec
		else:
			wantVec = self.fighter.getQuat(render).getBack()
			wantPos = self.fighter.getPos() + wantVec
		lerpPos = base.camera.getPos() + (wantPos - base.camera.getPos()) * globalClock.getDt() * DAMPING
		base.camera.setPos(lerpPos)
		
		base.camera.lookAt(self.fighter.getPos(), self.fighter.getQuat(render).getUp())

It works as I intended, so thank you.