How to set a pivot point on the camera?

Started by Melssj5, October 22, 2005, 08:01:19 PM

Previous topic - Next topic

Melssj5

Well, the Subject says all. I want to set a pivot point to the camera, I want to move the camera on cirlces with the centrer placed on another place, like moving on the perimeter of a cirlce. How can I do that.
Nada por ahora

rolz

cameraHeight - how far the camera is
cameraZAngle - increase/decrease to move around the object
cameraXAngle  - increase / decrease to look up/down


           SimpleVector pos = new SimpleVector(myCenter);
           pos.z += cameraHeight;
           float cameraZAngle = this.cameraZAngle;

           //place camera
           SimpleVector y = new SimpleVector(0, cameraHeight / 2.5, 0);
           y.rotateZ(cameraZAngle);
           pos.add(y);

           //rotate camera
           camera.getBack().setIdentity();
           camera.rotateZ(cameraZAngle);
           camera.rotateY((-(float) Math.PI));
           camera.rotateX(cameraXAngle);

           //check placement boundaries here
           camera.setPosition(pos);
Regards,
Andrei

Melssj5

Hi, I tried to do it by myself not even loking your way, and it works bad. It only turns the half before returning to the initial point. I am managing the angle on the arc rotation. I left my code here for help.

r=radius
teta=angle
derecha=right

The problem is that between -90 and 90º, it works well, but when it must go up from 90º it returns to -90. Its a trigonometric problem. But I dont know how to do it. I will try rolz way but I really will apreciate a help for this.


if (derecha) {
           Camera temp=mundo.getCamera ();
           float x=0;
           float z=0;
           float r;
           float tempx;
           float tempz;
           float teta;
           
           tempx=temp.getPosition ().x;
           tempz=temp.getPosition ().z;
           teta=(float) Math.atan(tempz/tempx);
           
           r=(float) Math.sqrt (tempx*tempx+tempz*tempz+temp.getPosition ().y*temp.getPosition ().y);
           
           
           //System.out.println (""+teta*180/3.14159256);
           x=(float) (r/Math.sqrt(1+Math.pow (Math.tan(teta+0.02), 2)));
           z=(float) (x*Math.tan (teta+0.02));
           
           
           mundo.getCamera ().setPosition (x, temp.getPosition ().y, z);
           mundo.getCamera ().lookAt (new SimpleVector (0, 0, 0));
       }
[/code]
Nada por ahora

Melssj5

I dont understand rolz answer, My programming skills are not good enough. What does the getBack method???

and the setIdentity one?

I find a easy way any way, I will place the camera on the center of the object and after that I will rotateY, later I will move out the radius distance.
Nada por ahora

Melssj5

!!!!!!! it was so easy, the problem was that I was trying to discover the warm water again, I mean that I wasnt using things already implementes on the engine like the lenght () method.

Now I post the code for turnig left and right using the (0, 0, 0) as pivot center.


   public void rotateLeft () {
       Camera temp=mundo.getCamera ();
       float radio=temp.getPosition ().length ();
       temp.setPosition (0, 0, 0);
       temp.rotateY (-0.02f);
       temp.moveCamera (Camera.CAMERA_MOVEOUT, radio);
   }
   
   public void rotateRight () {
       Camera temp=mundo.getCamera ();
       float radio=temp.getPosition ().length ();
       temp.setPosition (0, 0, 0);
       temp.rotateY (0.02f);
       temp.moveCamera (Camera.CAMERA_MOVEOUT, radio);
   }


I hope that someone finds this helpfull.
Nada por ahora