更新相机强制刷新矩阵
This commit is contained in:
8
source/bin/framework.d.ts
vendored
8
source/bin/framework.d.ts
vendored
@@ -330,12 +330,12 @@ declare class Camera extends Component {
|
||||
setMinimumZoom(minZoom: number): Camera;
|
||||
setMaximumZoom(maxZoom: number): Camera;
|
||||
setZoom(zoom: number): this;
|
||||
initialize(): void;
|
||||
update(): void;
|
||||
setPosition(position: Vector2): this;
|
||||
forceMatrixUpdate(): void;
|
||||
updateMatrixes(): void;
|
||||
screenToWorldPoint(screenPosition: Vector2): Vector2;
|
||||
worldToScreenPoint(worldPosition: Vector2): Vector2;
|
||||
onEntityTransformChanged(comp: ComponentTransform): void;
|
||||
destory(): void;
|
||||
}
|
||||
declare class CameraInset {
|
||||
@@ -574,6 +574,7 @@ declare class Time {
|
||||
declare abstract class Renderer {
|
||||
camera: Camera;
|
||||
onAddedToScene(scene: Scene): void;
|
||||
protected beginRender(cam: Camera): void;
|
||||
abstract render(scene: Scene): any;
|
||||
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void;
|
||||
}
|
||||
@@ -618,7 +619,7 @@ declare class Matrix2D {
|
||||
m32: number;
|
||||
private static _identity;
|
||||
static readonly identity: Matrix2D;
|
||||
constructor(m11: number, m12: number, m21: number, m22: number, m31: number, m32: number);
|
||||
constructor(m11?: number, m12?: number, m21?: number, m22?: number, m31?: number, m32?: number);
|
||||
translation: Vector2;
|
||||
rotation: number;
|
||||
rotationDegrees: number;
|
||||
@@ -880,6 +881,7 @@ declare class Vector2Ext {
|
||||
static perpendicular(first: Vector2, second: Vector2): Vector2;
|
||||
static normalize(vec: Vector2): Vector2;
|
||||
static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, destinationArray: Vector2[], destinationIndex: number, length: number): void;
|
||||
static transformR(position: Vector2, matrix: Matrix2D): Vector2;
|
||||
static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]): void;
|
||||
}
|
||||
declare class WebGLUtils {
|
||||
|
||||
@@ -1036,7 +1036,6 @@ var Entity = (function () {
|
||||
};
|
||||
Entity.prototype.update = function () {
|
||||
this.components.update();
|
||||
this.transform.updateTransform();
|
||||
};
|
||||
Entity.prototype.onAddedToScene = function () {
|
||||
};
|
||||
@@ -1156,6 +1155,9 @@ var Scene = (function (_super) {
|
||||
};
|
||||
Scene.prototype.render = function () {
|
||||
for (var i = 0; i < this._renderers.length; i++) {
|
||||
if (this._renderers[i].camera)
|
||||
this._renderers[i].camera.forceMatrixUpdate();
|
||||
this.camera.forceMatrixUpdate();
|
||||
this._renderers[i].render(this);
|
||||
}
|
||||
};
|
||||
@@ -1215,9 +1217,9 @@ var ComponentTransform;
|
||||
var Transform = (function () {
|
||||
function Transform(entity) {
|
||||
this._localRotation = 0;
|
||||
this._worldTransform = Matrix2D.identity;
|
||||
this._worldToLocalTransform = Matrix2D.identity;
|
||||
this._worldInverseTransform = Matrix2D.identity;
|
||||
this._worldTransform = new Matrix2D();
|
||||
this._worldToLocalTransform = new Matrix2D();
|
||||
this._worldInverseTransform = new Matrix2D();
|
||||
this._rotation = 0;
|
||||
this.entity = entity;
|
||||
this._scale = this._localScale = Vector2.one;
|
||||
@@ -1257,7 +1259,7 @@ var Transform = (function () {
|
||||
get: function () {
|
||||
if (this._worldToLocalDirty) {
|
||||
if (!this.parent) {
|
||||
this._worldInverseTransform = Matrix2D.identity;
|
||||
this._worldInverseTransform = new Matrix2D();
|
||||
}
|
||||
else {
|
||||
this.parent.updateTransform();
|
||||
@@ -1320,7 +1322,7 @@ var Transform = (function () {
|
||||
}
|
||||
else {
|
||||
this.parent.updateTransform();
|
||||
this._position = Vector2.transform(this._localPosition, this.parent._worldTransform);
|
||||
this._position = Vector2Ext.transformR(this._localPosition, this.parent._worldTransform);
|
||||
}
|
||||
return this._position;
|
||||
},
|
||||
@@ -1507,9 +1509,9 @@ var Camera = (function (_super) {
|
||||
function Camera() {
|
||||
var _this = _super.call(this) || this;
|
||||
_this._origin = Vector2.zero;
|
||||
_this._transformMatrix = Matrix2D.identity;
|
||||
_this._inverseTransformMatrix = Matrix2D.identity;
|
||||
_this._projectionMatrix = Matrix2D.identity;
|
||||
_this._transformMatrix = new Matrix2D();
|
||||
_this._inverseTransformMatrix = new Matrix2D();
|
||||
_this._projectionMatrix = new Matrix2D();
|
||||
_this._minimumZoom = 0.3;
|
||||
_this._maximumZoom = 3;
|
||||
_this._areMatrixesDirty = true;
|
||||
@@ -1648,14 +1650,13 @@ var Camera = (function (_super) {
|
||||
this._areMatrixesDirty = true;
|
||||
return this;
|
||||
};
|
||||
Camera.prototype.initialize = function () {
|
||||
};
|
||||
Camera.prototype.update = function () {
|
||||
};
|
||||
Camera.prototype.setPosition = function (position) {
|
||||
this.entity.transform.setPosition(position);
|
||||
return this;
|
||||
};
|
||||
Camera.prototype.forceMatrixUpdate = function () {
|
||||
this._areMatrixesDirty = true;
|
||||
};
|
||||
Camera.prototype.updateMatrixes = function () {
|
||||
if (!this._areMatrixesDirty)
|
||||
return;
|
||||
@@ -1665,6 +1666,10 @@ var Camera = (function (_super) {
|
||||
tempMat = Matrix2D.createScale(this._zoom, this._zoom);
|
||||
this._transformMatrix = Matrix2D.multiply(this._transformMatrix, tempMat);
|
||||
}
|
||||
if (this.entity.transform.rotation != 0) {
|
||||
tempMat = Matrix2D.createRotation(this.entity.rotation);
|
||||
this._transformMatrix = Matrix2D.multiply(this._transformMatrix, tempMat);
|
||||
}
|
||||
tempMat = Matrix2D.createTranslation(this._origin.x, this._origin.y, tempMat);
|
||||
this._transformMatrix = Matrix2D.multiply(this._transformMatrix, tempMat);
|
||||
this._inverseTransformMatrix = Matrix2D.invert(this._transformMatrix);
|
||||
@@ -1673,11 +1678,14 @@ var Camera = (function (_super) {
|
||||
};
|
||||
Camera.prototype.screenToWorldPoint = function (screenPosition) {
|
||||
this.updateMatrixes();
|
||||
return Vector2.transform(screenPosition, this._inverseTransformMatrix);
|
||||
return Vector2Ext.transformR(screenPosition, this._inverseTransformMatrix);
|
||||
};
|
||||
Camera.prototype.worldToScreenPoint = function (worldPosition) {
|
||||
this.updateMatrixes();
|
||||
return Vector2.transform(worldPosition, this._transformMatrix);
|
||||
return Vector2Ext.transformR(worldPosition, this._transformMatrix);
|
||||
};
|
||||
Camera.prototype.onEntityTransformChanged = function (comp) {
|
||||
this._areMatrixesDirty = true;
|
||||
};
|
||||
Camera.prototype.destory = function () {
|
||||
};
|
||||
@@ -1869,8 +1877,8 @@ var SpriteRenderer = (function (_super) {
|
||||
SpriteRenderer.prototype.render = function (camera) {
|
||||
if (!this.sprite)
|
||||
return;
|
||||
this.sprite.x = this.entity.transform.position.x;
|
||||
this.sprite.y = this.entity.transform.position.y;
|
||||
this.sprite.x = this.entity.transform.position.x - camera.transform.position.x;
|
||||
this.sprite.y = this.entity.transform.position.y - camera.transform.position.y;
|
||||
this.sprite.rotation = this.entity.transform.rotation;
|
||||
this.sprite.anchorOffsetX = this._origin.x;
|
||||
this.sprite.anchorOffsetY = this._origin.y;
|
||||
@@ -2717,6 +2725,13 @@ var Renderer = (function () {
|
||||
function Renderer() {
|
||||
}
|
||||
Renderer.prototype.onAddedToScene = function (scene) { };
|
||||
Renderer.prototype.beginRender = function (cam) {
|
||||
cam.transform.updateTransform();
|
||||
var entities = SceneManager.getActiveScene().entities;
|
||||
for (var i = 0; i < entities.buffer.length; i++) {
|
||||
entities.buffer[i].transform.updateTransform();
|
||||
}
|
||||
};
|
||||
Renderer.prototype.renderAfterStateCheck = function (renderable, cam) {
|
||||
renderable.render(cam);
|
||||
};
|
||||
@@ -2729,6 +2744,7 @@ var DefaultRenderer = (function (_super) {
|
||||
}
|
||||
DefaultRenderer.prototype.render = function (scene) {
|
||||
var cam = this.camera ? this.camera : scene.camera;
|
||||
this.beginRender(cam);
|
||||
for (var i = 0; i < scene.renderableComponents.count; i++) {
|
||||
var renderable = scene.renderableComponents.buffer[i];
|
||||
if (renderable.enabled && renderable.isVisibleFromCamera(cam))
|
||||
@@ -2810,12 +2826,12 @@ var Matrix2D = (function () {
|
||||
this.m22 = 0;
|
||||
this.m31 = 0;
|
||||
this.m32 = 0;
|
||||
this.m11 = m11;
|
||||
this.m12 = m12;
|
||||
this.m21 = m21;
|
||||
this.m22 = m22;
|
||||
this.m31 = m31;
|
||||
this.m32 = m32;
|
||||
this.m11 = m11 ? m11 : 1;
|
||||
this.m12 = m12 ? m12 : 0;
|
||||
this.m21 = m21 ? m21 : 0;
|
||||
this.m22 = m22 ? m22 : 1;
|
||||
this.m31 = m31 ? m31 : 0;
|
||||
this.m32 = m32 ? m32 : 0;
|
||||
}
|
||||
Object.defineProperty(Matrix2D, "identity", {
|
||||
get: function () {
|
||||
@@ -2890,19 +2906,20 @@ var Matrix2D = (function () {
|
||||
return matrix1;
|
||||
};
|
||||
Matrix2D.multiply = function (matrix1, matrix2) {
|
||||
var result = new Matrix2D();
|
||||
var m11 = (matrix1.m11 * matrix2.m11) + (matrix1.m12 * matrix2.m21);
|
||||
var m12 = (matrix1.m11 * matrix2.m12) + (matrix1.m12 * matrix2.m22);
|
||||
var m21 = (matrix1.m21 * matrix2.m11) + (matrix1.m22 * matrix2.m21);
|
||||
var m22 = (matrix1.m21 * matrix2.m12) + (matrix1.m22 * matrix2.m22);
|
||||
var m31 = (matrix1.m31 * matrix2.m11) + (matrix1.m32 * matrix2.m21) + matrix2.m31;
|
||||
var m32 = (matrix1.m31 * matrix2.m12) + (matrix1.m32 * matrix2.m22) + matrix2.m32;
|
||||
matrix1.m11 = m11;
|
||||
matrix1.m12 = m12;
|
||||
matrix1.m21 = m21;
|
||||
matrix1.m22 = m22;
|
||||
matrix1.m31 = m31;
|
||||
matrix1.m32 = m32;
|
||||
return matrix1;
|
||||
result.m11 = m11;
|
||||
result.m12 = m12;
|
||||
result.m21 = m21;
|
||||
result.m22 = m22;
|
||||
result.m31 = m31;
|
||||
result.m32 = m32;
|
||||
return result;
|
||||
};
|
||||
Matrix2D.multiplyTranslation = function (matrix, x, y) {
|
||||
var trans = Matrix2D.createTranslation(x, y);
|
||||
@@ -2912,7 +2929,7 @@ var Matrix2D = (function () {
|
||||
return this.m11 * this.m22 - this.m12 * this.m21;
|
||||
};
|
||||
Matrix2D.invert = function (matrix, result) {
|
||||
if (result === void 0) { result = Matrix2D.identity; }
|
||||
if (result === void 0) { result = new Matrix2D(); }
|
||||
var det = 1 / matrix.determinant();
|
||||
result.m11 = matrix.m22 * det;
|
||||
result.m12 = -matrix.m12 * det;
|
||||
@@ -2923,7 +2940,7 @@ var Matrix2D = (function () {
|
||||
return result;
|
||||
};
|
||||
Matrix2D.createTranslation = function (xPosition, yPosition, result) {
|
||||
if (result === void 0) { result = Matrix2D.identity; }
|
||||
result = result ? result : new Matrix2D();
|
||||
result.m11 = 1;
|
||||
result.m12 = 0;
|
||||
result.m21 = 0;
|
||||
@@ -2933,7 +2950,7 @@ var Matrix2D = (function () {
|
||||
return result;
|
||||
};
|
||||
Matrix2D.createRotation = function (radians, result) {
|
||||
result = Matrix2D.identity;
|
||||
result = new Matrix2D();
|
||||
var val1 = Math.cos(radians);
|
||||
var val2 = Math.sin(radians);
|
||||
result.m11 = val1;
|
||||
@@ -2943,7 +2960,7 @@ var Matrix2D = (function () {
|
||||
return result;
|
||||
};
|
||||
Matrix2D.createScale = function (xScale, yScale, result) {
|
||||
if (result === void 0) { result = Matrix2D.identity; }
|
||||
if (result === void 0) { result = new Matrix2D(); }
|
||||
result.m11 = xScale;
|
||||
result.m12 = 0;
|
||||
result.m21 = 0;
|
||||
@@ -4282,6 +4299,11 @@ var Vector2Ext = (function () {
|
||||
destinationArray[destinationIndex + i] = destination;
|
||||
}
|
||||
};
|
||||
Vector2Ext.transformR = function (position, matrix) {
|
||||
var x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31;
|
||||
var y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32;
|
||||
return new Vector2(x, y);
|
||||
};
|
||||
Vector2Ext.transform = function (sourceArray, matrix, destinationArray) {
|
||||
this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length);
|
||||
};
|
||||
|
||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -2,9 +2,9 @@
|
||||
class Camera extends Component {
|
||||
private _zoom;
|
||||
private _origin: Vector2 = Vector2.zero;
|
||||
private _transformMatrix: Matrix2D = Matrix2D.identity;
|
||||
private _inverseTransformMatrix = Matrix2D.identity;
|
||||
private _projectionMatrix = Matrix2D.identity;
|
||||
private _transformMatrix: Matrix2D = new Matrix2D();
|
||||
private _inverseTransformMatrix = new Matrix2D();
|
||||
private _projectionMatrix = new Matrix2D();
|
||||
|
||||
private _minimumZoom = 0.3;
|
||||
private _maximumZoom = 3;
|
||||
@@ -145,20 +145,16 @@ class Camera extends Component {
|
||||
return this;
|
||||
}
|
||||
|
||||
public initialize() {
|
||||
|
||||
}
|
||||
|
||||
public update(){
|
||||
|
||||
}
|
||||
|
||||
public setPosition(position: Vector2){
|
||||
this.entity.transform.setPosition(position);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public forceMatrixUpdate(){
|
||||
this._areMatrixesDirty = true;
|
||||
}
|
||||
|
||||
public updateMatrixes(){
|
||||
if (!this._areMatrixesDirty)
|
||||
return;
|
||||
@@ -170,6 +166,11 @@ class Camera extends Component {
|
||||
this._transformMatrix = Matrix2D.multiply(this._transformMatrix, tempMat);
|
||||
}
|
||||
|
||||
if (this.entity.transform.rotation != 0){
|
||||
tempMat = Matrix2D.createRotation(this.entity.rotation);
|
||||
this._transformMatrix = Matrix2D.multiply(this._transformMatrix, tempMat);
|
||||
}
|
||||
|
||||
tempMat = Matrix2D.createTranslation(this._origin.x, this._origin.y, tempMat);
|
||||
this._transformMatrix = Matrix2D.multiply(this._transformMatrix, tempMat);
|
||||
|
||||
@@ -181,12 +182,16 @@ class Camera extends Component {
|
||||
|
||||
public screenToWorldPoint(screenPosition: Vector2){
|
||||
this.updateMatrixes();
|
||||
return Vector2.transform(screenPosition, this._inverseTransformMatrix);
|
||||
return Vector2Ext.transformR(screenPosition, this._inverseTransformMatrix);
|
||||
}
|
||||
|
||||
public worldToScreenPoint(worldPosition: Vector2){
|
||||
this.updateMatrixes();
|
||||
return Vector2.transform(worldPosition, this._transformMatrix);
|
||||
return Vector2Ext.transformR(worldPosition, this._transformMatrix);
|
||||
}
|
||||
|
||||
public onEntityTransformChanged(comp: ComponentTransform){
|
||||
this._areMatrixesDirty = true;
|
||||
}
|
||||
|
||||
public destory() {
|
||||
|
||||
@@ -49,8 +49,8 @@ class SpriteRenderer extends RenderableComponent {
|
||||
if (!this.sprite)
|
||||
return;
|
||||
|
||||
this.sprite.x = this.entity.transform.position.x;
|
||||
this.sprite.y = this.entity.transform.position.y;
|
||||
this.sprite.x = this.entity.transform.position.x - camera.transform.position.x;
|
||||
this.sprite.y = this.entity.transform.position.y - camera.transform.position.y;
|
||||
this.sprite.rotation = this.entity.transform.rotation;
|
||||
this.sprite.anchorOffsetX = this._origin.x;
|
||||
this.sprite.anchorOffsetY = this._origin.y;
|
||||
|
||||
@@ -238,7 +238,6 @@ class Entity {
|
||||
|
||||
public update(){
|
||||
this.components.update();
|
||||
this.transform.updateTransform();
|
||||
}
|
||||
|
||||
public onAddedToScene(){
|
||||
|
||||
@@ -147,6 +147,9 @@ class Scene extends egret.DisplayObjectContainer {
|
||||
|
||||
public render(){
|
||||
for (let i = 0; i <this._renderers.length; i ++){
|
||||
if (this._renderers[i].camera)
|
||||
this._renderers[i].camera.forceMatrixUpdate();
|
||||
this.camera.forceMatrixUpdate();
|
||||
this._renderers[i].render(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ class Transform {
|
||||
private _rotationMatrix: Matrix2D;
|
||||
private _scaleMatrix: Matrix2D;
|
||||
|
||||
private _worldTransform = Matrix2D.identity;
|
||||
private _worldToLocalTransform = Matrix2D.identity;
|
||||
private _worldInverseTransform = Matrix2D.identity;
|
||||
private _worldTransform = new Matrix2D();
|
||||
private _worldToLocalTransform = new Matrix2D();
|
||||
private _worldInverseTransform = new Matrix2D();
|
||||
|
||||
private _rotation: number = 0;
|
||||
private _position: Vector2;
|
||||
@@ -75,7 +75,7 @@ class Transform {
|
||||
public get worldToLocalTransform(){
|
||||
if (this._worldToLocalDirty){
|
||||
if (!this.parent){
|
||||
this._worldInverseTransform = Matrix2D.identity;
|
||||
this._worldInverseTransform = new Matrix2D();
|
||||
} else{
|
||||
this.parent.updateTransform();
|
||||
this._worldToLocalTransform = Matrix2D.invert(this.parent._worldTransform, this._worldToLocalTransform);
|
||||
@@ -134,7 +134,7 @@ class Transform {
|
||||
this._position = this._localPosition;
|
||||
}else{
|
||||
this.parent.updateTransform();
|
||||
this._position = Vector2.transform(this._localPosition, this.parent._worldTransform);
|
||||
this._position = Vector2Ext.transformR(this._localPosition, this.parent._worldTransform);
|
||||
}
|
||||
|
||||
return this._position;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
class DefaultRenderer extends Renderer {
|
||||
public render(scene: Scene) {
|
||||
let cam = this.camera ? this.camera : scene.camera;
|
||||
this.beginRender(cam);
|
||||
|
||||
for (let i = 0; i < scene.renderableComponents.count; i++){
|
||||
let renderable = scene.renderableComponents.buffer[i];
|
||||
|
||||
@@ -15,6 +15,15 @@ abstract class Renderer {
|
||||
*/
|
||||
public onAddedToScene(scene: Scene){}
|
||||
|
||||
protected beginRender(cam: Camera){
|
||||
cam.transform.updateTransform();
|
||||
|
||||
let entities = SceneManager.getActiveScene().entities;
|
||||
for (let i = 0; i < entities.buffer.length; i ++){
|
||||
entities.buffer[i].transform.updateTransform();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param scene
|
||||
|
||||
@@ -20,15 +20,15 @@ class Matrix2D {
|
||||
return Matrix2D._identity;
|
||||
}
|
||||
|
||||
constructor(m11: number, m12: number, m21: number, m22: number, m31: number, m32: number){
|
||||
this.m11 = m11;
|
||||
this.m12 = m12;
|
||||
constructor(m11?: number, m12?: number, m21?: number, m22?: number, m31?: number, m32?: number){
|
||||
this.m11 = m11 ? m11 : 1;
|
||||
this.m12 = m12 ? m12 : 0;
|
||||
|
||||
this.m21 = m21;
|
||||
this.m22 = m22;
|
||||
this.m21 = m21 ? m21 : 0;
|
||||
this.m22 = m22 ? m22 : 1;
|
||||
|
||||
this.m31 = m31;
|
||||
this.m32 = m32;
|
||||
this.m31 = m31 ? m31 : 0;
|
||||
this.m32 = m32 ? m32 : 0;
|
||||
}
|
||||
|
||||
/** 存储在这个矩阵中的位置 */
|
||||
@@ -108,6 +108,8 @@ class Matrix2D {
|
||||
}
|
||||
|
||||
public static multiply(matrix1: Matrix2D, matrix2: Matrix2D){
|
||||
let result = new Matrix2D();
|
||||
|
||||
let m11 = ( matrix1.m11 * matrix2.m11 ) + ( matrix1.m12 * matrix2.m21 );
|
||||
let m12 = ( matrix1.m11 * matrix2.m12 ) + ( matrix1.m12 * matrix2.m22 );
|
||||
|
||||
@@ -117,15 +119,16 @@ class Matrix2D {
|
||||
let m31 = ( matrix1.m31 * matrix2.m11 ) + ( matrix1.m32 * matrix2.m21 ) + matrix2.m31;
|
||||
let m32 = ( matrix1.m31 * matrix2.m12 ) + ( matrix1.m32 * matrix2.m22 ) + matrix2.m32;
|
||||
|
||||
matrix1.m11 = m11;
|
||||
matrix1.m12 = m12;
|
||||
result.m11 = m11;
|
||||
result.m12 = m12;
|
||||
|
||||
matrix1.m21 = m21;
|
||||
matrix1.m22 = m22;
|
||||
result.m21 = m21;
|
||||
result.m22 = m22;
|
||||
|
||||
matrix1.m31 = m31;
|
||||
matrix1.m32 = m32;
|
||||
return matrix1;
|
||||
result.m31 = m31;
|
||||
result.m32 = m32;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static multiplyTranslation(matrix: Matrix2D, x: number, y: number){
|
||||
@@ -137,7 +140,7 @@ class Matrix2D {
|
||||
return this.m11 * this.m22 - this.m12 * this.m21;
|
||||
}
|
||||
|
||||
public static invert(matrix: Matrix2D, result: Matrix2D = Matrix2D.identity){
|
||||
public static invert(matrix: Matrix2D, result: Matrix2D = new Matrix2D()){
|
||||
let det = 1 / matrix.determinant();
|
||||
|
||||
result.m11 = matrix.m22 * det;
|
||||
@@ -152,7 +155,9 @@ class Matrix2D {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static createTranslation(xPosition: number, yPosition: number, result: Matrix2D = Matrix2D.identity){
|
||||
public static createTranslation(xPosition: number, yPosition: number, result?: Matrix2D){
|
||||
result = result ? result : new Matrix2D();
|
||||
|
||||
result.m11 = 1;
|
||||
result.m12 = 0;
|
||||
|
||||
@@ -166,7 +171,7 @@ class Matrix2D {
|
||||
}
|
||||
|
||||
public static createRotation(radians: number, result?: Matrix2D){
|
||||
result = Matrix2D.identity;
|
||||
result = new Matrix2D();
|
||||
|
||||
let val1 = Math.cos(radians);
|
||||
let val2 = Math.sin(radians);
|
||||
@@ -179,7 +184,7 @@ class Matrix2D {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static createScale(xScale: number, yScale: number, result: Matrix2D = Matrix2D.identity){
|
||||
public static createScale(xScale: number, yScale: number, result: Matrix2D = new Matrix2D()){
|
||||
result.m11 = xScale;
|
||||
result.m12 = 0;
|
||||
|
||||
|
||||
@@ -54,6 +54,12 @@ class Vector2Ext {
|
||||
}
|
||||
}
|
||||
|
||||
public static transformR(position: Vector2, matrix: Matrix2D){
|
||||
let x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31;
|
||||
let y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32;
|
||||
return new Vector2(x, y);
|
||||
}
|
||||
|
||||
public static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]) {
|
||||
this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user