Browse Source

Merge pull request #466 from m0ppers/followcamera-vs-quaternion

Camera should also work when rotation is specified via quaternion
David Catuhe 10 years ago
parent
commit
5fd15ad23b
1 changed files with 11 additions and 3 deletions
  1. 11 3
      Babylon/Cameras/babylon.followCamera.ts

+ 11 - 3
Babylon/Cameras/babylon.followCamera.ts

@@ -19,8 +19,16 @@
         private follow(cameraTarget:AbstractMesh) {
             if (!cameraTarget)
                 return;
-
-            var radians = this.getRadians(this.rotationOffset) + cameraTarget.rotation.y;
+            
+            var yRotation;
+            if (cameraTarget.rotationQuaternion) {
+                var rotMatrix = new Matrix();
+                cameraTarget.rotationQuaternion.toRotationMatrix(rotMatrix);
+                yRotation = Math.atan2(rotMatrix.m[8], rotMatrix.m[10]);
+            } else {
+                yRotation = cameraTarget.rotation.y;
+            }
+            var radians = this.getRadians(this.rotationOffset) + yRotation;
             var targetX:number = cameraTarget.position.x + Math.sin(radians) * this.radius;
 
             var targetZ:number = cameraTarget.position.z + Math.cos(radians) * this.radius;
@@ -52,4 +60,4 @@
             this.follow(this.target);
         }
     }
-} 
+}