jPCT-AE - a 3d engine for Android > Support

camera rotating problem demo

(1/1)

mgrabul:
Hi I have a problem with the rotation of the camera in the demo code at http://www.jpct.net/jpct-ae/, it seams that the camera rotates around its own axis i can't make it rotate around a paralel axis from the world.
for example if I rotate the camera down or up and then right or left I get a view that has not a paralel horizot to the first view horizont.
    this is my code:


      public void onDrawFrame(GL10 gl) {

         try {
            if (!stop) {
               if (paused) {
                  Thread.sleep(500);
               } else {
                  Camera cam = world.getCamera();
                  if (turn != 0) {
                     world.getCamera().rotateY(-turn);
                  }

                  if (touchTurn != 0) {
                     world.getCamera().rotateY(touchTurn);
                     touchTurn = 0;
                  }

                  if (touchTurnUp != 0) {
                     world.getCamera().rotateX(touchTurnUp);
                     touchTurnUp = 0;
                  }

                  if (move != 0) {
                     world.getCamera().moveCamera(cam.getDirection(), move);
                  }

                  fb.clear();
                  world.renderScene(fb);
                  world.draw(fb);
                  blitNumber(lfps, 5, 5);

                  fb.display();

                  sun.rotate(new SimpleVector(0, 0.05f, 0), plane.getTransformedCenter());

                  if (System.currentTimeMillis() - time >= 1000) {
                     lfps = (fps + lfps) >> 1;
                     fps = 0;
                     time = System.currentTimeMillis();
                  }
                  fps++;
                  ind += 0.02f;
                  if (ind > 1) {
                     ind -= 1;
                  }
               }
            } else {
               if (fb != null) {
                  fb.dispose();
                  fb = null;
               }
            }
         } catch (Exception e) {
            Logger.log("Drawing thread terminated!", Logger.MESSAGE);
         }
      }

raft:
that's right. Camera.rotateXXX(..) methods rotates camera around it's position. in other words camera's rotation pivot is always its position.
if you need to rotate camera around and arbitrary pivot, you should do the math yourself. it's not that hard. some trigonometry will be enough.

or alternatively, you can add a dummy child to a dummy object, rotate parent object as required and set camera's position to child object's position.

mgrabul:

--- Quote from: raft on September 17, 2010, 11:52:11 pm ---that's right. Camera.rotateXXX(..) methods rotates camera around it's position. in other words camera's rotation pivot is always its position.
if you need to rotate camera around and arbitrary pivot, you should do the math yourself. it's not that hard. some trigonometry will be enough.

or alternatively, you can add a dummy child to a dummy object, rotate parent object as required and set camera's position to child object's position.

--- End quote ---

Thanks for the replay
I'am new to open gl and the jpct class so I am sorry for the stupid questions:)
I tried this code for rotating left and right byt i stil get the same effect.
(the different line is the line whit the ****)
if (StartEngine.touchTurn != 0) {
                  
         ****   world.getCamera().rotateCameraAxis(new SimpleVector(0.0,1.0,0.0),StartEngine.touchTurn);
            Y=world.getCamera().getYAxis();
            X=world.getCamera().getXAxis();
         StartEngine.touchTurn = 0;
               }
how can I compute the roating vector ?
can you please tell me what am I doing wrong?
or show me how it is done
p.s
for the Y  vector when I am rottating around X(rotatin down up) i am geting this values:
for down rotatin:
Y AXIS(3182): (0.0,0.999803,0.019883258)
Y AXIS(3182): (0.0,0.999803,0.019883258)
Y AXIS(3182): (0.0,0.99955416,0.029880127)
Y AXIS(3182): (0.0,0.99955416,0.029880127)
and for up rottating:
Y AXIS(3182): (0.0,0.99955416,0.029880127)
Y AXIS(3182): (0.0,0.99955416,0.029880127)
Y AXIS(3182): (0.0,0.999803,0.019883258)
Y AXIS(3182): (0.0,0.999803,0.019883258)

raft:
Camera.rotateCameraAxis(..) isn't what you want. it rotates camera around an arbitrary axis but still uses camera position as rotation pivot.

think this way: rotateCameraX rotates camera around x axis. roateCameraAxis rotates around given axis. not around given point

Navigation

[0] Message Index

Go to full version