openfl
Version:
A fast, productive library for 2D cross-platform development.
132 lines (115 loc) • 6.1 kB
JavaScript
// Class: openfl.utils.PerspectiveMatrix3D
var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this
$global.Object.defineProperty(exports, "__esModule", {value: true});
var __map_reserved = {};
// Imports
var $hxClasses = require("./../../hxClasses_stub").default;
var $hxEnums = require("./../../hxEnums_stub").default;
var $import = require("./../../import_stub").default;
var $extend = require("./../../extend_stub").default;
function openfl_geom_Matrix3D() {return require("./../../openfl/geom/Matrix3D");}
function openfl_VectorData() {return require("./../../openfl/VectorData");}
function openfl_geom_Vector3D() {return require("./../../openfl/geom/Vector3D");}
// Constructor
var PerspectiveMatrix3D = function(v) {
this._w = new (openfl_geom_Vector3D().default)();
this._z = new (openfl_geom_Vector3D().default)();
this._y = new (openfl_geom_Vector3D().default)();
this._x = new (openfl_geom_Vector3D().default)();
(openfl_geom_Matrix3D().default).call(this,v);
}
// Meta
PerspectiveMatrix3D.__name__ = "openfl.utils.PerspectiveMatrix3D";
PerspectiveMatrix3D.__isInterface__ = false;
PerspectiveMatrix3D.__super__ = (openfl_geom_Matrix3D().default);
PerspectiveMatrix3D.prototype = $extend((openfl_geom_Matrix3D().default).prototype, {
lookAtLH: function(eye,at,up) {
this._z.copyFrom(at);
this._z.subtract(eye);
this._z.normalize();
this._z.w = 0.0;
this._x.copyFrom(up);
this._crossProductTo(this._x,this._z);
this._x.normalize();
this._x.w = 0.0;
this._y.copyFrom(this._z);
this._crossProductTo(this._y,this._x);
this._y.w = 0.0;
this._w.x = this._x.dotProduct(eye);
this._w.y = this._y.dotProduct(eye);
this._w.z = this._z.dotProduct(eye);
this._w.w = 1.0;
this.copyRowFrom(0,this._x);
this.copyRowFrom(1,this._y);
this.copyRowFrom(2,this._z);
this.copyRowFrom(3,this._w);
},
lookAtRH: function(eye,at,up) {
this._z.copyFrom(eye);
this._z.subtract(at);
this._z.normalize();
this._z.w = 0.0;
this._x.copyFrom(up);
this._crossProductTo(this._x,this._z);
this._x.normalize();
this._x.w = 0.0;
this._y.copyFrom(this._z);
this._crossProductTo(this._y,this._x);
this._y.w = 0.0;
this._w.x = this._x.dotProduct(eye);
this._w.y = this._y.dotProduct(eye);
this._w.z = this._z.dotProduct(eye);
this._w.w = 1.0;
this.copyRowFrom(0,this._x);
this.copyRowFrom(1,this._y);
this.copyRowFrom(2,this._z);
this.copyRowFrom(3,this._w);
},
orthoLH: function(width,height,zNear,zFar) {
this.copyRawDataFrom((openfl_VectorData().default).ofArray([2.0 / width,0.0,0.0,0.0,0.0,2.0 / height,0.0,0.0,0.0,0.0,1.0 / (zFar - zNear),0.0,0.0,0.0,zNear / (zNear - zFar),1.0]));
},
orthoOffCenterLH: function(left,right,bottom,top,zNear,zFar) {
this.copyRawDataFrom((openfl_VectorData().default).ofArray([2.0 / (right - left),0.0,0.0,0.0,0.0,2.0 * zNear / (top - bottom),0.0,0.0,-1.0 - 2.0 * left / (right - left),1.0 + 2.0 * top / (bottom - top),1.0 / (zFar - zNear),0.0,0.0,0.0,zNear / (zNear - zFar),1.0]));
},
orthoOffCenterRH: function(left,right,bottom,top,zNear,zFar) {
this.copyRawDataFrom((openfl_VectorData().default).ofArray([2.0 / (right - left),0.0,0.0,0.0,0.0,2.0 * zNear / (top - bottom),0.0,0.0,-1.0 - 2.0 * left / (right - left),1.0 + 2.0 * top / (bottom - top),1.0 / (zNear - zFar),0.0,0.0,0.0,zNear / (zNear - zFar),1.0]));
},
orthoRH: function(width,height,zNear,zFar) {
this.copyRawDataFrom((openfl_VectorData().default).ofArray([2.0 / width,0.0,0.0,0.0,0.0,2.0 / height,0.0,0.0,0.0,0.0,1.0 / (zNear - zNear),0.0,0.0,0.0,zNear / (zNear - zFar),1.0]));
},
perspectiveFieldOfViewLH: function(fieldOfViewY,aspectRatio,zNear,zFar) {
var yScale = 1.0 / Math.tan(fieldOfViewY / 2.0);
var xScale = yScale / aspectRatio;
this.copyRawDataFrom((openfl_VectorData().default).ofArray([xScale,0.0,0.0,0.0,0.0,yScale,0.0,0.0,0.0,0.0,zFar / (zFar - zNear),1.0,0.0,0.0,zNear * zFar / (zNear - zFar),0.0]));
},
perspectiveFieldOfViewRH: function(fieldOfViewY,aspectRatio,zNear,zFar) {
var yScale = 1.0 / Math.tan(fieldOfViewY / 2.0);
var xScale = yScale / aspectRatio;
this.copyRawDataFrom((openfl_VectorData().default).ofArray([xScale,0.0,0.0,0.0,0.0,yScale,0.0,0.0,0.0,0.0,zFar / (zNear - zFar),-1.0,0.0,0.0,zNear * zFar / (zNear - zFar),0.0]));
},
perspectiveOffCenterLH: function(left,right,bottom,top,zNear,zFar) {
this.copyRawDataFrom((openfl_VectorData().default).ofArray([2.0 * zNear / (right - left),0.0,0.0,0.0,0.0,-2.0 * zNear / (bottom - top),0.0,0.0,-1.0 - 2.0 * left / (right - left),1.0 + 2.0 * top / (bottom - top),-zFar / (zNear - zFar),1.0,0.0,0.0,zNear * zFar / (zNear - zFar),0.0]));
},
perspectiveLH: function(width,height,zNear,zFar) {
this.copyRawDataFrom((openfl_VectorData().default).ofArray([2.0 * zNear / width,0.0,0.0,0.0,0.0,2.0 * zNear / height,0.0,0.0,0.0,0.0,zFar / (zFar - zNear),1.0,0.0,0.0,zNear * zFar / (zNear - zFar),0.0]));
},
perspectiveOffCenterRH: function(left,right,bottom,top,zNear,zFar) {
this.copyRawDataFrom((openfl_VectorData().default).ofArray([2.0 * zNear / (right - left),0.0,0.0,0.0,0.0,-2.0 * zNear / (bottom - top),0.0,0.0,1.0 + 2.0 * left / (right - left),-1.0 - 2.0 * top / (bottom - top),zFar / (zNear - zFar),-1.0,0.0,0.0,zNear * zFar / (zNear - zFar),0.0]));
},
perspectiveRH: function(width,height,zNear,zFar) {
this.copyRawDataFrom((openfl_VectorData().default).ofArray([2.0 * zNear / width,0.0,0.0,0.0,0.0,2.0 * zNear / height,0.0,0.0,0.0,0.0,zFar / (zNear - zFar),-1.0,0.0,0.0,zNear * zFar / (zNear - zFar),0.0]));
},
_crossProductTo: function(a,b) {
this._w.x = a.y * b.z - a.z * b.y;
this._w.y = a.z * b.x - a.x * b.z;
this._w.z = a.x * b.y - a.y * b.x;
this._w.w = 1.0;
a.copyFrom(this._w);
}
});
PerspectiveMatrix3D.prototype.__class__ = PerspectiveMatrix3D.prototype.constructor = $hxClasses["openfl.utils.PerspectiveMatrix3D"] = PerspectiveMatrix3D;
// Init
// Statics
PerspectiveMatrix3D.__meta__ = { obj : { SuppressWarnings : ["checkstyle:FieldDocComment"]}}
// Export
exports.default = PerspectiveMatrix3D;