Skip to content

Commit

Permalink
v1.8.5
Browse files Browse the repository at this point in the history
Former-commit-id: 39df8f9
  • Loading branch information
deltakosh committed Jan 19, 2014
1 parent 4bd926b commit 89678c4
Show file tree
Hide file tree
Showing 28 changed files with 540 additions and 315 deletions.
57 changes: 30 additions & 27 deletions Babylon/Cameras/babylon.arcRotateCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ var BABYLON = BABYLON || {};

BABYLON.ArcRotateCamera = function (name, alpha, beta, radius, target, scene) {
BABYLON.Camera.call(this, name, BABYLON.Vector3.Zero(), scene);

this.alpha = alpha;
this.beta = beta;
this.radius = radius;
this.target = target;

this._keys = [];
this.keysUp = [38];
this.keysDown = [40];
Expand All @@ -22,10 +22,10 @@ var BABYLON = BABYLON || {};
this._viewMatrix = new BABYLON.Matrix();

BABYLON.ArcRotateCamera.prototype._initCache.call(this);

this.getViewMatrix();
};

BABYLON.ArcRotateCamera.prototype = Object.create(BABYLON.Camera.prototype);

// Members
Expand All @@ -43,7 +43,7 @@ var BABYLON = BABYLON || {};
BABYLON.ArcRotateCamera.prototype._getTargetPosition = function () {
return this.target.position || this.target;
};

// Cache
BABYLON.ArcRotateCamera.prototype._initCache = function () {
this._cache.target = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
Expand All @@ -53,9 +53,9 @@ var BABYLON = BABYLON || {};
};

BABYLON.ArcRotateCamera.prototype._updateCache = function (ignoreParentClass) {
if(!ignoreParentClass)
if (!ignoreParentClass)
BABYLON.Camera.prototype._updateCache.call(this);

this._cache.target.copyFrom(this._getTargetPosition());
this._cache.alpha = this.alpha;
this._cache.beta = this.beta;
Expand All @@ -66,19 +66,19 @@ var BABYLON = BABYLON || {};
BABYLON.ArcRotateCamera.prototype._isSynchronizedViewMatrix = function () {
if (!BABYLON.Camera.prototype._isSynchronizedViewMatrix.call(this))
return false;

return this._cache.target.equals(this._getTargetPosition())
&& this._cache.alpha === this.alpha
&& this._cache.beta === this.beta
&& this._cache.radius === this.radius;
};

// Methods
BABYLON.ArcRotateCamera.prototype.attachControl = function(canvas, noPreventDefault) {
BABYLON.ArcRotateCamera.prototype.attachControl = function (canvas, noPreventDefault) {
var previousPosition;
var that = this;
var pointerId;

if (this._attachedCanvas) {
return;
}
Expand All @@ -87,7 +87,7 @@ var BABYLON = BABYLON || {};
var engine = this._scene.getEngine();

if (this._onPointerDown === undefined) {
this._onPointerDown = function(evt) {
this._onPointerDown = function (evt) {

if (pointerId) {
return;
Expand All @@ -105,15 +105,16 @@ var BABYLON = BABYLON || {};
}
};

this._onPointerUp = function(evt) {
this._onPointerUp = function (evt) {
previousPosition = null;
pointerId = null;
if (!noPreventDefault) {
evt.preventDefault();
}
};

this._onPointerMove = function(evt) {

this._onPointerMove = function (evt) {
if (!previousPosition) {
return;
}
Expand All @@ -138,7 +139,7 @@ var BABYLON = BABYLON || {};
}
};

this._onMouseMove = function(evt) {
this._onMouseMove = function (evt) {
if (!engine.isPointerLock) {
return;
}
Expand All @@ -154,7 +155,7 @@ var BABYLON = BABYLON || {};
}
};

this._wheel = function(event) {
this._wheel = function (event) {
var delta = 0;
if (event.wheelDelta) {
delta = event.wheelDelta / 120;
Expand All @@ -172,7 +173,7 @@ var BABYLON = BABYLON || {};
}
};

this._onKeyDown = function(evt) {
this._onKeyDown = function (evt) {
if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
that.keysDown.indexOf(evt.keyCode) !== -1 ||
that.keysLeft.indexOf(evt.keyCode) !== -1 ||
Expand All @@ -191,7 +192,7 @@ var BABYLON = BABYLON || {};
}
};

this._onKeyUp = function(evt) {
this._onKeyUp = function (evt) {
if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
that.keysDown.indexOf(evt.keyCode) !== -1 ||
that.keysLeft.indexOf(evt.keyCode) !== -1 ||
Expand All @@ -210,7 +211,7 @@ var BABYLON = BABYLON || {};
}
};

this._onLostFocus = function() {
this._onLostFocus = function () {
that._keys = [];
pointerId = null;
};
Expand All @@ -228,9 +229,10 @@ var BABYLON = BABYLON || {};
that._MSGestureHandler.addPointer(e.pointerId);
};

this._onGesture = function(e) {
this._onGesture = function (e) {
that.radius *= e.scale;


if (e.preventDefault) {
if (!noPreventDefault) {
e.stopPropagation();
Expand All @@ -239,7 +241,7 @@ var BABYLON = BABYLON || {};
}
};

this._reset = function() {
this._reset = function () {
that._keys = [];
that.inertialAlphaOffset = 0;
that.inertialBetaOffset = 0;
Expand All @@ -260,7 +262,7 @@ var BABYLON = BABYLON || {};
window.addEventListener('mousewheel', this._wheel, false);
window.addEventListener("blur", this._onLostFocus, false);
};

BABYLON.ArcRotateCamera.prototype.detachControl = function (canvas) {
if (this._attachedCanvas != canvas) {
return;
Expand Down Expand Up @@ -301,7 +303,7 @@ var BABYLON = BABYLON || {};
this.inertialBetaOffset += 0.01;
}
}

// Inertia
if (this.inertialAlphaOffset != 0 || this.inertialBetaOffset != 0 || this.inertialRadiusOffset != 0) {

Expand All @@ -322,7 +324,7 @@ var BABYLON = BABYLON || {};
if (Math.abs(this.inertialRadiusOffset) < BABYLON.Engine.epsilon)
this.inertialRadiusOffset = 0;
}

// Limits
if (this.lowerAlphaLimit && this.alpha < this.lowerAlphaLimit) {
this.alpha = this.lowerAlphaLimit;
Expand All @@ -344,7 +346,7 @@ var BABYLON = BABYLON || {};
}
};

BABYLON.ArcRotateCamera.prototype.setPosition = function(position) {
BABYLON.ArcRotateCamera.prototype.setPosition = function (position) {
var radiusv3 = position.subtract(this._getTargetPosition());
this.radius = radiusv3.length();

Expand All @@ -366,10 +368,11 @@ var BABYLON = BABYLON || {};
var sinb = Math.sin(this.beta);

var target = this._getTargetPosition();

target.addToRef(new BABYLON.Vector3(this.radius * cosa * sinb, this.radius * cosb, this.radius * sina * sinb), this.position);
BABYLON.Matrix.LookAtLHToRef(this.position, target, this.upVector, this._viewMatrix);

return this._viewMatrix;
};
})();
})();

Loading

0 comments on commit 89678c4

Please sign in to comment.