Author Topic: plz help with Camera rotation aligned with orbiting object.  (Read 2290 times)

Offline stormp

  • byte
  • *
  • Posts: 38
    • View Profile
Hi, 

I wanted to help visualize my camera movements / rotations as I was getting some strange results.

I have made a simple applet (source link included at the bottom) which has a small cube orbiting a larger cube.  the cube movements are manually controlled by pressing the arrow keys and you can toggle the camera by pressing 1 for follow mode 2 for free float and R to reset the cam to it's original position.

The little cube rotates around the cube if you press UP and DOWN.  If you press 1 to set the camera to follow behind the little cube, the rendering seems to mess up (inversed).

I've been searching on the forums for reference to this problem but I can't seem to figure out how to fix it.   :(

This seemed my best bet: http://www.jpct.net/forum2/index.php/topic,641.0.html
but when i tried to use the invert3x3() it didn't seem to work.

I also tried the "follower" code with the same result: http://www.jpct.net/forum2/index.php/topic,616.msg3214.html#msg3214

If anyone can help out I'd appreciate it greatly.

Thanks:

cube rotation:
Code: [Select]
if(mvSpinLeft)                            // Cube2 orbit left
{
     objCube2.rotateAxis(objCube2.getYAxis(), rotSpeed);
} // if

if(mvSpinRight)                           // Cube2 obrit right
{
      objCube2.rotateAxis(objCube2.getYAxis(), -rotSpeed);
}  // if

camera follow small cube:
Code: [Select]
if(modeFollow)
{
      theCamera.setPositionToCenter(objCube2);                    // place camera inside cube2
      theCamera.align(objCube2);                                  // Copy the cube2 positive Z-axis.
      theCamera.lookAt(objCube1.getTransformedCenter());          // look at cube 1 center.
      theCamera.moveCamera(Camera.CAMERA_MOVEOUT, 50.0f);         // put camera behind cube2 a little

      // Problem is here?
}  // if


TEMPORARY HOSTED APPLET:
http://154.5.173.123:8001/test/index.html


FULL SOURCE:  (in case it might be useful to someone in the future) :)
http://154.5.173.123:8001/test/tester3d.java

« Last Edit: June 17, 2007, 12:25:01 am by stormp »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11749
    • View Profile
    • http://www.jpct.net
Re: plz help with Camera rotation aligned with orbiting object.
« Reply #1 on: June 17, 2007, 06:34:55 pm »
It's caused by the lookAt()-call of the camera. The lookAt() ensures that you look at the specified point but due to the way it works, it doesn't ensure that you do so in the specific orientation. There are extreme cases, where it flips...which is waht you see here.
However, i don't think that the lookAt() is even necessary in your case. I haven't tried it, but judging from the way the little box moves around the larger one, i would say that the outcome will look the same when using the align only. If not, maybe a fixed rotation around X with 90 degrees or something will make the camera face into the right direction.