Author Topic: using camera.lookAt  (Read 6172 times)

Offline acorn98

  • byte
  • *
  • Posts: 46
    • View Profile
using camera.lookAt
« on: October 31, 2005, 05:26:16 am »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
using camera.lookAt
« Reply #1 on: October 31, 2005, 11:08:55 pm »
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)?

Offline acorn98

  • byte
  • *
  • Posts: 46
    • View Profile
using camera.lookAt
« Reply #2 on: November 01, 2005, 01:23:50 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
using camera.lookAt
« Reply #3 on: November 01, 2005, 08:15:48 am »
I that case, you may either use Camera.getDirection() for this or get the rotation matrix directly from the camera like so:

Code: [Select]

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.

Offline acorn98

  • byte
  • *
  • Posts: 46
    • View Profile
using camera.lookAt
« Reply #4 on: November 02, 2005, 04:28:07 am »
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  :)