/ Published in: ActionScript 3

If you have multiple objects orbiting a 3D object and you want to determine the angle of a specific object, this will help you determine what rotationX you need to set your camera to if you want to be directly behind it.
Note: It works completely in 3d space. So if your Y, Z, X are not inversed or directly related to your comparison object, the angle will be a little off.
Note: It works completely in 3d space. So if your Y, Z, X are not inversed or directly related to your comparison object, the angle will be a little off.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var tempMatrix:Matrix3D = Matrix3D.inverse( new Matrix3D([0,0,0]) ); var vectorA:Number3D = new Number3D( 0,0,1 ); Matrix3D.multiplyVector( *OBJECT*.getPlane().transform, vectorA ); vectorA.normalize(); var vectorB:Number3D = new Number3D( 0,0,1 ); tempMatrix = Matrix3D.clone( *CLICKED-OBJECT*.transform ); Matrix3D.multiplyVector( tempMatrix, vectorB ); vectorB.normalize(); var angle:Number = Math.acos( Number3D.dot(vectorB, vectorA) / (vectorA.modulo*vectorB.modulo) )*180/Math.PI; trace( angle );
Comments
