arcRotateCamera.ts 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. import { serialize, serializeAsVector3 } from "../Misc/decorators";
  2. import { Observable } from "../Misc/observable";
  3. import { Nullable } from "../types";
  4. import { Scene } from "../scene";
  5. import { Matrix, Vector3, Vector2 } from "../Maths/math.vector";
  6. import { Node } from "../node";
  7. import { AbstractMesh } from "../Meshes/abstractMesh";
  8. import { Mesh } from "../Meshes/mesh";
  9. import { AutoRotationBehavior } from "../Behaviors/Cameras/autoRotationBehavior";
  10. import { BouncingBehavior } from "../Behaviors/Cameras/bouncingBehavior";
  11. import { FramingBehavior } from "../Behaviors/Cameras/framingBehavior";
  12. import { Camera } from "./camera";
  13. import { TargetCamera } from "./targetCamera";
  14. import { ArcRotateCameraPointersInput } from "../Cameras/Inputs/arcRotateCameraPointersInput";
  15. import { ArcRotateCameraKeyboardMoveInput } from "../Cameras/Inputs/arcRotateCameraKeyboardMoveInput";
  16. import { ArcRotateCameraMouseWheelInput } from "../Cameras/Inputs/arcRotateCameraMouseWheelInput";
  17. import { ArcRotateCameraInputsManager } from "../Cameras/arcRotateCameraInputsManager";
  18. import { Epsilon } from "../Maths/math.constants";
  19. import { Tools } from "../Misc/tools";
  20. declare type Collider = import("../Collisions/collider").Collider;
  21. Node.AddNodeConstructor("ArcRotateCamera", (name, scene) => {
  22. return () => new ArcRotateCamera(name, 0, 0, 1.0, Vector3.Zero(), scene);
  23. });
  24. /**
  25. * This represents an orbital type of camera.
  26. *
  27. * This camera always points towards a given target position and can be rotated around that target with the target as the centre of rotation. It can be controlled with cursors and mouse, or with touch events.
  28. * Think of this camera as one orbiting its target position, or more imaginatively as a spy satellite orbiting the earth. Its position relative to the target (earth) can be set by three parameters, alpha (radians) the longitudinal rotation, beta (radians) the latitudinal rotation and radius the distance from the target position.
  29. * @see https://doc.babylonjs.com/babylon101/cameras#arc-rotate-camera
  30. */
  31. export class ArcRotateCamera extends TargetCamera {
  32. /**
  33. * Defines the rotation angle of the camera along the longitudinal axis.
  34. */
  35. @serialize()
  36. public alpha: number;
  37. /**
  38. * Defines the rotation angle of the camera along the latitudinal axis.
  39. */
  40. @serialize()
  41. public beta: number;
  42. /**
  43. * Defines the radius of the camera from it s target point.
  44. */
  45. @serialize()
  46. public radius: number;
  47. @serializeAsVector3("target")
  48. protected _target: Vector3;
  49. protected _targetHost: Nullable<AbstractMesh>;
  50. /**
  51. * Defines the target point of the camera.
  52. * The camera looks towards it form the radius distance.
  53. * Please note that you can set the target to a mesh and thus the target will be copied from mesh.position
  54. */
  55. public get target(): Vector3 {
  56. return this._target;
  57. }
  58. public set target(value: Vector3) {
  59. this.setTarget(value);
  60. }
  61. /**
  62. * Define the current local position of the camera in the scene
  63. */
  64. public get position(): Vector3 {
  65. return this._position;
  66. }
  67. public set position(newPosition: Vector3) {
  68. this.setPosition(newPosition);
  69. }
  70. protected _upToYMatrix: Matrix;
  71. protected _YToUpMatrix: Matrix;
  72. /**
  73. * The vector the camera should consider as up. (default is Vector3(0, 1, 0) as returned by Vector3.Up())
  74. * Setting this will copy the given vector to the camera's upVector, and set rotation matrices to and from Y up.
  75. * DO NOT set the up vector using copyFrom or copyFromFloats, as this bypasses setting the above matrices.
  76. */
  77. set upVector(vec: Vector3) {
  78. if (!this._upToYMatrix) {
  79. this._YToUpMatrix = new Matrix();
  80. this._upToYMatrix = new Matrix();
  81. this._upVector = Vector3.Zero();
  82. }
  83. vec.normalize();
  84. this._upVector.copyFrom(vec);
  85. this.setMatUp();
  86. }
  87. get upVector() {
  88. return this._upVector;
  89. }
  90. /**
  91. * Sets the Y-up to camera up-vector rotation matrix, and the up-vector to Y-up rotation matrix.
  92. */
  93. public setMatUp() {
  94. // from y-up to custom-up (used in _getViewMatrix)
  95. Matrix.RotationAlignToRef(Vector3.UpReadOnly, this._upVector, this._YToUpMatrix);
  96. // from custom-up to y-up (used in rebuildAnglesAndRadius)
  97. Matrix.RotationAlignToRef(this._upVector, Vector3.UpReadOnly, this._upToYMatrix);
  98. }
  99. /**
  100. * Current inertia value on the longitudinal axis.
  101. * The bigger this number the longer it will take for the camera to stop.
  102. */
  103. @serialize()
  104. public inertialAlphaOffset = 0;
  105. /**
  106. * Current inertia value on the latitudinal axis.
  107. * The bigger this number the longer it will take for the camera to stop.
  108. */
  109. @serialize()
  110. public inertialBetaOffset = 0;
  111. /**
  112. * Current inertia value on the radius axis.
  113. * The bigger this number the longer it will take for the camera to stop.
  114. */
  115. @serialize()
  116. public inertialRadiusOffset = 0;
  117. /**
  118. * Minimum allowed angle on the longitudinal axis.
  119. * This can help limiting how the Camera is able to move in the scene.
  120. */
  121. @serialize()
  122. public lowerAlphaLimit: Nullable<number> = null;
  123. /**
  124. * Maximum allowed angle on the longitudinal axis.
  125. * This can help limiting how the Camera is able to move in the scene.
  126. */
  127. @serialize()
  128. public upperAlphaLimit: Nullable<number> = null;
  129. /**
  130. * Minimum allowed angle on the latitudinal axis.
  131. * This can help limiting how the Camera is able to move in the scene.
  132. */
  133. @serialize()
  134. public lowerBetaLimit = 0.01;
  135. /**
  136. * Maximum allowed angle on the latitudinal axis.
  137. * This can help limiting how the Camera is able to move in the scene.
  138. */
  139. @serialize()
  140. public upperBetaLimit = Math.PI - 0.01;
  141. /**
  142. * Minimum allowed distance of the camera to the target (The camera can not get closer).
  143. * This can help limiting how the Camera is able to move in the scene.
  144. */
  145. @serialize()
  146. public lowerRadiusLimit: Nullable<number> = null;
  147. /**
  148. * Maximum allowed distance of the camera to the target (The camera can not get further).
  149. * This can help limiting how the Camera is able to move in the scene.
  150. */
  151. @serialize()
  152. public upperRadiusLimit: Nullable<number> = null;
  153. /**
  154. * Defines the current inertia value used during panning of the camera along the X axis.
  155. */
  156. @serialize()
  157. public inertialPanningX: number = 0;
  158. /**
  159. * Defines the current inertia value used during panning of the camera along the Y axis.
  160. */
  161. @serialize()
  162. public inertialPanningY: number = 0;
  163. /**
  164. * Defines the distance used to consider the camera in pan mode vs pinch/zoom.
  165. * Basically if your fingers moves away from more than this distance you will be considered
  166. * in pinch mode.
  167. */
  168. @serialize()
  169. public pinchToPanMaxDistance: number = 20;
  170. /**
  171. * Defines the maximum distance the camera can pan.
  172. * This could help keeping the cammera always in your scene.
  173. */
  174. @serialize()
  175. public panningDistanceLimit: Nullable<number> = null;
  176. /**
  177. * Defines the target of the camera before paning.
  178. */
  179. @serializeAsVector3()
  180. public panningOriginTarget: Vector3 = Vector3.Zero();
  181. /**
  182. * Defines the value of the inertia used during panning.
  183. * 0 would mean stop inertia and one would mean no decelleration at all.
  184. */
  185. @serialize()
  186. public panningInertia = 0.9;
  187. //-- begin properties for backward compatibility for inputs
  188. /**
  189. * Gets or Set the pointer angular sensibility along the X axis or how fast is the camera rotating.
  190. */
  191. public get angularSensibilityX(): number {
  192. var pointers = <ArcRotateCameraPointersInput>this.inputs.attached["pointers"];
  193. if (pointers) {
  194. return pointers.angularSensibilityX;
  195. }
  196. return 0;
  197. }
  198. public set angularSensibilityX(value: number) {
  199. var pointers = <ArcRotateCameraPointersInput>this.inputs.attached["pointers"];
  200. if (pointers) {
  201. pointers.angularSensibilityX = value;
  202. }
  203. }
  204. /**
  205. * Gets or Set the pointer angular sensibility along the Y axis or how fast is the camera rotating.
  206. */
  207. public get angularSensibilityY(): number {
  208. var pointers = <ArcRotateCameraPointersInput>this.inputs.attached["pointers"];
  209. if (pointers) {
  210. return pointers.angularSensibilityY;
  211. }
  212. return 0;
  213. }
  214. public set angularSensibilityY(value: number) {
  215. var pointers = <ArcRotateCameraPointersInput>this.inputs.attached["pointers"];
  216. if (pointers) {
  217. pointers.angularSensibilityY = value;
  218. }
  219. }
  220. /**
  221. * Gets or Set the pointer pinch precision or how fast is the camera zooming.
  222. */
  223. public get pinchPrecision(): number {
  224. var pointers = <ArcRotateCameraPointersInput>this.inputs.attached["pointers"];
  225. if (pointers) {
  226. return pointers.pinchPrecision;
  227. }
  228. return 0;
  229. }
  230. public set pinchPrecision(value: number) {
  231. var pointers = <ArcRotateCameraPointersInput>this.inputs.attached["pointers"];
  232. if (pointers) {
  233. pointers.pinchPrecision = value;
  234. }
  235. }
  236. /**
  237. * Gets or Set the pointer pinch delta percentage or how fast is the camera zooming.
  238. * It will be used instead of pinchDeltaPrecision if different from 0.
  239. * It defines the percentage of current camera.radius to use as delta when pinch zoom is used.
  240. */
  241. public get pinchDeltaPercentage(): number {
  242. var pointers = <ArcRotateCameraPointersInput>this.inputs.attached["pointers"];
  243. if (pointers) {
  244. return pointers.pinchDeltaPercentage;
  245. }
  246. return 0;
  247. }
  248. public set pinchDeltaPercentage(value: number) {
  249. var pointers = <ArcRotateCameraPointersInput>this.inputs.attached["pointers"];
  250. if (pointers) {
  251. pointers.pinchDeltaPercentage = value;
  252. }
  253. }
  254. /**
  255. * Gets or Set the pointer use natural pinch zoom to override the pinch precision
  256. * and pinch delta percentage.
  257. * When useNaturalPinchZoom is true, multi touch zoom will zoom in such
  258. * that any object in the plane at the camera's target point will scale
  259. * perfectly with finger motion.
  260. */
  261. public get useNaturalPinchZoom(): boolean {
  262. var pointers = <ArcRotateCameraPointersInput>this.inputs.attached["pointers"];
  263. if (pointers) {
  264. return pointers.useNaturalPinchZoom;
  265. }
  266. return false;
  267. }
  268. public set useNaturalPinchZoom(value: boolean) {
  269. var pointers = <ArcRotateCameraPointersInput>this.inputs.attached["pointers"];
  270. if (pointers) {
  271. pointers.useNaturalPinchZoom = value;
  272. }
  273. }
  274. /**
  275. * Gets or Set the pointer panning sensibility or how fast is the camera moving.
  276. */
  277. public get panningSensibility(): number {
  278. var pointers = <ArcRotateCameraPointersInput>this.inputs.attached["pointers"];
  279. if (pointers) {
  280. return pointers.panningSensibility;
  281. }
  282. return 0;
  283. }
  284. public set panningSensibility(value: number) {
  285. var pointers = <ArcRotateCameraPointersInput>this.inputs.attached["pointers"];
  286. if (pointers) {
  287. pointers.panningSensibility = value;
  288. }
  289. }
  290. /**
  291. * Gets or Set the list of keyboard keys used to control beta angle in a positive direction.
  292. */
  293. public get keysUp(): number[] {
  294. var keyboard = <ArcRotateCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
  295. if (keyboard) {
  296. return keyboard.keysUp;
  297. }
  298. return [];
  299. }
  300. public set keysUp(value: number[]) {
  301. var keyboard = <ArcRotateCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
  302. if (keyboard) {
  303. keyboard.keysUp = value;
  304. }
  305. }
  306. /**
  307. * Gets or Set the list of keyboard keys used to control beta angle in a negative direction.
  308. */
  309. public get keysDown(): number[] {
  310. var keyboard = <ArcRotateCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
  311. if (keyboard) {
  312. return keyboard.keysDown;
  313. }
  314. return [];
  315. }
  316. public set keysDown(value: number[]) {
  317. var keyboard = <ArcRotateCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
  318. if (keyboard) {
  319. keyboard.keysDown = value;
  320. }
  321. }
  322. /**
  323. * Gets or Set the list of keyboard keys used to control alpha angle in a negative direction.
  324. */
  325. public get keysLeft(): number[] {
  326. var keyboard = <ArcRotateCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
  327. if (keyboard) {
  328. return keyboard.keysLeft;
  329. }
  330. return [];
  331. }
  332. public set keysLeft(value: number[]) {
  333. var keyboard = <ArcRotateCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
  334. if (keyboard) {
  335. keyboard.keysLeft = value;
  336. }
  337. }
  338. /**
  339. * Gets or Set the list of keyboard keys used to control alpha angle in a positive direction.
  340. */
  341. public get keysRight(): number[] {
  342. var keyboard = <ArcRotateCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
  343. if (keyboard) {
  344. return keyboard.keysRight;
  345. }
  346. return [];
  347. }
  348. public set keysRight(value: number[]) {
  349. var keyboard = <ArcRotateCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
  350. if (keyboard) {
  351. keyboard.keysRight = value;
  352. }
  353. }
  354. /**
  355. * Gets or Set the mouse wheel precision or how fast is the camera zooming.
  356. */
  357. public get wheelPrecision(): number {
  358. var mousewheel = <ArcRotateCameraMouseWheelInput>this.inputs.attached["mousewheel"];
  359. if (mousewheel) {
  360. return mousewheel.wheelPrecision;
  361. }
  362. return 0;
  363. }
  364. public set wheelPrecision(value: number) {
  365. var mousewheel = <ArcRotateCameraMouseWheelInput>this.inputs.attached["mousewheel"];
  366. if (mousewheel) {
  367. mousewheel.wheelPrecision = value;
  368. }
  369. }
  370. /**
  371. * Gets or Set the mouse wheel delta percentage or how fast is the camera zooming.
  372. * It will be used instead of pinchDeltaPrecision if different from 0.
  373. * It defines the percentage of current camera.radius to use as delta when pinch zoom is used.
  374. */
  375. public get wheelDeltaPercentage(): number {
  376. var mousewheel = <ArcRotateCameraMouseWheelInput>this.inputs.attached["mousewheel"];
  377. if (mousewheel) {
  378. return mousewheel.wheelDeltaPercentage;
  379. }
  380. return 0;
  381. }
  382. public set wheelDeltaPercentage(value: number) {
  383. var mousewheel = <ArcRotateCameraMouseWheelInput>this.inputs.attached["mousewheel"];
  384. if (mousewheel) {
  385. mousewheel.wheelDeltaPercentage = value;
  386. }
  387. }
  388. //-- end properties for backward compatibility for inputs
  389. /**
  390. * Defines how much the radius should be scaled while zomming on a particular mesh (through the zoomOn function)
  391. */
  392. @serialize()
  393. public zoomOnFactor = 1;
  394. /**
  395. * Defines a screen offset for the camera position.
  396. */
  397. @serialize()
  398. public targetScreenOffset = Vector2.Zero();
  399. /**
  400. * Allows the camera to be completely reversed.
  401. * If false the camera can not arrive upside down.
  402. */
  403. @serialize()
  404. public allowUpsideDown = true;
  405. /**
  406. * Define if double tap/click is used to restore the previously saved state of the camera.
  407. */
  408. @serialize()
  409. public useInputToRestoreState = true;
  410. /** @hidden */
  411. public _viewMatrix = new Matrix();
  412. /** @hidden */
  413. public _useCtrlForPanning: boolean;
  414. /** @hidden */
  415. public _panningMouseButton: number;
  416. /**
  417. * Defines the input associated to the camera.
  418. */
  419. public inputs: ArcRotateCameraInputsManager;
  420. /** @hidden */
  421. public _reset: () => void;
  422. /**
  423. * Defines the allowed panning axis.
  424. */
  425. public panningAxis: Vector3 = new Vector3(1, 1, 0);
  426. protected _localDirection: Vector3;
  427. protected _transformedDirection: Vector3;
  428. // Behaviors
  429. private _bouncingBehavior: Nullable<BouncingBehavior>;
  430. /**
  431. * Gets the bouncing behavior of the camera if it has been enabled.
  432. * @see https://doc.babylonjs.com/how_to/camera_behaviors#bouncing-behavior
  433. */
  434. public get bouncingBehavior(): Nullable<BouncingBehavior> {
  435. return this._bouncingBehavior;
  436. }
  437. /**
  438. * Defines if the bouncing behavior of the camera is enabled on the camera.
  439. * @see https://doc.babylonjs.com/how_to/camera_behaviors#bouncing-behavior
  440. */
  441. public get useBouncingBehavior(): boolean {
  442. return this._bouncingBehavior != null;
  443. }
  444. public set useBouncingBehavior(value: boolean) {
  445. if (value === this.useBouncingBehavior) {
  446. return;
  447. }
  448. if (value) {
  449. this._bouncingBehavior = new BouncingBehavior();
  450. this.addBehavior(this._bouncingBehavior);
  451. } else if (this._bouncingBehavior) {
  452. this.removeBehavior(this._bouncingBehavior);
  453. this._bouncingBehavior = null;
  454. }
  455. }
  456. private _framingBehavior: Nullable<FramingBehavior>;
  457. /**
  458. * Gets the framing behavior of the camera if it has been enabled.
  459. * @see https://doc.babylonjs.com/how_to/camera_behaviors#framing-behavior
  460. */
  461. public get framingBehavior(): Nullable<FramingBehavior> {
  462. return this._framingBehavior;
  463. }
  464. /**
  465. * Defines if the framing behavior of the camera is enabled on the camera.
  466. * @see https://doc.babylonjs.com/how_to/camera_behaviors#framing-behavior
  467. */
  468. public get useFramingBehavior(): boolean {
  469. return this._framingBehavior != null;
  470. }
  471. public set useFramingBehavior(value: boolean) {
  472. if (value === this.useFramingBehavior) {
  473. return;
  474. }
  475. if (value) {
  476. this._framingBehavior = new FramingBehavior();
  477. this.addBehavior(this._framingBehavior);
  478. } else if (this._framingBehavior) {
  479. this.removeBehavior(this._framingBehavior);
  480. this._framingBehavior = null;
  481. }
  482. }
  483. private _autoRotationBehavior: Nullable<AutoRotationBehavior>;
  484. /**
  485. * Gets the auto rotation behavior of the camera if it has been enabled.
  486. * @see https://doc.babylonjs.com/how_to/camera_behaviors#autorotation-behavior
  487. */
  488. public get autoRotationBehavior(): Nullable<AutoRotationBehavior> {
  489. return this._autoRotationBehavior;
  490. }
  491. /**
  492. * Defines if the auto rotation behavior of the camera is enabled on the camera.
  493. * @see https://doc.babylonjs.com/how_to/camera_behaviors#autorotation-behavior
  494. */
  495. public get useAutoRotationBehavior(): boolean {
  496. return this._autoRotationBehavior != null;
  497. }
  498. public set useAutoRotationBehavior(value: boolean) {
  499. if (value === this.useAutoRotationBehavior) {
  500. return;
  501. }
  502. if (value) {
  503. this._autoRotationBehavior = new AutoRotationBehavior();
  504. this.addBehavior(this._autoRotationBehavior);
  505. } else if (this._autoRotationBehavior) {
  506. this.removeBehavior(this._autoRotationBehavior);
  507. this._autoRotationBehavior = null;
  508. }
  509. }
  510. /**
  511. * Observable triggered when the mesh target has been changed on the camera.
  512. */
  513. public onMeshTargetChangedObservable = new Observable<Nullable<AbstractMesh>>();
  514. /**
  515. * Event raised when the camera is colliding with a mesh.
  516. */
  517. public onCollide: (collidedMesh: AbstractMesh) => void;
  518. /**
  519. * Defines whether the camera should check collision with the objects oh the scene.
  520. * @see https://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity#how-can-i-do-this
  521. */
  522. public checkCollisions = false;
  523. /**
  524. * Defines the collision radius of the camera.
  525. * This simulates a sphere around the camera.
  526. * @see https://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity#arcrotatecamera
  527. */
  528. public collisionRadius = new Vector3(0.5, 0.5, 0.5);
  529. protected _collider: Collider;
  530. protected _previousPosition = Vector3.Zero();
  531. protected _collisionVelocity = Vector3.Zero();
  532. protected _newPosition = Vector3.Zero();
  533. protected _previousAlpha: number;
  534. protected _previousBeta: number;
  535. protected _previousRadius: number;
  536. //due to async collision inspection
  537. protected _collisionTriggered: boolean;
  538. protected _targetBoundingCenter: Nullable<Vector3>;
  539. private _computationVector: Vector3 = Vector3.Zero();
  540. /**
  541. * Instantiates a new ArcRotateCamera in a given scene
  542. * @param name Defines the name of the camera
  543. * @param alpha Defines the camera rotation along the logitudinal axis
  544. * @param beta Defines the camera rotation along the latitudinal axis
  545. * @param radius Defines the camera distance from its target
  546. * @param target Defines the camera target
  547. * @param scene Defines the scene the camera belongs to
  548. * @param setActiveOnSceneIfNoneActive Defines wheter the camera should be marked as active if not other active cameras have been defined
  549. */
  550. constructor(name: string, alpha: number, beta: number, radius: number, target: Vector3, scene: Scene, setActiveOnSceneIfNoneActive = true) {
  551. super(name, Vector3.Zero(), scene, setActiveOnSceneIfNoneActive);
  552. this._target = Vector3.Zero();
  553. if (target) {
  554. this.setTarget(target);
  555. }
  556. this.alpha = alpha;
  557. this.beta = beta;
  558. this.radius = radius;
  559. this.getViewMatrix();
  560. this.inputs = new ArcRotateCameraInputsManager(this);
  561. this.inputs.addKeyboard().addMouseWheel().addPointers();
  562. }
  563. // Cache
  564. /** @hidden */
  565. public _initCache(): void {
  566. super._initCache();
  567. this._cache._target = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  568. this._cache.alpha = undefined;
  569. this._cache.beta = undefined;
  570. this._cache.radius = undefined;
  571. this._cache.targetScreenOffset = Vector2.Zero();
  572. }
  573. /** @hidden */
  574. public _updateCache(ignoreParentClass?: boolean): void {
  575. if (!ignoreParentClass) {
  576. super._updateCache();
  577. }
  578. this._cache._target.copyFrom(this._getTargetPosition());
  579. this._cache.alpha = this.alpha;
  580. this._cache.beta = this.beta;
  581. this._cache.radius = this.radius;
  582. this._cache.targetScreenOffset.copyFrom(this.targetScreenOffset);
  583. }
  584. protected _getTargetPosition(): Vector3 {
  585. if (this._targetHost && this._targetHost.getAbsolutePosition) {
  586. var pos: Vector3 = this._targetHost.absolutePosition;
  587. if (this._targetBoundingCenter) {
  588. pos.addToRef(this._targetBoundingCenter, this._target);
  589. } else {
  590. this._target.copyFrom(pos);
  591. }
  592. }
  593. var lockedTargetPosition = this._getLockedTargetPosition();
  594. if (lockedTargetPosition) {
  595. return lockedTargetPosition;
  596. }
  597. return this._target;
  598. }
  599. private _storedAlpha: number;
  600. private _storedBeta: number;
  601. private _storedRadius: number;
  602. private _storedTarget: Vector3;
  603. private _storedTargetScreenOffset: Vector2;
  604. /**
  605. * Stores the current state of the camera (alpha, beta, radius and target)
  606. * @returns the camera itself
  607. */
  608. public storeState(): Camera {
  609. this._storedAlpha = this.alpha;
  610. this._storedBeta = this.beta;
  611. this._storedRadius = this.radius;
  612. this._storedTarget = this._getTargetPosition().clone();
  613. this._storedTargetScreenOffset = this.targetScreenOffset.clone();
  614. return super.storeState();
  615. }
  616. /**
  617. * @hidden
  618. * Restored camera state. You must call storeState() first
  619. */
  620. public _restoreStateValues(): boolean {
  621. if (!super._restoreStateValues()) {
  622. return false;
  623. }
  624. this.setTarget(this._storedTarget.clone());
  625. this.alpha = this._storedAlpha;
  626. this.beta = this._storedBeta;
  627. this.radius = this._storedRadius;
  628. this.targetScreenOffset = this._storedTargetScreenOffset.clone();
  629. this.inertialAlphaOffset = 0;
  630. this.inertialBetaOffset = 0;
  631. this.inertialRadiusOffset = 0;
  632. this.inertialPanningX = 0;
  633. this.inertialPanningY = 0;
  634. return true;
  635. }
  636. // Synchronized
  637. /** @hidden */
  638. public _isSynchronizedViewMatrix(): boolean {
  639. if (!super._isSynchronizedViewMatrix()) {
  640. return false;
  641. }
  642. return this._cache._target.equals(this._getTargetPosition()) && this._cache.alpha === this.alpha && this._cache.beta === this.beta && this._cache.radius === this.radius && this._cache.targetScreenOffset.equals(this.targetScreenOffset);
  643. }
  644. /**
  645. * Attach the input controls to a specific dom element to get the input from.
  646. * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  647. */
  648. public attachControl(noPreventDefault?: boolean): void;
  649. /**
  650. * Attach the input controls to a specific dom element to get the input from.
  651. * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
  652. * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  653. */
  654. public attachControl(ignored: any, noPreventDefault?: boolean): void;
  655. /**
  656. * Attached controls to the current camera.
  657. * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  658. * @param useCtrlForPanning Defines whether ctrl is used for paning within the controls
  659. */
  660. public attachControl(noPreventDefault: boolean, useCtrlForPanning: boolean): void;
  661. /**
  662. * Attached controls to the current camera.
  663. * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
  664. * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  665. * @param useCtrlForPanning Defines whether ctrl is used for paning within the controls
  666. */
  667. public attachControl(ignored: any, noPreventDefault: boolean, useCtrlForPanning: boolean): void;
  668. /**
  669. * Attached controls to the current camera.
  670. * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  671. * @param useCtrlForPanning Defines whether ctrl is used for paning within the controls
  672. * @param panningMouseButton Defines whether panning is allowed through mouse click button
  673. */
  674. public attachControl(noPreventDefault: boolean, useCtrlForPanning: boolean, panningMouseButton: number): void;
  675. /**
  676. * Attached controls to the current camera.
  677. * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
  678. * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  679. * @param useCtrlForPanning Defines whether ctrl is used for paning within the controls
  680. * @param panningMouseButton Defines whether panning is allowed through mouse click button
  681. */
  682. public attachControl(ignored: any, noPreventDefault?: boolean, useCtrlForPanning: boolean | number = true, panningMouseButton: number = 2): void {
  683. noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);
  684. if (typeof arguments[0] === "boolean") {
  685. this._useCtrlForPanning = arguments[1];
  686. this._panningMouseButton = arguments[2];
  687. } else {
  688. this._useCtrlForPanning = useCtrlForPanning as boolean;
  689. this._panningMouseButton = panningMouseButton;
  690. }
  691. this.inputs.attachElement(noPreventDefault);
  692. this._reset = () => {
  693. this.inertialAlphaOffset = 0;
  694. this.inertialBetaOffset = 0;
  695. this.inertialRadiusOffset = 0;
  696. this.inertialPanningX = 0;
  697. this.inertialPanningY = 0;
  698. };
  699. }
  700. /**
  701. * Detach the current controls from the camera.
  702. * The camera will stop reacting to inputs.
  703. */
  704. public detachControl(): void {
  705. this.inputs.detachElement();
  706. if (this._reset) {
  707. this._reset();
  708. }
  709. }
  710. /** @hidden */
  711. public _checkInputs(): void {
  712. //if (async) collision inspection was triggered, don't update the camera's position - until the collision callback was called.
  713. if (this._collisionTriggered) {
  714. return;
  715. }
  716. this.inputs.checkInputs();
  717. // Inertia
  718. if (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0 || this.inertialRadiusOffset !== 0) {
  719. let inertialAlphaOffset = this.inertialAlphaOffset;
  720. if (this.beta <= 0) {
  721. inertialAlphaOffset *= -1;
  722. }
  723. if (this.getScene().useRightHandedSystem) {
  724. inertialAlphaOffset *= -1;
  725. }
  726. if (this.parent && this.parent._getWorldMatrixDeterminant() < 0) {
  727. inertialAlphaOffset *= -1;
  728. }
  729. this.alpha += inertialAlphaOffset;
  730. this.beta += this.inertialBetaOffset;
  731. this.radius -= this.inertialRadiusOffset;
  732. this.inertialAlphaOffset *= this.inertia;
  733. this.inertialBetaOffset *= this.inertia;
  734. this.inertialRadiusOffset *= this.inertia;
  735. if (Math.abs(this.inertialAlphaOffset) < Epsilon) {
  736. this.inertialAlphaOffset = 0;
  737. }
  738. if (Math.abs(this.inertialBetaOffset) < Epsilon) {
  739. this.inertialBetaOffset = 0;
  740. }
  741. if (Math.abs(this.inertialRadiusOffset) < this.speed * Epsilon) {
  742. this.inertialRadiusOffset = 0;
  743. }
  744. }
  745. // Panning inertia
  746. if (this.inertialPanningX !== 0 || this.inertialPanningY !== 0) {
  747. if (!this._localDirection) {
  748. this._localDirection = Vector3.Zero();
  749. this._transformedDirection = Vector3.Zero();
  750. }
  751. this._localDirection.copyFromFloats(this.inertialPanningX, this.inertialPanningY, this.inertialPanningY);
  752. this._localDirection.multiplyInPlace(this.panningAxis);
  753. this._viewMatrix.invertToRef(this._cameraTransformMatrix);
  754. Vector3.TransformNormalToRef(this._localDirection, this._cameraTransformMatrix, this._transformedDirection);
  755. //Eliminate y if map panning is enabled (panningAxis == 1,0,1)
  756. if (!this.panningAxis.y) {
  757. this._transformedDirection.y = 0;
  758. }
  759. if (!this._targetHost) {
  760. if (this.panningDistanceLimit) {
  761. this._transformedDirection.addInPlace(this._target);
  762. var distanceSquared = Vector3.DistanceSquared(this._transformedDirection, this.panningOriginTarget);
  763. if (distanceSquared <= this.panningDistanceLimit * this.panningDistanceLimit) {
  764. this._target.copyFrom(this._transformedDirection);
  765. }
  766. } else {
  767. this._target.addInPlace(this._transformedDirection);
  768. }
  769. }
  770. this.inertialPanningX *= this.panningInertia;
  771. this.inertialPanningY *= this.panningInertia;
  772. if (Math.abs(this.inertialPanningX) < this.speed * Epsilon) {
  773. this.inertialPanningX = 0;
  774. }
  775. if (Math.abs(this.inertialPanningY) < this.speed * Epsilon) {
  776. this.inertialPanningY = 0;
  777. }
  778. }
  779. // Limits
  780. this._checkLimits();
  781. super._checkInputs();
  782. }
  783. protected _checkLimits() {
  784. if (this.lowerBetaLimit === null || this.lowerBetaLimit === undefined) {
  785. if (this.allowUpsideDown && this.beta > Math.PI) {
  786. this.beta = this.beta - 2 * Math.PI;
  787. }
  788. } else {
  789. if (this.beta < this.lowerBetaLimit) {
  790. this.beta = this.lowerBetaLimit;
  791. }
  792. }
  793. if (this.upperBetaLimit === null || this.upperBetaLimit === undefined) {
  794. if (this.allowUpsideDown && this.beta < -Math.PI) {
  795. this.beta = this.beta + 2 * Math.PI;
  796. }
  797. } else {
  798. if (this.beta > this.upperBetaLimit) {
  799. this.beta = this.upperBetaLimit;
  800. }
  801. }
  802. if (this.lowerAlphaLimit !== null && this.alpha < this.lowerAlphaLimit) {
  803. this.alpha = this.lowerAlphaLimit;
  804. }
  805. if (this.upperAlphaLimit !== null && this.alpha > this.upperAlphaLimit) {
  806. this.alpha = this.upperAlphaLimit;
  807. }
  808. if (this.lowerRadiusLimit !== null && this.radius < this.lowerRadiusLimit) {
  809. this.radius = this.lowerRadiusLimit;
  810. this.inertialRadiusOffset = 0;
  811. }
  812. if (this.upperRadiusLimit !== null && this.radius > this.upperRadiusLimit) {
  813. this.radius = this.upperRadiusLimit;
  814. this.inertialRadiusOffset = 0;
  815. }
  816. }
  817. /**
  818. * Rebuilds angles (alpha, beta) and radius from the give position and target
  819. */
  820. public rebuildAnglesAndRadius(): void {
  821. this._position.subtractToRef(this._getTargetPosition(), this._computationVector);
  822. // need to rotate to Y up equivalent if up vector not Axis.Y
  823. if (this._upVector.x !== 0 || this._upVector.y !== 1.0 || this._upVector.z !== 0) {
  824. Vector3.TransformCoordinatesToRef(this._computationVector, this._upToYMatrix, this._computationVector);
  825. }
  826. this.radius = this._computationVector.length();
  827. if (this.radius === 0) {
  828. this.radius = 0.0001; // Just to avoid division by zero
  829. }
  830. // Alpha
  831. if (this._computationVector.x === 0 && this._computationVector.z === 0) {
  832. this.alpha = Math.PI / 2; // avoid division by zero when looking along up axis, and set to acos(0)
  833. } else {
  834. this.alpha = Math.acos(this._computationVector.x / Math.sqrt(Math.pow(this._computationVector.x, 2) + Math.pow(this._computationVector.z, 2)));
  835. }
  836. if (this._computationVector.z < 0) {
  837. this.alpha = 2 * Math.PI - this.alpha;
  838. }
  839. // Beta
  840. this.beta = Math.acos(this._computationVector.y / this.radius);
  841. this._checkLimits();
  842. }
  843. /**
  844. * Use a position to define the current camera related information like alpha, beta and radius
  845. * @param position Defines the position to set the camera at
  846. */
  847. public setPosition(position: Vector3): void {
  848. if (this._position.equals(position)) {
  849. return;
  850. }
  851. this._position.copyFrom(position);
  852. this.rebuildAnglesAndRadius();
  853. }
  854. /**
  855. * Defines the target the camera should look at.
  856. * This will automatically adapt alpha beta and radius to fit within the new target.
  857. * @param target Defines the new target as a Vector or a mesh
  858. * @param toBoundingCenter In case of a mesh target, defines whether to target the mesh position or its bounding information center
  859. * @param allowSamePosition If false, prevents reapplying the new computed position if it is identical to the current one (optim)
  860. */
  861. public setTarget(target: AbstractMesh | Vector3, toBoundingCenter = false, allowSamePosition = false): void {
  862. if ((<any>target).getBoundingInfo) {
  863. if (toBoundingCenter) {
  864. this._targetBoundingCenter = (<any>target).getBoundingInfo().boundingBox.centerWorld.clone();
  865. } else {
  866. this._targetBoundingCenter = null;
  867. }
  868. (<AbstractMesh>target).computeWorldMatrix();
  869. this._targetHost = <AbstractMesh>target;
  870. this._target = this._getTargetPosition();
  871. this.onMeshTargetChangedObservable.notifyObservers(this._targetHost);
  872. } else {
  873. var newTarget = <Vector3>target;
  874. var currentTarget = this._getTargetPosition();
  875. if (currentTarget && !allowSamePosition && currentTarget.equals(newTarget)) {
  876. return;
  877. }
  878. this._targetHost = null;
  879. this._target = newTarget;
  880. this._targetBoundingCenter = null;
  881. this.onMeshTargetChangedObservable.notifyObservers(null);
  882. }
  883. this.rebuildAnglesAndRadius();
  884. }
  885. /** @hidden */
  886. public _getViewMatrix(): Matrix {
  887. // Compute
  888. var cosa = Math.cos(this.alpha);
  889. var sina = Math.sin(this.alpha);
  890. var cosb = Math.cos(this.beta);
  891. var sinb = Math.sin(this.beta);
  892. if (sinb === 0) {
  893. sinb = 0.0001;
  894. }
  895. if (this.radius === 0) {
  896. this.radius = 0.0001; // Just to avoid division by zero
  897. }
  898. var target = this._getTargetPosition();
  899. this._computationVector.copyFromFloats(this.radius * cosa * sinb, this.radius * cosb, this.radius * sina * sinb);
  900. // Rotate according to up vector
  901. if (this._upVector.x !== 0 || this._upVector.y !== 1.0 || this._upVector.z !== 0) {
  902. Vector3.TransformCoordinatesToRef(this._computationVector, this._YToUpMatrix, this._computationVector);
  903. }
  904. target.addToRef(this._computationVector, this._newPosition);
  905. if (this.getScene().collisionsEnabled && this.checkCollisions) {
  906. const coordinator = this.getScene().collisionCoordinator;
  907. if (!this._collider) {
  908. this._collider = coordinator.createCollider();
  909. }
  910. this._collider._radius = this.collisionRadius;
  911. this._newPosition.subtractToRef(this._position, this._collisionVelocity);
  912. this._collisionTriggered = true;
  913. coordinator.getNewPosition(this._position, this._collisionVelocity, this._collider, 3, null, this._onCollisionPositionChange, this.uniqueId);
  914. } else {
  915. this._position.copyFrom(this._newPosition);
  916. var up = this.upVector;
  917. if (this.allowUpsideDown && sinb < 0) {
  918. up = up.negate();
  919. }
  920. this._computeViewMatrix(this._position, target, up);
  921. this._viewMatrix.addAtIndex(12, this.targetScreenOffset.x);
  922. this._viewMatrix.addAtIndex(13, this.targetScreenOffset.y);
  923. }
  924. this._currentTarget = target;
  925. return this._viewMatrix;
  926. }
  927. protected _onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: Nullable<AbstractMesh> = null) => {
  928. if (!collidedMesh) {
  929. this._previousPosition.copyFrom(this._position);
  930. } else {
  931. this.setPosition(newPosition);
  932. if (this.onCollide) {
  933. this.onCollide(collidedMesh);
  934. }
  935. }
  936. // Recompute because of constraints
  937. var cosa = Math.cos(this.alpha);
  938. var sina = Math.sin(this.alpha);
  939. var cosb = Math.cos(this.beta);
  940. var sinb = Math.sin(this.beta);
  941. if (sinb === 0) {
  942. sinb = 0.0001;
  943. }
  944. var target = this._getTargetPosition();
  945. this._computationVector.copyFromFloats(this.radius * cosa * sinb, this.radius * cosb, this.radius * sina * sinb);
  946. target.addToRef(this._computationVector, this._newPosition);
  947. this._position.copyFrom(this._newPosition);
  948. var up = this.upVector;
  949. if (this.allowUpsideDown && this.beta < 0) {
  950. up = up.clone();
  951. up = up.negate();
  952. }
  953. this._computeViewMatrix(this._position, target, up);
  954. this._viewMatrix.addAtIndex(12, this.targetScreenOffset.x);
  955. this._viewMatrix.addAtIndex(13, this.targetScreenOffset.y);
  956. this._collisionTriggered = false;
  957. };
  958. /**
  959. * Zooms on a mesh to be at the min distance where we could see it fully in the current viewport.
  960. * @param meshes Defines the mesh to zoom on
  961. * @param doNotUpdateMaxZ Defines whether or not maxZ should be updated whilst zooming on the mesh (this can happen if the mesh is big and the maxradius pretty small for instance)
  962. */
  963. public zoomOn(meshes?: AbstractMesh[], doNotUpdateMaxZ = false): void {
  964. meshes = meshes || this.getScene().meshes;
  965. var minMaxVector = Mesh.MinMax(meshes);
  966. var distance = Vector3.Distance(minMaxVector.min, minMaxVector.max);
  967. this.radius = distance * this.zoomOnFactor;
  968. this.focusOn({ min: minMaxVector.min, max: minMaxVector.max, distance: distance }, doNotUpdateMaxZ);
  969. }
  970. /**
  971. * Focus on a mesh or a bounding box. This adapts the target and maxRadius if necessary but does not update the current radius.
  972. * The target will be changed but the radius
  973. * @param meshesOrMinMaxVectorAndDistance Defines the mesh or bounding info to focus on
  974. * @param doNotUpdateMaxZ Defines whether or not maxZ should be updated whilst zooming on the mesh (this can happen if the mesh is big and the maxradius pretty small for instance)
  975. */
  976. public focusOn(meshesOrMinMaxVectorAndDistance: AbstractMesh[] | { min: Vector3; max: Vector3; distance: number }, doNotUpdateMaxZ = false): void {
  977. var meshesOrMinMaxVector: { min: Vector3; max: Vector3 };
  978. var distance: number;
  979. if ((<any>meshesOrMinMaxVectorAndDistance).min === undefined) {
  980. // meshes
  981. var meshes = <AbstractMesh[]>meshesOrMinMaxVectorAndDistance || this.getScene().meshes;
  982. meshesOrMinMaxVector = Mesh.MinMax(meshes);
  983. distance = Vector3.Distance(meshesOrMinMaxVector.min, meshesOrMinMaxVector.max);
  984. } else {
  985. //minMaxVector and distance
  986. var minMaxVectorAndDistance = <any>meshesOrMinMaxVectorAndDistance;
  987. meshesOrMinMaxVector = minMaxVectorAndDistance;
  988. distance = minMaxVectorAndDistance.distance;
  989. }
  990. this._target = Mesh.Center(meshesOrMinMaxVector);
  991. if (!doNotUpdateMaxZ) {
  992. this.maxZ = distance * 2;
  993. }
  994. }
  995. /**
  996. * @override
  997. * Override Camera.createRigCamera
  998. */
  999. public createRigCamera(name: string, cameraIndex: number): Camera {
  1000. var alphaShift: number = 0;
  1001. switch (this.cameraRigMode) {
  1002. case Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:
  1003. case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:
  1004. case Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:
  1005. case Camera.RIG_MODE_STEREOSCOPIC_INTERLACED:
  1006. case Camera.RIG_MODE_VR:
  1007. alphaShift = this._cameraRigParams.stereoHalfAngle * (cameraIndex === 0 ? 1 : -1);
  1008. break;
  1009. case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:
  1010. alphaShift = this._cameraRigParams.stereoHalfAngle * (cameraIndex === 0 ? -1 : 1);
  1011. break;
  1012. }
  1013. var rigCam = new ArcRotateCamera(name, this.alpha + alphaShift, this.beta, this.radius, this._target, this.getScene());
  1014. rigCam._cameraRigParams = {};
  1015. rigCam.isRigCamera = true;
  1016. rigCam.rigParent = this;
  1017. rigCam.upVector = this.upVector;
  1018. return rigCam;
  1019. }
  1020. /**
  1021. * @hidden
  1022. * @override
  1023. * Override Camera._updateRigCameras
  1024. */
  1025. public _updateRigCameras() {
  1026. var camLeft = <ArcRotateCamera>this._rigCameras[0];
  1027. var camRight = <ArcRotateCamera>this._rigCameras[1];
  1028. camLeft.beta = camRight.beta = this.beta;
  1029. switch (this.cameraRigMode) {
  1030. case Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:
  1031. case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:
  1032. case Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:
  1033. case Camera.RIG_MODE_STEREOSCOPIC_INTERLACED:
  1034. case Camera.RIG_MODE_VR:
  1035. camLeft.alpha = this.alpha - this._cameraRigParams.stereoHalfAngle;
  1036. camRight.alpha = this.alpha + this._cameraRigParams.stereoHalfAngle;
  1037. break;
  1038. case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:
  1039. camLeft.alpha = this.alpha + this._cameraRigParams.stereoHalfAngle;
  1040. camRight.alpha = this.alpha - this._cameraRigParams.stereoHalfAngle;
  1041. break;
  1042. }
  1043. super._updateRigCameras();
  1044. }
  1045. /**
  1046. * Destroy the camera and release the current resources hold by it.
  1047. */
  1048. public dispose(): void {
  1049. this.inputs.clear();
  1050. super.dispose();
  1051. }
  1052. /**
  1053. * Gets the current object class name.
  1054. * @return the class name
  1055. */
  1056. public getClassName(): string {
  1057. return "ArcRotateCamera";
  1058. }
  1059. }