661
Support / How to set a pivot point on the camera?
« on: November 04, 2005, 02:43:45 am »
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.
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.
Code: [Select]
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]