We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Align to velocity - orientation
Pages: 1 2 
Align to velocity - orientation (Read 3210 times)
Align to velocity - orientation
Feb 1st, 2010, 5:11am
 
Hi, I am trying to translate a 2D steering behaviour code to 3D, so far I have a very simple wander behaviour going on but I am stuck trying to orientate the agents (vehicles) to their velocity direction.

I found this post that gave me an idea of how this show be implemented, but I don't understand the use of what they call the basis vectors.

On this very famous document http://www.red3d.com/cwr/papers/1999/gdc99steer.pdf
Quote:
The simple vehicle model maintains its velocity-aligned local space by incremental adjustment from the previous time step. The local coordinate system is defined in terms of four vectors: a position vector specifying the local origin, and three direction vectors serving as the basis vectors of the space. The basis vectors indicate the direction and length of coordinate units in each of three mutually perpendicular directions relative to the vehicle. These axes will be referred to here as forward, up, and side.


So forward is the velocity vector, up is where I am confuse, and side is the cross product of forward and up.

So my question is how can I get up?

Thanks for you help
rS
Re: Align to velocity - orientation
Reply #1 - Feb 1st, 2010, 7:26am
 
you can just define it to be the y axis. that'll work.

think of a plane - it can be flying forwards as usual (its local up is the same as the global up) and it can be flying forwards whilst upside down (its local up is the same as the global down). that's what this up vector lets you do.
Re: Align to velocity - orientation
Reply #2 - Feb 1st, 2010, 8:00am
 
Hi koogy, so this is what I need?

Code:
PVector side_up = new PVector(0.0, velocity.y, 0.0); 


Cheers
rS
Re: Align to velocity - orientation
Reply #3 - Feb 1st, 2010, 8:16am
 
Very cool!

I almost got it, now they are facing the velocity vector, but I am having some vertex transformation problems, so I move into a new problem, the never-ending-story...

Many thanks koogy
rS
Re: Align to velocity - orientation
Reply #4 - Feb 1st, 2010, 8:54am
 
i was just thinking (0, 1, 0) but yours is just that with a multiplier. you might see oddness if velocity.y is negative - the plane doesn't need to flip in order to descend...

(oh, and if yours is ever (0, 0, 0) that would be bad)

(there was a story a few years ago about someone who wrote software for planes and tested it and everything was fine. fine until they crossed the equator... (oh, here - http://catless.ncl.ac.uk/Risks/3.44.html))
Re: Align to velocity - orientation
Reply #5 - Feb 1st, 2010, 9:02am
 
Hi koogy, I am having that problem, I fix the transformation issue by recalculating the up vector again by forward.cross(side), so now the geometry is perfectly render.

So back to that problem, they tend to flip backwards at specific areas of the coordinate system, I haven't read the article yet, but I will post anything I can get out of it.

Cheers
rS
Re: Align to velocity - orientation
Reply #6 - Feb 1st, 2010, 9:29am
 
hard to guess what you're doing from the details you've given.

have you tried keeping up as (0, 1, 0)? am not sure that'll work if you ever loop or roll but...

Re: Align to velocity - orientation
Reply #7 - Feb 2nd, 2010, 2:28am
 
Hi koogy, I send you a PM with more details and a link, I am  still trying to work it out

Thanks
rS
Re: Align to velocity - orientation
Reply #8 - Feb 2nd, 2010, 3:17am
 
ok. am at work now, but will take a look tonight
Re: Align to velocity - orientation
Reply #9 - Feb 2nd, 2010, 6:57am
 
had a quick look at lunchtime.

i think your problem could be the use of tan()

see the graph here (about halfway down):

http://www.clarku.edu/~djoyce/trig/functions.html

it's discontinuous - small changes in angle can cause wild changes in tan(angle) and might be why you get sudden flipping. change the code to have only one boid and print tan(angle) out for every frame, should make it obvious.

don't really know what to suggest, except constraining the angle you're using to a continuous piece of the curve (plus / minus HALF_PI for instance)
Re: Align to velocity - orientation
Reply #10 - Feb 2nd, 2010, 10:21am
 
Hi koogy thanks a lot for the help, very useful stuff.

I am still struggling to get this right, so I will refresh here in the post, to see if others can help as well Wink

I have a 3D steering behaviour, there is an problem with the orientation of the agents and target positions

In the following  link you can see what I meant. Click so the agents seek the mouse position, relese and they will resume wander behaviour.

http://nardove.com/p5/misc/steering_3/

As you can see when you click and drag to the left up or down the agents flip to the opposite up direction.

The rotation code is in the display method of the Boid Class.

Cheers
rS
Re: Align to velocity - orientation
Reply #11 - Feb 2nd, 2010, 11:05am
 
I manage to sort the problem, but I have to admit I dont understand how it got fix...

From an old PM from dlp, he said

Code:
PVector new_dir = velocity.get();
PVector new_up = new PVector(0.0, 0.0, 1.0);
new_up.normalize();
PVector crss = velocity.cross(new_up);

float theAngle = PVector.angleBetween(new_dir, new_up);
crss.normalize();

pushMatrix();
rotate(-theAngle, crss.x, crss.y, crss.z);
popMatrix();


I remove this block from the Boid class display()
Code:
PVector new_forward = velocity;
new_forward.normalize();
PVector new_up = new PVector(0.0, 1.0, 0.0);
new_up.normalize();
PVector new_side = new_up.cross(new_forward);
new_side.normalize();
new_up = new_side.cross(new_forward);
new_up.normalize();

and the applyMatrix() for the rotation, and change it to dlp suggestion

Notice the new_up orientation change
Code:
PVector new_up = new PVector(0.0, 1.0, 0.0);
to
PVector new_up = new PVector(0.0, 0.0, 1.0);


Old version
http://nardove.com/p5/misc/steering_3/

New version
http://nardove.com/p5/misc/steering_3a/

It works fine, so far I havent spot any irregularities.

Thanks to all involved
rS
Re: Align to velocity - orientation
Reply #12 - Feb 4th, 2010, 2:57am
 
I found one problem, that rotation formula makes the agents to disappear at some random moments I haven't figure out yet.

Any ideas?

Cheers
rS
Re: Align to velocity - orientation
Reply #13 - Feb 4th, 2010, 3:41am
 
again, try reducing it to only one boid and printing out the details on every step and see if there's anything odd about the numbers around the disappearance.

(although this won't help if the problem is the way you are managing the entire flock, like the arraylist problem someone else was having the other day)

or is it just clipping? you can't draw things too close to the front or too far towards the back of the screen, generally.
Re: Align to velocity - orientation
Reply #14 - Feb 4th, 2010, 3:59am
 
Hi koogy, thanks for the suggestions.

I am printing values, using just one agent, but I cant see anything odd.

There is no clipping problem because if I comment the rotation method, they  dont disappear.

Cheers
rS
Pages: 1 2