/home/lindsay/xeolabs/xeogl-next/xeogl/src/camera/customProjection.js
API Docs for:

File: /home/lindsay/xeolabs/xeogl-next/xeogl/src/camera/customProjection.js

  1. /**
  2. A **CustomProjection** defines a projection for a {{#crossLink "Camera"}}Camera{{/crossLink}} as a custom 4x4 matrix..
  3.  
  4. ## Overview
  5.  
  6. * A {{#crossLink "Camera"}}Camera{{/crossLink}} has a CustomProjection to configure its custom projection mode.
  7. * A CustomProjection lets us explicitly set the elements of its 4x4 transformation matrix.
  8.  
  9. ## Examples
  10.  
  11. * [Camera with a CustomProjection](../../examples/#camera_customProjection)
  12.  
  13. ## Usage
  14.  
  15. * See {{#crossLink "Camera"}}{{/crossLink}}
  16.  
  17. @class CustomProjection
  18. @module xeogl
  19. @submodule camera
  20. @constructor
  21. @param [owner] {Component} Owner component. When destroyed, the owner will destroy this component as well. Creates this component within the default {{#crossLink "Scene"}}{{/crossLink}} when omitted.
  22. @param [cfg] {*} Configs
  23. @param [cfg.id] {String} Optional ID, unique among all components in the parent scene, generated automatically when omitted.
  24. @param [cfg.meta] {String:Object} Optional map of user-defined metadata to attach to this CustomProjection.
  25. @param [cfg.matrix=] {Float32Array} 4x4 transform matrix.
  26. @extends Component
  27. */
  28. import {math} from '../math/math.js';
  29. import {Component} from '../component.js';
  30. import {State} from '../renderer/state.js';
  31. import {componentClasses} from "./../componentClasses.js";
  32.  
  33. const type = "xeogl.CustomProjection";
  34.  
  35. class CustomProjection extends Component {
  36.  
  37. /**
  38. JavaScript class name for this Component.
  39.  
  40. For example: "xeogl.AmbientLight", "xeogl.MetallicMaterial" etc.
  41.  
  42. @property type
  43. @type String
  44. @final
  45. */
  46. get type() {
  47. return type;
  48. }
  49.  
  50. init(cfg) {
  51. super.init(cfg);
  52. this._state = new State({
  53. matrix: math.mat4()
  54. });
  55. this.matrix = cfg.matrix;
  56. }
  57.  
  58.  
  59. /**
  60. The CustomProjection's projection transform matrix.
  61.  
  62. Fires a {{#crossLink "CustomProjection/matrix:event"}}{{/crossLink}} event on change.
  63.  
  64. @property matrix
  65. @default [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
  66. @type {Float32Array}
  67. */
  68. set matrix(matrix) {
  69.  
  70. this._state.matrix.set(matrix || [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
  71.  
  72. /**
  73. Fired whenever this CustomProjection's {{#crossLink "CustomProjection/matrix:property"}}{{/crossLink}} property changes.
  74.  
  75. @event matrix
  76. @param value The property's new value
  77. */
  78. this.fire("far", this._state.matrix);
  79. }
  80.  
  81. get matrix() {
  82. return this._state.matrix;
  83. }
  84.  
  85. destroy() {
  86. super.destroy();
  87. this._state.destroy();
  88. }
  89. }
  90.  
  91. componentClasses[type] = CustomProjection;
  92.  
  93. export{CustomProjection};
  94.