using camera.lookAt

Started by acorn98, October 31, 2005, 05:26:16 AM

Previous topic - Next topic

acorn98

Hi Helge,

I'm trying to point a camera at an object with this:

camera.lookAt(obj.getTransformedCenter());

It works, but afterwards my camera movement develops a fault. If I move the camera forward, the camera moves along the 'old' path (the path I would expect it to take if I hadn't performed the lookAt() ).

Any idea what might be happening?

EgonOlsen

I can't verify this. How exactly are you moving the camera, i.e. moveCamera(int mode, float speed) or moveCamera(SimpleVector direction, float speed)?

acorn98

I'm actually using world.checkCameraCollisionEllipsoid().

I'm using a matrix (playerDirection) to move the camera forwards using world.checkCameraCollisionEllipsoid(), like this:

tempVector=playerDirection.getZAxis();
..
if (!theWorld.checkCameraCollisionEllipsoid(tempVector, ELLIPSOID_RADIUS, MOVE_SPEED, 4)){
   //ok, moved the camera
}

But in the code where I perform the camera.lookAt(), I think I need to somehow rotate playerDirection to match the new orientation of the camera. I'll have a play around and see what turns up.

EgonOlsen

I that case, you may either use Camera.getDirection() for this or get the rotation matrix directly from the camera like so:


Matrix pd=w.getCamera().getBack();
pd=pd.invert3x3();


However, i assume that movement should stay parallel to the floor even when looking slightly up or down to the object in question. Then you have to maintain the player's rotation matrix yourself, i'm afraid. That's what the fps example does too.

acorn98

Thanks - that code snippet worked perfectly, and movement parallel to the floor seems to be unaffected.

I tried using getBack() last night, but without invert3x3(), and had some strange results  :)