babylon.anaglyphCamera.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. (function () {
  4. // Common
  5. var buildCamera = function (that, name) {
  6. that._leftCamera.isIntermediate = true;
  7. that.subCameras.push(that._leftCamera);
  8. that.subCameras.push(that._rightCamera);
  9. that._leftTexture = new BABYLON.PassPostProcess(name + "_leftTexture", 1.0, that._leftCamera);
  10. that._anaglyphPostProcess = new BABYLON.AnaglyphPostProcess(name + "_anaglyph", 1.0, that._rightCamera);
  11. that._anaglyphPostProcess.onApply = function(effect) {
  12. effect.setTextureFromPostProcess("leftSampler", that._leftTexture);
  13. };
  14. that._update();
  15. };
  16. // ArcRotate
  17. BABYLON.AnaglyphArcRotateCamera = function (name, alpha, beta, radius, target, eyeSpace, scene) {
  18. BABYLON.ArcRotateCamera.call(this, name, alpha, beta, radius, target, scene);
  19. this._eyeSpace = BABYLON.Tools.ToRadians(eyeSpace);
  20. this._leftCamera = new BABYLON.ArcRotateCamera(name + "_left", alpha - this._eyeSpace, beta, radius, target, scene);
  21. this._rightCamera = new BABYLON.ArcRotateCamera(name + "_right", alpha + this._eyeSpace, beta, radius, target, scene);
  22. buildCamera(this, name);
  23. };
  24. BABYLON.AnaglyphArcRotateCamera.prototype = Object.create(BABYLON.ArcRotateCamera.prototype);
  25. BABYLON.AnaglyphArcRotateCamera.prototype._update = function () {
  26. this._updateCamera(this._leftCamera);
  27. this._updateCamera(this._rightCamera);
  28. this._leftCamera.alpha = this.alpha - this._eyeSpace;
  29. this._rightCamera.alpha = this.alpha + this._eyeSpace;
  30. BABYLON.ArcRotateCamera.prototype._update.call(this);
  31. };
  32. BABYLON.AnaglyphArcRotateCamera.prototype._updateCamera = function (camera) {
  33. camera.beta = this.beta;
  34. camera.radius = this.radius;
  35. camera.minZ = this.minZ;
  36. camera.maxZ = this.maxZ;
  37. camera.fov = this.fov;
  38. camera.target = this.target;
  39. };
  40. // FreeCamera
  41. BABYLON.AnaglyphFreeCamera = function (name, position, eyeSpace, scene) {
  42. BABYLON.FreeCamera.call(this, name, position, scene);
  43. this._eyeSpace = BABYLON.Tools.ToRadians(eyeSpace);
  44. this._transformMatrix = new BABYLON.Matrix();
  45. this._leftCamera = new BABYLON.FreeCamera(name + "_left", position, scene);
  46. this._rightCamera = new BABYLON.FreeCamera(name + "_right", position, scene);
  47. buildCamera(this, name, eyeSpace);
  48. };
  49. BABYLON.AnaglyphFreeCamera.prototype = Object.create(BABYLON.FreeCamera.prototype);
  50. BABYLON.AnaglyphFreeCamera.prototype._getSubCameraPosition = function(eyeSpace, result) {
  51. var target = this.getTarget();
  52. BABYLON.Matrix.Translation(-target.x, -target.y, -target.z).multiplyToRef(BABYLON.Matrix.RotationY(eyeSpace), this._transformMatrix);
  53. this._transformMatrix = this._transformMatrix.multiply(BABYLON.Matrix.Translation(target.x, target.y, target.z));
  54. BABYLON.Vector3.TransformCoordinatesToRef(this.position, this._transformMatrix, result);
  55. };
  56. BABYLON.AnaglyphFreeCamera.prototype._update = function () {
  57. this._getSubCameraPosition(-this._eyeSpace, this._leftCamera.position);
  58. this._getSubCameraPosition(this._eyeSpace, this._rightCamera.position);
  59. this._updateCamera(this._leftCamera);
  60. this._updateCamera(this._rightCamera);
  61. BABYLON.FreeCamera.prototype._update.call(this);
  62. };
  63. BABYLON.AnaglyphFreeCamera.prototype._updateCamera = function (camera) {
  64. camera.minZ = this.minZ;
  65. camera.maxZ = this.maxZ;
  66. camera.fov = this.fov;
  67. camera.setTarget(this.getTarget());
  68. };
  69. })();