mirror of
https://github.com/wassname/phaser.git
synced 2026-08-14 12:40:17 +08:00
After a mammoth debugging session we now have advanced physics colliding and responding accurately :)
This commit is contained in:
@@ -23,12 +23,8 @@ module Phaser {
|
||||
this.c = Math.cos(angle);
|
||||
this.s = Math.sin(angle);
|
||||
|
||||
this._tempVec = new Phaser.Vec2;
|
||||
|
||||
}
|
||||
|
||||
private _tempVec: Phaser.Vec2;
|
||||
|
||||
public t: Phaser.Vec2;
|
||||
public c: number;
|
||||
public s: number;
|
||||
@@ -68,28 +64,6 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
public rotate(v:Phaser.Vec2):Phaser.Vec2 {
|
||||
return this._tempVec.setTo(v.x * this.c - v.y * this.s, v.x * this.s + v.y * this.c);
|
||||
}
|
||||
|
||||
public unrotate(v:Phaser.Vec2):Phaser.Vec2 {
|
||||
return this._tempVec.setTo(v.x * this.c + v.y * this.s, -v.x * this.s + v.y * this.c);
|
||||
}
|
||||
|
||||
public transform(v:Phaser.Vec2):Phaser.Vec2 {
|
||||
return this._tempVec.setTo(v.x * this.c - v.y * this.s + this.t.x, v.x * this.s + v.y * this.c + this.t.y);
|
||||
}
|
||||
|
||||
public untransform(v:Phaser.Vec2):Phaser.Vec2 {
|
||||
|
||||
var px = v.x - this.t.x;
|
||||
var py = v.y - this.t.y;
|
||||
|
||||
// expensive - check for alternatives
|
||||
return this._tempVec.setTo(px * this.c + py * this.s, -px * this.s + py * this.c);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="Vec2.ts" />
|
||||
/// <reference path="Transform.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - TransformUtils
|
||||
*
|
||||
* A collection of methods useful for manipulating and performing operations on 2D Transforms.
|
||||
*
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class TransformUtils {
|
||||
|
||||
public static rotate(t: Transform, v:Phaser.Vec2, out?: Vec2 = new Vec2):Phaser.Vec2 {
|
||||
return out.setTo(v.x * t.c - v.y * t.s, v.x * t.s + v.y * t.c);
|
||||
}
|
||||
|
||||
public static unrotate(t: Transform, v:Phaser.Vec2, out?: Vec2 = new Vec2):Phaser.Vec2 {
|
||||
return out.setTo(v.x * t.c + v.y * t.s, -v.x * t.s + v.y * t.c);
|
||||
}
|
||||
|
||||
public static transform(t: Transform, v:Phaser.Vec2, out?: Vec2 = new Vec2):Phaser.Vec2 {
|
||||
return out.setTo(v.x * t.c - v.y * t.s + t.t.x, v.x * t.s + v.y * t.c + t.t.y);
|
||||
}
|
||||
|
||||
public static untransform(t: Transform, v:Phaser.Vec2, out?: Vec2 = new Vec2):Phaser.Vec2 {
|
||||
|
||||
var px = v.x - t.t.x;
|
||||
var py = v.y - t.t.y;
|
||||
|
||||
return out.setTo(px * t.c + py * t.s, -px * t.s + py * t.c);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../math/Vec2.ts" />
|
||||
/// <reference path="Vec2.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Vec2Utils
|
||||
|
||||
Reference in New Issue
Block a user