@awayjs/scene
Version:
AwayJS scene classes
73 lines (72 loc) • 2.99 kB
JavaScript
import { __extends } from "tslib";
import { PerspectiveProjection } from '@awayjs/core';
import { BoundingVolumeType } from '@awayjs/view';
import { CameraEvent } from '../events/CameraEvent';
import { DisplayObjectContainer } from './DisplayObjectContainer';
var Camera = /** @class */ (function (_super) {
__extends(Camera, _super);
function Camera(projection) {
if (projection === void 0) { projection = null; }
var _this = _super.call(this) || this;
_this._projection = projection || new PerspectiveProjection();
_this._projection.transform = _this._transform;
_this.z = -1000;
return _this;
}
Object.defineProperty(Camera.prototype, "assetType", {
//@override
get: function () {
return Camera.assetType;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Camera.prototype, "projection", {
/**
*
*/
get: function () {
return this._projection;
},
set: function (value) {
if (this._projection == value)
return;
if (!value)
throw new Error('Projection cannot be null!');
this._projection.transform = null;
this._projection = value;
this._projection.transform = this._transform;
this.dispatchEvent(new CameraEvent(CameraEvent.PROJECTION_CHANGED, this));
},
enumerable: false,
configurable: true
});
/**
* Calculates the normalised position in screen space of the given scene position.
*
* @param point3d the position vector of the scene coordinates to be projected.
* @return The normalised screen position of the given scene coordinates.
*/
Camera.prototype.project = function (position, target) {
if (target === void 0) { target = null; }
return this._projection.project(this._transform.inverseMatrix3D.transformVector(position, target), target);
};
/**
* Calculates the scene position of the given normalized coordinates in screen space.
*
* @param nX The normalised x coordinate in screen space, minus the originX offset of the projection property.
* @param nY The normalised y coordinate in screen space, minus the originY offset of the projection property.
* @param sZ The z coordinate in screen space, representing the distance into the screen.
* @return The scene position of the given screen coordinates.
*/
Camera.prototype.unproject = function (nX, nY, sZ, target) {
if (target === void 0) { target = null; }
return this._transform.matrix3D.transformVector(this._projection.unproject(nX, nY, sZ, target));
};
Camera.prototype._getDefaultBoundingVolume = function () {
return BoundingVolumeType.NULL;
};
Camera.assetType = '[asset Camera]';
return Camera;
}(DisplayObjectContainer));
export { Camera };