Posted By

kyoji on 02/13/09


Tagged

Papervision3D


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Akuma99


lookTo


 / Published in: ActionScript 3
 

Make a DisplayObject3D Object look to a position defined by a Number3D (with ease)

  1. public function lookTo(do3d : DisplayObject3D, ray : Number3D) : void {
  2.  
  3. var ease : Number = 0.1;
  4. var mainPosition : Number3D = new Number3D(do3d.x, do3d.y, do3d.z);
  5.  
  6. var dir : Number3D = Number3D.sub(ray, mainPosition); // 指向ray
  7. dir.normalize();
  8.  
  9. var front : Number3D = new Number3D(do3d.transform.n13, do3d.transform.n23, do3d.transform.n33);
  10. front.normalize();
  11.  
  12. var cross : Number3D = Number3D.cross(dir, front);
  13. var dot : Number = Number3D.dot(front, dir);
  14.  
  15. var angle : Number = Math.acos(dot);
  16.  
  17. var targetQuat : Quaternion = Quaternion.createFromAxisAngle(cross.x, cross.y, cross.z, angle * ease);
  18.  
  19. do3d.transform.calculateMultiply3x3(targetQuat.matrix, do3d.transform);
  20. }

Report this snippet  

You need to login to post a comment.