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 › 3D orientation/rotation 101 help
Pages: 1 2 
3D orientation/rotation 101 help (Read 3330 times)
Re: 3D orientation/rotation 101 help
Reply #15 - Feb 9th, 2010, 12:32pm
 
well said davbol
Re: 3D orientation/rotation 101 help
Reply #16 - Feb 9th, 2010, 11:23pm
 
Cool I get it.

Summary of the different method to achieve orientation towards a velocity vector:

Method 1 from V Code:
    Vec3D new_dir = new Vec3D(velocity);
   new_dir.normalize();
   Vec3D new_up = new Vec3D(0.0, 1.0, 0.0);
   new_up.normalize();
   Vec3D crossP = new_dir.cross(new_up);
   crossP.normalize();
   
   float dotP  = new_dir.dot(new_up);
   float angle = new_dir.angleBetween(new_up, true);
   
   
   pushMatrix();
   // update location
   translate(location.x, location.y, location.z);
   // orientation to velocity
   rotate(-angle, crossP.x, crossP.y, crossP.z);
   
   // draw your stuff here
   
   popMatrix();


Method 2 from davbol Code:
    // Rotation vectors
   // use to perform orientation to velocity vector
   Vec3D new_dir = new Vec3D(velocity);
   float r = sqrt(new_dir.x * new_dir.x + new_dir.y * new_dir.y + new_dir.z * new_dir.z);
   float theta = atan2(new_dir.y, new_dir.x);
   float phi = acos(new_dir.z / r);
   
   pushMatrix();
   // update location
   translate(location.x, location.y, location.z);
   // orientation to velocity
   rotateZ(theta);
   rotateY(phi);
   rotateX(HALF_PI);
   
   // draw your stuff here
   
   popMatrix();


I try both and they work fine, but there are some considerations, like davbol said Quote:
that doesn't account for is "roll" (to use the airplane analogy).  with only two points (well, a position and a velocity vector, if I've correctly followed your several threads) you can't nail down all three implied axes, all you can get is two. (which is enough to "point at", but not enough to determine where "up/roll" should be)

typically if you need all three axes you'll have to carry around your own pitch/roll/yaw or a frenet frame or orthonormal TNB vectors or etcetera, potentially converting back and forth to quats if you need to slerp them, and WON'T be attempting to "derive" them from velocity-position alone.  

you can try faking that third local axes ("up") by hard-coding it (perhaps as the world y-axis) sometimes.  then you can cross your "at" vector (vel-pos) with "up" to get "right" and you now have local TNB.  keep in mind that crossing only guarantees perpendicular, not WHICH perpendicular, so you typically cross back, maybe iterate, etc, yuck -- it's still only a partial solution.  so you can expect to experience problems as your velocity approaches being colinear with whatever hard-coded value you choose.


Now I need to work on the SLERP to get the orientation updates nice and smooth.

Thanks to all involve!
rS
Pages: 1 2