感谢NEZ库提供的思路
This commit is contained in:
@@ -8,5 +8,9 @@ module es {
|
||||
* 每帧更新事件
|
||||
*/
|
||||
frameUpdated,
|
||||
/**
|
||||
* 当渲染发生时触发
|
||||
*/
|
||||
renderChanged,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ module es {
|
||||
}
|
||||
|
||||
public render(scene: Scene): void {
|
||||
if (!this.renderDirty)
|
||||
return;
|
||||
|
||||
this.renderDirty = false;
|
||||
let cam = this.camera ? this.camera : scene.camera;
|
||||
this.beginRender(cam);
|
||||
|
||||
|
||||
@@ -3,10 +3,13 @@ module es {
|
||||
public camera: ICamera;
|
||||
public readonly renderOrder: number = 0;
|
||||
public shouldDebugRender: boolean = true;
|
||||
protected renderDirty: boolean = true;
|
||||
|
||||
constructor(renderOrder: number, camera: ICamera) {
|
||||
this.renderOrder = renderOrder;
|
||||
this.camera = camera;
|
||||
|
||||
Core.emitter.addObserver(CoreEvents.renderChanged, this.onRenderChanged, this);
|
||||
}
|
||||
|
||||
public onAddedToScene(scene: es.Scene) { }
|
||||
@@ -26,6 +29,10 @@ module es {
|
||||
|
||||
Graphics.instance.batcher.end();
|
||||
}
|
||||
|
||||
protected onRenderChanged() {
|
||||
this.renderDirty = true;
|
||||
}
|
||||
|
||||
public abstract render(scene: Scene): void;
|
||||
|
||||
|
||||
@@ -381,6 +381,16 @@ module es {
|
||||
return this.repeat(this.approach(start, start + deltaAngle, shift), 360);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Vector 投影到另一个 Vector 上
|
||||
* @param other
|
||||
*/
|
||||
public static project(self: Vector2, other: Vector2) {
|
||||
let amt = Vector2.dot(self, other) / other.lengthSquared();
|
||||
let vec = new Vector2(amt * other.x, amt * other.y);
|
||||
return vec;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过将偏移量(全部以弧度为单位)夹住结果并选择最短路径,起始角度朝向终止角度。
|
||||
* 起始值可以小于或大于终止值。
|
||||
|
||||
@@ -3,6 +3,15 @@ module es {
|
||||
* 代表右手4x4浮点矩阵,可以存储平移、比例和旋转信息
|
||||
*/
|
||||
export class Matrix {
|
||||
private static identity = new Matrix(1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
|
||||
public static get Identity() {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
public m11: number;
|
||||
public m12: number;
|
||||
public m13: number;
|
||||
@@ -20,6 +29,26 @@ module es {
|
||||
public m43: number;
|
||||
public m44: number;
|
||||
|
||||
constructor(m11?, m12?, m13?, m14?, m21?, m22?, m23?, m24?, m31?,
|
||||
m32?, m33?, m34?, m41?, m42?, m43?, m44?) {
|
||||
this.m11 = m11;
|
||||
this.m12 = m12;
|
||||
this.m13 = m13;
|
||||
this.m14 = m14;
|
||||
this.m21 = m21;
|
||||
this.m22 = m22;
|
||||
this.m23 = m23;
|
||||
this.m24 = m24;
|
||||
this.m31 = m31;
|
||||
this.m32 = m32;
|
||||
this.m33 = m33;
|
||||
this.m34 = m34;
|
||||
this.m41 = m41;
|
||||
this.m42 = m42;
|
||||
this.m43 = m43;
|
||||
this.m44 = m44;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为自定义的正交视图创建一个新的投影矩阵
|
||||
* @param left
|
||||
@@ -47,6 +76,39 @@ module es {
|
||||
result.m44 = 1;
|
||||
}
|
||||
|
||||
public static createTranslation(position: Vector2, result: Matrix)
|
||||
{
|
||||
result.m11 = 1;
|
||||
result.m12 = 0;
|
||||
result.m13 = 0;
|
||||
result.m14 = 0;
|
||||
result.m21 = 0;
|
||||
result.m22 = 1;
|
||||
result.m23 = 0;
|
||||
result.m24 = 0;
|
||||
result.m31 = 0;
|
||||
result.m32 = 0;
|
||||
result.m33 = 1;
|
||||
result.m34 = 0;
|
||||
result.m41 = position.x;
|
||||
result.m42 = position.y;
|
||||
result.m43 = 0;
|
||||
result.m44 = 1;
|
||||
}
|
||||
|
||||
public static createRotationZ(radians: number, result: Matrix)
|
||||
{
|
||||
result = Matrix.Identity;
|
||||
|
||||
var val1 = Math.cos(radians);
|
||||
var val2 = Math.sin(radians);
|
||||
|
||||
result.m11 = val1;
|
||||
result.m12 = val2;
|
||||
result.m21 = -val2;
|
||||
result.m22 = val1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个新的矩阵,其中包含两个矩阵的乘法。
|
||||
* @param matrix1
|
||||
@@ -69,23 +131,23 @@ module es {
|
||||
let m41 = (((matrix1.m41 * matrix2.m11) + (matrix1.m42 * matrix2.m21)) + (matrix1.m43 * matrix2.m31)) + (matrix1.m44 * matrix2.m41);
|
||||
let m42 = (((matrix1.m41 * matrix2.m12) + (matrix1.m42 * matrix2.m22)) + (matrix1.m43 * matrix2.m32)) + (matrix1.m44 * matrix2.m42);
|
||||
let m43 = (((matrix1.m41 * matrix2.m13) + (matrix1.m42 * matrix2.m23)) + (matrix1.m43 * matrix2.m33)) + (matrix1.m44 * matrix2.m43);
|
||||
let m44 = (((matrix1.m41 * matrix2.m14) + (matrix1.m42 * matrix2.m24)) + (matrix1.m43 * matrix2.m34)) + (matrix1.m44 * matrix2.m44);
|
||||
let m44 = (((matrix1.m41 * matrix2.m14) + (matrix1.m42 * matrix2.m24)) + (matrix1.m43 * matrix2.m34)) + (matrix1.m44 * matrix2.m44);
|
||||
result.m11 = m11;
|
||||
result.m12 = m12;
|
||||
result.m13 = m13;
|
||||
result.m14 = m14;
|
||||
result.m21 = m21;
|
||||
result.m22 = m22;
|
||||
result.m23 = m23;
|
||||
result.m24 = m24;
|
||||
result.m31 = m31;
|
||||
result.m32 = m32;
|
||||
result.m33 = m33;
|
||||
result.m34 = m34;
|
||||
result.m41 = m41;
|
||||
result.m42 = m42;
|
||||
result.m43 = m43;
|
||||
result.m44 = m44;
|
||||
result.m12 = m12;
|
||||
result.m13 = m13;
|
||||
result.m14 = m14;
|
||||
result.m21 = m21;
|
||||
result.m22 = m22;
|
||||
result.m23 = m23;
|
||||
result.m24 = m24;
|
||||
result.m31 = m31;
|
||||
result.m32 = m32;
|
||||
result.m33 = m33;
|
||||
result.m34 = m34;
|
||||
result.m41 = m41;
|
||||
result.m42 = m42;
|
||||
result.m43 = m43;
|
||||
result.m44 = m44;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ module es {
|
||||
* 在碰撞器中开始的射线/直线是否强制转换检测到那些碰撞器
|
||||
*/
|
||||
public static raycastsStartInColliders = false;
|
||||
public static debugRender: boolean = false;
|
||||
/**
|
||||
* 我们保留它以避免在每次raycast发生时分配它
|
||||
*/
|
||||
@@ -43,7 +44,8 @@ module es {
|
||||
}
|
||||
|
||||
public static debugDraw(secondsToDisplay) {
|
||||
this._spatialHash.debugDraw(secondsToDisplay);
|
||||
if (this.debugRender)
|
||||
this._spatialHash.debugDraw(secondsToDisplay);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user