Author Topic: camera basics  (Read 3032 times)

Offline raft

  • quad
  • ******
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
camera basics
« on: February 25, 2005, 04:27:02 pm »
hi,

i am moving camera in a simple world (an xz plane at origin) with

Code: [Select]
SimpleVector normalizedDirection = direction.normalize();
world.checkCameraCollisionEllipsoid(normalizedDirection, COLLISION_ELLIPSOID, moveSpeed, RECURSE_DEPTH);

when i move camera down (+y) i expected it go down to COLLISION_ELLIPSOID.y but this is not the case. independent of ellipsoid.y it moves to ellipsoid.z + a small amount depending on move speed.

couldnt get why ?

Code: [Select]
r a f t
RECURSE_DEPTH : 5
moveSpeed : 2 - 10

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
camera basics
« Reply #1 on: February 25, 2005, 05:55:56 pm »
What is "direction"? A SimpleVector like (0,1,0)? The behaviour that it moves according to moveSpeed is correct. The ellipsoid just defines the bounds of the object/camera, not the translation that it makes when moving. That's what moveSpeed is for.
Regarding your directional problem, i assume that you are applying a rotation to the level, so that object space and world space don't match anymore (for example: You do a rotateZ(a) on an object and the same on the camera (explicit of implicit (lookAt() or similar may cause this). This looks exactly the same as if you hadn't rotated anything at all, but when moving in world space (which the camera does), the outcome will be different).  If this is the case, you either have to apply this rotation to your direction vector too, or rotate the level object permanently by using the rotateMesh()-approach.

Edit: As a rule of thumb: Make sure that object space and world space match (except for translations..they don't matter in this case) for your world/level/main object. That makes life a lot easier.

Offline raft

  • quad
  • ******
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
camera basics
« Reply #2 on: February 25, 2005, 09:34:30 pm »
still unclear :(

in our case direction is (0, -1, 0)  (upwards) and move speed is negative resulting in moving downwards.

this was the code piece creating and rotating the plane to make it an xz plane (to which you can approach up to ellipsoid.z)
Code: [Select]
       
map = Primitives.getPlane(6, 100);
map.rotateX((float)(Math.PI / 2f));


as you suggested i added a rotate mesh:
Code: [Select]
       
map = Primitives.getPlane(6, 100);
map.rotateX((float)(Math.PI / 2f));
map.rotateMesh();


very strange, it resulted in a xy plane facing -z (can be seen best when camera direction is 0, 0, -1) and can be approached upto to ellipsoid.z (collision radius is correct in this case)  it behaved like i made a rotateY(pi) :?: :?:

what s up ?
Code: [Select]
r a f t
damn ! i was almost good at linear algebra

Offline raft

  • quad
  • ******
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
camera basics
« Reply #3 on: February 26, 2005, 02:01:42 pm »
here it is. one must reset rotation matrix after rotating mesh, without it the result is as rotating it twice  8)

Code: [Select]
       
map = Primitives.getPlane(6, 100);
map.rotateX((float)(Math.PI / 2f));
map.rotateMesh();
map.setRotationMatrix(new Matrix());


all is well now, both appereance and collision radius. men, it is really a great library !

Code: [Select]
r a f tdamn it ! i almost gone mad

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
camera basics
« Reply #4 on: February 26, 2005, 02:07:08 pm »
Quote from: "raft"
here it is. one must reset rotation matrix after rotating mesh, without it the result is as rotating it twice  8)
Yes, i should have mentioned this... :wink: