www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: bionicoz on April 20, 2011, 09:51:06 am

Title: Moving and rotating the cam
Post by: bionicoz on April 20, 2011, 09:51:06 am
I'm sorry but I need your help another time. I'm writing a method that smooth move the cam to a point in the 3Dworld. For now it's frame based, and the trajectory and speed are linear.
Code: [Select]
public void flyTo(SimpleVector s, float speed) {...}The moving part seems to be ok
Code: [Select]
SimpleVector whereIam = this.getPosition();
SimpleVector direction = s; //the point where I have to go
direction.sub(whereIam);
if (direction.length() > PROXIMITY) { //I stop PROXIMITY units before the point
this.moveCamera(direction, speed);
}
but I have problems with the rotating part.
using calcAngle() give me always positive result, so in i have to rotate 15° left, what happens is that I rotate 345° right. Is there a better way to do that? I think using rotation vector, but i don't clearly understand how do they works.
Ty as always,
Bio.


 
Title: Re: Moving and rotating the cam
Post by: EgonOlsen on April 20, 2011, 12:19:11 pm
...so in i have to rotate 15° left, what happens is that I rotate 345° right
What's the problem with that as long as the outcome is the same?
Title: Re: Moving and rotating the cam
Post by: bionicoz on April 20, 2011, 12:36:12 pm
The problem subsists because I do that step by step. All the information I get (but it's probably my fault) is that my position has an angle of, let's say, 15° with the destination, but calcAngle() tell me 15° even if the angle is 345°.
I rotate the cam with something like that
Code: [Select]
this.rotateCameraAxis(this.getYAxis(), speed);I would like to rotate with -speed if the angle is > of 180°.
Any suggestions?


 
Title: Re: Moving and rotating the cam
Post by: Kaiidyn on April 20, 2011, 05:01:09 pm
im not sure, but could this be related to the fact that (im not sure though) the angles are not 0 - 360 but -180 - 180 ?
Title: Re: Moving and rotating the cam
Post by: bionicoz on April 20, 2011, 05:37:48 pm
Hi, I solved with a really simple check:
Code: [Select]
SimpleVector rotation=this.getDirection();
rotation.y=0; //I don't care about y angle, for now at least
rotation.normalize(rotation);

direction=s;
direction.y=0;
direction.normalize(direction);
float f=(direction.x-rotation.x); //This is the really clever check :D
float angle=direction.calcAngle(rotation);
if ( !(angle>-0.03f && angle<0.03f) ) {
    this.rotateCameraAxis(this.getYAxis(), Math.signum(f)*speed);
} else {
    this.turning = false;
}

Ty all for support.

EDIT: nope, isn't really working as expected :\
Title: Re: Moving and rotating the cam
Post by: Kaiidyn on April 20, 2011, 06:28:39 pm
angle is in radians (correct word?) and not in degrees?
Title: Re: Moving and rotating the cam
Post by: EgonOlsen on April 20, 2011, 08:58:57 pm
This thread deals with the same problem. Maybe it helps: http://www.jpct.net/forum2/index.php/topic,1762.0.html (http://www.jpct.net/forum2/index.php/topic,1762.0.html)
Title: Re: Moving and rotating the cam
Post by: bionicoz on April 21, 2011, 11:19:31 am
That helped a lot, ty Egon.