Moving and rotating the cam

Started by bionicoz, April 20, 2011, 09:51:06 AM

Previous topic - Next topic

bionicoz

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.
public void flyTo(SimpleVector s, float speed) {...}
The moving part seems to be ok

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.



EgonOlsen

Quote from: bionicoz on April 20, 2011, 09:51:06 AM
...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?

bionicoz

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
this.rotateCameraAxis(this.getYAxis(), speed);
I would like to rotate with -speed if the angle is > of 180°.
Any suggestions?


 

Kaiidyn

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 ?
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer's intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch

bionicoz

#4
Hi, I solved with a really simple check:
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 :\

Kaiidyn

angle is in radians (correct word?) and not in degrees?
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer's intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch

EgonOlsen


bionicoz