babylon.camera.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var BABYLON = BABYLON || {};
  2. (function () {
  3. BABYLON.Camera = function (name, position, scene) {
  4. this.name = name;
  5. this.id = name;
  6. this.position = position;
  7. this._scene = scene;
  8. scene.cameras.push(this);
  9. if (!scene.activeCamera) {
  10. scene.activeCamera = this;
  11. }
  12. };
  13. // Statics
  14. BABYLON.Camera.PERSPECTIVE_CAMERA = 0;
  15. BABYLON.Camera.ORTHOGRAPHIC_CAMERA = 1;
  16. // Members
  17. BABYLON.Camera.prototype.fov = 0.8;
  18. BABYLON.Camera.prototype.orthoLeft = null;
  19. BABYLON.Camera.prototype.orthoRight = null;
  20. BABYLON.Camera.prototype.orthoBottom = null;
  21. BABYLON.Camera.prototype.orthoTop = null;
  22. BABYLON.Camera.prototype.fov = 0.8;
  23. BABYLON.Camera.prototype.minZ = 0.1;
  24. BABYLON.Camera.prototype.maxZ = 1000.0;
  25. BABYLON.Camera.prototype.inertia = 0.9;
  26. BABYLON.Camera.prototype.mode = BABYLON.Camera.PERSPECTIVE_CAMERA;
  27. // Methods
  28. BABYLON.Camera.prototype.attachControl = function (canvas) {
  29. };
  30. BABYLON.Camera.prototype.detachControl = function (canvas) {
  31. };
  32. BABYLON.Camera.prototype._update = function () {
  33. };
  34. BABYLON.Camera.prototype.getViewMatrix = function () {
  35. return BABYLON.Matrix.Identity();
  36. };
  37. BABYLON.Camera.prototype.getProjectionMatrix = function () {
  38. if (!this._projectionMatrix) {
  39. this._projectionMatrix = new BABYLON.Matrix();
  40. }
  41. var engine = this._scene.getEngine();
  42. if (this.mode === BABYLON.Camera.PERSPECTIVE_CAMERA) {
  43. BABYLON.Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(), this.minZ, this.maxZ, this._projectionMatrix);
  44. return this._projectionMatrix;
  45. }
  46. var halfWidth = engine.getRenderWidth() / 2.0;
  47. var halfHeight = engine.getRenderHeight() / 2.0;
  48. BABYLON.Matrix.OrthoOffCenterLHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
  49. return this._projectionMatrix;
  50. };
  51. })();