|
@@ -4,6 +4,8 @@ var BABYLON = BABYLON || {};
|
|
|
|
|
|
(function () {
|
|
|
BABYLON.Camera = function (name, position, scene) {
|
|
|
+ BABYLON.Node.call(this);
|
|
|
+
|
|
|
this.name = name;
|
|
|
this.id = name;
|
|
|
this.position = position;
|
|
@@ -28,6 +30,9 @@ var BABYLON = BABYLON || {};
|
|
|
|
|
|
// Viewport
|
|
|
this.viewport = new BABYLON.Viewport(0, 0, 1.0, 1.0);
|
|
|
+
|
|
|
+ //Cache
|
|
|
+ BABYLON.Camera.prototype._initCache.call(this);
|
|
|
};
|
|
|
|
|
|
BABYLON.Camera.prototype = Object.create(BABYLON.Node.prototype);
|
|
@@ -51,6 +56,30 @@ var BABYLON = BABYLON || {};
|
|
|
BABYLON.Camera.prototype.getScene = function () {
|
|
|
return this._scene;
|
|
|
};
|
|
|
+
|
|
|
+ //Cache
|
|
|
+ BABYLON.Camera.prototype._initCache = function () {
|
|
|
+ this._cache.position = this.position.clone();
|
|
|
+ this._cache.upVector = this.upVector.clone();
|
|
|
+ };
|
|
|
+
|
|
|
+ BABYLON.Camera.prototype._updateCache = function (ignoreParentClass) {
|
|
|
+
|
|
|
+ if(!ignoreParentClass)
|
|
|
+ BABYLON.Node.prototype._updateCache.call(this);
|
|
|
+
|
|
|
+ this._cache.position.copyFrom(this.position);
|
|
|
+ this._cache.upVector.copyFrom(this.upVector);
|
|
|
+ };
|
|
|
+
|
|
|
+ // Synchronized
|
|
|
+ BABYLON.Camera.prototype._isSynchronized = function () {
|
|
|
+ if (!BABYLON.Node.prototype._isSynchronized.call(this))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ return this._cache.position.equals(this.position)
|
|
|
+ && this._cache.upVector.equals(this.upVector);
|
|
|
+ };
|
|
|
|
|
|
// Methods
|
|
|
BABYLON.Camera.prototype.attachControl = function (canvas) {
|
|
@@ -61,6 +90,11 @@ var BABYLON = BABYLON || {};
|
|
|
|
|
|
BABYLON.Camera.prototype._update = function () {
|
|
|
};
|
|
|
+
|
|
|
+ BABYLON.Camera.prototype._updateFromScene = function () {
|
|
|
+ this.updateCache();
|
|
|
+ this._update();
|
|
|
+ };
|
|
|
|
|
|
BABYLON.Camera.prototype.getWorldMatrix = function () {
|
|
|
var viewMatrix = this.getViewMatrix();
|
|
@@ -79,22 +113,30 @@ var BABYLON = BABYLON || {};
|
|
|
};
|
|
|
|
|
|
BABYLON.Camera.prototype.getViewMatrix = function () {
|
|
|
- this._computedViewMatrix = this._getViewMatrix();
|
|
|
+ this._computedViewMatrix = this._computeViewMatrix();
|
|
|
|
|
|
- if (this.parent && this.parent.getWorldMatrix) {
|
|
|
- if (!this._worldMatrix) {
|
|
|
- this._worldMatrix = BABYLON.Matrix.Identity();
|
|
|
- }
|
|
|
+ if(!this.parent
|
|
|
+ || !this.parent.getWorldMatrix
|
|
|
+ || (!this.hasNewParent() && this.parent.isSynchronized())) {
|
|
|
+ return this._computedViewMatrix;
|
|
|
+ }
|
|
|
+
|
|
|
+ this._computedViewMatrix.invertToRef(this._worldMatrix);
|
|
|
|
|
|
- this._computedViewMatrix.invertToRef(this._worldMatrix);
|
|
|
+ this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._computedViewMatrix);
|
|
|
|
|
|
- this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._computedViewMatrix);
|
|
|
+ this._computedViewMatrix.invert();
|
|
|
|
|
|
- this._computedViewMatrix.invert();
|
|
|
+ return this._computedViewMatrix;
|
|
|
+ };
|
|
|
+
|
|
|
+ BABYLON.Camera.prototype._computeViewMatrix = function (force) {
|
|
|
|
|
|
+ if (!force && this.isSynchronized()) {
|
|
|
return this._computedViewMatrix;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ this._computedViewMatrix = this._getViewMatrix();
|
|
|
return this._computedViewMatrix;
|
|
|
};
|
|
|
|