Skip to content

Commit 461f7ee

Browse files
committed
Added lots more classes into the Advanced Physics package
1 parent 038cb21 commit 461f7ee

15 files changed

Lines changed: 4486 additions & 31 deletions

Phaser/Phaser.csproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@
184184
<Content Include="physics\advanced\Bounds.js">
185185
<DependentUpon>Bounds.ts</DependentUpon>
186186
</Content>
187+
<TypeScriptCompile Include="physics\advanced\Contact.ts" />
188+
<TypeScriptCompile Include="physics\advanced\Collision.ts" />
189+
<Content Include="physics\advanced\Collision.js">
190+
<DependentUpon>Collision.ts</DependentUpon>
191+
</Content>
192+
<Content Include="physics\advanced\Contact.js">
193+
<DependentUpon>Contact.ts</DependentUpon>
194+
</Content>
195+
<TypeScriptCompile Include="physics\advanced\ContactSolver.ts" />
196+
<Content Include="physics\advanced\ContactSolver.js">
197+
<DependentUpon>ContactSolver.ts</DependentUpon>
198+
</Content>
187199
<Content Include="physics\advanced\Joint.js">
188200
<DependentUpon>Joint.ts</DependentUpon>
189201
</Content>
@@ -196,9 +208,25 @@
196208
<DependentUpon>Shape.ts</DependentUpon>
197209
</Content>
198210
<TypeScriptCompile Include="physics\advanced\ShapeCircle.ts" />
211+
<TypeScriptCompile Include="physics\advanced\ShapeBox.ts" />
212+
<Content Include="physics\advanced\ShapeBox.js">
213+
<DependentUpon>ShapeBox.ts</DependentUpon>
214+
</Content>
199215
<Content Include="physics\advanced\ShapeCircle.js">
200216
<DependentUpon>ShapeCircle.ts</DependentUpon>
201217
</Content>
218+
<TypeScriptCompile Include="physics\advanced\ShapeSegment.ts" />
219+
<TypeScriptCompile Include="physics\advanced\ShapePoly.ts" />
220+
<Content Include="physics\advanced\ShapePoly.js">
221+
<DependentUpon>ShapePoly.ts</DependentUpon>
222+
</Content>
223+
<Content Include="physics\advanced\ShapeSegment.js">
224+
<DependentUpon>ShapeSegment.ts</DependentUpon>
225+
</Content>
226+
<TypeScriptCompile Include="physics\advanced\ShapeTriangle.ts" />
227+
<Content Include="physics\advanced\ShapeTriangle.js">
228+
<DependentUpon>ShapeTriangle.ts</DependentUpon>
229+
</Content>
202230
<Content Include="physics\ArcadePhysics.js">
203231
<DependentUpon>ArcadePhysics.ts</DependentUpon>
204232
</Content>

Phaser/math/Vec2.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,20 @@ module Phaser {
137137
return (this.x * this.x) + (this.y * this.y);
138138
}
139139

140+
/**
141+
* Normalize this vector.
142+
*
143+
* @return {Vec2} This for chaining.
144+
*/
145+
public normalize(): Vec2 {
146+
147+
var inv = (this.x != 0 || this.y != 0) ? 1 / Math.sqrt(this.x * this.x + this.y * this.y) : 0;
148+
this.x *= inv;
149+
this.y *= inv;
150+
return this;
151+
152+
}
153+
140154
/**
141155
* The dot product of two 2D vectors.
142156
*

Phaser/math/Vec2Utils.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ module Phaser {
8585
return out.setTo(a.x + b.x * s, a.y + b.y * s);
8686
}
8787

88+
/**
89+
* Return a negative vector.
90+
*
91+
* @param {Vec2} a Reference to a source Vec2 object.
92+
* @param {Vec2} out The output Vec2 that is the result of the operation.
93+
* @return {Vec2} A Vec2 that is the negative vector.
94+
*/
95+
static negative(a: Vec2, out?: Vec2 = new Vec2): Vec2 {
96+
return out.setTo(-a.x, -a.y);
97+
}
98+
8899
/**
89100
* Return a perpendicular vector (90 degrees rotation)
90101
*
@@ -277,12 +288,30 @@ module Phaser {
277288
* @param {Vec2} out The output Vec2 that is the result of the operation.
278289
* @return {Vec2} A Vec2.
279290
*/
280-
static rotate(a: Vec2, b: Vec2, theta: number, out?: Vec2 = new Vec2): Vec2 {
291+
static rotateAroundOrigin(a: Vec2, b: Vec2, theta: number, out?: Vec2 = new Vec2): Vec2 {
281292
var x = a.x - b.x;
282293
var y = a.y - b.y;
283294
return out.setTo(x * Math.cos(theta) - y * Math.sin(theta) + b.x, x * Math.sin(theta) + y * Math.cos(theta) + b.y);
284295
}
285296

297+
/**
298+
* Rotate a 2D vector to the given angle (theta).
299+
*
300+
* @param {Vec2} a Reference to a source Vec2 object.
301+
* @param {Vec2} b Reference to a source Vec2 object.
302+
* @param {Number} theta The angle of rotation in radians.
303+
* @param {Vec2} out The output Vec2 that is the result of the operation.
304+
* @return {Vec2} A Vec2.
305+
*/
306+
static rotate(a: Vec2, theta: number, out?: Vec2 = new Vec2): Vec2 {
307+
308+
var c = Math.cos(theta);
309+
var s = Math.sin(theta);
310+
311+
return out.setTo(a.x * c - a.y * s, a.x * s + a.y * c);
312+
313+
}
314+
286315
/**
287316
* Clone a 2D vector.
288317
*

0 commit comments

Comments
 (0)