Author Topic: Moving and rotating the cam  (Read 4716 times)

Offline bionicoz

  • byte
  • *
  • Posts: 10
    • View Profile
Moving and rotating the cam
« 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.


 

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Moving and rotating the cam
« Reply #1 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?

Offline bionicoz

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Moving and rotating the cam
« Reply #2 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?


 

Offline Kaiidyn

  • long
  • ***
  • Posts: 103
    • View Profile
Re: Moving and rotating the cam
« Reply #3 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 ?
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

Offline bionicoz

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Moving and rotating the cam
« Reply #4 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 :\
« Last Edit: April 20, 2011, 06:02:51 pm by bionicoz »

Offline Kaiidyn

  • long
  • ***
  • Posts: 103
    • View Profile
Re: Moving and rotating the cam
« Reply #5 on: April 20, 2011, 06:28:39 pm »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Moving and rotating the cam
« Reply #6 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

Offline bionicoz

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Moving and rotating the cam
« Reply #7 on: April 21, 2011, 11:19:31 am »
That helped a lot, ty Egon.