Author Topic: Camera: moveCamera(int mode, float speed)  (Read 3557 times)

Offline rainfalls

  • byte
  • *
  • Posts: 27
    • View Profile
Camera: moveCamera(int mode, float speed)
« on: November 17, 2013, 01:03:29 am »
Hi,

I had this code:

Code: [Select]
cam.setPosition(camLookat);
Logger.log("1  " + cam.getPosition());
cam.moveCamera(Camera.CAMERA_MOVEOUT, 5);
Logger.log("2  " + cam.getPosition());

And then I got the log:

Code: [Select]
1  (-10512.435,409.47632,1982.2085)
2  (-11233.428,366.8882,1982.152)

Why the distance between the two positions were much larger than 5?
In the javadoc, its written like this: "speed - the speed (positional change in units)". Any where I missed some hidden scaling factor?

Thanks.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Camera: moveCamera(int mode, float speed)
« Reply #1 on: November 17, 2013, 10:27:40 am »
There's no way how this can happen except if

  • The code you posted is not the complete code that you are using.
  • Your camera matrix is completely screwed somehow. Please print out camera.getBack() and post the result.

Offline rainfalls

  • byte
  • *
  • Posts: 27
    • View Profile
Re: Camera: moveCamera(int mode, float speed)
« Reply #2 on: November 17, 2013, 03:07:53 pm »
The complete code is too long to post, the part related to Camera is:

Code: [Select]
cam.align(obj); // align camera with an Object3D
cam.rotateCameraX(C.D90); // rotate view
cam.rotateCameraY(C.D90); // rotate view

cam.setPosition(camLookat); // set its position to a SimpleVector camLookat
cam.moveCamera(Camera.CAMERA_MOVERIGHT, offsetH); // move right
cam.moveCamera(Camera.CAMERA_MOVEUP, offsetV); // move up
cam.getPosition(offsetSV); // save the camera's position to a SimpleVector

cam.setPosition(camLookat); // reset its position to camLookat
Logger.log("1  " + cam.getPosition());
Logger.log(cam.getBack().toString());
cam.moveCamera(Camera.CAMERA_MOVEOUT, 5); // move out
Logger.log("2  " + cam.getPosition());
Logger.log(cam.getBack().toString());

The two lines logging cam.getBack() returned this same matrix which I don't understand its meaning:

Code: [Select]
(
-0.01639 8.512504 144.19896 0.0
-4.0E-6 -144.19896 8.512505 0.0
144.45 9.62E-4 0.016362 0.0
0.0 0.0 0.0 1.0
)


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Camera: moveCamera(int mode, float speed)
« Reply #3 on: November 17, 2013, 03:42:12 pm »
That matrix is complete nonsense. I wonder how you created it...which version of jPCT are you using? There was a problem with align() once, but it has been fixed over 3 years ago with 1.19!?

If you aren't using a version that old, could you please:

  • print out cam.getBack(); before the align() call
  • print out obj.getRotationMatrix(); before the align() call
  • print out obj.getScale(); before the align() call
  • print out cam.getBack(); after the align() call

 ???
« Last Edit: November 17, 2013, 04:54:05 pm by EgonOlsen »

Offline rainfalls

  • byte
  • *
  • Posts: 27
    • View Profile
Re: Camera: moveCamera(int mode, float speed)
« Reply #4 on: November 17, 2013, 04:10:55 pm »
That matrix is complete nonsense. I wonder how you created it...which version of jPCT are you using? There was a problem
  • print out cam.getScale(); before the align() call

Did you mean obj.getScale()? I can't find Camera has this method.

And I'm using jpct version: jpct.1.27.2013.07.04

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Camera: moveCamera(int mode, float speed)
« Reply #5 on: November 17, 2013, 04:12:46 pm »
Yes, sorry. I mean obj.getScale().

Offline rainfalls

  • byte
  • *
  • Posts: 27
    • View Profile
Re: Camera: moveCamera(int mode, float speed)
« Reply #6 on: November 17, 2013, 07:33:35 pm »
Hi Egon,

Thanks for your suggestions. The camera problem did originate from the object's rotationMatrix which I read from my collada model. I added rotationMatrix.orthonormalize() and the camera worked properly.