浏览代码

Camera doc

sebastien 7 年之前
父节点
当前提交
cd057b06a9
共有 2 个文件被更改,包括 55 次插入20 次删除
  1. 3 2
      src/Cameras/babylon.camera.ts
  2. 52 18
      src/Cameras/babylon.followCamera.ts

+ 3 - 2
src/Cameras/babylon.camera.ts

@@ -63,7 +63,7 @@
         public static ForceAttachControlToAlwaysPreventDefault = false;
         public static ForceAttachControlToAlwaysPreventDefault = false;
 
 
         /**
         /**
-         * @hidden.
+         * @hidden
          * Might be removed once multiview will be a thing
          * Might be removed once multiview will be a thing
          */
          */
         public static UseAlternateWebVRRendering = false;
         public static UseAlternateWebVRRendering = false;
@@ -336,7 +336,6 @@
 
 
         /**
         /**
          * Gets the current world space position of the camera.
          * Gets the current world space position of the camera.
-         * @returns the world space position
          */
          */
         public get globalPosition(): Vector3 {
         public get globalPosition(): Vector3 {
             return this._globalPosition;
             return this._globalPosition;
@@ -869,6 +868,7 @@
 
 
         /**
         /**
          * Gets the left camera target of a rig setup in case of Rigged Camera
          * Gets the left camera target of a rig setup in case of Rigged Camera
+         * @returns the target position
          */
          */
         public getLeftTarget(): Nullable<Vector3> {
         public getLeftTarget(): Nullable<Vector3> {
             if (this._rigCameras.length < 1) {
             if (this._rigCameras.length < 1) {
@@ -879,6 +879,7 @@
 
 
         /**
         /**
          * Gets the right camera target of a rig setup in case of Rigged Camera
          * Gets the right camera target of a rig setup in case of Rigged Camera
+         * @returns the target position
          */
          */
         public getRightTarget(): Nullable<Vector3> {
         public getRightTarget(): Nullable<Vector3> {
             if (this._rigCameras.length < 2) {
             if (this._rigCameras.length < 2) {

+ 52 - 18
src/Cameras/babylon.followCamera.ts

@@ -7,36 +7,64 @@
         return () => new ArcFollowCamera(name, 0, 0, 1.0, null, scene);
         return () => new ArcFollowCamera(name, 0, 0, 1.0, null, scene);
     });
     });
 
 
+    /**
+     * A follow camera takes a mesh as a target and follows it as it moves. Both a free camera version followCamera and 
+     * an arc rotate version arcFollowCamera are available.
+     * @see http://doc.babylonjs.com/features/cameras#follow-camera
+     */
     export class FollowCamera extends TargetCamera {
     export class FollowCamera extends TargetCamera {
+        /**
+         * Distance the follow camera should follow an object at
+         */
         @serialize()
         @serialize()
         public radius: number = 12;
         public radius: number = 12;
 
 
+        /**
+         * Define a rotation offset between the camera and the object it follows
+         */
         @serialize()
         @serialize()
         public rotationOffset: number = 0;
         public rotationOffset: number = 0;
 
 
+        /**
+         * Define a height offset between the camera and the object it follows.
+         * It can help following an object from the top (like a car chaing a plane)
+         */
         @serialize()
         @serialize()
         public heightOffset: number = 4;
         public heightOffset: number = 4;
 
 
+        /**
+         * Define how fast the camera can accelerate to follow it s target.
+         */
         @serialize()
         @serialize()
         public cameraAcceleration: number = 0.05;
         public cameraAcceleration: number = 0.05;
 
 
+        /**
+         * Define the speed limit of the camera following an object.
+         */
         @serialize()
         @serialize()
         public maxCameraSpeed: number = 20;
         public maxCameraSpeed: number = 20;
 
 
+        /**
+         * Define the target of the camera.
+         */
         @serializeAsMeshReference("lockedTargetId")
         @serializeAsMeshReference("lockedTargetId")
         public lockedTarget: Nullable<AbstractMesh>;
         public lockedTarget: Nullable<AbstractMesh>;
 
 
+        /**
+         * Instantiates the follow camera.
+         * @see http://doc.babylonjs.com/features/cameras#follow-camera
+         * @param name Define the name of the camera in the scene
+         * @param position Define the position of the camera
+         * @param scene Define the scene the camera belong to
+         * @param lockedTarget Define the target of the camera
+         */
         constructor(name: string, position: Vector3, scene: Scene, lockedTarget: Nullable<AbstractMesh> = null) {
         constructor(name: string, position: Vector3, scene: Scene, lockedTarget: Nullable<AbstractMesh> = null) {
             super(name, position, scene);
             super(name, position, scene);
 
 
             this.lockedTarget = lockedTarget;
             this.lockedTarget = lockedTarget;
         }
         }
 
 
-        private getRadians(degrees: number): number {
-            return degrees * Math.PI / 180;
-        }
-
-        private follow(cameraTarget: AbstractMesh) {
+        private _follow(cameraTarget: AbstractMesh) {
             if (!cameraTarget)
             if (!cameraTarget)
                 return;
                 return;
 
 
@@ -48,7 +76,7 @@
             } else {
             } else {
                 yRotation = cameraTarget.rotation.y;
                 yRotation = cameraTarget.rotation.y;
             }
             }
-            var radians = this.getRadians(this.rotationOffset) + yRotation;
+            var radians = Tools.ToRadians(this.rotationOffset) + yRotation;
             var targetPosition = cameraTarget.getAbsolutePosition();
             var targetPosition = cameraTarget.getAbsolutePosition();
             var targetX: number = targetPosition.x + Math.sin(radians) * this.radius;
             var targetX: number = targetPosition.x + Math.sin(radians) * this.radius;
 
 
@@ -80,10 +108,14 @@
         public _checkInputs(): void {
         public _checkInputs(): void {
             super._checkInputs();
             super._checkInputs();
             if (this.lockedTarget) {
             if (this.lockedTarget) {
-                this.follow(this.lockedTarget);
+                this._follow(this.lockedTarget);
             }
             }
         }
         }
 
 
+        /**
+         * Gets the camera class name.
+         * @returns the class name
+         */
         public getClassName(): string {
         public getClassName(): string {
             return "FollowCamera";
             return "FollowCamera";
         }
         }
@@ -91,7 +123,8 @@
 
 
     /**
     /**
      * Arc Rotate version of the follow camera.
      * Arc Rotate version of the follow camera.
-     * It still follows a defined mesh but in an Arc Rotate Camera fashion.
+     * It still follows a Defined mesh but in an Arc Rotate Camera fashion.
+     * @see http://doc.babylonjs.com/features/cameras#follow-camera
      */
      */
     export class ArcFollowCamera extends TargetCamera {
     export class ArcFollowCamera extends TargetCamera {
 
 
@@ -99,12 +132,13 @@
 
 
         /**
         /**
          * Instantiates a new ArcFollowCamera
          * Instantiates a new ArcFollowCamera
-         * @param name Defines the name of the camera
-         * @param alpha Defines the rotation angle of the camera around the logitudinal axis
-         * @param beta Defines the rotation angle of the camera around the elevation axis
-         * @param radius Defines the radius of the camera from its target point
-         * @param target Defines the target of the camera
-         * @param scene Defines the scene the camera belongs to
+         * @see http://doc.babylonjs.com/features/cameras#follow-camera
+         * @param name Define the name of the camera
+         * @param alpha Define the rotation angle of the camera around the logitudinal axis
+         * @param beta Define the rotation angle of the camera around the elevation axis
+         * @param radius Define the radius of the camera from its target point
+         * @param target Define the target of the camera
+         * @param scene Define the scene the camera belongs to
          */
          */
         constructor(name: string, 
         constructor(name: string, 
             /** The longitudinal angle of the camera */
             /** The longitudinal angle of the camera */
@@ -113,14 +147,14 @@
             public beta: number, 
             public beta: number, 
             /** The radius of the camera from its target */
             /** The radius of the camera from its target */
             public radius: number, 
             public radius: number, 
-            /** Defines the camera target (the messh it should follow) */
+            /** Define the camera target (the messh it should follow) */
             public target: Nullable<AbstractMesh>, 
             public target: Nullable<AbstractMesh>, 
             scene: Scene) {
             scene: Scene) {
             super(name, Vector3.Zero(), scene);
             super(name, Vector3.Zero(), scene);
-            this.follow();
+            this._follow();
         }
         }
 
 
-        private follow(): void {
+        private _follow(): void {
             if (!this.target) {
             if (!this.target) {
                 return;
                 return;
             }
             }
@@ -136,7 +170,7 @@
         /** @hidden */
         /** @hidden */
         public _checkInputs(): void {
         public _checkInputs(): void {
             super._checkInputs();
             super._checkInputs();
-            this.follow();
+            this._follow();
         }
         }
 
 
         /**
         /**