awayjs-display
Version:
AwayJS displaylist classes
232 lines • 9 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var MathConsts_1 = require("awayjs-core/lib/geom/MathConsts");
var ControllerBase_1 = require("../controllers/ControllerBase");
/**
* Extended camera used to hover round a specified target object.
*
* @see away3d.containers.View3D
*/
var FirstPersonController = (function (_super) {
__extends(FirstPersonController, _super);
/**
* Creates a new <code>HoverController</code> object.
*/
function FirstPersonController(targetObject, panAngle, tiltAngle, minTiltAngle, maxTiltAngle, steps, wrapPanAngle) {
if (targetObject === void 0) { targetObject = null; }
if (panAngle === void 0) { panAngle = 0; }
if (tiltAngle === void 0) { tiltAngle = 90; }
if (minTiltAngle === void 0) { minTiltAngle = -90; }
if (maxTiltAngle === void 0) { maxTiltAngle = 90; }
if (steps === void 0) { steps = 8; }
if (wrapPanAngle === void 0) { wrapPanAngle = false; }
_super.call(this, targetObject);
this._iCurrentPanAngle = 0;
this._iCurrentTiltAngle = 90;
this._panAngle = 0;
this._tiltAngle = 90;
this._minTiltAngle = -90;
this._maxTiltAngle = 90;
this._steps = 8;
this._walkIncrement = 0;
this._strafeIncrement = 0;
this._wrapPanAngle = false;
this.fly = false;
this.panAngle = panAngle;
this.tiltAngle = tiltAngle;
this.minTiltAngle = minTiltAngle;
this.maxTiltAngle = maxTiltAngle;
this.steps = steps;
this.wrapPanAngle = wrapPanAngle;
//values passed in contrustor are applied immediately
this._iCurrentPanAngle = this._panAngle;
this._iCurrentTiltAngle = this._tiltAngle;
}
Object.defineProperty(FirstPersonController.prototype, "steps", {
/**
* Fractional step taken each time the <code>hover()</code> method is called. Defaults to 8.
*
* Affects the speed at which the <code>tiltAngle</code> and <code>panAngle</code> resolve to their targets.
*
* @see #tiltAngle
* @see #panAngle
*/
get: function () {
return this._steps;
},
set: function (val) {
val = (val < 1) ? 1 : val;
if (this._steps == val)
return;
this._steps = val;
this.pNotifyUpdate();
},
enumerable: true,
configurable: true
});
Object.defineProperty(FirstPersonController.prototype, "panAngle", {
/**
* Rotation of the camera in degrees around the y axis. Defaults to 0.
*/
get: function () {
return this._panAngle;
},
set: function (val) {
if (this._panAngle == val)
return;
this._panAngle = val;
this.pNotifyUpdate();
},
enumerable: true,
configurable: true
});
Object.defineProperty(FirstPersonController.prototype, "tiltAngle", {
/**
* Elevation angle of the camera in degrees. Defaults to 90.
*/
get: function () {
return this._tiltAngle;
},
set: function (val) {
val = Math.max(this._minTiltAngle, Math.min(this._maxTiltAngle, val));
if (this._tiltAngle == val)
return;
this._tiltAngle = val;
this.pNotifyUpdate();
},
enumerable: true,
configurable: true
});
Object.defineProperty(FirstPersonController.prototype, "minTiltAngle", {
/**
* Minimum bounds for the <code>tiltAngle</code>. Defaults to -90.
*
* @see #tiltAngle
*/
get: function () {
return this._minTiltAngle;
},
set: function (val) {
if (this._minTiltAngle == val)
return;
this._minTiltAngle = val;
this.tiltAngle = Math.max(this._minTiltAngle, Math.min(this._maxTiltAngle, this._tiltAngle));
},
enumerable: true,
configurable: true
});
Object.defineProperty(FirstPersonController.prototype, "maxTiltAngle", {
/**
* Maximum bounds for the <code>tiltAngle</code>. Defaults to 90.
*
* @see #tiltAngle
*/
get: function () {
return this._maxTiltAngle;
},
set: function (val) {
if (this._maxTiltAngle == val)
return;
this._maxTiltAngle = val;
this.tiltAngle = Math.max(this._minTiltAngle, Math.min(this._maxTiltAngle, this._tiltAngle));
},
enumerable: true,
configurable: true
});
Object.defineProperty(FirstPersonController.prototype, "wrapPanAngle", {
/**
* Defines whether the value of the pan angle wraps when over 360 degrees or under 0 degrees. Defaults to false.
*/
get: function () {
return this._wrapPanAngle;
},
set: function (val) {
if (this._wrapPanAngle == val)
return;
this._wrapPanAngle = val;
this.pNotifyUpdate();
},
enumerable: true,
configurable: true
});
/**
* Updates the current tilt angle and pan angle values.
*
* Values are calculated using the defined <code>tiltAngle</code>, <code>panAngle</code> and <code>steps</code> variables.
*
* @param interpolate If the update to a target pan- or tiltAngle is interpolated. Default is true.
*
* @see #tiltAngle
* @see #panAngle
* @see #steps
*/
FirstPersonController.prototype.update = function (interpolate) {
if (interpolate === void 0) { interpolate = true; }
if (this._tiltAngle != this._iCurrentTiltAngle || this._panAngle != this._iCurrentPanAngle) {
this._pControllerDirty = true;
if (this._wrapPanAngle) {
if (this._panAngle < 0) {
this._iCurrentPanAngle += this._panAngle % 360 + 360 - this._panAngle;
this._panAngle = this._panAngle % 360 + 360;
}
else {
this._iCurrentPanAngle += this._panAngle % 360 - this._panAngle;
this._panAngle = this._panAngle % 360;
}
while (this._panAngle - this._iCurrentPanAngle < -180)
this._iCurrentPanAngle -= 360;
while (this._panAngle - this._iCurrentPanAngle > 180)
this._iCurrentPanAngle += 360;
}
if (interpolate) {
this._iCurrentTiltAngle += (this._tiltAngle - this._iCurrentTiltAngle) / (this.steps + 1);
this._iCurrentPanAngle += (this._panAngle - this._iCurrentPanAngle) / (this.steps + 1);
}
else {
this._iCurrentTiltAngle = this._tiltAngle;
this._iCurrentPanAngle = this._panAngle;
}
//snap coords if angle differences are close
if ((Math.abs(this.tiltAngle - this._iCurrentTiltAngle) < 0.01) && (Math.abs(this._panAngle - this._iCurrentPanAngle) < 0.01)) {
this._iCurrentTiltAngle = this._tiltAngle;
this._iCurrentPanAngle = this._panAngle;
}
}
this.targetObject.rotationX = this._iCurrentTiltAngle;
this.targetObject.rotationY = this._iCurrentPanAngle;
if (this._walkIncrement) {
if (this.fly) {
this.targetObject.transform.moveForward(this._walkIncrement);
}
else {
this.targetObject.x += this._walkIncrement * Math.sin(this._panAngle * MathConsts_1.default.DEGREES_TO_RADIANS);
this.targetObject.z += this._walkIncrement * Math.cos(this._panAngle * MathConsts_1.default.DEGREES_TO_RADIANS);
}
this._walkIncrement = 0;
}
if (this._strafeIncrement) {
this.targetObject.transform.moveRight(this._strafeIncrement);
this._strafeIncrement = 0;
}
};
FirstPersonController.prototype.incrementWalk = function (val) {
if (val == 0)
return;
this._walkIncrement += val;
this.pNotifyUpdate();
};
FirstPersonController.prototype.incrementStrafe = function (val) {
if (val == 0)
return;
this._strafeIncrement += val;
this.pNotifyUpdate();
};
return FirstPersonController;
}(ControllerBase_1.default));
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = FirstPersonController;
//# sourceMappingURL=FirstPersonController.js.map