|
@@ -7,36 +7,64 @@
|
|
|
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 {
|
|
|
+ /**
|
|
|
+ * Distance the follow camera should follow an object at
|
|
|
+ */
|
|
|
@serialize()
|
|
|
public radius: number = 12;
|
|
|
|
|
|
+ /**
|
|
|
+ * Define a rotation offset between the camera and the object it follows
|
|
|
+ */
|
|
|
@serialize()
|
|
|
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()
|
|
|
public heightOffset: number = 4;
|
|
|
|
|
|
+ /**
|
|
|
+ * Define how fast the camera can accelerate to follow it s target.
|
|
|
+ */
|
|
|
@serialize()
|
|
|
public cameraAcceleration: number = 0.05;
|
|
|
|
|
|
+ /**
|
|
|
+ * Define the speed limit of the camera following an object.
|
|
|
+ */
|
|
|
@serialize()
|
|
|
public maxCameraSpeed: number = 20;
|
|
|
|
|
|
+ /**
|
|
|
+ * Define the target of the camera.
|
|
|
+ */
|
|
|
@serializeAsMeshReference("lockedTargetId")
|
|
|
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) {
|
|
|
super(name, position, scene);
|
|
|
|
|
|
this.lockedTarget = lockedTarget;
|
|
|
}
|
|
|
|
|
|
- private getRadians(degrees: number): number {
|
|
|
- return degrees * Math.PI / 180;
|
|
|
- }
|
|
|
-
|
|
|
- private follow(cameraTarget: AbstractMesh) {
|
|
|
+ private _follow(cameraTarget: AbstractMesh) {
|
|
|
if (!cameraTarget)
|
|
|
return;
|
|
|
|
|
@@ -48,7 +76,7 @@
|
|
|
} else {
|
|
|
yRotation = cameraTarget.rotation.y;
|
|
|
}
|
|
|
- var radians = this.getRadians(this.rotationOffset) + yRotation;
|
|
|
+ var radians = Tools.ToRadians(this.rotationOffset) + yRotation;
|
|
|
var targetPosition = cameraTarget.getAbsolutePosition();
|
|
|
var targetX: number = targetPosition.x + Math.sin(radians) * this.radius;
|
|
|
|
|
@@ -80,10 +108,14 @@
|
|
|
public _checkInputs(): void {
|
|
|
super._checkInputs();
|
|
|
if (this.lockedTarget) {
|
|
|
- this.follow(this.lockedTarget);
|
|
|
+ this._follow(this.lockedTarget);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Gets the camera class name.
|
|
|
+ * @returns the class name
|
|
|
+ */
|
|
|
public getClassName(): string {
|
|
|
return "FollowCamera";
|
|
|
}
|
|
@@ -91,7 +123,8 @@
|
|
|
|
|
|
/**
|
|
|
* 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 {
|
|
|
|
|
@@ -99,12 +132,13 @@
|
|
|
|
|
|
/**
|
|
|
* 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,
|
|
|
/** The longitudinal angle of the camera */
|
|
@@ -113,14 +147,14 @@
|
|
|
public beta: number,
|
|
|
/** The radius of the camera from its target */
|
|
|
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>,
|
|
|
scene: Scene) {
|
|
|
super(name, Vector3.Zero(), scene);
|
|
|
- this.follow();
|
|
|
+ this._follow();
|
|
|
}
|
|
|
|
|
|
- private follow(): void {
|
|
|
+ private _follow(): void {
|
|
|
if (!this.target) {
|
|
|
return;
|
|
|
}
|
|
@@ -136,7 +170,7 @@
|
|
|
/** @hidden */
|
|
|
public _checkInputs(): void {
|
|
|
super._checkInputs();
|
|
|
- this.follow();
|
|
|
+ this._follow();
|
|
|
}
|
|
|
|
|
|
/**
|