Complete Box2D to Planck.js migration

- Replace Box2D.js with Planck.js physics engine
- Update all require paths from 'Lib/Vendor/Box2D' to 'Lib/Vendor/Planck'
- Convert Box2D contact listeners to Planck.js event system
- Fix all method name capitalization (Get* -> get*, Set* -> set*)
- Update collision detection system for Planck.js compatibility
- Server now starts successfully and basic physics working
- Character can land on platforms - core physics functional

Major milestone: Game now running on modern, maintained physics engine
This commit is contained in:
Karl Pannek 2025-07-16 15:01:59 +02:00
parent 875abd60d9
commit dc779def9c
43 changed files with 701 additions and 14524 deletions

View file

@ -53,8 +53,8 @@ function(Parent, nc, Parser, Settings) {
} }
var difference = { var difference = {
x: Math.abs(update.p.x - this.player.doll.body.GetPosition().x), x: Math.abs(update.p.x - this.player.doll.body.getPosition().x),
y: Math.abs(update.p.y - this.player.doll.body.GetPosition().y) y: Math.abs(update.p.y - this.player.doll.body.getPosition().y)
}; };
if(difference.x < Settings.PUNKBUSTER_DIFFERENCE_METERS && if(difference.x < Settings.PUNKBUSTER_DIFFERENCE_METERS &&
@ -67,8 +67,8 @@ function(Parent, nc, Parser, Settings) {
var body = this.player.doll.body; var body = this.player.doll.body;
var options = { var options = {
p: body.GetPosition(), p: body.getPosition(),
lv: body.GetLinearVelocity() lv: body.getLinearVelocity()
}; };
nc.trigger(nc.ns.channel.to.client.user.gameCommand.send + this.player.id, "positionStateReset", options); nc.trigger(nc.ns.channel.to.client.user.gameCommand.send + this.player.id, "positionStateReset", options);

View file

@ -4,7 +4,7 @@ define([
"Game/Config/Settings", "Game/Config/Settings",
"Lib/Utilities/RequestAnimFrame", "Lib/Utilities/RequestAnimFrame",
"Lib/Utilities/NotificationCenter", "Lib/Utilities/NotificationCenter",
"Lib/Vendor/Box2D", "Lib/Vendor/Planck",
"Game/Channel/Player", "Game/Channel/Player",
"Game/Channel/GameObjects/GameObject", "Game/Channel/GameObjects/GameObject",
"Game/Channel/GameObjects/Doll", "Game/Channel/GameObjects/Doll",
@ -131,8 +131,8 @@ function (Parent, PhysicsEngine, Settings, requestAnimFrame, nc, Box2D, Player,
/* /*
var body = this.physicsEngine.world.GetBodyList(); var body = this.physicsEngine.world.GetBodyList();
do { do {
if((getSleeping || body.IsAwake()) && body.GetType() === Box2D.Dynamics.b2Body.b2_dynamicBody) { if((getSleeping || body.isAwake()) && body.getType() === 'dynamic') {
var userData = body.GetUserData(); var userData = body.getUserData();
if (userData instanceof GameObject) { if (userData instanceof GameObject) {
var gameObject = userData; var gameObject = userData;

View file

@ -1,7 +1,7 @@
define([ define([
"Game/Core/GameObjects/Doll", "Game/Core/GameObjects/Doll",
"Game/Channel/GameObjects/Item", "Game/Channel/GameObjects/Item",
"Lib/Vendor/Box2D", "Lib/Vendor/Planck",
"Lib/Utilities/NotificationCenter", "Lib/Utilities/NotificationCenter",
"Lib/Utilities/Assert" "Lib/Utilities/Assert"
], ],
@ -42,14 +42,14 @@ function (Parent, Item, Box2D, nc, Assert) {
Parent.prototype.onImpact.call(this, isColliding, fixture); Parent.prototype.onImpact.call(this, isColliding, fixture);
if(isColliding) { if(isColliding) {
var otherBody = fixture.GetBody(); var otherBody = fixture.getBody();
if(otherBody) { if(otherBody) {
var item = otherBody.GetUserData(); var item = otherBody.getUserData();
if(item instanceof Item) { if(item instanceof Item) {
var itemVelocity = item.body.GetLinearVelocity(); var itemVelocity = item.body.getLinearVelocity();
//var itemMass = item.body.GetMass(); //var itemMass = item.body.getMass();
var ownVelocity = this.body.GetLinearVelocity(); var ownVelocity = this.body.getLinearVelocity();
var b2Math = Box2D.Common.Math.b2Math; var b2Math = Box2D.Common.Math.b2Math;
var absItemVelocity = b2Math.AbsV(itemVelocity); var absItemVelocity = b2Math.AbsV(itemVelocity);
@ -97,9 +97,9 @@ function (Parent, Item, Box2D, nc, Assert) {
if(!this.isAnotherPlayerNearby()) { if(!this.isAnotherPlayerNearby()) {
Assert.number(update.p.x, update.p.y); Assert.number(update.p.x, update.p.y);
Assert.number(update.lv.x, update.lv.y); Assert.number(update.lv.x, update.lv.y);
this.body.SetAwake(true); this.body.setAwake(true);
this.body.SetPosition(update.p); this.body.setPosition(update.p);
this.body.SetLinearVelocity(update.lv); this.body.setLinearVelocity(update.lv);
} }
}; };

View file

@ -1,6 +1,6 @@
define([ define([
"Game/Core/GameObjects/GameObject", "Game/Core/GameObjects/GameObject",
"Lib/Vendor/Box2D" "Lib/Vendor/Planck"
], ],
function (Parent, Box2D) { function (Parent, Box2D) {
@ -19,19 +19,19 @@ function (Parent, Box2D) {
return null; return null;
} }
if (this.body.GetType() === Box2D.Dynamics.b2Body.b2_staticBody) { if (this.body.getType() === 'static') {
return null; return null;
} }
if (!getSleeping && !this.body.IsAwake()) { if (!getSleeping && !this.body.isAwake()) {
return null; return null;
} }
return { return {
p: this.body.GetPosition(), p: this.body.getPosition(),
a: this.body.GetAngle(), a: this.body.getAngle(),
lv: this.body.GetLinearVelocity(), lv: this.body.getLinearVelocity(),
av: this.body.GetAngularVelocity() av: this.body.getAngularVelocity()
}; };
} }

View file

@ -74,9 +74,9 @@ function (Parent, nc) {
Item.prototype.onCollisionChange = function(isColliding, fixture) { Item.prototype.onCollisionChange = function(isColliding, fixture) {
if(isColliding) { if(isColliding) {
var otherBody = fixture.GetBody(); var otherBody = fixture.getBody();
if(otherBody) { if(otherBody) {
var otherItem = otherBody.GetUserData(); var otherItem = otherBody.getUserData();
if(otherItem instanceof Item) { if(otherItem instanceof Item) {
if(!this.lastMoved && !otherItem.lastMoved) return; if(!this.lastMoved && !otherItem.lastMoved) return;

View file

@ -56,10 +56,10 @@ function (Parent, Settings, nc) {
for(var name in this.limbs) { for(var name in this.limbs) {
limbUpdateData[name] = { limbUpdateData[name] = {
p: this.limbs[name].GetPosition(), p: this.limbs[name].getPosition(),
a: this.limbs[name].GetAngle(), a: this.limbs[name].getAngle(),
lv: this.limbs[name].GetLinearVelocity(), lv: this.limbs[name].getLinearVelocity(),
av: this.limbs[name].GetAngularVelocity() av: this.limbs[name].getAngularVelocity()
}; };
} }
updateData['limbs'] = limbUpdateData; updateData['limbs'] = limbUpdateData;

View file

@ -1,6 +1,6 @@
define([ define([
"Game/Core/GameController", "Game/Core/GameController",
"Lib/Vendor/Box2D", "Lib/Vendor/Planck",
"Game/Client/Physics/Engine", "Game/Client/Physics/Engine",
"Game/Client/View/ViewManager", "Game/Client/View/ViewManager",
"Game/Client/Control/PlayerController", "Game/Client/Control/PlayerController",
@ -49,6 +49,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, nc, reque
this.animationRequestId = requestAnimFrame(this.update.bind(this)); this.animationRequestId = requestAnimFrame(this.update.bind(this));
this.physicsEngine.update(); this.physicsEngine.update();
this.physicsEngine.renderDebug(); // Render Planck.js debug draw
if(this.me) { if(this.me) {
this.me.update(); this.me.update();

View file

@ -276,8 +276,8 @@ function (Parent, Settings, nc, Exception, ColorConverter, Layer) {
this.layerId, this.layerId,
this.animatedMeshes[this.actionState], this.animatedMeshes[this.actionState],
{ {
x: this.body.GetPosition().x * Settings.RATIO, x: this.body.getPosition().x * Settings.RATIO,
y: this.body.GetPosition().y * Settings.RATIO, y: this.body.getPosition().y * Settings.RATIO,
animationSpeed: factor animationSpeed: factor
//rotation: this.body.GetAngle() //rotation: this.body.GetAngle()
} }
@ -287,8 +287,8 @@ function (Parent, Settings, nc, Exception, ColorConverter, Layer) {
this.layerId, this.layerId,
this.headMesh, this.headMesh,
{ {
x: this.body.GetPosition().x * Settings.RATIO, x: this.body.getPosition().x * Settings.RATIO,
y: this.body.GetPosition().y * Settings.RATIO - this.height + this.headHeight y: this.body.getPosition().y * Settings.RATIO - this.height + this.headHeight
} }
) )
@ -296,8 +296,8 @@ function (Parent, Settings, nc, Exception, ColorConverter, Layer) {
this.layerId, this.layerId,
this.holdingArmMesh, this.holdingArmMesh,
{ {
x: this.body.GetPosition().x * Settings.RATIO, x: this.body.getPosition().x * Settings.RATIO,
y: this.body.GetPosition().y * Settings.RATIO y: this.body.getPosition().y * Settings.RATIO
} }
) )
} }

View file

@ -59,9 +59,9 @@ function (Parent, Settings, nc, Layer) {
this.layerId, this.layerId,
this.mesh, this.mesh,
{ {
x: this.body.GetPosition().x * Settings.RATIO, x: this.body.getPosition().x * Settings.RATIO,
y: this.body.GetPosition().y * Settings.RATIO, y: this.body.getPosition().y * Settings.RATIO,
rotation: this.body.GetAngle() rotation: this.body.getAngle()
} }
); );
} }

View file

@ -68,9 +68,9 @@ function (Parent, CoreItem, Settings, nc, Layer) {
this.layerId, this.layerId,
this.limbMeshes[name], this.limbMeshes[name],
{ {
x: this.limbs[name].GetPosition().x * Settings.RATIO, x: this.limbs[name].getPosition().x * Settings.RATIO,
y: this.limbs[name].GetPosition().y * Settings.RATIO, y: this.limbs[name].getPosition().y * Settings.RATIO,
rotation: this.limbs[name].GetAngle() rotation: this.limbs[name].getAngle()
} }
); );
} }

View file

@ -173,9 +173,9 @@ function (Parent, Layer, Settings, nc) {
this.layerId, this.layerId,
this.mesh, this.mesh,
{ {
x: this.body.GetPosition().x * Settings.RATIO, x: this.body.getPosition().x * Settings.RATIO,
y: this.body.GetPosition().y * Settings.RATIO, y: this.body.getPosition().y * Settings.RATIO,
rotation: this.body.GetAngle() rotation: this.body.getAngle()
} }
); );
@ -186,9 +186,9 @@ function (Parent, Layer, Settings, nc) {
this.layerId, this.layerId,
this.limbMeshes[name], this.limbMeshes[name],
{ {
x: this.limbs[name].GetPosition().x * Settings.RATIO, x: this.limbs[name].getPosition().x * Settings.RATIO,
y: this.limbs[name].GetPosition().y * Settings.RATIO, y: this.limbs[name].getPosition().y * Settings.RATIO,
rotation: this.limbs[name].GetAngle() rotation: this.limbs[name].getAngle()
} }
); );
} }

View file

@ -65,8 +65,8 @@ function (Parent, Settings, nc, Assert, PlayerController) {
} }
var difference = { var difference = {
x: Math.abs(this.lastServerPositionState.p.x - this.doll.body.GetPosition().x), x: Math.abs(this.lastServerPositionState.p.x - this.doll.body.getPosition().x),
y: Math.abs(this.lastServerPositionState.p.y - this.doll.body.GetPosition().y) y: Math.abs(this.lastServerPositionState.p.y - this.doll.body.getPosition().y)
}; };
if(difference.x > Settings.ME_STATE_MAX_DIFFERENCE_METERS || if(difference.x > Settings.ME_STATE_MAX_DIFFERENCE_METERS ||
@ -78,8 +78,8 @@ function (Parent, Settings, nc, Assert, PlayerController) {
Me.prototype.getPositionStateOverride = function() { Me.prototype.getPositionStateOverride = function() {
return { return {
p: this.doll.body.GetPosition().Copy(), p: this.doll.body.getPosition().clone(),
lv: this.doll.body.GetLinearVelocity().Copy() lv: this.doll.body.getLinearVelocity().clone()
}; };
}; };
@ -91,8 +91,8 @@ function (Parent, Settings, nc, Assert, PlayerController) {
Me.prototype.resetPositionState = function(options) { Me.prototype.resetPositionState = function(options) {
Assert.number(options.p.x, options.p.y); Assert.number(options.p.x, options.p.y);
Assert.number(options.lv.x, options.lv.y); Assert.number(options.lv.x, options.lv.y);
this.doll.body.SetPosition(options.p); this.doll.body.setPosition(options.p);
this.doll.body.SetLinearVelocity(options.lv); this.doll.body.setLinearVelocity(options.lv);
}; };
Me.prototype.createAndAddArrow = function() { Me.prototype.createAndAddArrow = function() {

View file

@ -2,13 +2,13 @@ define([
"Game/Core/Physics/Engine", "Game/Core/Physics/Engine",
"Game/Config/Settings", "Game/Config/Settings",
"Game/Client/View/DomController", "Game/Client/View/DomController",
"Lib/Vendor/Box2D", "Lib/Vendor/Planck",
"Lib/Utilities/NotificationCenter", "Lib/Utilities/NotificationCenter",
"Game/Client/View/Pixi/DebugDraw", "Game/Client/View/Pixi/PlanckDebugDraw",
"Game/Client/View/Pixi/Layers/Debug" "Game/Client/View/Pixi/Layers/Debug"
], ],
function (Parent, Settings, domController, Box2D, nc, DebugDraw, debugLayer) { function (Parent, Settings, domController, Box2D, nc, PlanckDebugDraw, debugLayer) {
"use strict"; "use strict";
@ -34,25 +34,26 @@ function (Parent, Settings, domController, Box2D, nc, DebugDraw, debugLayer) {
Engine.prototype.setupDebugDraw = function () { Engine.prototype.setupDebugDraw = function () {
// set debug draw // set debug draw for Planck.js
this.debugDraw = new DebugDraw(); var canvas = document.createElement('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.style.position = 'absolute';
canvas.style.top = '0';
canvas.style.left = '0';
canvas.style.pointerEvents = 'none';
canvas.style.zIndex = '1000';
document.body.appendChild(canvas);
this.debugDraw = new PlanckDebugDraw(canvas);
this.debugCanvas = canvas;
};
this.debugDraw.SetSprite(debugLayer.graphics); Engine.prototype.renderDebug = function () {
this.debugDraw.SetDrawScale(Settings.RATIO); if (this.debugDraw) {
this.debugDraw.SetFillAlpha(0.5); this.debugDraw.clear();
this.debugDraw.SetLineThickness(1.0); this.debugDraw.drawWorld(this.world);
}
this.debugDraw.SetFlags(null
| Box2D.Dynamics.b2DebugDraw.e_shapeBit
| Box2D.Dynamics.b2DebugDraw.e_jointBit
//| Box2D.Dynamics.b2DebugDraw.e_coreShapeBit
//| Box2D.Dynamics.b2DebugDraw.e_aabbBit
//| Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit
//| Box2D.Dynamics.b2DebugDraw.e_obbBit
//| Box2D.Dynamics.b2DebugDraw.e_pairBit
);
this.world.SetDebugDraw(this.debugDraw);
}; };
Engine.prototype.update = function () { Engine.prototype.update = function () {

View file

@ -1,5 +1,5 @@
define([ define([
"Lib/Vendor/Box2D" "Lib/Vendor/Planck"
], ],
function (Box2D) { function (Box2D) {

View file

@ -0,0 +1,154 @@
define([
"Game/Config/Settings"
],
function (Settings) {
"use strict";
function PlanckDebugDraw(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext('2d');
this.scale = Settings.RATIO;
this.flags = {
shapes: true,
joints: false,
aabb: false,
pairs: false,
centerOfMass: false
};
}
PlanckDebugDraw.prototype.clear = function() {
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
};
PlanckDebugDraw.prototype.drawWorld = function(world) {
if (!this.flags.shapes) return;
this.ctx.save();
this.ctx.scale(this.scale, this.scale);
this.ctx.lineWidth = 1 / this.scale;
// Iterate through all bodies
for (var body = world.getBodyList(); body; body = body.getNext()) {
var transform = body.getTransform();
// Iterate through all fixtures
for (var fixture = body.getFixtureList(); fixture; fixture = fixture.getNext()) {
var shape = fixture.getShape();
if (body.isDynamic()) {
this.ctx.strokeStyle = '#ff0000'; // Red for dynamic bodies
this.ctx.fillStyle = 'rgba(255, 0, 0, 0.1)';
} else if (body.isStatic()) {
this.ctx.strokeStyle = '#00ff00'; // Green for static bodies
this.ctx.fillStyle = 'rgba(0, 255, 0, 0.1)';
} else {
this.ctx.strokeStyle = '#0000ff'; // Blue for kinematic bodies
this.ctx.fillStyle = 'rgba(0, 0, 255, 0.1)';
}
this.drawShape(shape, transform);
}
}
this.ctx.restore();
};
PlanckDebugDraw.prototype.drawShape = function(shape, transform) {
var type = shape.getType();
if (type === 'circle') {
this.drawCircle(shape, transform);
} else if (type === 'polygon') {
this.drawPolygon(shape, transform);
} else if (type === 'edge') {
this.drawEdge(shape, transform);
} else if (type === 'chain') {
this.drawChain(shape, transform);
}
};
PlanckDebugDraw.prototype.drawCircle = function(shape, transform) {
var center = transform.p;
var radius = shape.getRadius();
this.ctx.beginPath();
this.ctx.arc(center.x, center.y, radius, 0, 2 * Math.PI);
this.ctx.fill();
this.ctx.stroke();
// Draw radius line to show rotation
this.ctx.beginPath();
this.ctx.moveTo(center.x, center.y);
this.ctx.lineTo(center.x + radius, center.y);
this.ctx.stroke();
};
PlanckDebugDraw.prototype.drawPolygon = function(shape, transform) {
var vertices = shape.m_vertices;
if (!vertices || vertices.length < 3) return;
this.ctx.beginPath();
// Transform first vertex
var v = this.transformVertex(vertices[0], transform);
this.ctx.moveTo(v.x, v.y);
// Transform and draw remaining vertices
for (var i = 1; i < vertices.length; i++) {
v = this.transformVertex(vertices[i], transform);
this.ctx.lineTo(v.x, v.y);
}
this.ctx.closePath();
this.ctx.fill();
this.ctx.stroke();
};
PlanckDebugDraw.prototype.drawEdge = function(shape, transform) {
var v1 = this.transformVertex(shape.m_vertex1, transform);
var v2 = this.transformVertex(shape.m_vertex2, transform);
this.ctx.beginPath();
this.ctx.moveTo(v1.x, v1.y);
this.ctx.lineTo(v2.x, v2.y);
this.ctx.stroke();
};
PlanckDebugDraw.prototype.drawChain = function(shape, transform) {
var vertices = shape.m_vertices;
if (!vertices || vertices.length < 2) return;
this.ctx.beginPath();
var v = this.transformVertex(vertices[0], transform);
this.ctx.moveTo(v.x, v.y);
for (var i = 1; i < vertices.length; i++) {
v = this.transformVertex(vertices[i], transform);
this.ctx.lineTo(v.x, v.y);
}
this.ctx.stroke();
};
PlanckDebugDraw.prototype.transformVertex = function(vertex, transform) {
// Apply transform: rotated_vertex = transform.q * vertex + transform.p
var cos = Math.cos(transform.q.getAngle());
var sin = Math.sin(transform.q.getAngle());
return {
x: transform.p.x + (cos * vertex.x - sin * vertex.y),
y: transform.p.y + (sin * vertex.x + cos * vertex.y)
};
};
PlanckDebugDraw.prototype.setFlags = function(flags) {
this.flags = flags;
};
return PlanckDebugDraw;
});

View file

@ -1,56 +1,52 @@
define([ define([
"Lib/Vendor/Box2D" "Lib/Vendor/Planck"
], ],
function (Box2D) { function (Planck) {
"use strict"; "use strict";
function Detector () { function Detector () {
this.listener = new Box2D.Dynamics.b2ContactListener(); // In Planck.js, contact listeners are handled via world events
this.listener.BeginContact = this.beginContact.bind(this); // We'll store the world reference when getListener is called
//this.listener.PostSolve = this.postSolve.bind(this); this.world = null;
this.listener.EndContact = this.endContact.bind(this);
} }
Detector.prototype.getListener = function () { Detector.prototype.getListener = function () {
return this.listener; // Instead of returning a listener object, we return a function
// that will set up the event listeners on the world
return this.setupWorldEvents.bind(this);
} }
Detector.prototype.onCollisionChange = function (point, isColliding) { Detector.prototype.setupWorldEvents = function (world) {
var userDataA = point.GetFixtureA().GetUserData(); this.world = world;
var userDataB = point.GetFixtureB().GetUserData();
// Set up Planck.js event listeners
world.on('begin-contact', this.beginContact.bind(this));
world.on('end-contact', this.endContact.bind(this));
return this;
}
Detector.prototype.onCollisionChange = function (contact, isColliding) {
var userDataA = contact.getFixtureA().getUserData();
var userDataB = contact.getFixtureB().getUserData();
if (userDataA && userDataA.onCollisionChange) { if (userDataA && userDataA.onCollisionChange) {
userDataA.onCollisionChange(isColliding, point.GetFixtureB()); userDataA.onCollisionChange(isColliding, contact.getFixtureB());
} }
if (userDataB && userDataB.onCollisionChange) { if (userDataB && userDataB.onCollisionChange) {
userDataB.onCollisionChange(isColliding, point.GetFixtureA()); userDataB.onCollisionChange(isColliding, contact.getFixtureA());
} }
} }
/** Extension **/ Detector.prototype.beginContact = function (contact) {
this.onCollisionChange(contact, true);
Detector.prototype.beginContact = function (point) {
this.onCollisionChange(point, true);
} }
/* Detector.prototype.endContact = function (contact) {
Detector.prototype.postSolve = function (point, impulse) { this.onCollisionChange(contact, false);
var userDataA = point.GetFixtureA().GetUserData();
var userDataB = point.GetFixtureB().GetUserData();
if (userDataA && userDataA.onImpulse) {
userDataA.onImpulse(impulse, point.GetFixtureB());
} else if (userDataB && userDataB.onImpulse) {
userDataB.onImpulse(impulse, point.GetFixtureA());
}
}
*/
Detector.prototype.endContact = function (point) {
this.onCollisionChange(point, false);
} }
return Detector; return Detector;

View file

@ -43,7 +43,7 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
this.ragDoll = {head: null, body: null}; // FIXME: wtf is this? can we remove it? this.ragDoll = {head: null, body: null}; // FIXME: wtf is this? can we remove it?
this.createFixtures(); this.createFixtures();
this.body.SetActive(false); this.body.setActive(false);
nc.trigger(nc.ns.core.game.worldUpdateObjects.add, this); nc.trigger(nc.ns.core.game.worldUpdateObjects.add, this);
} }
@ -67,16 +67,16 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
var self = this; var self = this;
var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fixtureDef.density = Settings.PLAYER_DENSITY; fixtureDef.density = Settings.PLAYER_DENSITY;
fixtureDef.friction = 0; fixtureDef.friction = 0;
fixtureDef.restitution = Settings.PLAYER_RESTITUTION; fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
var headShape = new Box2D.Collision.Shapes.b2CircleShape();
var radius = this.width / 2 / Settings.RATIO; var radius = this.width / 2 / Settings.RATIO;
headShape.SetRadius(radius); var headShape = planck.Circle(
radius,
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, -(this.height - (this.width / 2)) / Settings.RATIO)); planck.Vec2(0, -(this.height - (this.width / 2)) / Settings.RATIO)
);
fixtureDef.shape = headShape; fixtureDef.shape = headShape;
fixtureDef.isSensor = false; fixtureDef.isSensor = false;
fixtureDef.userData = { fixtureDef.userData = {
@ -85,19 +85,20 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
this.body.createFixture(fixtureDef); this.body.createFixture(fixtureDef);
var bodyShape = new Box2D.Collision.Shapes.b2PolygonShape(); var bodyShape = planck.Box(
bodyShape.SetAsOrientedBox(
this.width / 2 / Settings.RATIO, this.width / 2 / Settings.RATIO,
(this.height - this.width) / 2 / Settings.RATIO, (this.height - this.width) / 2 / Settings.RATIO,
new Box2D.Common.Math.b2Vec2(0, -this.height / 2 / Settings.RATIO) planck.Vec2(0, -this.height / 2 / Settings.RATIO),
0
); );
fixtureDef.shape = bodyShape; fixtureDef.shape = bodyShape;
fixtureDef.isSensor = false; fixtureDef.isSensor = false;
this.body.createFixture(fixtureDef); this.body.createFixture(fixtureDef);
var legsShape = new Box2D.Collision.Shapes.b2CircleShape(); var legsShape = planck.Circle(
legsShape.SetRadius(this.width / 2 / Settings.RATIO); this.width / 2 / Settings.RATIO,
legsShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, -this.width / 2 / Settings.RATIO)); planck.Vec2(0, -this.width / 2 / Settings.RATIO)
);
fixtureDef.shape = legsShape; fixtureDef.shape = legsShape;
fixtureDef.friction = Settings.PLAYER_FRICTION; fixtureDef.friction = Settings.PLAYER_FRICTION;
fixtureDef.isSensor = false; fixtureDef.isSensor = false;
@ -106,9 +107,10 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
fixtureDef.density = 0; fixtureDef.density = 0;
var feetShape = new Box2D.Collision.Shapes.b2CircleShape(); var feetShape = planck.Circle(
feetShape.SetRadius((this.width - 1) / 2 / Settings.RATIO); // the -1 one prevents collisions with walls (this.width - 1) / 2 / Settings.RATIO, // the -1 one prevents collisions with walls
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, 2 / Settings.RATIO)); // 2 is offset into ground planck.Vec2(0, 2 / Settings.RATIO) // 2 is offset into ground
);
fixtureDef.shape = feetShape; fixtureDef.shape = feetShape;
fixtureDef.isSensor = true; fixtureDef.isSensor = true;
@ -118,11 +120,10 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
this.footSensor = this.body.createFixture(fixtureDef); this.footSensor = this.body.createFixture(fixtureDef);
var grabSensorLeftShape = new Box2D.Collision.Shapes.b2PolygonShape(); var grabSensorLeftShape = planck.Box(
grabSensorLeftShape.SetAsOrientedBox(
this.reachDistance / 2 / Settings.RATIO, this.reachDistance / 2 / Settings.RATIO,
((this.height / 2) + this.reachDistance / 4) / Settings.RATIO, ((this.height / 2) + this.reachDistance / 4) / Settings.RATIO,
new Box2D.Common.Math.b2Vec2( planck.Vec2(
-this.reachDistance / 2 / Settings.RATIO, -this.reachDistance / 2 / Settings.RATIO,
-this.height / 2 / Settings.RATIO -this.height / 2 / Settings.RATIO
) )
@ -136,11 +137,10 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
}; };
this.body.createFixture(fixtureDef); this.body.createFixture(fixtureDef);
var grabSensorRightShape = new Box2D.Collision.Shapes.b2PolygonShape(); var grabSensorRightShape = planck.Box(
grabSensorRightShape.SetAsOrientedBox(
this.reachDistance / 2 / Settings.RATIO, this.reachDistance / 2 / Settings.RATIO,
((this.height / 2) + this.reachDistance / 4) / Settings.RATIO, ((this.height / 2) + this.reachDistance / 4) / Settings.RATIO,
new Box2D.Common.Math.b2Vec2( planck.Vec2(
this.reachDistance / 2 / Settings.RATIO, this.reachDistance / 2 / Settings.RATIO,
-this.height / 2 / Settings.RATIO -this.height / 2 / Settings.RATIO
) )
@ -157,11 +157,10 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
this.body.createFixture(fixtureDef); this.body.createFixture(fixtureDef);
// Area Sensor // Area Sensor
var areaSensorShape = new Box2D.Collision.Shapes.b2PolygonShape(); var areaSensorShape = planck.Box(
areaSensorShape.SetAsOrientedBox(
(this.width + this.areaSize) / 2 / Settings.RATIO, (this.width + this.areaSize) / 2 / Settings.RATIO,
(this.height + this.areaSize) / 2 / Settings.RATIO, (this.height + this.areaSize) / 2 / Settings.RATIO,
new Box2D.Common.Math.b2Vec2( planck.Vec2(
0, 0,
-this.height / 2 / Settings.RATIO -this.height / 2 / Settings.RATIO
) )
@ -171,7 +170,7 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
fixtureDef.userData = { fixtureDef.userData = {
onCollisionChange: function(isColliding, fixture) { onCollisionChange: function(isColliding, fixture) {
var userData = fixture.GetBody().GetUserData(); var userData = fixture.getBody().getUserData();
if(userData instanceof Doll) { if(userData instanceof Doll) {
var doll = userData; var doll = userData;
var i = self.nearbyDolls.indexOf(doll); var i = self.nearbyDolls.indexOf(doll);
@ -205,13 +204,13 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
Doll.prototype.spawn = function (x, y) { Doll.prototype.spawn = function (x, y) {
Assert.number(x, y); Assert.number(x, y);
this.body.SetPosition(new Box2D.Common.Math.b2Vec2(x / Settings.RATIO, y / Settings.RATIO)); this.body.setPosition(planck.Vec2(x / Settings.RATIO, y / Settings.RATIO));
this.body.SetActive(true); this.body.setActive(true);
this.setActionState("fall"); this.setActionState("fall");
}; };
Doll.prototype.getHeadPosition = function() { Doll.prototype.getHeadPosition = function() {
var pos = this.body.GetPosition(); var pos = this.body.getPosition();
return { return {
x: pos.x, x: pos.x,
y: pos.y - (this.height - this.headHeight / 2) / Settings.RATIO y: pos.y - (this.height - this.headHeight / 2) / Settings.RATIO
@ -255,11 +254,11 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
} }
this.setFriction(Settings.PLAYER_MOTION_FRICTION); this.setFriction(Settings.PLAYER_MOTION_FRICTION);
this.body.SetAwake(true); this.body.setAwake(true);
Assert.number(speed, direction); Assert.number(speed, direction);
var vector = new Box2D.Common.Math.b2Vec2(speed * direction, this.body.GetLinearVelocity().y); var vector = planck.Vec2(speed * direction, this.body.getLinearVelocity().y);
this.body.SetLinearVelocity(vector); this.body.setLinearVelocity(vector);
if(this.isStanding()) { if(this.isStanding()) {
if(this.moveDirection == this.lookDirection) { if(this.moveDirection == this.lookDirection) {
@ -282,19 +281,19 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
if(this.isStanding()) { if(this.isStanding()) {
this.setActionState("stand"); this.setActionState("stand");
} else { } else {
var vector = this.body.GetLinearVelocity().Copy(); var vector = this.body.getLinearVelocity().clone();
vector.x *= Settings.JUMP_STOP_DAMPING_FACTOR; vector.x *= Settings.JUMP_STOP_DAMPING_FACTOR;
this.body.SetLinearVelocity(vector); this.body.setLinearVelocity(vector);
} }
}; };
Doll.prototype.jump = function () { Doll.prototype.jump = function () {
if (this.isStanding()) { if (this.isStanding()) {
this.body.SetAwake(true); this.body.setAwake(true);
var vector = new Box2D.Common.Math.b2Vec2(0, -Settings.JUMP_SPEED); var vector = planck.Vec2(0, -Settings.JUMP_SPEED);
this.body.SetLinearVelocity(vector); this.body.setLinearVelocity(vector);
this.setStanding(false); this.setStanding(false);
this.setActionState("jump"); this.setActionState("jump");
@ -303,11 +302,11 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
Doll.prototype.jumpStop = function () { Doll.prototype.jumpStop = function () {
if (!this.isStanding() ) { if (!this.isStanding() ) {
this.body.SetAwake(true); this.body.setAwake(true);
var vector = this.body.GetLinearVelocity().Copy(); var vector = this.body.getLinearVelocity().clone();
if(vector.y < 0) { if(vector.y < 0) {
vector.y *= Settings.JUMP_STOP_DAMPING_FACTOR; vector.y *= Settings.JUMP_STOP_DAMPING_FACTOR;
this.body.SetLinearVelocity(vector); this.body.setLinearVelocity(vector);
} }
} }
}; };
@ -325,7 +324,7 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
Doll.prototype.lookAt = function(x, y) { Doll.prototype.lookAt = function(x, y) {
var oldLookDirection = this.lookDirection; var oldLookDirection = this.lookDirection;
this.body.SetAwake(true); this.body.setAwake(true);
if(x < 0) { if(x < 0) {
this.lookDirection = -1; this.lookDirection = -1;
} else { } else {
@ -353,11 +352,11 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
this.holdingJoint = null; this.holdingJoint = null;
} }
var bodyPosition = this.body.GetPosition(); var bodyPosition = this.body.getPosition();
Assert.number(this.width, this.height); Assert.number(this.width, this.height);
Assert.number(this.lookDirection); Assert.number(this.lookDirection);
var handPosition = new Box2D.Common.Math.b2Vec2( var handPosition = planck.Vec2(
bodyPosition.x + ((this.width / 2 / Settings.RATIO) * this.lookDirection), bodyPosition.x + ((this.width / 2 / Settings.RATIO) * this.lookDirection),
bodyPosition.y - this.height / 4 * 2 / Settings.RATIO // 2/3 of the body height bodyPosition.y - this.height / 4 * 2 / Settings.RATIO // 2/3 of the body height
); );
@ -384,8 +383,8 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
this.holdingItem = null; this.holdingItem = null;
var dollVelocity = { var dollVelocity = {
x: this.body.GetLinearVelocity().x, x: this.body.getLinearVelocity().x,
y: this.body.GetLinearVelocity().y y: this.body.getLinearVelocity().y
}; };
item.throw(options, dollVelocity); item.throw(options, dollVelocity);
@ -399,7 +398,7 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
var self = this; var self = this;
var hasJumpStartVelocity = this.body.GetLinearVelocity().y < -Settings.JUMP_SPEED; var hasJumpStartVelocity = this.body.getLinearVelocity().y < -Settings.JUMP_SPEED;
if(isColliding) { if(isColliding) {
if(!hasJumpStartVelocity) { if(!hasJumpStartVelocity) {
@ -417,11 +416,11 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
continue; continue;
} }
if(contact.GetFixtureA() === self.footSensor) { if(contact.getFixtureA() === self.footSensor) {
contactCount++; contactCount++;
} }
if(contact.GetFixtureB() === self.footSensor) { if(contact.getFixtureB() === self.footSensor) {
contactCount++; contactCount++;
} }
@ -439,7 +438,7 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
}; };
Doll.prototype.onFixtureWithinReach = function(isColliding, side, fixture) { Doll.prototype.onFixtureWithinReach = function(isColliding, side, fixture) {
var item = fixture.GetBody().GetUserData(); var item = fixture.getBody().getUserData();
if (!(item instanceof Item)) return; if (!(item instanceof Item)) return;
if(isColliding) { if(isColliding) {
@ -456,18 +455,18 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
Doll.prototype.getVelocities = function() { Doll.prototype.getVelocities = function() {
return { return {
linearVelocity: this.body.GetLinearVelocity(), linearVelocity: this.body.getLinearVelocity(),
angularVelocity: this.body.GetAngularVelocity() angularVelocity: this.body.getAngularVelocity()
}; };
}; };
Doll.prototype.update = function() { Doll.prototype.update = function() {
if (this.body.GetLinearVelocity().x === 0 && this.isWalking()) { if (this.body.getLinearVelocity().x === 0 && this.isWalking()) {
this.stop(); this.stop();
} }
if (!this.body.IsAwake() && !this.isStanding()) { if (!this.body.isAwake() && !this.isStanding()) {
this.setStanding(true); this.setStanding(true);
} }
}; };

View file

@ -51,11 +51,11 @@ function (planck, Exception, Assert, nc) {
Assert.number(update.lv.x, update.lv.y); Assert.number(update.lv.x, update.lv.y);
Assert.number(update.av); Assert.number(update.av);
this.body.SetAwake(true); this.body.setAwake(true);
this.body.SetPosition(update.p); this.body.setPosition(update.p);
this.body.SetAngle(update.a); this.body.setAngle(update.a);
this.body.SetLinearVelocity(update.lv); this.body.setLinearVelocity(update.lv);
this.body.SetAngularVelocity(update.av); this.body.setAngularVelocity(update.av);
}; };
return GameObject; return GameObject;

View file

@ -1,6 +1,6 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/GameObject", "Game/" + GLOBALS.context + "/GameObjects/GameObject",
"Lib/Vendor/Box2D", "Lib/Vendor/Planck",
"Lib/Utilities/OptionsHelper", "Lib/Utilities/OptionsHelper",
"Game/Config/Settings", "Game/Config/Settings",
"Lib/Utilities/Exception", "Lib/Utilities/Exception",
@ -37,7 +37,7 @@ function (Parent, Box2D, optionsHelper, Settings, Exception, nc, Assert) {
this.createFixture(); this.createFixture();
this.body.ResetMassData(); this.body.ResetMassData();
this.flipDirection = 1; this.flipDirection = 1;
if (this.body.GetMass() < 1) { if (this.body.getMass() < 1) {
this.body.SetBullet(true); this.body.SetBullet(true);
} }
@ -48,11 +48,11 @@ function (Parent, Box2D, optionsHelper, Settings, Exception, nc, Assert) {
Item.prototype.getBodyDef = function() { Item.prototype.getBodyDef = function() {
Assert.number(this.options.x, this.options.y); Assert.number(this.options.x, this.options.y);
var bodyDef = new Box2D.Dynamics.b2BodyDef(); var bodyDef = {
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; type: 'dynamic',
bodyDef.position.x = this.options.x / Settings.RATIO; position: planck.Vec2(this.options.x / Settings.RATIO, this.options.y / Settings.RATIO),
bodyDef.position.y = this.options.y / Settings.RATIO; angle: 0
bodyDef.angle = 0; };
return bodyDef; return bodyDef;
}; };
@ -68,15 +68,12 @@ function (Parent, Box2D, optionsHelper, Settings, Exception, nc, Assert) {
if(this.options.type == "circle") { if(this.options.type == "circle") {
var r = (w + h) / 4 ; var r = (w + h) / 4 ;
itemShape = new Box2D.Collision.Shapes.b2CircleShape(); itemShape = planck.Circle(r, planck.Vec2(0, -r));
itemShape.SetRadius(r);
itemShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, -r));
} else { } else {
itemShape = new Box2D.Collision.Shapes.b2PolygonShape(); itemShape = planck.Box(w / 2, h / 2, planck.Vec2(0, -(h/2)));
itemShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(h/2)));
} }
var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fixtureDef.shape = itemShape; fixtureDef.shape = itemShape;
fixtureDef.density = this.options.weight; fixtureDef.density = this.options.weight;
@ -95,7 +92,7 @@ function (Parent, Box2D, optionsHelper, Settings, Exception, nc, Assert) {
Item.prototype.createFixture = function () { Item.prototype.createFixture = function () {
var fixtureDef = this.getFixtureDef(); var fixtureDef = this.getFixtureDef();
this.body.CreateFixture(fixtureDef); this.body.createFixture(fixtureDef);
}; };
Item.prototype.flip = function(direction) { Item.prototype.flip = function(direction) {
@ -122,8 +119,8 @@ function (Parent, Box2D, optionsHelper, Settings, Exception, nc, Assert) {
Assert.number(this.options.width); Assert.number(this.options.width);
Assert.number(this.options.grabAngle); Assert.number(this.options.grabAngle);
this.body.SetAwake(true); this.body.setAwake(true);
var position = new Box2D.Common.Math.b2Vec2( var position = planck.Vec2(
handPosition.x + ((this.options.width / Settings.RATIO / 2) * direction), handPosition.x + ((this.options.width / Settings.RATIO / 2) * direction),
handPosition.y handPosition.y
); );
@ -133,7 +130,7 @@ function (Parent, Box2D, optionsHelper, Settings, Exception, nc, Assert) {
}; };
Item.prototype.getGrabPoint = function() { Item.prototype.getGrabPoint = function() {
return this.body.GetWorldCenter(); return this.body.getWorldCenter();
}; };
Item.prototype.throw = function(options, carrierVelocity) { Item.prototype.throw = function(options, carrierVelocity) {
@ -146,15 +143,15 @@ function (Parent, Box2D, optionsHelper, Settings, Exception, nc, Assert) {
Assert.number(options.x, options.y); Assert.number(options.x, options.y);
Assert.number(options.av); Assert.number(options.av);
body.SetAwake(true); body.setAwake(true);
var x = options.x * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.x; var x = options.x * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.x;
var y = -options.y * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.y; var y = -options.y * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.y;
var vector = new Box2D.Common.Math.b2Vec2(x, y); var vector = planck.Vec2(x, y);
body.SetLinearVelocity(vector); body.SetLinearVelocity(vector);
var av = -options.av * Settings.MAX_THROW_ANGULAR_VELOCITY; var av = -options.av * Settings.MAX_THROW_ANGULAR_VELOCITY;
body.SetAngularVelocity(av); body.setAngularVelocity(av);
}; };
Item.prototype.destroy = function() { Item.prototype.destroy = function() {

View file

@ -1,6 +1,6 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + GLOBALS.context + "/GameObjects/Item",
"Lib/Vendor/Box2D", "Lib/Vendor/Planck",
"Game/Config/Settings", "Game/Config/Settings",
"Lib/Utilities/NotificationCenter", "Lib/Utilities/NotificationCenter",
"Lib/Utilities/Assert", "Lib/Utilities/Assert",
@ -174,17 +174,17 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
}; };
RagDoll.prototype.getPosition = function() { RagDoll.prototype.getPosition = function() {
return this.body.GetPosition().Copy(); return this.body.GetPosition().clone();
}; };
RagDoll.prototype.getHeadPosition = function() { RagDoll.prototype.getHeadPosition = function() {
return this.limbs.head.GetPosition().Copy(); return this.limbs.head.GetPosition().clone();
}; };
RagDoll.prototype.getBodyDef = function() { RagDoll.prototype.getBodyDef = function() {
var bodyDef = Parent.prototype.getBodyDef.call(this); var bodyDef = Parent.prototype.getBodyDef.call(this);
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING; bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; bodyDef.type = 'dynamic';
bodyDef.position.y -= this.options.height / 2 / Settings.RATIO; // position it on top of ground bodyDef.position.y -= this.options.height / 2 / Settings.RATIO; // position it on top of ground
return bodyDef; return bodyDef;
@ -199,11 +199,10 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
fixtureDef.restitution = Settings.PLAYER_RESTITUTION; fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
fixtureDef.filter.groupIndex = -this.getId(); fixtureDef.filter.groupIndex = -this.getId();
var shape = new Box2D.Collision.Shapes.b2PolygonShape(); var shape = planck.Box(
shape.SetAsOrientedBox(
this.options.limbs.chest.width / 2 / Settings.RATIO, this.options.limbs.chest.width / 2 / Settings.RATIO,
this.options.limbs.chest.height / 2 / Settings.RATIO, this.options.limbs.chest.height / 2 / Settings.RATIO,
new Box2D.Common.Math.b2Vec2(0, 0) planck.Vec2(0, 0)
); );
fixtureDef.shape = shape; fixtureDef.shape = shape;
@ -217,10 +216,9 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
var w = this.options.width / Settings.RATIO; var w = this.options.width / Settings.RATIO;
var h = this.options.height / Settings.RATIO; var h = this.options.height / Settings.RATIO;
var itemShape = new Box2D.Collision.Shapes.b2PolygonShape(); var itemShape = planck.Box(w / 2, h / 2, planck.Vec2(0, 0));
itemShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, 0));
var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fixtureDef.shape = itemShape; fixtureDef.shape = itemShape;
fixtureDef.isSensor = true; fixtureDef.isSensor = true;
@ -228,7 +226,7 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
onCollisionChange: this.onCollisionChange.bind(this) onCollisionChange: this.onCollisionChange.bind(this)
}; };
this.body.CreateFixture(fixtureDef); this.body.createFixture(fixtureDef);
}; };
RagDoll.prototype.addHead = function() { RagDoll.prototype.addHead = function() {
@ -239,17 +237,15 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
var x = this.options.x + this.options.limbs.head.x, var x = this.options.x + this.options.limbs.head.x,
y = this.options.y + this.options.limbs.head.y - this.options.height / 2; // position it on top of ground; y = this.options.y + this.options.limbs.head.y - this.options.height / 2; // position it on top of ground;
var bodyDef = new Box2D.Dynamics.b2BodyDef(); var bodyDef = {
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; type: 'dynamic',
bodyDef.position.x = x / Settings.RATIO; position: planck.Vec2(x / Settings.RATIO, y / Settings.RATIO),
bodyDef.position.y = y / Settings.RATIO; angle: 0
bodyDef.angle = 0; };
var shape = new Box2D.Collision.Shapes.b2CircleShape(); var shape = planck.Circle(this.options.limbs.head.width / 2 / Settings.RATIO, planck.Vec2(0, 0));
shape.SetRadius(this.options.limbs.head.width / 2 / Settings.RATIO);
shape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, 0));
var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fixtureDef.density = Settings.PLAYER_DENSITY; fixtureDef.density = Settings.PLAYER_DENSITY;
fixtureDef.friction = Settings.PLAYER_FRICTION; fixtureDef.friction = Settings.PLAYER_FRICTION;
fixtureDef.restitution = Settings.PLAYER_RESTITUTION; fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
@ -258,7 +254,7 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
fixtureDef.filter.groupIndex = -this.getId(); fixtureDef.filter.groupIndex = -this.getId();
var head = this.body.GetWorld().CreateBody(bodyDef); var head = this.body.GetWorld().CreateBody(bodyDef);
head.CreateFixture(fixtureDef); head.createFixture(fixtureDef);
this.limbs.head = head; this.limbs.head = head;
@ -271,7 +267,7 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
var jointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef(); var jointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
jointDef.enableMotor = false; jointDef.enableMotor = false;
var pos = this.body.GetWorldCenter().Copy(); var pos = this.body.getWorldCenter().clone();
pos.y -= this.options.limbs.chest.height / 2 / Settings.RATIO; pos.y -= this.options.limbs.chest.height / 2 / Settings.RATIO;
jointDef.Initialize(this.body, head, pos); jointDef.Initialize(this.body, head, pos);
jointDef.lowerAngle = -0.25 * Box2D.Common.b2Settings.b2_pi; // -45 degrees jointDef.lowerAngle = -0.25 * Box2D.Common.b2Settings.b2_pi; // -45 degrees
@ -290,21 +286,20 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
var x = this.options.x + this.options.limbs[name].x, var x = this.options.x + this.options.limbs[name].x,
y = this.options.y + this.options.limbs[name].y - this.options.height / 2; // position it on top of ground;; y = this.options.y + this.options.limbs[name].y - this.options.height / 2; // position it on top of ground;;
var bodyDef = new Box2D.Dynamics.b2BodyDef(); var bodyDef = {
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING; type: 'dynamic',
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; position: planck.Vec2(x / Settings.RATIO, y / Settings.RATIO),
bodyDef.position.x = x / Settings.RATIO; angle: 0,
bodyDef.position.y = y / Settings.RATIO; linearDamping: Settings.PLAYER_LINEAR_DAMPING
bodyDef.angle = 0; };
var shape = new Box2D.Collision.Shapes.b2PolygonShape(); var shape = planck.Box(
shape.SetAsOrientedBox(
this.options.limbs[name].width / 2 / Settings.RATIO, this.options.limbs[name].width / 2 / Settings.RATIO,
this.options.limbs[name].height / 2 / Settings.RATIO, this.options.limbs[name].height / 2 / Settings.RATIO,
new Box2D.Common.Math.b2Vec2(0, this.options.limbs[name].height / 2 / Settings.RATIO) planck.Vec2(0, this.options.limbs[name].height / 2 / Settings.RATIO)
); );
var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fixtureDef.density = Settings.PLAYER_DENSITY; fixtureDef.density = Settings.PLAYER_DENSITY;
fixtureDef.friction = Settings.PLAYER_FRICTION; fixtureDef.friction = Settings.PLAYER_FRICTION;
fixtureDef.restitution = Settings.PLAYER_RESTITUTION; fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
@ -313,14 +308,14 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
fixtureDef.filter.groupIndex = -this.getId(); fixtureDef.filter.groupIndex = -this.getId();
var limb = this.body.GetWorld().CreateBody(bodyDef); var limb = this.body.GetWorld().CreateBody(bodyDef);
limb.CreateFixture(fixtureDef); limb.createFixture(fixtureDef);
this.limbs[name] = limb; this.limbs[name] = limb;
var jointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef(); var jointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
jointDef.enableMotor = false; jointDef.enableMotor = false;
var pos = connectTo.GetWorldCenter().Copy(); var pos = connectTo.getWorldCenter().clone();
pos.x += (xOffset / Settings.RATIO); pos.x += (xOffset / Settings.RATIO);
pos.y += (yOffset / Settings.RATIO); pos.y += (yOffset / Settings.RATIO);
jointDef.Initialize(connectTo, limb, pos); jointDef.Initialize(connectTo, limb, pos);
@ -347,7 +342,7 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
var chestPosition = this.body.GetPosition(); var chestPosition = this.body.GetPosition();
var position = new Box2D.Common.Math.b2Vec2( var position = planck.Vec2(
chestPosition.x + this.options.limbs.head.x / Settings.RATIO, chestPosition.x + this.options.limbs.head.x / Settings.RATIO,
chestPosition.y + this.options.limbs.head.y / Settings.RATIO chestPosition.y + this.options.limbs.head.y / Settings.RATIO
); );
@ -370,7 +365,7 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
Assert.number(options.angularVelocity); Assert.number(options.angularVelocity);
this.body.SetLinearVelocity(options.linearVelocity); this.body.SetLinearVelocity(options.linearVelocity);
this.body.SetAngularVelocity(options.angularVelocity); this.body.setAngularVelocity(options.angularVelocity);
for(var name in this.limbs) { for(var name in this.limbs) {
this.limbs[name].SetLinearVelocity(options.linearVelocity); this.limbs[name].SetLinearVelocity(options.linearVelocity);
} }

View file

@ -1,6 +1,6 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + GLOBALS.context + "/GameObjects/Item",
"Lib/Vendor/Box2D", "Lib/Vendor/Planck",
"Game/Config/Settings" "Game/Config/Settings"
], ],
@ -24,13 +24,13 @@ function (Parent, Box2D, Settings) {
var bodies = []; var bodies = [];
var joints = []; var joints = [];
{ {
var bd = new Box2D.Dynamics.b2BodyDef(); var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody; bd.type = 'dynamic';
bd.position.Set(-1.917114257812500e-01, 1.433728694915771e+00); bd.position.Set(-1.917114257812500e-01, 1.433728694915771e+00);
bodies[0] = world.CreateBody(bd); bodies[0] = world.CreateBody(bd);
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION; fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION; fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY; fd.density = Settings.PLAYER_DENSITY;
@ -38,45 +38,45 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1; fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape(); var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = []; var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(6.299880146980286e-02, -2.545155882835388e-01); vs[0] = planck.Vec2(6.299880146980286e-02, -2.545155882835388e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(6.299880146980286e-02, 2.545149326324463e-01); vs[1] = planck.Vec2(6.299880146980286e-02, 2.545149326324463e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-6.299890577793121e-02, 2.545149326324463e-01); vs[2] = planck.Vec2(-6.299890577793121e-02, 2.545149326324463e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-6.299890577793121e-02, -2.545155882835388e-01); vs[3] = planck.Vec2(-6.299890577793121e-02, -2.545155882835388e-01);
shape.SetAsArray(vs, 4); shape.SetAsArray(vs, 4);
fd.shape = shape; fd.shape = shape;
bodies[0].CreateFixture(fd); bodies[0].createFixture(fd);
} }
} }
{ {
var bd = new Box2D.Dynamics.b2BodyDef(); var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody; bd.type = 'dynamic';
bd.position.Set(-6.397294998168945e-02, 1.267420768737793e+00); bd.position.Set(-6.397294998168945e-02, 1.267420768737793e+00);
bodies[1] = world.CreateBody(bd); bodies[1] = world.CreateBody(bd);
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION; fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION; fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY; fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = -1; fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape(); var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = []; var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(1.883362084627151e-01, -4.305148720741272e-01); vs[0] = planck.Vec2(1.883362084627151e-01, -4.305148720741272e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(1.846363544464111e-01, 5.393795371055603e-01); vs[1] = planck.Vec2(1.846363544464111e-01, 5.393795371055603e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(1.850083470344543e-03, 5.393795371055603e-01); vs[2] = planck.Vec2(1.850083470344543e-03, 5.393795371055603e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-1.883361339569092e-01, 4.209862351417542e-01); vs[3] = planck.Vec2(-1.883361339569092e-01, 4.209862351417542e-01);
vs[4] = new Box2D.Common.Math.b2Vec2(-1.883361339569092e-01, -4.607573151588440e-01); vs[4] = planck.Vec2(-1.883361339569092e-01, -4.607573151588440e-01);
vs[5] = new Box2D.Common.Math.b2Vec2(1.600667834281921e-03, -4.952520132064819e-01); vs[5] = planck.Vec2(1.600667834281921e-03, -4.952520132064819e-01);
shape.SetAsArray(vs, 6); shape.SetAsArray(vs, 6);
fd.shape = shape; fd.shape = shape;
bodies[1].CreateFixture(fd); bodies[1].createFixture(fd);
} }
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION; fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION; fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY; fd.density = Settings.PLAYER_DENSITY;
@ -84,25 +84,25 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1; fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape(); var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = []; var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(1.840525716543198e-01, 4.875739216804504e-01); vs[0] = planck.Vec2(1.840525716543198e-01, 4.875739216804504e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(1.840525716543198e-01, 6.762337088584900e-01); vs[1] = planck.Vec2(1.840525716543198e-01, 6.762337088584900e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-4.607129842042923e-03, 6.762337088584900e-01); vs[2] = planck.Vec2(-4.607129842042923e-03, 6.762337088584900e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-4.607129842042923e-03, 4.875739216804504e-01); vs[3] = planck.Vec2(-4.607129842042923e-03, 4.875739216804504e-01);
shape.SetAsArray(vs, 4); shape.SetAsArray(vs, 4);
fd.shape = shape; fd.shape = shape;
bodies[1].CreateFixture(fd); bodies[1].createFixture(fd);
} }
} }
{ {
var bd = new Box2D.Dynamics.b2BodyDef(); var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody; bd.type = 'dynamic';
bd.position.Set(4.118728637695312e-02, 2.199305295944214e+00); bd.position.Set(4.118728637695312e-02, 2.199305295944214e+00);
bodies[2] = world.CreateBody(bd); bodies[2] = world.CreateBody(bd);
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = 2.000000029802322e-01; fd.friction = 2.000000029802322e-01;
fd.restitution = 0.000000000000000e+00; fd.restitution = 0.000000000000000e+00;
fd.density = 2.204959988594055e-01; fd.density = 2.204959988594055e-01;
@ -114,10 +114,10 @@ function (Parent, Box2D, Settings) {
fd.shape = shape; fd.shape = shape;
bodies[2].CreateFixture(fd); bodies[2].createFixture(fd);
} }
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = 2.000000029802322e-01; fd.friction = 2.000000029802322e-01;
fd.restitution = 0.000000000000000e+00; fd.restitution = 0.000000000000000e+00;
fd.density = 2.204959988594055e-01; fd.density = 2.204959988594055e-01;
@ -129,17 +129,17 @@ function (Parent, Box2D, Settings) {
fd.shape = shape; fd.shape = shape;
bodies[2].CreateFixture(fd); bodies[2].createFixture(fd);
} }
} }
{ {
var bd = new Box2D.Dynamics.b2BodyDef(); var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody; bd.type = 'dynamic';
bd.position.Set(1.235442161560059e-01, 1.142371892929077e+00); bd.position.Set(1.235442161560059e-01, 1.142371892929077e+00);
bodies[3] = world.CreateBody(bd); bodies[3] = world.CreateBody(bd);
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION; fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION; fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY; fd.density = Settings.PLAYER_DENSITY;
@ -147,26 +147,26 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1; fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape(); var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = []; var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(6.299892067909241e-02, -1.556134223937988e-01); vs[0] = planck.Vec2(6.299892067909241e-02, -1.556134223937988e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(6.299892067909241e-02, 1.556134223937988e-01); vs[1] = planck.Vec2(6.299892067909241e-02, 1.556134223937988e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-6.299898028373718e-02, 1.556134223937988e-01); vs[2] = planck.Vec2(-6.299898028373718e-02, 1.556134223937988e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-6.299898028373718e-02, -1.556134223937988e-01); vs[3] = planck.Vec2(-6.299898028373718e-02, -1.556134223937988e-01);
shape.SetAsArray(vs, 4); shape.SetAsArray(vs, 4);
fd.shape = shape; fd.shape = shape;
bodies[3].CreateFixture(fd); bodies[3].createFixture(fd);
} }
} }
{ {
var bd = new Box2D.Dynamics.b2BodyDef(); var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody; bd.type = 'dynamic';
bd.position.Set(-9.663248062133789e-02, 3.554300665855408e-01); bd.position.Set(-9.663248062133789e-02, 3.554300665855408e-01);
bodies[4] = world.CreateBody(bd); bodies[4] = world.CreateBody(bd);
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION; fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION; fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY; fd.density = Settings.PLAYER_DENSITY;
@ -174,18 +174,18 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1; fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape(); var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = []; var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(1.550966501235962e-01, -1.253567039966583e-01); vs[0] = planck.Vec2(1.550966501235962e-01, -1.253567039966583e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(1.550966501235962e-01, -6.225190684199333e-02); vs[1] = planck.Vec2(1.550966501235962e-01, -6.225190684199333e-02);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.268096834421158e-02, -6.225190684199333e-02); vs[2] = planck.Vec2(-9.268096834421158e-02, -6.225190684199333e-02);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.268096834421158e-02, -1.253567039966583e-01); vs[3] = planck.Vec2(-9.268096834421158e-02, -1.253567039966583e-01);
shape.SetAsArray(vs, 4); shape.SetAsArray(vs, 4);
fd.shape = shape; fd.shape = shape;
bodies[4].CreateFixture(fd); bodies[4].createFixture(fd);
} }
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION; fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION; fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY; fd.density = Settings.PLAYER_DENSITY;
@ -193,26 +193,26 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1; fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape(); var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = []; var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(9.449840337038040e-02, -1.247676759958267e-01); vs[0] = planck.Vec2(9.449840337038040e-02, -1.247676759958267e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(9.449840337038040e-02, 1.715210527181625e-01); vs[1] = planck.Vec2(9.449840337038040e-02, 1.715210527181625e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.449829906225204e-02, 1.715210527181625e-01); vs[2] = planck.Vec2(-9.449829906225204e-02, 1.715210527181625e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.449829906225204e-02, -1.247676759958267e-01); vs[3] = planck.Vec2(-9.449829906225204e-02, -1.247676759958267e-01);
shape.SetAsArray(vs, 4); shape.SetAsArray(vs, 4);
fd.shape = shape; fd.shape = shape;
bodies[4].CreateFixture(fd); bodies[4].createFixture(fd);
} }
} }
{ {
var bd = new Box2D.Dynamics.b2BodyDef(); var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody; bd.type = 'dynamic';
bd.position.Set(-1.917138099670410e-01, 1.142371892929077e+00); bd.position.Set(-1.917138099670410e-01, 1.142371892929077e+00);
bodies[5] = world.CreateBody(bd); bodies[5] = world.CreateBody(bd);
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION; fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION; fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY; fd.density = Settings.PLAYER_DENSITY;
@ -220,26 +220,26 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1; fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape(); var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = []; var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(6.299891322851181e-02, -1.556134223937988e-01); vs[0] = planck.Vec2(6.299891322851181e-02, -1.556134223937988e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(6.299891322851181e-02, 1.556134223937988e-01); vs[1] = planck.Vec2(6.299891322851181e-02, 1.556134223937988e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-6.299878656864166e-02, 1.556134223937988e-01); vs[2] = planck.Vec2(-6.299878656864166e-02, 1.556134223937988e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-6.299878656864166e-02, -1.556134223937988e-01); vs[3] = planck.Vec2(-6.299878656864166e-02, -1.556134223937988e-01);
shape.SetAsArray(vs, 4); shape.SetAsArray(vs, 4);
fd.shape = shape; fd.shape = shape;
bodies[5].CreateFixture(fd); bodies[5].createFixture(fd);
} }
} }
{ {
var bd = new Box2D.Dynamics.b2BodyDef(); var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody; bd.type = 'dynamic';
bd.position.Set(1.235442161560059e-01, 1.433728694915771e+00); bd.position.Set(1.235442161560059e-01, 1.433728694915771e+00);
bodies[6] = world.CreateBody(bd); bodies[6] = world.CreateBody(bd);
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION; fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION; fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY; fd.density = Settings.PLAYER_DENSITY;
@ -247,25 +247,25 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1; fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape(); var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = []; var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(6.299892067909241e-02, -2.545155882835388e-01); vs[0] = planck.Vec2(6.299892067909241e-02, -2.545155882835388e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(6.299892067909241e-02, 2.545149326324463e-01); vs[1] = planck.Vec2(6.299892067909241e-02, 2.545149326324463e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-6.299898028373718e-02, 2.545149326324463e-01); vs[2] = planck.Vec2(-6.299898028373718e-02, 2.545149326324463e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-6.299898028373718e-02, -2.545155882835388e-01); vs[3] = planck.Vec2(-6.299898028373718e-02, -2.545155882835388e-01);
shape.SetAsArray(vs, 4); shape.SetAsArray(vs, 4);
fd.shape = shape; fd.shape = shape;
bodies[6].CreateFixture(fd); bodies[6].createFixture(fd);
} }
} }
{ {
var bd = new Box2D.Dynamics.b2BodyDef(); var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody; bd.type = 'dynamic';
bd.position.Set(2.897095680236816e-02, 6.702435612678528e-01); bd.position.Set(2.897095680236816e-02, 6.702435612678528e-01);
bodies[7] = world.CreateBody(bd); bodies[7] = world.CreateBody(bd);
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION; fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION; fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY; fd.density = Settings.PLAYER_DENSITY;
@ -273,26 +273,26 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1; fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape(); var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = []; var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(9.449830651283264e-02, -2.537839412689209e-01); vs[0] = planck.Vec2(9.449830651283264e-02, -2.537839412689209e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(9.449830651283264e-02, 2.537844777107239e-01); vs[1] = planck.Vec2(9.449830651283264e-02, 2.537844777107239e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.449817240238190e-02, 2.537844777107239e-01); vs[2] = planck.Vec2(-9.449817240238190e-02, 2.537844777107239e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.449817240238190e-02, -2.537839412689209e-01); vs[3] = planck.Vec2(-9.449817240238190e-02, -2.537839412689209e-01);
shape.SetAsArray(vs, 4); shape.SetAsArray(vs, 4);
fd.shape = shape; fd.shape = shape;
bodies[7].CreateFixture(fd); bodies[7].createFixture(fd);
} }
} }
{ {
var bd = new Box2D.Dynamics.b2BodyDef(); var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody; bd.type = 'dynamic';
bd.position.Set(-9.663248062133789e-02, 6.702435612678528e-01); bd.position.Set(-9.663248062133789e-02, 6.702435612678528e-01);
bodies[8] = world.CreateBody(bd); bodies[8] = world.CreateBody(bd);
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION; fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION; fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY; fd.density = Settings.PLAYER_DENSITY;
@ -300,26 +300,26 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1; fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape(); var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = []; var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(9.449842572212219e-02, -2.537839412689209e-01); vs[0] = planck.Vec2(9.449842572212219e-02, -2.537839412689209e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(9.449842572212219e-02, 2.537844777107239e-01); vs[1] = planck.Vec2(9.449842572212219e-02, 2.537844777107239e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.449826925992966e-02, 2.537844777107239e-01); vs[2] = planck.Vec2(-9.449826925992966e-02, 2.537844777107239e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.449826925992966e-02, -2.537839412689209e-01); vs[3] = planck.Vec2(-9.449826925992966e-02, -2.537839412689209e-01);
shape.SetAsArray(vs, 4); shape.SetAsArray(vs, 4);
fd.shape = shape; fd.shape = shape;
bodies[8].CreateFixture(fd); bodies[8].createFixture(fd);
} }
} }
{ {
var bd = new Box2D.Dynamics.b2BodyDef(); var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody; bd.type = 'dynamic';
bd.position.Set(2.897095680236816e-02, 3.554300665855408e-01); bd.position.Set(2.897095680236816e-02, 3.554300665855408e-01);
bodies[9] = world.CreateBody(bd); bodies[9] = world.CreateBody(bd);
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION; fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION; fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY; fd.density = Settings.PLAYER_DENSITY;
@ -327,18 +327,18 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1; fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape(); var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = []; var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(1.550965905189514e-01, -1.253567039966583e-01); vs[0] = planck.Vec2(1.550965905189514e-01, -1.253567039966583e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(1.550965905189514e-01, -6.225190684199333e-02); vs[1] = planck.Vec2(1.550965905189514e-01, -6.225190684199333e-02);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.268099069595337e-02, -6.225190684199333e-02); vs[2] = planck.Vec2(-9.268099069595337e-02, -6.225190684199333e-02);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.268099069595337e-02, -1.253567039966583e-01); vs[3] = planck.Vec2(-9.268099069595337e-02, -1.253567039966583e-01);
shape.SetAsArray(vs, 4); shape.SetAsArray(vs, 4);
fd.shape = shape; fd.shape = shape;
bodies[9].CreateFixture(fd); bodies[9].createFixture(fd);
} }
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION; fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION; fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY; fd.density = Settings.PLAYER_DENSITY;
@ -346,29 +346,29 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1; fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape(); var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = []; var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(9.449830651283264e-02, -1.247680261731148e-01); vs[0] = planck.Vec2(9.449830651283264e-02, -1.247680261731148e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(9.449830651283264e-02, 1.713046580553055e-01); vs[1] = planck.Vec2(9.449830651283264e-02, 1.713046580553055e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.449817240238190e-02, 1.713046580553055e-01); vs[2] = planck.Vec2(-9.449817240238190e-02, 1.713046580553055e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.449817240238190e-02, -1.247680261731148e-01); vs[3] = planck.Vec2(-9.449817240238190e-02, -1.247680261731148e-01);
shape.SetAsArray(vs, 4); shape.SetAsArray(vs, 4);
fd.shape = shape; fd.shape = shape;
bodies[9].CreateFixture(fd); bodies[9].createFixture(fd);
} }
} }
/*{ /*{
ground body ground body
var bd = new Box2D.Dynamics.b2BodyDef(); var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = b2BodyType(0); bd.type = b2BodyType(0);
bd.position.Set(3.118395805358887e-03, -6.553649902343750e-03); bd.position.Set(3.118395805358887e-03, -6.553649902343750e-03);
bodies[10] = world.CreateBody(bd); bodies[10] = world.CreateBody(bd);
{ {
var fd = new Box2D.Dynamics.b2FixtureDef(); var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION; fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION; fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY; fd.density = Settings.PLAYER_DENSITY;
@ -376,8 +376,8 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = int16(0); fd.filter.groupIndex = int16(0);
b2ChainShape shape; b2ChainShape shape;
b2Vec2 vs[2]; b2Vec2 vs[2];
vs[0] = new Box2D.Common.Math.b2Vec2(-4.179394245147705e+00, 0.000000000000000e+00); vs[0] = planck.Vec2(-4.179394245147705e+00, 0.000000000000000e+00);
vs[1] = new Box2D.Common.Math.b2Vec2(4.179394245147705e+00, 0.000000000000000e+00); vs[1] = planck.Vec2(4.179394245147705e+00, 0.000000000000000e+00);
shape.CreateChain(vs, 2); shape.CreateChain(vs, 2);
shape.m_prevVertex.Set(-1.998532295227051e+00, -2.391039296991059e-23); shape.m_prevVertex.Set(-1.998532295227051e+00, -2.391039296991059e-23);
shape.m_nextVertex.Set(4.949933242915726e-38, 3.363116314379561e-44); shape.m_nextVertex.Set(4.949933242915726e-38, 3.363116314379561e-44);
@ -386,7 +386,7 @@ function (Parent, Box2D, Settings) {
fd.shape = shape; fd.shape = shape;
bodies[10].CreateFixture(fd); bodies[10].createFixture(fd);
} }
}*/ }*/
{ {
@ -548,7 +548,7 @@ function (Parent, Box2D, Settings) {
lowerRightLeg: bodies[9] lowerRightLeg: bodies[9]
}; };
this.body.SetPosition(new Box2D.Common.Math.b2Vec2(20,0)); this.body.SetPosition(planck.Vec2(20,0));
}; };
RagDoll.prototype.destroy = function() { RagDoll.prototype.destroy = function() {

View file

@ -1,21 +1,25 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + GLOBALS.context + "/GameObjects/Item",
"Lib/Vendor/RubeLoader", // "Lib/Vendor/RubeLoader", // Temporarily disabled during Planck.js migration
"Lib/Vendor/Box2D", "Lib/Vendor/Planck",
"Game/Config/Settings", "Game/Config/Settings",
"Lib/Utilities/Assert", "Lib/Utilities/Assert",
"Lib/Utilities/NotificationCenter", "Lib/Utilities/NotificationCenter",
"Lib/Utilities/Matrix", "Lib/Utilities/Matrix"
"json!Game/Asset/RubeDoll.json" // using requirejs json loader plugin // "json!Game/Asset/RubeDoll.json" // Temporarily disabled during Planck.js migration
], ],
function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson) { function (Parent, /* RubeLoader, */ Box2D, Settings, Assert, nc, Matrix /* , RubeDollJson */) {
"use strict"; "use strict";
function RubeDoll(physicsEngine, uid, options) { function RubeDoll(physicsEngine, uid, options) {
Assert.number(options.x, options.y); Assert.number(options.x, options.y);
// TODO: Implement RubeDoll with Planck.js
// Temporarily stubbed out during Box2D -> Planck.js migration
console.warn("RubeDoll is temporarily disabled during Planck.js migration");
this.rubeLoader = null; this.rubeLoader = null;
this.body = null; this.body = null;
this.limbs = {}; this.limbs = {};
@ -23,9 +27,8 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
this.limits = []; this.limits = [];
var chest = null; var chest = null;
this.rubeLoader = new RubeLoader(RubeDollJson, physicsEngine.getWorldForRubeLoader()); // this.rubeLoader = new RubeLoader(RubeDollJson, physicsEngine.getWorldForRubeLoader());
// this.loadRubeDollFromScene(options);
this.loadRubeDollFromScene(options);
Parent.call(this, physicsEngine, uid, options); Parent.call(this, physicsEngine, uid, options);
physicsEngine.destroyBody(this.body); physicsEngine.destroyBody(this.body);
@ -46,8 +49,8 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
for (var i in scene.bodies) { for (var i in scene.bodies) {
var body = scene.bodies[i]; var body = scene.bodies[i];
var position = body.GetPosition().Copy(); var position = body.GetPosition().clone();
position.Add(new Box2D.Common.Math.b2Vec2( position.Add(planck.Vec2(
options.x / Settings.RATIO, options.x / Settings.RATIO,
options.y / Settings.RATIO options.y / Settings.RATIO
)); ));
@ -86,7 +89,7 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
}; };
RubeDoll.prototype.getFixtureDef = function() { RubeDoll.prototype.getFixtureDef = function() {
var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fixtureDef.shape = new Box2D.Collision.Shapes.b2CircleShape(); fixtureDef.shape = new Box2D.Collision.Shapes.b2CircleShape();
return fixtureDef; return fixtureDef;
}; };
@ -134,7 +137,7 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
var differenceAngle = oldAngle - this.body.GetAngle(); var differenceAngle = oldAngle - this.body.GetAngle();
//this.body.SetLinearVelocity(new Box2D.Common.Math.b2Vec2(0, 0)); //this.body.SetLinearVelocity(planck.Vec2(0, 0));
var offset = Box2D.Common.Math.b2Math.SubtractVV(this.getPosition(), oldPosition); var offset = Box2D.Common.Math.b2Math.SubtractVV(this.getPosition(), oldPosition);
var grabAngle = (this.options.grabAngle || 0.001); var grabAngle = (this.options.grabAngle || 0.001);
@ -143,12 +146,12 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
var limb = this.limbs[key]; var limb = this.limbs[key];
// Setting position offset first (floor to hand) // Setting position offset first (floor to hand)
var position = limb.GetPosition().Copy(); var position = limb.GetPosition().clone();
position.Add(offset); position.Add(offset);
limb.SetPosition(position); limb.SetPosition(position);
// grabing local point to "rotate" around (x, y position transform only) // grabing local point to "rotate" around (x, y position transform only)
var localPoint = this.body.GetLocalPoint(limb.GetPosition().Copy()); var localPoint = this.body.getLocalPoint(limb.GetPosition().clone());
// create rotation matrix from chest rotation difference // create rotation matrix from chest rotation difference
var mat = Box2D.Common.Math.b2Mat22.FromAngle(differenceAngle); var mat = Box2D.Common.Math.b2Mat22.FromAngle(differenceAngle);
@ -157,15 +160,15 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
position = Box2D.Common.Math.b2Math.MulTMV(mat, localPoint); position = Box2D.Common.Math.b2Math.MulTMV(mat, localPoint);
// translating back to global position // translating back to global position
var globalPoint = this.body.GetWorldPoint(position); var globalPoint = this.body.getWorldPoint(position);
limb.SetPosition(globalPoint); limb.SetPosition(globalPoint);
// relative limb rotating by chest rotation difference // relative limb rotating by chest rotation difference
var d = (oldDirection == direction) ? -1 : 1; var d = (oldDirection == direction) ? -1 : 1;
limb.SetAngle((limb.GetAngle() - differenceAngle) * d); limb.SetAngle((limb.GetAngle() - differenceAngle) * d);
//limb.SetType(Box2D.Dynamics.b2Body.b2_staticBody); //limb.SetType('static');
//limb.SetLinearVelocity(new Box2D.Common.Math.b2Vec2(0, 0)); //limb.SetLinearVelocity(planck.Vec2(0, 0));
} }
}; };
@ -174,18 +177,18 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
Assert.number(options.angularVelocity); Assert.number(options.angularVelocity);
this.body.SetLinearVelocity(options.linearVelocity); this.body.SetLinearVelocity(options.linearVelocity);
this.body.SetAngularVelocity(options.angularVelocity); this.body.setAngularVelocity(options.angularVelocity);
for(var name in this.limbs) { for(var name in this.limbs) {
this.limbs[name].SetLinearVelocity(options.linearVelocity); this.limbs[name].SetLinearVelocity(options.linearVelocity);
} }
}; };
RubeDoll.prototype.getPosition = function() { RubeDoll.prototype.getPosition = function() {
return this.body.GetPosition().Copy(); return this.body.GetPosition().clone();
}; };
RubeDoll.prototype.getHeadPosition = function() { RubeDoll.prototype.getHeadPosition = function() {
return this.limbs.head.GetPosition().Copy(); return this.limbs.head.GetPosition().clone();
}; };
RubeDoll.prototype.setUpdateData = function(update) { RubeDoll.prototype.setUpdateData = function(update) {
@ -199,11 +202,11 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
Assert.number(update.limbs[name].lv.x, update.limbs[name].lv.y); Assert.number(update.limbs[name].lv.x, update.limbs[name].lv.y);
Assert.number(update.limbs[name].av); Assert.number(update.limbs[name].av);
this.limbs[name].SetAwake(true); this.limbs[name].setAwake(true);
this.limbs[name].SetPosition(update.limbs[name].p); this.limbs[name].SetPosition(update.limbs[name].p);
this.limbs[name].SetAngle(update.limbs[name].a); this.limbs[name].SetAngle(update.limbs[name].a);
this.limbs[name].SetLinearVelocity(update.limbs[name].lv); this.limbs[name].SetLinearVelocity(update.limbs[name].lv);
this.limbs[name].SetAngularVelocity(update.limbs[name].av); this.limbs[name].setAngularVelocity(update.limbs[name].av);
} }
*/ */
} }

View file

@ -1,6 +1,6 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + GLOBALS.context + "/GameObjects/Item",
"Lib/Vendor/Box2D", "Lib/Vendor/Planck",
"Game/Config/Settings", "Game/Config/Settings",
"Lib/Utilities/Assert" "Lib/Utilities/Assert"
], ],
@ -20,12 +20,11 @@ function (Parent, Box2D, Settings, Assert) {
Assert.number(this.options.width, this.options.height); Assert.number(this.options.width, this.options.height);
Assert.number(this.options.weight); Assert.number(this.options.weight);
var deckShape = new Box2D.Collision.Shapes.b2PolygonShape();
var w = this.options.width / Settings.RATIO; var w = this.options.width / Settings.RATIO;
var h = 2 / Settings.RATIO; var h = 2 / Settings.RATIO;
deckShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(4.5 / Settings.RATIO))); var deckShape = planck.Box(w / 2, h / 2, planck.Vec2(0, -(4.5 / Settings.RATIO)));
var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fixtureDef.shape = deckShape; fixtureDef.shape = deckShape;
var offset = 4, var offset = 4,
@ -36,7 +35,7 @@ function (Parent, Box2D, Settings, Assert) {
fixtureDef.restitution = 0.2; fixtureDef.restitution = 0.2;
fixtureDef.isSensor = false; fixtureDef.isSensor = false;
this.body.CreateFixture(fixtureDef); this.body.createFixture(fixtureDef);
this.addWheel( this.addWheel(
@ -54,18 +53,16 @@ function (Parent, Box2D, Settings, Assert) {
Skateboard.prototype.addWheel = function(x, y) { Skateboard.prototype.addWheel = function(x, y) {
Assert.number(x, y); Assert.number(x, y);
var bodyDef = new Box2D.Dynamics.b2BodyDef(); var bodyDef = {
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; type: 'dynamic',
bodyDef.position.x = x / Settings.RATIO; position: planck.Vec2(x / Settings.RATIO, y / Settings.RATIO),
bodyDef.position.y = y / Settings.RATIO; angle: 0
bodyDef.angle = 0; };
var wheelShape = new Box2D.Collision.Shapes.b2CircleShape(); var wheelShape = planck.Circle(2.5 / Settings.RATIO, planck.Vec2(x / Settings.RATIO, y / Settings.RATIO));
wheelShape.SetRadius(2.5 / Settings.RATIO);
wheelShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(x / Settings.RATIO, y / Settings.RATIO));
var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
var offset = 4, var offset = 4,
factor = 80; factor = 80;
var density = ((0.1 + offset) / 3 / 3) * factor; var density = ((0.1 + offset) / 3 / 3) * factor;
@ -75,7 +72,7 @@ function (Parent, Box2D, Settings, Assert) {
fixtureDef.isSensor = false; fixtureDef.isSensor = false;
fixtureDef.friction = 0.0005; fixtureDef.friction = 0.0005;
this.body.CreateFixture(fixtureDef); this.body.createFixture(fixtureDef);
}; };
Skateboard.prototype.flip = function(direction) { Skateboard.prototype.flip = function(direction) {
@ -90,7 +87,7 @@ function (Parent, Box2D, Settings, Assert) {
/* /*
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + GLOBALS.context + "/GameObjects/Item",
"Lib/Vendor/Box2D", "Lib/Vendor/Planck",
"Game/Config/Settings", "Game/Config/Settings",
"Lib/Utilities/Assert" "Lib/Utilities/Assert"
], ],
@ -121,12 +118,11 @@ function (Parent, Box2D, Settings, Assert) {
Assert.number(this.options.width, this.options.height); Assert.number(this.options.width, this.options.height);
Assert.number(this.options.weight); Assert.number(this.options.weight);
var deckShape = new Box2D.Collision.Shapes.b2PolygonShape();
var w = this.options.width / Settings.RATIO; var w = this.options.width / Settings.RATIO;
var h = 1.5 / Settings.RATIO; var h = 1.5 / Settings.RATIO;
deckShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(4.5 / Settings.RATIO))); var deckShape = planck.Box(w / 2, h / 2, planck.Vec2(0, -(4.5 / Settings.RATIO)));
var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fixtureDef.shape = deckShape; fixtureDef.shape = deckShape;
var offset = 4, var offset = 4,
@ -137,23 +133,21 @@ function (Parent, Box2D, Settings, Assert) {
fixtureDef.restitution = Settings.ITEM_RESTITUTION; fixtureDef.restitution = Settings.ITEM_RESTITUTION;
fixtureDef.isSensor = false; fixtureDef.isSensor = false;
this.body.CreateFixture(fixtureDef); this.body.createFixture(fixtureDef);
}; };
Skateboard.prototype.addWheel = function(x, y) { Skateboard.prototype.addWheel = function(x, y) {
Assert.number(x, y); Assert.number(x, y);
var bodyDef = new Box2D.Dynamics.b2BodyDef(); var bodyDef = {
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; type: 'dynamic',
bodyDef.position.x = x / Settings.RATIO; position: planck.Vec2(x / Settings.RATIO, y / Settings.RATIO),
bodyDef.position.y = y / Settings.RATIO; angle: 0
bodyDef.angle = 0; };
var wheelShape = new Box2D.Collision.Shapes.b2CircleShape(); var wheelShape = planck.Circle(1.5 / Settings.RATIO, planck.Vec2(0, 0));
wheelShape.SetRadius(1.5 / Settings.RATIO);
wheelShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, 0));
var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
var offset = 4, var offset = 4,
factor = 80; factor = 80;
var density = ((0.1 + offset) / 3 / 3) * factor; var density = ((0.1 + offset) / 3 / 3) * factor;
@ -163,7 +157,7 @@ function (Parent, Box2D, Settings, Assert) {
fixtureDef.friction = 0; fixtureDef.friction = 0;
var wheelBody = this.body.GetWorld().CreateBody(bodyDef); var wheelBody = this.body.GetWorld().CreateBody(bodyDef);
wheelBody.CreateFixture(fixtureDef); wheelBody.createFixture(fixtureDef);
//var revoluteJointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef(); //var revoluteJointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
var revoluteJointDef = new Box2D.Dynamics.Joints.b2WeldJointDef(); var revoluteJointDef = new Box2D.Dynamics.Joints.b2WeldJointDef();
@ -171,7 +165,7 @@ function (Parent, Box2D, Settings, Assert) {
revoluteJointDef.Initialize(this.body, wheelBody, wheelBody.GetWorldCenter()); revoluteJointDef.Initialize(this.body, wheelBody, wheelBody.getWorldCenter());
var j = this.body.GetWorld().CreateJoint(revoluteJointDef); var j = this.body.GetWorld().CreateJoint(revoluteJointDef);

View file

@ -1,6 +1,6 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/GameObject", "Game/" + GLOBALS.context + "/GameObjects/GameObject",
"Lib/Vendor/Box2D" "Lib/Vendor/Planck"
], ],
function (Parent, Box2D) { function (Parent, Box2D) {
@ -14,8 +14,8 @@ function (Parent, Box2D) {
SpectatorDoll.prototype = Object.create(Parent.prototype); SpectatorDoll.prototype = Object.create(Parent.prototype);
SpectatorDoll.prototype.getBodyDef = function() { SpectatorDoll.prototype.getBodyDef = function() {
var bodyDef = new Box2D.Dynamics.b2BodyDef(); var bodyDef = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; bodyDef.type = 'dynamic';
bodyDef.position.x = this.getPosition().x; bodyDef.position.x = this.getPosition().x;
bodyDef.position.y = this.getPosition().y; bodyDef.position.y = this.getPosition().y;
bodyDef.angle = 0; bodyDef.angle = 0;

View file

@ -1,6 +1,6 @@
define([ define([
"Game/Config/Settings", "Game/Config/Settings",
"Lib/Vendor/Box2D", "Lib/Vendor/Planck",
"Lib/Utilities/NotificationCenter", "Lib/Utilities/NotificationCenter",
"Lib/Utilities/Abstract", "Lib/Utilities/Abstract",
"Game/" + GLOBALS.context + "/Collision/Detector", "Game/" + GLOBALS.context + "/Collision/Detector",

View file

@ -2,7 +2,7 @@ define([
"Game/" + GLOBALS.context + "/Loader/Level", "Game/" + GLOBALS.context + "/Loader/Level",
"Game/Config/Settings", "Game/Config/Settings",
"Game/Config/ItemSettings", "Game/Config/ItemSettings",
"Lib/Vendor/Box2D", "Lib/Vendor/Planck",
"Lib/Utilities/OptionsHelper", "Lib/Utilities/OptionsHelper",
"Lib/Utilities/Exception", "Lib/Utilities/Exception",
"Lib/Utilities/NotificationCenter", "Lib/Utilities/NotificationCenter",

View file

@ -24,7 +24,7 @@ function (Settings, planck, CollisionDetector, nc) {
Engine.prototype.setCollisionDetector = function () { Engine.prototype.setCollisionDetector = function () {
var detector = new CollisionDetector(); var detector = new CollisionDetector();
this.world.on('begin-contact', detector.getListener()); detector.setupWorldEvents(this.world);
} }
Engine.prototype.getWorldForRubeLoader = function() { Engine.prototype.getWorldForRubeLoader = function() {

View file

@ -1413,7 +1413,7 @@ Box2D.postDefs = [];
}; };
b2DistanceProxy.b2DistanceProxy = function () {}; b2DistanceProxy.b2DistanceProxy = function () {};
b2DistanceProxy.prototype.Set = function (shape) { b2DistanceProxy.prototype.Set = function (shape) {
switch (shape.GetType()) { switch (shape.getType()) {
case b2Shape.e_circleShape: case b2Shape.e_circleShape:
{ {
var circle = (shape instanceof b2CircleShape ? shape : null); var circle = (shape instanceof b2CircleShape ? shape : null);
@ -4447,7 +4447,7 @@ Box2D.postDefs = [];
var def = new b2FixtureDef(); var def = new b2FixtureDef();
def.shape = shape; def.shape = shape;
def.density = density; def.density = density;
return this.CreateFixture(def); return this.createFixture(def);
} }
b2Body.prototype.DestroyFixture = function (fixture) { b2Body.prototype.DestroyFixture = function (fixture) {
if (this.m_world.IsLocked() == true) { if (this.m_world.IsLocked() == true) {
@ -4556,7 +4556,7 @@ Box2D.postDefs = [];
} }
b2Body.prototype.GetDefinition = function () { b2Body.prototype.GetDefinition = function () {
var bd = new b2BodyDef(); var bd = new b2BodyDef();
bd.type = this.GetType(); bd.type = this.getType();
bd.allowSleep = (this.m_flags & b2Body.e_allowSleepFlag) == b2Body.e_allowSleepFlag; bd.allowSleep = (this.m_flags & b2Body.e_allowSleepFlag) == b2Body.e_allowSleepFlag;
bd.angle = this.GetAngle(); bd.angle = this.GetAngle();
bd.angularDamping = this.m_angularDamping; bd.angularDamping = this.m_angularDamping;
@ -4574,8 +4574,8 @@ Box2D.postDefs = [];
if (this.m_type != b2Body.b2_dynamicBody) { if (this.m_type != b2Body.b2_dynamicBody) {
return; return;
} }
if (this.IsAwake() == false) { if (this.isAwake() == false) {
this.SetAwake(true); this.setAwake(true);
} }
this.m_force.x += force.x; this.m_force.x += force.x;
this.m_force.y += force.y; this.m_force.y += force.y;
@ -4586,8 +4586,8 @@ Box2D.postDefs = [];
if (this.m_type != b2Body.b2_dynamicBody) { if (this.m_type != b2Body.b2_dynamicBody) {
return; return;
} }
if (this.IsAwake() == false) { if (this.isAwake() == false) {
this.SetAwake(true); this.setAwake(true);
} }
this.m_torque += torque; this.m_torque += torque;
} }
@ -4595,17 +4595,17 @@ Box2D.postDefs = [];
if (this.m_type != b2Body.b2_dynamicBody) { if (this.m_type != b2Body.b2_dynamicBody) {
return; return;
} }
if (this.IsAwake() == false) { if (this.isAwake() == false) {
this.SetAwake(true); this.setAwake(true);
} }
this.m_linearVelocity.x += this.m_invMass * impulse.x; this.m_linearVelocity.x += this.m_invMass * impulse.x;
this.m_linearVelocity.y += this.m_invMass * impulse.y; this.m_linearVelocity.y += this.m_invMass * impulse.y;
this.m_angularVelocity += this.m_invI * ((point.x - this.m_sweep.c.x) * impulse.y - (point.y - this.m_sweep.c.y) * impulse.x); this.m_angularVelocity += this.m_invI * ((point.x - this.m_sweep.c.x) * impulse.y - (point.y - this.m_sweep.c.y) * impulse.x);
} }
b2Body.prototype.Split = function (callback) { b2Body.prototype.Split = function (callback) {
var linearVelocity = this.GetLinearVelocity().Copy(); var linearVelocity = this.GetLinearVelocity().clone();
var angularVelocity = this.GetAngularVelocity(); var angularVelocity = this.getAngularVelocity();
var center = this.GetWorldCenter(); var center = this.getWorldCenter();
var body1 = this; var body1 = this;
var body2 = this.m_world.CreateBody(this.GetDefinition()); var body2 = this.m_world.CreateBody(this.GetDefinition());
var prev; var prev;
@ -4632,14 +4632,14 @@ Box2D.postDefs = [];
} }
body1.ResetMassData(); body1.ResetMassData();
body2.ResetMassData(); body2.ResetMassData();
var center1 = body1.GetWorldCenter(); var center1 = body1.getWorldCenter();
var center2 = body2.GetWorldCenter(); var center2 = body2.getWorldCenter();
var velocity1 = b2Math.AddVV(linearVelocity, b2Math.CrossFV(angularVelocity, b2Math.SubtractVV(center1, center))); var velocity1 = b2Math.AddVV(linearVelocity, b2Math.CrossFV(angularVelocity, b2Math.SubtractVV(center1, center)));
var velocity2 = b2Math.AddVV(linearVelocity, b2Math.CrossFV(angularVelocity, b2Math.SubtractVV(center2, center))); var velocity2 = b2Math.AddVV(linearVelocity, b2Math.CrossFV(angularVelocity, b2Math.SubtractVV(center2, center)));
body1.SetLinearVelocity(velocity1); body1.SetLinearVelocity(velocity1);
body2.SetLinearVelocity(velocity2); body2.SetLinearVelocity(velocity2);
body1.SetAngularVelocity(angularVelocity); body1.setAngularVelocity(angularVelocity);
body2.SetAngularVelocity(angularVelocity); body2.setAngularVelocity(angularVelocity);
body1.SynchronizeFixtures(); body1.SynchronizeFixtures();
body2.SynchronizeFixtures(); body2.SynchronizeFixtures();
return body2; return body2;
@ -4660,12 +4660,12 @@ Box2D.postDefs = [];
var body1 = this; var body1 = this;
var body2 = other; var body2 = other;
var center1 = body1.GetWorldCenter(); var center1 = body1.getWorldCenter();
var center2 = body2.GetWorldCenter(); var center2 = body2.getWorldCenter();
var velocity1 = body1.GetLinearVelocity().Copy(); var velocity1 = body1.GetLinearVelocity().clone();
var velocity2 = body2.GetLinearVelocity().Copy(); var velocity2 = body2.GetLinearVelocity().clone();
var angular1 = body1.GetAngularVelocity(); var angular1 = body1.getAngularVelocity();
var angular = body2.GetAngularVelocity(); var angular = body2.getAngularVelocity();
body1.ResetMassData(); body1.ResetMassData();
this.SynchronizeFixtures(); this.SynchronizeFixtures();
} }
@ -4700,7 +4700,7 @@ Box2D.postDefs = [];
this.m_I = massData.I - this.m_mass * (massData.center.x * massData.center.x + massData.center.y * massData.center.y); this.m_I = massData.I - this.m_mass * (massData.center.x * massData.center.x + massData.center.y * massData.center.y);
this.m_invI = 1.0 / this.m_I; this.m_invI = 1.0 / this.m_I;
} }
var oldCenter = this.m_sweep.c.Copy(); var oldCenter = this.m_sweep.c.clone();
this.m_sweep.localCenter.SetV(massData.center); this.m_sweep.localCenter.SetV(massData.center);
this.m_sweep.c0.SetV(b2Math.MulX(this.m_xf, this.m_sweep.localCenter)); this.m_sweep.c0.SetV(b2Math.MulX(this.m_xf, this.m_sweep.localCenter));
this.m_sweep.c.SetV(this.m_sweep.c0); this.m_sweep.c.SetV(this.m_sweep.c0);
@ -4746,7 +4746,7 @@ Box2D.postDefs = [];
this.m_I = 0.0; this.m_I = 0.0;
this.m_invI = 0.0; this.m_invI = 0.0;
} }
var oldCenter = this.m_sweep.c.Copy(); var oldCenter = this.m_sweep.c.clone();
this.m_sweep.localCenter.SetV(center); this.m_sweep.localCenter.SetV(center);
this.m_sweep.c0.SetV(b2Math.MulX(this.m_xf, this.m_sweep.localCenter)); this.m_sweep.c0.SetV(b2Math.MulX(this.m_xf, this.m_sweep.localCenter));
this.m_sweep.c.SetV(this.m_sweep.c0); this.m_sweep.c.SetV(this.m_sweep.c0);
@ -4804,7 +4804,7 @@ Box2D.postDefs = [];
this.m_linearVelocity.SetZero(); this.m_linearVelocity.SetZero();
this.m_angularVelocity = 0.0; this.m_angularVelocity = 0.0;
} }
this.SetAwake(true); this.setAwake(true);
this.m_force.SetZero(); this.m_force.SetZero();
this.m_torque = 0.0; this.m_torque = 0.0;
for (var ce = this.m_contactList; ce; ce = ce.next) { for (var ce = this.m_contactList; ce; ce = ce.next) {
@ -4831,7 +4831,7 @@ Box2D.postDefs = [];
} }
else { else {
this.m_flags &= ~b2Body.e_allowSleepFlag; this.m_flags &= ~b2Body.e_allowSleepFlag;
this.SetAwake(true); this.setAwake(true);
} }
} }
b2Body.prototype.SetAwake = function (flag) { b2Body.prototype.SetAwake = function (flag) {
@ -5029,9 +5029,9 @@ Box2D.postDefs = [];
Box2D.Dynamics.b2Body.e_bulletFlag = 0x0008; Box2D.Dynamics.b2Body.e_bulletFlag = 0x0008;
Box2D.Dynamics.b2Body.e_fixedRotationFlag = 0x0010; Box2D.Dynamics.b2Body.e_fixedRotationFlag = 0x0010;
Box2D.Dynamics.b2Body.e_activeFlag = 0x0020; Box2D.Dynamics.b2Body.e_activeFlag = 0x0020;
Box2D.Dynamics.b2Body.b2_staticBody = 0; 'static' = 0;
Box2D.Dynamics.b2Body.b2_kinematicBody = 1; 'kinematic' = 1;
Box2D.Dynamics.b2Body.b2_dynamicBody = 2; 'dynamic' = 2;
}); });
b2BodyDef.b2BodyDef = function () { b2BodyDef.b2BodyDef = function () {
this.position = new b2Vec2(); this.position = new b2Vec2();
@ -5191,7 +5191,7 @@ Box2D.postDefs = [];
var fixtureB = c.GetFixtureB(); var fixtureB = c.GetFixtureB();
var bodyA = fixtureA.GetBody(); var bodyA = fixtureA.GetBody();
var bodyB = fixtureB.GetBody(); var bodyB = fixtureB.GetBody();
if (bodyA.IsAwake() == false && bodyB.IsAwake() == false) { if (bodyA.isAwake() == false && bodyB.isAwake() == false) {
c = c.GetNext(); c = c.GetNext();
continue; continue;
} }
@ -5301,7 +5301,7 @@ Box2D.postDefs = [];
this.m_filter = new b2FilterData(); this.m_filter = new b2FilterData();
}; };
b2Fixture.prototype.GetType = function () { b2Fixture.prototype.GetType = function () {
return this.m_shape.GetType(); return this.m_shape.getType();
} }
b2Fixture.prototype.GetShape = function () { b2Fixture.prototype.GetShape = function () {
return this.m_shape; return this.m_shape;
@ -5323,7 +5323,7 @@ Box2D.postDefs = [];
return this.m_isSensor; return this.m_isSensor;
} }
b2Fixture.prototype.SetFilterData = function (filter) { b2Fixture.prototype.SetFilterData = function (filter) {
this.m_filter = filter.Copy(); this.m_filter = filter.clone();
if (this.m_body) return; if (this.m_body) return;
var edge = this.m_body.GetContactList(); var edge = this.m_body.GetContactList();
while (edge) { while (edge) {
@ -5335,7 +5335,7 @@ Box2D.postDefs = [];
} }
} }
b2Fixture.prototype.GetFilterData = function () { b2Fixture.prototype.GetFilterData = function () {
return this.m_filter.Copy(); return this.m_filter.clone();
} }
b2Fixture.prototype.GetBody = function () { b2Fixture.prototype.GetBody = function () {
return this.m_body; return this.m_body;
@ -5403,9 +5403,9 @@ Box2D.postDefs = [];
this.m_restitution = def.restitution; this.m_restitution = def.restitution;
this.m_body = body; this.m_body = body;
this.m_next = null; this.m_next = null;
this.m_filter = def.filter.Copy(); this.m_filter = def.filter.clone();
this.m_isSensor = def.isSensor; this.m_isSensor = def.isSensor;
this.m_shape = def.shape.Copy(); this.m_shape = def.shape.clone();
this.m_density = def.density; this.m_density = def.density;
} }
b2Fixture.prototype.Destroy = function () { b2Fixture.prototype.Destroy = function () {
@ -5489,7 +5489,7 @@ Box2D.postDefs = [];
for (i = 0; for (i = 0;
i < this.m_bodyCount; ++i) { i < this.m_bodyCount; ++i) {
b = this.m_bodies[i]; b = this.m_bodies[i];
if (b.GetType() != b2Body.b2_dynamicBody) continue; if (b.getType() != b2Body.b2_dynamicBody) continue;
b.m_linearVelocity.x += step.dt * (gravity.x + b.m_invMass * b.m_force.x); b.m_linearVelocity.x += step.dt * (gravity.x + b.m_invMass * b.m_force.x);
b.m_linearVelocity.y += step.dt * (gravity.y + b.m_invMass * b.m_force.y); b.m_linearVelocity.y += step.dt * (gravity.y + b.m_invMass * b.m_force.y);
b.m_angularVelocity += step.dt * b.m_invI * b.m_torque; b.m_angularVelocity += step.dt * b.m_invI * b.m_torque;
@ -5522,7 +5522,7 @@ Box2D.postDefs = [];
for (i = 0; for (i = 0;
i < this.m_bodyCount; ++i) { i < this.m_bodyCount; ++i) {
b = this.m_bodies[i]; b = this.m_bodies[i];
if (b.GetType() == b2Body.b2_staticBody) continue; if (b.getType() == b2Body.b2_staticBody) continue;
var translationX = step.dt * b.m_linearVelocity.x; var translationX = step.dt * b.m_linearVelocity.x;
var translationY = step.dt * b.m_linearVelocity.y; var translationY = step.dt * b.m_linearVelocity.y;
if ((translationX * translationX + translationY * translationY) > b2Settings.b2_maxTranslationSquared) { if ((translationX * translationX + translationY * translationY) > b2Settings.b2_maxTranslationSquared) {
@ -5568,7 +5568,7 @@ Box2D.postDefs = [];
for (i = 0; for (i = 0;
i < this.m_bodyCount; ++i) { i < this.m_bodyCount; ++i) {
b = this.m_bodies[i]; b = this.m_bodies[i];
if (b.GetType() == b2Body.b2_staticBody) { if (b.getType() == b2Body.b2_staticBody) {
continue; continue;
} }
if ((b.m_flags & b2Body.e_allowSleepFlag) == 0) { if ((b.m_flags & b2Body.e_allowSleepFlag) == 0) {
@ -5588,7 +5588,7 @@ Box2D.postDefs = [];
for (i = 0; for (i = 0;
i < this.m_bodyCount; ++i) { i < this.m_bodyCount; ++i) {
b = this.m_bodies[i]; b = this.m_bodies[i];
b.SetAwake(false); b.setAwake(false);
} }
} }
} }
@ -5613,7 +5613,7 @@ Box2D.postDefs = [];
for (i = 0; for (i = 0;
i < this.m_bodyCount; ++i) { i < this.m_bodyCount; ++i) {
var b = this.m_bodies[i]; var b = this.m_bodies[i];
if (b.GetType() == b2Body.b2_staticBody) continue; if (b.getType() == b2Body.b2_staticBody) continue;
var translationX = subStep.dt * b.m_linearVelocity.x; var translationX = subStep.dt * b.m_linearVelocity.x;
var translationY = subStep.dt * b.m_linearVelocity.y; var translationY = subStep.dt * b.m_linearVelocity.y;
if ((translationX * translationX + translationY * translationY) > b2Settings.b2_maxTranslationSquared) { if ((translationX * translationX + translationY * translationY) > b2Settings.b2_maxTranslationSquared) {
@ -5850,8 +5850,8 @@ Box2D.postDefs = [];
} }
var bodyA = j.m_bodyA; var bodyA = j.m_bodyA;
var bodyB = j.m_bodyB; var bodyB = j.m_bodyB;
bodyA.SetAwake(true); bodyA.setAwake(true);
bodyB.SetAwake(true); bodyB.setAwake(true);
if (j.m_edgeA.prev) { if (j.m_edgeA.prev) {
j.m_edgeA.prev.next = j.m_edgeA.next; j.m_edgeA.prev.next = j.m_edgeA.next;
} }
@ -6015,15 +6015,15 @@ Box2D.postDefs = [];
color.Set(0.5, 0.5, 0.3); color.Set(0.5, 0.5, 0.3);
this.DrawShape(s, xf, color); this.DrawShape(s, xf, color);
} }
else if (b.GetType() == b2Body.b2_staticBody) { else if (b.getType() == b2Body.b2_staticBody) {
color.Set(0.5, 0.9, 0.5); color.Set(0.5, 0.9, 0.5);
this.DrawShape(s, xf, color); this.DrawShape(s, xf, color);
} }
else if (b.GetType() == b2Body.b2_kinematicBody) { else if (b.getType() == b2Body.b2_kinematicBody) {
color.Set(0.5, 0.5, 0.9); color.Set(0.5, 0.5, 0.9);
this.DrawShape(s, xf, color); this.DrawShape(s, xf, color);
} }
else if (b.IsAwake() == false) { else if (b.isAwake() == false) {
color.Set(0.6, 0.6, 0.6); color.Set(0.6, 0.6, 0.6);
this.DrawShape(s, xf, color); this.DrawShape(s, xf, color);
} }
@ -6079,7 +6079,7 @@ Box2D.postDefs = [];
b; b = b.m_next) { b; b = b.m_next) {
xf = b2World.s_xf; xf = b2World.s_xf;
xf.R = b.m_xf.R; xf.R = b.m_xf.R;
xf.position = b.GetWorldCenter(); xf.position = b.getWorldCenter();
this.m_debugDraw.DrawTransform(xf); this.m_debugDraw.DrawTransform(xf);
} }
} }
@ -6203,10 +6203,10 @@ Box2D.postDefs = [];
if (seed.m_flags & b2Body.e_islandFlag) { if (seed.m_flags & b2Body.e_islandFlag) {
continue; continue;
} }
if (seed.IsAwake() == false || seed.IsActive() == false) { if (seed.isAwake() == false || seed.IsActive() == false) {
continue; continue;
} }
if (seed.GetType() == b2Body.b2_staticBody) { if (seed.getType() == b2Body.b2_staticBody) {
continue; continue;
} }
island.Clear(); island.Clear();
@ -6216,10 +6216,10 @@ Box2D.postDefs = [];
while (stackCount > 0) { while (stackCount > 0) {
b = stack[--stackCount]; b = stack[--stackCount];
island.AddBody(b); island.AddBody(b);
if (b.IsAwake() == false) { if (b.isAwake() == false) {
b.SetAwake(true); b.setAwake(true);
} }
if (b.GetType() == b2Body.b2_staticBody) { if (b.getType() == b2Body.b2_staticBody) {
continue; continue;
} }
var other; var other;
@ -6259,7 +6259,7 @@ Box2D.postDefs = [];
island.Solve(step, this.m_gravity, this.m_allowSleep); island.Solve(step, this.m_gravity, this.m_allowSleep);
for (var i = 0; i < island.m_bodyCount; ++i) { for (var i = 0; i < island.m_bodyCount; ++i) {
b = island.m_bodies[i]; b = island.m_bodies[i];
if (b.GetType() == b2Body.b2_staticBody) { if (b.getType() == b2Body.b2_staticBody) {
b.m_flags &= ~b2Body.e_islandFlag; b.m_flags &= ~b2Body.e_islandFlag;
} }
} }
@ -6271,10 +6271,10 @@ Box2D.postDefs = [];
} }
for (b = this.m_bodyList; for (b = this.m_bodyList;
b; b = b.m_next) { b; b = b.m_next) {
if (b.IsAwake() == false || b.IsActive() == false) { if (b.isAwake() == false || b.IsActive() == false) {
continue; continue;
} }
if (b.GetType() == b2Body.b2_staticBody) { if (b.getType() == b2Body.b2_staticBody) {
continue; continue;
} }
b.SynchronizeFixtures(); b.SynchronizeFixtures();
@ -6323,7 +6323,7 @@ Box2D.postDefs = [];
fB = c.m_fixtureB; fB = c.m_fixtureB;
bA = fA.m_body; bA = fA.m_body;
bB = fB.m_body; bB = fB.m_body;
if ((bA.GetType() != b2Body.b2_dynamicBody || bA.IsAwake() == false) && (bB.GetType() != b2Body.b2_dynamicBody || bB.IsAwake() == false)) { if ((bA.getType() != b2Body.b2_dynamicBody || bA.isAwake() == false) && (bB.getType() != b2Body.b2_dynamicBody || bB.isAwake() == false)) {
continue; continue;
} }
var t0 = bA.m_sweep.t0; var t0 = bA.m_sweep.t0;
@ -6373,7 +6373,7 @@ Box2D.postDefs = [];
continue; continue;
} }
var seed = bA; var seed = bA;
if (seed.GetType() != b2Body.b2_dynamicBody) { if (seed.getType() != b2Body.b2_dynamicBody) {
seed = bB; seed = bB;
} }
island.Clear(); island.Clear();
@ -6385,10 +6385,10 @@ Box2D.postDefs = [];
b = queue[queueStart++]; b = queue[queueStart++];
--queueSize; --queueSize;
island.AddBody(b); island.AddBody(b);
if (b.IsAwake() == false) { if (b.isAwake() == false) {
b.SetAwake(true); b.setAwake(true);
} }
if (b.GetType() != b2Body.b2_dynamicBody) { if (b.getType() != b2Body.b2_dynamicBody) {
continue; continue;
} }
for (cEdge = b.m_contactList; for (cEdge = b.m_contactList;
@ -6408,9 +6408,9 @@ Box2D.postDefs = [];
if (other.m_flags & b2Body.e_islandFlag) { if (other.m_flags & b2Body.e_islandFlag) {
continue; continue;
} }
if (other.GetType() != b2Body.b2_staticBody) { if (other.getType() != b2Body.b2_staticBody) {
other.Advance(minTOI); other.Advance(minTOI);
other.SetAwake(true); other.setAwake(true);
} }
queue[queueStart + queueSize] = other; queue[queueStart + queueSize] = other;
++queueSize; ++queueSize;
@ -6426,9 +6426,9 @@ Box2D.postDefs = [];
island.AddJoint(jEdge.joint); island.AddJoint(jEdge.joint);
jEdge.joint.m_islandFlag = true; jEdge.joint.m_islandFlag = true;
if (other.m_flags & b2Body.e_islandFlag) continue; if (other.m_flags & b2Body.e_islandFlag) continue;
if (other.GetType() != b2Body.b2_staticBody) { if (other.getType() != b2Body.b2_staticBody) {
other.Advance(minTOI); other.Advance(minTOI);
other.SetAwake(true); other.setAwake(true);
} }
queue[queueStart + queueSize] = other; queue[queueStart + queueSize] = other;
++queueSize; ++queueSize;
@ -6448,10 +6448,10 @@ Box2D.postDefs = [];
i < island.m_bodyCount; ++i) { i < island.m_bodyCount; ++i) {
b = island.m_bodies[i]; b = island.m_bodies[i];
b.m_flags &= ~b2Body.e_islandFlag; b.m_flags &= ~b2Body.e_islandFlag;
if (b.IsAwake() == false) { if (b.isAwake() == false) {
continue; continue;
} }
if (b.GetType() != b2Body.b2_dynamicBody) { if (b.getType() != b2Body.b2_dynamicBody) {
continue; continue;
} }
b.SynchronizeFixtures(); b.SynchronizeFixtures();
@ -6716,7 +6716,7 @@ Box2D.postDefs = [];
} }
var bodyA = fixtureA.GetBody(); var bodyA = fixtureA.GetBody();
var bodyB = fixtureB.GetBody(); var bodyB = fixtureB.GetBody();
if (bodyA.GetType() != b2Body.b2_dynamicBody || bodyA.IsBullet() || bodyB.GetType() != b2Body.b2_dynamicBody || bodyB.IsBullet()) { if (bodyA.getType() != b2Body.b2_dynamicBody || bodyA.IsBullet() || bodyB.getType() != b2Body.b2_dynamicBody || bodyB.IsBullet()) {
this.m_flags |= b2Contact.e_continuousFlag; this.m_flags |= b2Contact.e_continuousFlag;
} }
this.m_fixtureA = fixtureA; this.m_fixtureA = fixtureA;
@ -6754,7 +6754,7 @@ Box2D.postDefs = [];
this.m_manifold.m_pointCount = 0; this.m_manifold.m_pointCount = 0;
} }
else { else {
if (bodyA.GetType() != b2Body.b2_dynamicBody || bodyA.IsBullet() || bodyB.GetType() != b2Body.b2_dynamicBody || bodyB.IsBullet()) { if (bodyA.getType() != b2Body.b2_dynamicBody || bodyA.IsBullet() || bodyB.getType() != b2Body.b2_dynamicBody || bodyB.IsBullet()) {
this.m_flags |= b2Contact.e_continuousFlag; this.m_flags |= b2Contact.e_continuousFlag;
} }
else { else {
@ -6782,8 +6782,8 @@ Box2D.postDefs = [];
this.m_manifold.m_pointCount = 0; this.m_manifold.m_pointCount = 0;
} }
if (touching != wasTouching) { if (touching != wasTouching) {
bodyA.SetAwake(true); bodyA.setAwake(true);
bodyB.SetAwake(true); bodyB.setAwake(true);
} }
} }
if (touching) { if (touching) {
@ -6872,8 +6872,8 @@ Box2D.postDefs = [];
this.AddType(b2PolyAndEdgeContact.Create, b2PolyAndEdgeContact.Destroy, b2Shape.e_polygonShape, b2Shape.e_edgeShape); this.AddType(b2PolyAndEdgeContact.Create, b2PolyAndEdgeContact.Destroy, b2Shape.e_polygonShape, b2Shape.e_edgeShape);
} }
b2ContactFactory.prototype.Create = function (fixtureA, fixtureB) { b2ContactFactory.prototype.Create = function (fixtureA, fixtureB) {
var type1 = parseInt(fixtureA.GetType()); var type1 = parseInt(fixtureA.getType());
var type2 = parseInt(fixtureB.GetType()); var type2 = parseInt(fixtureB.getType());
var reg = this.m_registers[type1][type2]; var reg = this.m_registers[type1][type2];
var c; var c;
if (reg.pool) { if (reg.pool) {
@ -6902,11 +6902,11 @@ Box2D.postDefs = [];
} }
b2ContactFactory.prototype.Destroy = function (contact) { b2ContactFactory.prototype.Destroy = function (contact) {
if (contact.m_manifold.m_pointCount > 0) { if (contact.m_manifold.m_pointCount > 0) {
contact.m_fixtureA.m_body.SetAwake(true); contact.m_fixtureA.m_body.setAwake(true);
contact.m_fixtureB.m_body.SetAwake(true); contact.m_fixtureB.m_body.setAwake(true);
} }
var type1 = parseInt(contact.m_fixtureA.GetType()); var type1 = parseInt(contact.m_fixtureA.getType());
var type2 = parseInt(contact.m_fixtureB.GetType()); var type2 = parseInt(contact.m_fixtureB.getType());
var reg = this.m_registers[type1][type2]; var reg = this.m_registers[type1][type2];
if (true) { if (true) {
reg.poolCount++; reg.poolCount++;
@ -7367,8 +7367,8 @@ Box2D.postDefs = [];
b2PolyAndCircleContact.Destroy = function (contact, allocator) {} b2PolyAndCircleContact.Destroy = function (contact, allocator) {}
b2PolyAndCircleContact.prototype.Reset = function (fixtureA, fixtureB) { b2PolyAndCircleContact.prototype.Reset = function (fixtureA, fixtureB) {
this.__super.Reset.call(this, fixtureA, fixtureB); this.__super.Reset.call(this, fixtureA, fixtureB);
b2Settings.b2Assert(fixtureA.GetType() == b2Shape.e_polygonShape); b2Settings.b2Assert(fixtureA.getType() == b2Shape.e_polygonShape);
b2Settings.b2Assert(fixtureB.GetType() == b2Shape.e_circleShape); b2Settings.b2Assert(fixtureB.getType() == b2Shape.e_circleShape);
} }
b2PolyAndCircleContact.prototype.Evaluate = function () { b2PolyAndCircleContact.prototype.Evaluate = function () {
var bA = this.m_fixtureA.m_body; var bA = this.m_fixtureA.m_body;
@ -7386,8 +7386,8 @@ Box2D.postDefs = [];
b2PolyAndEdgeContact.Destroy = function (contact, allocator) {} b2PolyAndEdgeContact.Destroy = function (contact, allocator) {}
b2PolyAndEdgeContact.prototype.Reset = function (fixtureA, fixtureB) { b2PolyAndEdgeContact.prototype.Reset = function (fixtureA, fixtureB) {
this.__super.Reset.call(this, fixtureA, fixtureB); this.__super.Reset.call(this, fixtureA, fixtureB);
b2Settings.b2Assert(fixtureA.GetType() == b2Shape.e_polygonShape); b2Settings.b2Assert(fixtureA.getType() == b2Shape.e_polygonShape);
b2Settings.b2Assert(fixtureB.GetType() == b2Shape.e_edgeShape); b2Settings.b2Assert(fixtureB.getType() == b2Shape.e_edgeShape);
} }
b2PolyAndEdgeContact.prototype.Evaluate = function () { b2PolyAndEdgeContact.prototype.Evaluate = function () {
var bA = this.m_fixtureA.GetBody(); var bA = this.m_fixtureA.GetBody();
@ -7566,11 +7566,11 @@ Box2D.postDefs = [];
b2BuoyancyController.prototype.Step = function (step) { b2BuoyancyController.prototype.Step = function (step) {
if (!this.m_bodyList) return; if (!this.m_bodyList) return;
if (this.useWorldGravity) { if (this.useWorldGravity) {
this.gravity = this.GetWorld().GetGravity().Copy(); this.gravity = this.GetWorld().GetGravity().clone();
} }
for (var i = this.m_bodyList; i; i = i.nextBody) { for (var i = this.m_bodyList; i; i = i.nextBody) {
var body = i.body; var body = i.body;
if (body.IsAwake() == false) { if (body.isAwake() == false) {
continue; continue;
} }
var areac = new b2Vec2(); var areac = new b2Vec2();
@ -7601,12 +7601,12 @@ Box2D.postDefs = [];
if (area < Number.MIN_VALUE) continue; if (area < Number.MIN_VALUE) continue;
var buoyancyForce = this.gravity.GetNegative(); var buoyancyForce = this.gravity.GetNegative();
buoyancyForce.Multiply(this.density * area); buoyancyForce.Multiply(this.density * area);
body.ApplyForce(buoyancyForce, massc); body.applyForce(buoyancyForce, massc);
var dragForce = body.GetLinearVelocityFromWorldPoint(areac); var dragForce = body.GetLinearVelocityFromWorldPoint(areac);
dragForce.Subtract(this.velocity); dragForce.Subtract(this.velocity);
dragForce.Multiply((-this.linearDrag * area)); dragForce.Multiply((-this.linearDrag * area));
body.ApplyForce(dragForce, areac); body.applyForce(dragForce, areac);
body.ApplyTorque((-body.GetInertia() / body.GetMass() * area * body.GetAngularVelocity() * this.angularDrag)); body.applyTorque((-body.getInertia() / body.getMass() * area * body.getAngularVelocity() * this.angularDrag));
} }
} }
b2BuoyancyController.prototype.Draw = function (debugDraw) { b2BuoyancyController.prototype.Draw = function (debugDraw) {
@ -7630,7 +7630,7 @@ Box2D.postDefs = [];
var smallA = new b2Vec2(this.A.x * step.dt, this.A.y * step.dt); var smallA = new b2Vec2(this.A.x * step.dt, this.A.y * step.dt);
for (var i = this.m_bodyList; i; i = i.nextBody) { for (var i = this.m_bodyList; i; i = i.nextBody) {
var body = i.body; var body = i.body;
if (!body.IsAwake()) continue; if (!body.isAwake()) continue;
body.SetLinearVelocity(new b2Vec2(body.GetLinearVelocity().x + smallA.x, body.GetLinearVelocity().y + smallA.y)); body.SetLinearVelocity(new b2Vec2(body.GetLinearVelocity().x + smallA.x, body.GetLinearVelocity().y + smallA.y));
} }
} }
@ -7643,8 +7643,8 @@ Box2D.postDefs = [];
b2ConstantForceController.prototype.Step = function (step) { b2ConstantForceController.prototype.Step = function (step) {
for (var i = this.m_bodyList; i; i = i.nextBody) { for (var i = this.m_bodyList; i; i = i.nextBody) {
var body = i.body; var body = i.body;
if (!body.IsAwake()) continue; if (!body.isAwake()) continue;
body.ApplyForce(this.F, body.GetWorldCenter()); body.applyForce(this.F, body.getWorldCenter());
} }
} }
b2Controller.b2Controller = function () {}; b2Controller.b2Controller = function () {};
@ -7715,21 +7715,21 @@ Box2D.postDefs = [];
for (i = this.m_bodyList; for (i = this.m_bodyList;
i; i = i.nextBody) { i; i = i.nextBody) {
body1 = i.body; body1 = i.body;
p1 = body1.GetWorldCenter(); p1 = body1.getWorldCenter();
mass1 = body1.GetMass(); mass1 = body1.getMass();
for (j = this.m_bodyList; for (j = this.m_bodyList;
j != i; j = j.nextBody) { j != i; j = j.nextBody) {
body2 = j.body; body2 = j.body;
p2 = body2.GetWorldCenter(); p2 = body2.getWorldCenter();
dx = p2.x - p1.x; dx = p2.x - p1.x;
dy = p2.y - p1.y; dy = p2.y - p1.y;
r2 = dx * dx + dy * dy; r2 = dx * dx + dy * dy;
if (r2 < Number.MIN_VALUE) continue; if (r2 < Number.MIN_VALUE) continue;
f = new b2Vec2(dx, dy); f = new b2Vec2(dx, dy);
f.Multiply(this.G / r2 / Math.sqrt(r2) * mass1 * body2.GetMass()); f.Multiply(this.G / r2 / Math.sqrt(r2) * mass1 * body2.getMass());
if (body1.IsAwake()) body1.ApplyForce(f, p1); if (body1.isAwake()) body1.applyForce(f, p1);
f.Multiply((-1)); f.Multiply((-1));
if (body2.IsAwake()) body2.ApplyForce(f, p2); if (body2.isAwake()) body2.applyForce(f, p2);
} }
} }
} }
@ -7737,21 +7737,21 @@ Box2D.postDefs = [];
for (i = this.m_bodyList; for (i = this.m_bodyList;
i; i = i.nextBody) { i; i = i.nextBody) {
body1 = i.body; body1 = i.body;
p1 = body1.GetWorldCenter(); p1 = body1.getWorldCenter();
mass1 = body1.GetMass(); mass1 = body1.getMass();
for (j = this.m_bodyList; for (j = this.m_bodyList;
j != i; j = j.nextBody) { j != i; j = j.nextBody) {
body2 = j.body; body2 = j.body;
p2 = body2.GetWorldCenter(); p2 = body2.getWorldCenter();
dx = p2.x - p1.x; dx = p2.x - p1.x;
dy = p2.y - p1.y; dy = p2.y - p1.y;
r2 = dx * dx + dy * dy; r2 = dx * dx + dy * dy;
if (r2 < Number.MIN_VALUE) continue; if (r2 < Number.MIN_VALUE) continue;
f = new b2Vec2(dx, dy); f = new b2Vec2(dx, dy);
f.Multiply(this.G / r2 * mass1 * body2.GetMass()); f.Multiply(this.G / r2 * mass1 * body2.getMass());
if (body1.IsAwake()) body1.ApplyForce(f, p1); if (body1.isAwake()) body1.applyForce(f, p1);
f.Multiply((-1)); f.Multiply((-1));
if (body2.IsAwake()) body2.ApplyForce(f, p2); if (body2.isAwake()) body2.applyForce(f, p2);
} }
} }
} }
@ -7783,7 +7783,7 @@ Box2D.postDefs = [];
if (timestep > this.maxTimestep && this.maxTimestep > 0) timestep = this.maxTimestep; if (timestep > this.maxTimestep && this.maxTimestep > 0) timestep = this.maxTimestep;
for (var i = this.m_bodyList; i; i = i.nextBody) { for (var i = this.m_bodyList; i; i = i.nextBody) {
var body = i.body; var body = i.body;
if (!body.IsAwake()) { if (!body.isAwake()) {
continue; continue;
} }
var damping = body.GetWorldVector(b2Math.MulMV(this.T, body.GetLocalVector(body.GetLinearVelocity()))); var damping = body.GetWorldVector(b2Math.MulMV(this.T, body.GetLocalVector(body.GetLinearVelocity())));
@ -7848,10 +7848,10 @@ Box2D.postDefs = [];
this.m_u = new b2Vec2(); this.m_u = new b2Vec2();
}; };
b2DistanceJoint.prototype.GetAnchorA = function () { b2DistanceJoint.prototype.GetAnchorA = function () {
return this.m_bodyA.GetWorldPoint(this.m_localAnchor1); return this.m_bodyA.getWorldPoint(this.m_localAnchor1);
} }
b2DistanceJoint.prototype.GetAnchorB = function () { b2DistanceJoint.prototype.GetAnchorB = function () {
return this.m_bodyB.GetWorldPoint(this.m_localAnchor2); return this.m_bodyB.getWorldPoint(this.m_localAnchor2);
} }
b2DistanceJoint.prototype.GetReactionForce = function (inv_dt) { b2DistanceJoint.prototype.GetReactionForce = function (inv_dt) {
if (inv_dt === undefined) inv_dt = 0; if (inv_dt === undefined) inv_dt = 0;
@ -8042,8 +8042,8 @@ Box2D.postDefs = [];
b2DistanceJointDef.prototype.Initialize = function (bA, bB, anchorA, anchorB) { b2DistanceJointDef.prototype.Initialize = function (bA, bB, anchorA, anchorB) {
this.bodyA = bA; this.bodyA = bA;
this.bodyB = bB; this.bodyB = bB;
this.localAnchorA.SetV(this.bodyA.GetLocalPoint(anchorA)); this.localAnchorA.SetV(this.bodyA.getLocalPoint(anchorA));
this.localAnchorB.SetV(this.bodyB.GetLocalPoint(anchorB)); this.localAnchorB.SetV(this.bodyB.getLocalPoint(anchorB));
var dX = anchorB.x - anchorA.x; var dX = anchorB.x - anchorA.x;
var dY = anchorB.y - anchorA.y; var dY = anchorB.y - anchorA.y;
this.length = Math.sqrt(dX * dX + dY * dY); this.length = Math.sqrt(dX * dX + dY * dY);
@ -8060,10 +8060,10 @@ Box2D.postDefs = [];
this.m_linearImpulse = new b2Vec2(); this.m_linearImpulse = new b2Vec2();
}; };
b2FrictionJoint.prototype.GetAnchorA = function () { b2FrictionJoint.prototype.GetAnchorA = function () {
return this.m_bodyA.GetWorldPoint(this.m_localAnchorA); return this.m_bodyA.getWorldPoint(this.m_localAnchorA);
} }
b2FrictionJoint.prototype.GetAnchorB = function () { b2FrictionJoint.prototype.GetAnchorB = function () {
return this.m_bodyB.GetWorldPoint(this.m_localAnchorB); return this.m_bodyB.getWorldPoint(this.m_localAnchorB);
} }
b2FrictionJoint.prototype.GetReactionForce = function (inv_dt) { b2FrictionJoint.prototype.GetReactionForce = function (inv_dt) {
if (inv_dt === undefined) inv_dt = 0; if (inv_dt === undefined) inv_dt = 0;
@ -8192,7 +8192,7 @@ Box2D.postDefs = [];
var CdotX = vB.x - wB * rBY - vA.x + wA * rAY; var CdotX = vB.x - wB * rBY - vA.x + wA * rAY;
var CdotY = vB.y + wB * rBX - vA.y - wA * rAX; var CdotY = vB.y + wB * rBX - vA.y - wA * rAX;
var impulseV = b2Math.MulMV(this.m_linearMass, new b2Vec2((-CdotX), (-CdotY))); var impulseV = b2Math.MulMV(this.m_linearMass, new b2Vec2((-CdotX), (-CdotY)));
var oldImpulseV = this.m_linearImpulse.Copy(); var oldImpulseV = this.m_linearImpulse.clone();
this.m_linearImpulse.Add(impulseV); this.m_linearImpulse.Add(impulseV);
maxImpulse = step.dt * this.m_maxForce; maxImpulse = step.dt * this.m_maxForce;
if (this.m_linearImpulse.LengthSquared() > maxImpulse * maxImpulse) { if (this.m_linearImpulse.LengthSquared() > maxImpulse * maxImpulse) {
@ -8230,8 +8230,8 @@ Box2D.postDefs = [];
b2FrictionJointDef.prototype.Initialize = function (bA, bB, anchor) { b2FrictionJointDef.prototype.Initialize = function (bA, bB, anchor) {
this.bodyA = bA; this.bodyA = bA;
this.bodyB = bB; this.bodyB = bB;
this.localAnchorA.SetV(this.bodyA.GetLocalPoint(anchor)); this.localAnchorA.SetV(this.bodyA.getLocalPoint(anchor));
this.localAnchorB.SetV(this.bodyB.GetLocalPoint(anchor)); this.localAnchorB.SetV(this.bodyB.getLocalPoint(anchor));
} }
Box2D.inherit(b2GearJoint, Box2D.Dynamics.Joints.b2Joint); Box2D.inherit(b2GearJoint, Box2D.Dynamics.Joints.b2Joint);
b2GearJoint.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype; b2GearJoint.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
@ -8244,10 +8244,10 @@ Box2D.postDefs = [];
this.m_J = new b2Jacobian(); this.m_J = new b2Jacobian();
}; };
b2GearJoint.prototype.GetAnchorA = function () { b2GearJoint.prototype.GetAnchorA = function () {
return this.m_bodyA.GetWorldPoint(this.m_localAnchor1); return this.m_bodyA.getWorldPoint(this.m_localAnchor1);
} }
b2GearJoint.prototype.GetAnchorB = function () { b2GearJoint.prototype.GetAnchorB = function () {
return this.m_bodyB.GetWorldPoint(this.m_localAnchor2); return this.m_bodyB.getWorldPoint(this.m_localAnchor2);
} }
b2GearJoint.prototype.GetReactionForce = function (inv_dt) { b2GearJoint.prototype.GetReactionForce = function (inv_dt) {
if (inv_dt === undefined) inv_dt = 0; if (inv_dt === undefined) inv_dt = 0;
@ -8613,10 +8613,10 @@ Box2D.postDefs = [];
this.m_impulse = new b2Vec2(); this.m_impulse = new b2Vec2();
}; };
b2LineJoint.prototype.GetAnchorA = function () { b2LineJoint.prototype.GetAnchorA = function () {
return this.m_bodyA.GetWorldPoint(this.m_localAnchor1); return this.m_bodyA.getWorldPoint(this.m_localAnchor1);
} }
b2LineJoint.prototype.GetAnchorB = function () { b2LineJoint.prototype.GetAnchorB = function () {
return this.m_bodyB.GetWorldPoint(this.m_localAnchor2); return this.m_bodyB.getWorldPoint(this.m_localAnchor2);
} }
b2LineJoint.prototype.GetReactionForce = function (inv_dt) { b2LineJoint.prototype.GetReactionForce = function (inv_dt) {
if (inv_dt === undefined) inv_dt = 0; if (inv_dt === undefined) inv_dt = 0;
@ -8630,8 +8630,8 @@ Box2D.postDefs = [];
var bA = this.m_bodyA; var bA = this.m_bodyA;
var bB = this.m_bodyB; var bB = this.m_bodyB;
var tMat; var tMat;
var p1 = bA.GetWorldPoint(this.m_localAnchor1); var p1 = bA.getWorldPoint(this.m_localAnchor1);
var p2 = bB.GetWorldPoint(this.m_localAnchor2); var p2 = bB.getWorldPoint(this.m_localAnchor2);
var dX = p2.x - p1.x; var dX = p2.x - p1.x;
var dY = p2.y - p1.y; var dY = p2.y - p1.y;
var axis = bA.GetWorldVector(this.m_localXAxis1); var axis = bA.GetWorldVector(this.m_localXAxis1);
@ -8672,8 +8672,8 @@ Box2D.postDefs = [];
return this.m_enableLimit; return this.m_enableLimit;
} }
b2LineJoint.prototype.EnableLimit = function (flag) { b2LineJoint.prototype.EnableLimit = function (flag) {
this.m_bodyA.SetAwake(true); this.m_bodyA.setAwake(true);
this.m_bodyB.SetAwake(true); this.m_bodyB.setAwake(true);
this.m_enableLimit = flag; this.m_enableLimit = flag;
} }
b2LineJoint.prototype.GetLowerLimit = function () { b2LineJoint.prototype.GetLowerLimit = function () {
@ -8685,8 +8685,8 @@ Box2D.postDefs = [];
b2LineJoint.prototype.SetLimits = function (lower, upper) { b2LineJoint.prototype.SetLimits = function (lower, upper) {
if (lower === undefined) lower = 0; if (lower === undefined) lower = 0;
if (upper === undefined) upper = 0; if (upper === undefined) upper = 0;
this.m_bodyA.SetAwake(true); this.m_bodyA.setAwake(true);
this.m_bodyB.SetAwake(true); this.m_bodyB.setAwake(true);
this.m_lowerTranslation = lower; this.m_lowerTranslation = lower;
this.m_upperTranslation = upper; this.m_upperTranslation = upper;
} }
@ -8694,14 +8694,14 @@ Box2D.postDefs = [];
return this.m_enableMotor; return this.m_enableMotor;
} }
b2LineJoint.prototype.EnableMotor = function (flag) { b2LineJoint.prototype.EnableMotor = function (flag) {
this.m_bodyA.SetAwake(true); this.m_bodyA.setAwake(true);
this.m_bodyB.SetAwake(true); this.m_bodyB.setAwake(true);
this.m_enableMotor = flag; this.m_enableMotor = flag;
} }
b2LineJoint.prototype.SetMotorSpeed = function (speed) { b2LineJoint.prototype.SetMotorSpeed = function (speed) {
if (speed === undefined) speed = 0; if (speed === undefined) speed = 0;
this.m_bodyA.SetAwake(true); this.m_bodyA.setAwake(true);
this.m_bodyB.SetAwake(true); this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed; this.m_motorSpeed = speed;
} }
b2LineJoint.prototype.GetMotorSpeed = function () { b2LineJoint.prototype.GetMotorSpeed = function () {
@ -8709,8 +8709,8 @@ Box2D.postDefs = [];
} }
b2LineJoint.prototype.SetMaxMotorForce = function (force) { b2LineJoint.prototype.SetMaxMotorForce = function (force) {
if (force === undefined) force = 0; if (force === undefined) force = 0;
this.m_bodyA.SetAwake(true); this.m_bodyA.setAwake(true);
this.m_bodyB.SetAwake(true); this.m_bodyB.setAwake(true);
this.m_maxMotorForce = force; this.m_maxMotorForce = force;
} }
b2LineJoint.prototype.GetMaxMotorForce = function () { b2LineJoint.prototype.GetMaxMotorForce = function () {
@ -8867,7 +8867,7 @@ Box2D.postDefs = [];
var Cdot1 = this.m_perp.x * (v2.x - v1.x) + this.m_perp.y * (v2.y - v1.y) + this.m_s2 * w2 - this.m_s1 * w1; var Cdot1 = this.m_perp.x * (v2.x - v1.x) + this.m_perp.y * (v2.y - v1.y) + this.m_s2 * w2 - this.m_s1 * w1;
if (this.m_enableLimit && this.m_limitState != b2Joint.e_inactiveLimit) { if (this.m_enableLimit && this.m_limitState != b2Joint.e_inactiveLimit) {
var Cdot2 = this.m_axis.x * (v2.x - v1.x) + this.m_axis.y * (v2.y - v1.y) + this.m_a2 * w2 - this.m_a1 * w1; var Cdot2 = this.m_axis.x * (v2.x - v1.x) + this.m_axis.y * (v2.y - v1.y) + this.m_a2 * w2 - this.m_a1 * w1;
var f1 = this.m_impulse.Copy(); var f1 = this.m_impulse.clone();
var df = this.m_K.Solve(new b2Vec2(), (-Cdot1), (-Cdot2)); var df = this.m_K.Solve(new b2Vec2(), (-Cdot1), (-Cdot2));
this.m_impulse.Add(df); this.m_impulse.Add(df);
if (this.m_limitState == b2Joint.e_atLowerLimit) { if (this.m_limitState == b2Joint.e_atLowerLimit) {
@ -9053,8 +9053,8 @@ Box2D.postDefs = [];
b2LineJointDef.prototype.Initialize = function (bA, bB, anchor, axis) { b2LineJointDef.prototype.Initialize = function (bA, bB, anchor, axis) {
this.bodyA = bA; this.bodyA = bA;
this.bodyB = bB; this.bodyB = bB;
this.localAnchorA = this.bodyA.GetLocalPoint(anchor); this.localAnchorA = this.bodyA.getLocalPoint(anchor);
this.localAnchorB = this.bodyB.GetLocalPoint(anchor); this.localAnchorB = this.bodyB.getLocalPoint(anchor);
this.localAxisA = this.bodyA.GetLocalVector(axis); this.localAxisA = this.bodyA.GetLocalVector(axis);
} }
Box2D.inherit(b2MouseJoint, Box2D.Dynamics.Joints.b2Joint); Box2D.inherit(b2MouseJoint, Box2D.Dynamics.Joints.b2Joint);
@ -9074,7 +9074,7 @@ Box2D.postDefs = [];
return this.m_target; return this.m_target;
} }
b2MouseJoint.prototype.GetAnchorB = function () { b2MouseJoint.prototype.GetAnchorB = function () {
return this.m_bodyB.GetWorldPoint(this.m_localAnchor); return this.m_bodyB.getWorldPoint(this.m_localAnchor);
} }
b2MouseJoint.prototype.GetReactionForce = function (inv_dt) { b2MouseJoint.prototype.GetReactionForce = function (inv_dt) {
if (inv_dt === undefined) inv_dt = 0; if (inv_dt === undefined) inv_dt = 0;
@ -9088,8 +9088,8 @@ Box2D.postDefs = [];
return this.m_target; return this.m_target;
} }
b2MouseJoint.prototype.SetTarget = function (target) { b2MouseJoint.prototype.SetTarget = function (target) {
if (this.m_bodyB.IsAwake() == false) { if (this.m_bodyB.isAwake() == false) {
this.m_bodyB.SetAwake(true); this.m_bodyB.setAwake(true);
} }
this.m_target = target; this.m_target = target;
} }
@ -9131,7 +9131,7 @@ Box2D.postDefs = [];
} }
b2MouseJoint.prototype.InitVelocityConstraints = function (step) { b2MouseJoint.prototype.InitVelocityConstraints = function (step) {
var b = this.m_bodyB; var b = this.m_bodyB;
var mass = b.GetMass(); var mass = b.getMass();
var omega = 2.0 * Math.PI * this.m_frequencyHz; var omega = 2.0 * Math.PI * this.m_frequencyHz;
var d = 2.0 * mass * this.m_dampingRatio * omega; var d = 2.0 * mass * this.m_dampingRatio * omega;
var k = mass * omega * omega; var k = mass * omega * omega;
@ -9229,10 +9229,10 @@ Box2D.postDefs = [];
this.m_impulse = new b2Vec3(); this.m_impulse = new b2Vec3();
}; };
b2PrismaticJoint.prototype.GetAnchorA = function () { b2PrismaticJoint.prototype.GetAnchorA = function () {
return this.m_bodyA.GetWorldPoint(this.m_localAnchor1); return this.m_bodyA.getWorldPoint(this.m_localAnchor1);
} }
b2PrismaticJoint.prototype.GetAnchorB = function () { b2PrismaticJoint.prototype.GetAnchorB = function () {
return this.m_bodyB.GetWorldPoint(this.m_localAnchor2); return this.m_bodyB.getWorldPoint(this.m_localAnchor2);
} }
b2PrismaticJoint.prototype.GetReactionForce = function (inv_dt) { b2PrismaticJoint.prototype.GetReactionForce = function (inv_dt) {
if (inv_dt === undefined) inv_dt = 0; if (inv_dt === undefined) inv_dt = 0;
@ -9246,8 +9246,8 @@ Box2D.postDefs = [];
var bA = this.m_bodyA; var bA = this.m_bodyA;
var bB = this.m_bodyB; var bB = this.m_bodyB;
var tMat; var tMat;
var p1 = bA.GetWorldPoint(this.m_localAnchor1); var p1 = bA.getWorldPoint(this.m_localAnchor1);
var p2 = bB.GetWorldPoint(this.m_localAnchor2); var p2 = bB.getWorldPoint(this.m_localAnchor2);
var dX = p2.x - p1.x; var dX = p2.x - p1.x;
var dY = p2.y - p1.y; var dY = p2.y - p1.y;
var axis = bA.GetWorldVector(this.m_localXAxis1); var axis = bA.GetWorldVector(this.m_localXAxis1);
@ -9288,8 +9288,8 @@ Box2D.postDefs = [];
return this.m_enableLimit; return this.m_enableLimit;
} }
b2PrismaticJoint.prototype.EnableLimit = function (flag) { b2PrismaticJoint.prototype.EnableLimit = function (flag) {
this.m_bodyA.SetAwake(true); this.m_bodyA.setAwake(true);
this.m_bodyB.SetAwake(true); this.m_bodyB.setAwake(true);
this.m_enableLimit = flag; this.m_enableLimit = flag;
} }
b2PrismaticJoint.prototype.GetLowerLimit = function () { b2PrismaticJoint.prototype.GetLowerLimit = function () {
@ -9301,8 +9301,8 @@ Box2D.postDefs = [];
b2PrismaticJoint.prototype.SetLimits = function (lower, upper) { b2PrismaticJoint.prototype.SetLimits = function (lower, upper) {
if (lower === undefined) lower = 0; if (lower === undefined) lower = 0;
if (upper === undefined) upper = 0; if (upper === undefined) upper = 0;
this.m_bodyA.SetAwake(true); this.m_bodyA.setAwake(true);
this.m_bodyB.SetAwake(true); this.m_bodyB.setAwake(true);
this.m_lowerTranslation = lower; this.m_lowerTranslation = lower;
this.m_upperTranslation = upper; this.m_upperTranslation = upper;
} }
@ -9310,14 +9310,14 @@ Box2D.postDefs = [];
return this.m_enableMotor; return this.m_enableMotor;
} }
b2PrismaticJoint.prototype.EnableMotor = function (flag) { b2PrismaticJoint.prototype.EnableMotor = function (flag) {
this.m_bodyA.SetAwake(true); this.m_bodyA.setAwake(true);
this.m_bodyB.SetAwake(true); this.m_bodyB.setAwake(true);
this.m_enableMotor = flag; this.m_enableMotor = flag;
} }
b2PrismaticJoint.prototype.SetMotorSpeed = function (speed) { b2PrismaticJoint.prototype.SetMotorSpeed = function (speed) {
if (speed === undefined) speed = 0; if (speed === undefined) speed = 0;
this.m_bodyA.SetAwake(true); this.m_bodyA.setAwake(true);
this.m_bodyB.SetAwake(true); this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed; this.m_motorSpeed = speed;
} }
b2PrismaticJoint.prototype.GetMotorSpeed = function () { b2PrismaticJoint.prototype.GetMotorSpeed = function () {
@ -9325,8 +9325,8 @@ Box2D.postDefs = [];
} }
b2PrismaticJoint.prototype.SetMaxMotorForce = function (force) { b2PrismaticJoint.prototype.SetMaxMotorForce = function (force) {
if (force === undefined) force = 0; if (force === undefined) force = 0;
this.m_bodyA.SetAwake(true); this.m_bodyA.setAwake(true);
this.m_bodyB.SetAwake(true); this.m_bodyB.setAwake(true);
this.m_maxMotorForce = force; this.m_maxMotorForce = force;
} }
b2PrismaticJoint.prototype.GetMotorForce = function () { b2PrismaticJoint.prototype.GetMotorForce = function () {
@ -9487,7 +9487,7 @@ Box2D.postDefs = [];
var Cdot1Y = w2 - w1; var Cdot1Y = w2 - w1;
if (this.m_enableLimit && this.m_limitState != b2Joint.e_inactiveLimit) { if (this.m_enableLimit && this.m_limitState != b2Joint.e_inactiveLimit) {
var Cdot2 = this.m_axis.x * (v2.x - v1.x) + this.m_axis.y * (v2.y - v1.y) + this.m_a2 * w2 - this.m_a1 * w1; var Cdot2 = this.m_axis.x * (v2.x - v1.x) + this.m_axis.y * (v2.y - v1.y) + this.m_a2 * w2 - this.m_a1 * w1;
var f1 = this.m_impulse.Copy(); var f1 = this.m_impulse.clone();
var df = this.m_K.Solve33(new b2Vec3(), (-Cdot1X), (-Cdot1Y), (-Cdot2)); var df = this.m_K.Solve33(new b2Vec3(), (-Cdot1X), (-Cdot1Y), (-Cdot2));
this.m_impulse.Add(df); this.m_impulse.Add(df);
if (this.m_limitState == b2Joint.e_atLowerLimit) { if (this.m_limitState == b2Joint.e_atLowerLimit) {
@ -9672,8 +9672,8 @@ Box2D.postDefs = [];
b2PrismaticJointDef.prototype.Initialize = function (bA, bB, anchor, axis) { b2PrismaticJointDef.prototype.Initialize = function (bA, bB, anchor, axis) {
this.bodyA = bA; this.bodyA = bA;
this.bodyB = bB; this.bodyB = bB;
this.localAnchorA = this.bodyA.GetLocalPoint(anchor); this.localAnchorA = this.bodyA.getLocalPoint(anchor);
this.localAnchorB = this.bodyB.GetLocalPoint(anchor); this.localAnchorB = this.bodyB.getLocalPoint(anchor);
this.localAxisA = this.bodyA.GetLocalVector(axis); this.localAxisA = this.bodyA.GetLocalVector(axis);
this.referenceAngle = this.bodyB.GetAngle() - this.bodyA.GetAngle(); this.referenceAngle = this.bodyB.GetAngle() - this.bodyA.GetAngle();
} }
@ -9689,10 +9689,10 @@ Box2D.postDefs = [];
this.m_u2 = new b2Vec2(); this.m_u2 = new b2Vec2();
}; };
b2PulleyJoint.prototype.GetAnchorA = function () { b2PulleyJoint.prototype.GetAnchorA = function () {
return this.m_bodyA.GetWorldPoint(this.m_localAnchor1); return this.m_bodyA.getWorldPoint(this.m_localAnchor1);
} }
b2PulleyJoint.prototype.GetAnchorB = function () { b2PulleyJoint.prototype.GetAnchorB = function () {
return this.m_bodyB.GetWorldPoint(this.m_localAnchor2); return this.m_bodyB.getWorldPoint(this.m_localAnchor2);
} }
b2PulleyJoint.prototype.GetReactionForce = function (inv_dt) { b2PulleyJoint.prototype.GetReactionForce = function (inv_dt) {
if (inv_dt === undefined) inv_dt = 0; if (inv_dt === undefined) inv_dt = 0;
@ -9703,17 +9703,17 @@ Box2D.postDefs = [];
return 0.0; return 0.0;
} }
b2PulleyJoint.prototype.GetGroundAnchorA = function () { b2PulleyJoint.prototype.GetGroundAnchorA = function () {
var a = this.m_ground.m_xf.position.Copy(); var a = this.m_ground.m_xf.position.clone();
a.Add(this.m_groundAnchor1); a.Add(this.m_groundAnchor1);
return a; return a;
} }
b2PulleyJoint.prototype.GetGroundAnchorB = function () { b2PulleyJoint.prototype.GetGroundAnchorB = function () {
var a = this.m_ground.m_xf.position.Copy(); var a = this.m_ground.m_xf.position.clone();
a.Add(this.m_groundAnchor2); a.Add(this.m_groundAnchor2);
return a; return a;
} }
b2PulleyJoint.prototype.GetLength1 = function () { b2PulleyJoint.prototype.GetLength1 = function () {
var p = this.m_bodyA.GetWorldPoint(this.m_localAnchor1); var p = this.m_bodyA.getWorldPoint(this.m_localAnchor1);
var sX = this.m_ground.m_xf.position.x + this.m_groundAnchor1.x; var sX = this.m_ground.m_xf.position.x + this.m_groundAnchor1.x;
var sY = this.m_ground.m_xf.position.y + this.m_groundAnchor1.y; var sY = this.m_ground.m_xf.position.y + this.m_groundAnchor1.y;
var dX = p.x - sX; var dX = p.x - sX;
@ -9721,7 +9721,7 @@ Box2D.postDefs = [];
return Math.sqrt(dX * dX + dY * dY); return Math.sqrt(dX * dX + dY * dY);
} }
b2PulleyJoint.prototype.GetLength2 = function () { b2PulleyJoint.prototype.GetLength2 = function () {
var p = this.m_bodyB.GetWorldPoint(this.m_localAnchor2); var p = this.m_bodyB.getWorldPoint(this.m_localAnchor2);
var sX = this.m_ground.m_xf.position.x + this.m_groundAnchor2.x; var sX = this.m_ground.m_xf.position.x + this.m_groundAnchor2.x;
var sY = this.m_ground.m_xf.position.y + this.m_groundAnchor2.y; var sY = this.m_ground.m_xf.position.y + this.m_groundAnchor2.y;
var dX = p.x - sX; var dX = p.x - sX;
@ -10086,8 +10086,8 @@ Box2D.postDefs = [];
this.bodyB = bB; this.bodyB = bB;
this.groundAnchorA.SetV(gaA); this.groundAnchorA.SetV(gaA);
this.groundAnchorB.SetV(gaB); this.groundAnchorB.SetV(gaB);
this.localAnchorA = this.bodyA.GetLocalPoint(anchorA); this.localAnchorA = this.bodyA.getLocalPoint(anchorA);
this.localAnchorB = this.bodyB.GetLocalPoint(anchorB); this.localAnchorB = this.bodyB.getLocalPoint(anchorB);
var d1X = anchorA.x - gaA.x; var d1X = anchorA.x - gaA.x;
var d1Y = anchorA.y - gaA.y; var d1Y = anchorA.y - gaA.y;
this.lengthA = Math.sqrt(d1X * d1X + d1Y * d1Y); this.lengthA = Math.sqrt(d1X * d1X + d1Y * d1Y);
@ -10116,10 +10116,10 @@ Box2D.postDefs = [];
this.m_mass = new b2Mat33(); this.m_mass = new b2Mat33();
}; };
b2RevoluteJoint.prototype.GetAnchorA = function () { b2RevoluteJoint.prototype.GetAnchorA = function () {
return this.m_bodyA.GetWorldPoint(this.m_localAnchor1); return this.m_bodyA.getWorldPoint(this.m_localAnchor1);
} }
b2RevoluteJoint.prototype.GetAnchorB = function () { b2RevoluteJoint.prototype.GetAnchorB = function () {
return this.m_bodyB.GetWorldPoint(this.m_localAnchor2); return this.m_bodyB.getWorldPoint(this.m_localAnchor2);
} }
b2RevoluteJoint.prototype.GetReactionForce = function (inv_dt) { b2RevoluteJoint.prototype.GetReactionForce = function (inv_dt) {
if (inv_dt === undefined) inv_dt = 0; if (inv_dt === undefined) inv_dt = 0;
@ -10155,8 +10155,8 @@ Box2D.postDefs = [];
this.m_upperAngle = upper; this.m_upperAngle = upper;
} }
b2RevoluteJoint.prototype.IsMotorEnabled = function () { b2RevoluteJoint.prototype.IsMotorEnabled = function () {
this.m_bodyA.SetAwake(true); this.m_bodyA.setAwake(true);
this.m_bodyB.SetAwake(true); this.m_bodyB.setAwake(true);
return this.m_enableMotor; return this.m_enableMotor;
} }
b2RevoluteJoint.prototype.EnableMotor = function (flag) { b2RevoluteJoint.prototype.EnableMotor = function (flag) {
@ -10164,8 +10164,8 @@ Box2D.postDefs = [];
} }
b2RevoluteJoint.prototype.SetMotorSpeed = function (speed) { b2RevoluteJoint.prototype.SetMotorSpeed = function (speed) {
if (speed === undefined) speed = 0; if (speed === undefined) speed = 0;
this.m_bodyA.SetAwake(true); this.m_bodyA.setAwake(true);
this.m_bodyB.SetAwake(true); this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed; this.m_motorSpeed = speed;
} }
b2RevoluteJoint.prototype.GetMotorSpeed = function () { b2RevoluteJoint.prototype.GetMotorSpeed = function () {
@ -10509,8 +10509,8 @@ Box2D.postDefs = [];
b2RevoluteJointDef.prototype.Initialize = function (bA, bB, anchor) { b2RevoluteJointDef.prototype.Initialize = function (bA, bB, anchor) {
this.bodyA = bA; this.bodyA = bA;
this.bodyB = bB; this.bodyB = bB;
this.localAnchorA = this.bodyA.GetLocalPoint(anchor); this.localAnchorA = this.bodyA.getLocalPoint(anchor);
this.localAnchorB = this.bodyB.GetLocalPoint(anchor); this.localAnchorB = this.bodyB.getLocalPoint(anchor);
this.referenceAngle = this.bodyB.GetAngle() - this.bodyA.GetAngle(); this.referenceAngle = this.bodyB.GetAngle() - this.bodyA.GetAngle();
} }
Box2D.inherit(b2WeldJoint, Box2D.Dynamics.Joints.b2Joint); Box2D.inherit(b2WeldJoint, Box2D.Dynamics.Joints.b2Joint);
@ -10523,10 +10523,10 @@ Box2D.postDefs = [];
this.m_mass = new b2Mat33(); this.m_mass = new b2Mat33();
}; };
b2WeldJoint.prototype.GetAnchorA = function () { b2WeldJoint.prototype.GetAnchorA = function () {
return this.m_bodyA.GetWorldPoint(this.m_localAnchorA); return this.m_bodyA.getWorldPoint(this.m_localAnchorA);
} }
b2WeldJoint.prototype.GetAnchorB = function () { b2WeldJoint.prototype.GetAnchorB = function () {
return this.m_bodyB.GetWorldPoint(this.m_localAnchorB); return this.m_bodyB.getWorldPoint(this.m_localAnchorB);
} }
b2WeldJoint.prototype.GetReactionForce = function (inv_dt) { b2WeldJoint.prototype.GetReactionForce = function (inv_dt) {
if (inv_dt === undefined) inv_dt = 0; if (inv_dt === undefined) inv_dt = 0;
@ -10697,8 +10697,8 @@ Box2D.postDefs = [];
b2WeldJointDef.prototype.Initialize = function (bA, bB, anchor) { b2WeldJointDef.prototype.Initialize = function (bA, bB, anchor) {
this.bodyA = bA; this.bodyA = bA;
this.bodyB = bB; this.bodyB = bB;
this.localAnchorA.SetV(this.bodyA.GetLocalPoint(anchor)); this.localAnchorA.SetV(this.bodyA.getLocalPoint(anchor));
this.localAnchorB.SetV(this.bodyB.GetLocalPoint(anchor)); this.localAnchorB.SetV(this.bodyB.getLocalPoint(anchor));
this.referenceAngle = this.bodyB.GetAngle() - this.bodyA.GetAngle(); this.referenceAngle = this.bodyB.GetAngle() - this.bodyA.GetAngle();
} }
})(); })();

View file

@ -68,7 +68,7 @@ function loadFixtureFromRUBE(body, fixtureJso) {
fd.shape.m_radius = fixtureJso.circle.radius; fd.shape.m_radius = fixtureJso.circle.radius;
if ( fixtureJso.circle.center ) if ( fixtureJso.circle.center )
fd.shape.m_p.SetV(fixtureJso.circle.center); fd.shape.m_p.SetV(fixtureJso.circle.center);
var fixture = body.CreateFixture(fd); var fixture = body.createFixture(fd);
if ( fixtureJso.name ) if ( fixtureJso.name )
fixture.name = fixtureJso.name; fixture.name = fixtureJso.name;
} }
@ -78,7 +78,7 @@ function loadFixtureFromRUBE(body, fixtureJso) {
for (v = 0; v < fixtureJso.polygon.vertices.x.length; v++) for (v = 0; v < fixtureJso.polygon.vertices.x.length; v++)
verts.push( new b2Vec2( fixtureJso.polygon.vertices.x[v], fixtureJso.polygon.vertices.y[v] ) ); verts.push( new b2Vec2( fixtureJso.polygon.vertices.x[v], fixtureJso.polygon.vertices.y[v] ) );
fd.shape.SetAsArray(verts, verts.length); fd.shape.SetAsArray(verts, verts.length);
var fixture = body.CreateFixture(fd); var fixture = body.createFixture(fd);
if ( fixture && fixtureJso.name ) if ( fixture && fixtureJso.name )
fixture.name = fixtureJso.name; fixture.name = fixtureJso.name;
} }
@ -89,7 +89,7 @@ function loadFixtureFromRUBE(body, fixtureJso) {
var thisVertex = new b2Vec2( fixtureJso.chain.vertices.x[v], fixtureJso.chain.vertices.y[v] ); var thisVertex = new b2Vec2( fixtureJso.chain.vertices.x[v], fixtureJso.chain.vertices.y[v] );
if ( v > 0 ) { if ( v > 0 ) {
fd.shape.SetAsEdge( lastVertex, thisVertex ); fd.shape.SetAsEdge( lastVertex, thisVertex );
var fixture = body.CreateFixture(fd); var fixture = body.createFixture(fd);
if ( fixtureJso.name ) if ( fixtureJso.name )
fixture.name = fixtureJso.name; fixture.name = fixtureJso.name;
} }

View file

@ -1,5 +1,5 @@
define([ define([
"Lib/Vendor/Box2D", "Lib/Vendor/Planck",
], ],
/* /*
@ -72,7 +72,7 @@ function (Box2D) {
ClipVertex = Box2D.Collision.ClipVertex, ClipVertex = Box2D.Collision.ClipVertex,
Features = Box2D.Collision.Features, Features = Box2D.Collision.Features,
IBroadPhase = Box2D.Collision.IBroadPhase; IBroadPhase = Box2D.Collision.IBroadPhase;
b2_dynamicBody = Box2D.Dynamics.b2Body.b2_dynamicBody; b2_dynamicBody = 'dynamic';
b2ControllerEdge = Box2D.Dynamics.Controllers.b2ControllerEdge, b2ControllerEdge = Box2D.Dynamics.Controllers.b2ControllerEdge,
IBroadPhase = Box2D.Collision.IBroadPhase, IBroadPhase = Box2D.Collision.IBroadPhase,
b2CircleContact = Box2D.Dynamics.Contacts.b2CircleContact, b2CircleContact = Box2D.Dynamics.Contacts.b2CircleContact,
@ -194,7 +194,7 @@ function (Box2D) {
fd.shape.m_radius = fixtureJson.circle.radius; fd.shape.m_radius = fixtureJson.circle.radius;
if ( fixtureJson.circle.center ) if ( fixtureJson.circle.center )
fd.shape.m_p.SetV(fixtureJson.circle.center); fd.shape.m_p.SetV(fixtureJson.circle.center);
var fixture = body.CreateFixture(fd); var fixture = body.createFixture(fd);
if ( fixtureJson.name ) if ( fixtureJson.name )
fixture.name = fixtureJson.name; fixture.name = fixtureJson.name;
} }
@ -206,7 +206,7 @@ function (Box2D) {
for (v = fixtureJson.polygon.vertices.x.length - 1; v >= 0 ; v--) for (v = fixtureJson.polygon.vertices.x.length - 1; v >= 0 ; v--)
verts.push( new b2Vec2( fixtureJson.polygon.vertices.x[v], -fixtureJson.polygon.vertices.y[v] ) ); verts.push( new b2Vec2( fixtureJson.polygon.vertices.x[v], -fixtureJson.polygon.vertices.y[v] ) );
fd.shape.SetAsArray(verts, verts.length); fd.shape.SetAsArray(verts, verts.length);
var fixture = body.CreateFixture(fd); var fixture = body.createFixture(fd);
if ( fixture && fixtureJson.name ) if ( fixture && fixtureJson.name )
fixture.name = fixtureJson.name; fixture.name = fixtureJson.name;
} }
@ -217,7 +217,7 @@ function (Box2D) {
var thisVertex = new b2Vec2( fixtureJson.chain.vertices.x[v], -fixtureJson.chain.vertices.y[v] ); var thisVertex = new b2Vec2( fixtureJson.chain.vertices.x[v], -fixtureJson.chain.vertices.y[v] );
if ( v < fixtureJson.chain.vertices.x.length - 1 ) { if ( v < fixtureJson.chain.vertices.x.length - 1 ) {
fd.shape.SetAsEdge( lastVertex, thisVertex ); fd.shape.SetAsEdge( lastVertex, thisVertex );
var fixture = body.CreateFixture(fd); var fixture = body.createFixture(fd);
if ( fixtureJson.name ) if ( fixtureJson.name )
fixture.name = fixtureJson.name; fixture.name = fixtureJson.name;
} }

View file

@ -1,53 +0,0 @@
define([
"Game/Client/Networker",
"Lib/Utilities/Protocol/Helper",
"Game/Client/GameController",
"Game/Client/User",
"Lib/Utilities/NotificationCenter"
],
function (Parent, ProtocolHelper, GameController, User) {
function Worker () {
//this.socketLink = socketLink;
this.gameController = null;
this.users = {};
this.init();
}
Worker.prototype = Object.create(Parent.prototype);
Worker.prototype.init = function () {
ProtocolHelper.applyCommand({
"joinSuccess":{
"userId":"k31HvnDM7Jy6mfmKOe3y",
"channelName":"dungeon",
"joinedUsers":[],
"spawnedPlayers":[]
}
}, this);
ProtocolHelper.applyCommand({
"gameCommand":{
"spawnPlayer":{
"id":"k31HvnDM7Jy6mfmKOe3y",
"x":150,
"y":50
}
}
}, this);
nc.on(nc.ns.client.to.server.gameCommand.send, this.sendGameCommand, this);
}
Worker.prototype.sendCommand = function (command, options) {
var message = ProtocolHelper.encodeCommand(command, options);
//this.socketLink.send(message);
}
return Worker;
});

View file

@ -1 +0,0 @@
../app

View file

@ -1,21 +0,0 @@
GLOBALS = { context: "Client" };
requirejs.config({
baseUrl: 'app',
deps: ['Lib/Utilities/Extensions']
});
var inspector = {};
requirejs([
"Game/Config/Settings",
"Worker.js"
],
function (Settings, Worker) {
var worker = new Worker();
inspector.worker = worker;
inspector.settings = Settings;
});

View file

@ -1,34 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Chuck</title>
<style>
html, body {
margin: 0;
padding: 0;
display: table;
width: 100%;
height: 100%;
background: #000;
}
#canvasContainer {
text-align: center;
display: table-cell;
vertical-align: middle;
height: 100%;
}
canvas {
background: #333;
margin: 10px;
}
#canvasContainer canvas:first-child {
}
</style>
</head>
<body>
<div id="canvasContainer">
</div>
<script data-main="client" src="../node_modules/requirejs/require.js"></script>
</body>
</html>

File diff suppressed because it is too large Load diff

View file

@ -1,78 +0,0 @@
<html>
<head>
<title>Box2D javascript (box2dweb) testbed</title>
<script type="text/javascript" src="box2dweb.js"></script>
<script type="text/javascript" src="loadrube.js"></script>
<script type="text/javascript" src="testbed.js"></script>
<script type="text/javascript" src="jack-min.js"></script>
<script type="text/javascript" src="jackinthebox.js"></script>
<script type="text/javascript" src="ragdoll-min.js"></script>
<script type="text/javascript" src="ragdoll.js"></script>
<style>
html, body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<canvas id="canvas" width="640" height="480" tabindex='1'></canvas>
<div style="display: none;text-align:center">
<br>
Try the latest version of Chrome or Firefox for best performance.<br>
<br>
<div style="margin:auto;width:640px;padding:2px;border:1px solid #888;text-align:left">
<!--
If you change the size of the canvas, you'll also need to change
the value of 'viewCenterPixel' in testbed.js
-->
<div style="width:636px;padding:2px;background-color:#ddd">
<div style="text-align:center">
Select test: <select id="testSelection" onchange="changeTest();">
<option value="ragdoll">Ragdoll of Chuck</option>
<option value="jackinthebox">Jack-in-the-box</option>
</select><br>
<div style="height:6px"></div>
<div id="sceneinfo" style="width:500px;margin:auto;background-color:#eee;text-align:left">
Loading...
</div>
<div id="testcomments" style="width:500px;margin:auto;background-color:#eee;text-align:left">
</div>
<br>
<button id="reloadButton" onclick="resetScene();">Reset</button>
<button id="pauseButton" onclick="pause();">Pause</button>
<button id="stepButton" onclick="step();">Single step</button>
(Keyboard: R, P, S)<br>
Zoom
<button id="zoomInButton" onclick="zoomIn();">+</button>
<button id="zoomOutButton" onclick="zoomOut();">-</button>
(Keyboard: X, Z)<br>
Hold down Shift while moving the mouse to pan (Keyboard: arrow keys)<br>
You need to click on the canvas before using the keyboard.<br>
</div>
<br>
Debug draw flags:<br>
<input id="drawShapesCheck" type="checkbox" onclick="updateWorldFromDebugDrawCheckboxes();">Shapes<br>
<input id="drawJointsCheck" type="checkbox" onclick="updateWorldFromDebugDrawCheckboxes();">Joints<br>
<input id="drawAABBsCheck" type="checkbox" onclick="updateWorldFromDebugDrawCheckboxes();">AABBs<br>
<input id="drawTransformsCheck" type="checkbox" onclick="updateWorldFromDebugDrawCheckboxes();">Transforms<br>
<br>
<input id="showStatsCheck" type="checkbox" onclick="updateContinuousRefreshStatus();">Show stats<br>
<span id="feedbackSpan"></span>
<br>
</div>
</div>
</div>
</body>
</html>

File diff suppressed because one or more lines are too long

View file

@ -1,26 +0,0 @@
var jackinthebox = function() {
//constructor
}
jackinthebox.prototype.setNiceViewCenter = function() {
//called once when the user changes to this test from another test
PTM = 70;
setViewCenterWorld( new b2Vec2(0, 10.5), true );
}
jackinthebox.prototype.setup = function() {
//set up the Box2D scene here - the world is already created
if ( loadSceneFromRUBE(jack_scene) ) //jack_scene is defined in jack-min.js
console.log("RUBE scene loaded successfully.");
else
console.log("Failed to load RUBE scene");
doAfterLoading();
}
jackinthebox.prototype.getComments = function(canvas, evt) {
return "Created in R.U.B.E editor. Pull the latch to the side to open the box.";
}

View file

@ -1,416 +0,0 @@
Object.prototype.hasOwnProperty = function(property) {
return typeof(this[property]) !== 'undefined'
};
function loadBodyFromRUBE(bodyJso, world) {
//console.log(bodyJso);
if ( ! bodyJso.hasOwnProperty('type') ) {
console.log("Body does not have a 'type' property");
return null;
}
var bd = new b2BodyDef();
if ( bodyJso.type == 2 )
bd.type = b2_dynamicBody;
else if ( bodyJso.type == 1 )
bd.type = b2_kinematicBody;
if ( bodyJso.hasOwnProperty('angle') )
bd.angle = bodyJso.angle;
if ( bodyJso.hasOwnProperty('angularVelocity') )
bd.angularVelocity = bodyJso.angularVelocity;
if ( bodyJso.hasOwnProperty('active') )
bd.awake = bodyJso.active;
if ( bodyJso.hasOwnProperty('fixedRotation') )
bd.fixedRotation = bodyJso.fixedRotation;
if ( bodyJso.hasOwnProperty('linearVelocity') && bodyJso.linearVelocity instanceof Object )
bd.linearVelocity.SetV( bodyJso.linearVelocity );
if ( bodyJso.hasOwnProperty('position') && bodyJso.position instanceof Object )
bd.position.SetV( bodyJso.position );
if ( bodyJso.hasOwnProperty('awake') )
bd.awake = bodyJso.awake;
else
bd.awake = false;
var body = world.CreateBody(bd);
if ( bodyJso.hasOwnProperty('fixture') ) {
for (k = 0; k < bodyJso['fixture'].length; k++) {
var fixtureJso = bodyJso['fixture'][k];
loadFixtureFromRUBE(body, fixtureJso);
}
}
if ( bodyJso.hasOwnProperty('name') )
body.name = bodyJso.name;
if ( bodyJso.hasOwnProperty('customProperties') )
body.customProperties = bodyJso.customProperties;
return body;
}
function loadFixtureFromRUBE(body, fixtureJso) {
//console.log(fixtureJso);
var fd = new b2FixtureDef();
if (fixtureJso.hasOwnProperty('friction'))
fd.friction = fixtureJso.friction;
if (fixtureJso.hasOwnProperty('density'))
fd.density = fixtureJso.density;
if (fixtureJso.hasOwnProperty('restitution'))
fd.restitution = fixtureJso.restitution;
if (fixtureJso.hasOwnProperty('sensor'))
fd.isSensor = fixtureJso.sensor;
if ( fixtureJso.hasOwnProperty('filter-categoryBits') )
fd.filter.categoryBits = fixtureJso['filter-categoryBits'];
if ( fixtureJso.hasOwnProperty('filter-maskBits') )
fd.filter.maskBits = fixtureJso['filter-maskBits'];
if ( fixtureJso.hasOwnProperty('filter-groupIndex') )
fd.filter.groupIndex = fixtureJso['filter-groupIndex'];
if (fixtureJso.hasOwnProperty('circle')) {
fd.shape = new b2CircleShape();
fd.shape.m_radius = fixtureJso.circle.radius;
if ( fixtureJso.circle.center )
fd.shape.m_p.SetV(fixtureJso.circle.center);
var fixture = body.CreateFixture(fd);
if ( fixtureJso.name )
fixture.name = fixtureJso.name;
}
else if (fixtureJso.hasOwnProperty('polygon')) {
fd.shape = new b2PolygonShape();
var verts = [];
for (v = 0; v < fixtureJso.polygon.vertices.x.length; v++)
verts.push( new b2Vec2( fixtureJso.polygon.vertices.x[v], fixtureJso.polygon.vertices.y[v] ) );
fd.shape.SetAsArray(verts, verts.length);
var fixture = body.CreateFixture(fd);
if ( fixture && fixtureJso.name )
fixture.name = fixtureJso.name;
}
else if (fixtureJso.hasOwnProperty('chain')) {
fd.shape = new b2PolygonShape();
var lastVertex = new b2Vec2();
for (v = 0; v < fixtureJso.chain.vertices.x.length; v++) {
var thisVertex = new b2Vec2( fixtureJso.chain.vertices.x[v], fixtureJso.chain.vertices.y[v] );
if ( v > 0 ) {
fd.shape.SetAsEdge( lastVertex, thisVertex );
var fixture = body.CreateFixture(fd);
if ( fixtureJso.name )
fixture.name = fixtureJso.name;
}
lastVertex = thisVertex;
}
}
else {
console.log("Could not find shape type for fixture");
}
}
function getVectorValue(val) {
if ( val instanceof Object )
return val;
else
return { x:0, y:0 };
}
function loadJointCommonProperties(jd, jointJso, loadedBodies) {
jd.bodyA = loadedBodies[jointJso.bodyA];
jd.bodyB = loadedBodies[jointJso.bodyB];
jd.localAnchorA.SetV( getVectorValue(jointJso.anchorA) );
jd.localAnchorB.SetV( getVectorValue(jointJso.anchorB) );
if ( jointJso.collideConnected )
jd.collideConnected = jointJso.collideConnected;
}
function loadJointFromRUBE(jointJso, world, loadedBodies)
{
if ( ! jointJso.hasOwnProperty('type') ) {
console.log("Joint does not have a 'type' property");
return null;
}
if ( jointJso.bodyA >= loadedBodies.length ) {
console.log("Index for bodyA is invalid: " + jointJso.bodyA );
return null;
}
if ( jointJso.bodyB >= loadedBodies.length ) {
console.log("Index for bodyB is invalid: " + jointJso.bodyB );
return null;
}
var joint = null;
if ( jointJso.type == "revolute" ) {
var jd = new b2RevoluteJointDef();
loadJointCommonProperties(jd, jointJso, loadedBodies);
if ( jointJso.hasOwnProperty('refAngle') )
jd.referenceAngle = jointJso.refAngle;
if ( jointJso.hasOwnProperty('lowerLimit') )
jd.lowerAngle = jointJso.lowerLimit;
if ( jointJso.hasOwnProperty('upperLimit') )
jd.upperAngle = jointJso.upperLimit;
if ( jointJso.hasOwnProperty('maxMotorTorque') )
jd.maxMotorTorque = jointJso.maxMotorTorque;
if ( jointJso.hasOwnProperty('motorSpeed') )
jd.motorSpeed = jointJso.motorSpeed;
if ( jointJso.hasOwnProperty('enableLimit') )
jd.enableLimit = jointJso.enableLimit;
if ( jointJso.hasOwnProperty('enableMotor') )
jd.enableMotor = jointJso.enableMotor;
joint = world.CreateJoint(jd);
}
else if ( jointJso.type == "distance" || jointJso.type == "rope" ) {
if ( jointJso.type == "rope" )
console.log("Replacing unsupported rope joint with distance joint!");
var jd = new b2DistanceJointDef();
loadJointCommonProperties(jd, jointJso, loadedBodies);
if ( jointJso.hasOwnProperty('length') )
jd.length = jointJso.length;
if ( jointJso.hasOwnProperty('dampingRatio') )
jd.dampingRatio = jointJso.dampingRatio;
if ( jointJso.hasOwnProperty('frequency') )
jd.frequencyHz = jointJso.frequency;
joint = world.CreateJoint(jd);
}
else if ( jointJso.type == "prismatic" ) {
var jd = new b2PrismaticJointDef();
loadJointCommonProperties(jd, jointJso, loadedBodies);
if ( jointJso.hasOwnProperty('localAxisA') )
jd.localAxisA.SetV( getVectorValue(jointJso.localAxisA) );
if ( jointJso.hasOwnProperty('refAngle') )
jd.referenceAngle = jointJso.refAngle;
if ( jointJso.hasOwnProperty('enableLimit') )
jd.enableLimit = jointJso.enableLimit;
if ( jointJso.hasOwnProperty('lowerLimit') )
jd.lowerTranslation = jointJso.lowerLimit;
if ( jointJso.hasOwnProperty('upperLimit') )
jd.upperTranslation = jointJso.upperLimit;
if ( jointJso.hasOwnProperty('enableMotor') )
jd.enableMotor = jointJso.enableMotor;
if ( jointJso.hasOwnProperty('maxMotorForce') )
jd.maxMotorForce = jointJso.maxMotorForce;
if ( jointJso.hasOwnProperty('motorSpeed') )
jd.motorSpeed = jointJso.motorSpeed;
joint = world.CreateJoint(jd);
}
else if ( jointJso.type == "wheel" ) {
//Make a fake wheel joint using a line joint and a distance joint.
//Return the line joint because it has the linear motor controls.
//Use ApplyTorque on the bodies to spin the wheel...
var jd = new b2DistanceJointDef();
loadJointCommonProperties(jd, jointJso, loadedBodies);
jd.length = 0.0;
if ( jointJso.hasOwnProperty('springDampingRatio') )
jd.dampingRatio = jointJso.springDampingRatio;
if ( jointJso.hasOwnProperty('springFrequency') )
jd.frequencyHz = jointJso.springFrequency;
world.CreateJoint(jd);
jd = new b2LineJointDef();
loadJointCommonProperties(jd, jointJso, loadedBodies);
if ( jointJso.hasOwnProperty('localAxisA') )
jd.localAxisA.SetV( getVectorValue(jointJso.localAxisA) );
joint = world.CreateJoint(jd);
}
else if ( jointJso.type == "friction" ) {
var jd = new b2FrictionJointDef();
loadJointCommonProperties(jd, jointJso, loadedBodies);
if ( jointJso.hasOwnProperty('maxForce') )
jd.maxForce = jointJso.maxForce;
if ( jointJso.hasOwnProperty('maxTorque') )
jd.maxTorque = jointJso.maxTorque;
joint = world.CreateJoint(jd);
}
else if ( jointJso.type == "weld" ) {
var jd = new b2WeldJointDef();
loadJointCommonProperties(jd, jointJso, loadedBodies);
if ( jointJso.hasOwnProperty('referenceAngle') )
jd.referenceAngle = jointJso.referenceAngle;
joint = world.CreateJoint(jd);
}
else {
console.log("Unsupported joint type: " + jointJso.type);
console.log(jointJso);
}
if ( joint && jointJso.name )
joint.name = jointJso.name;
return joint;
}
function makeClone(obj) {
var newObj = (obj instanceof Array) ? [] : {};
for (var i in obj) {
if (obj[i] && typeof obj[i] == "object")
newObj[i] = makeClone(obj[i]);
else
newObj[i] = obj[i];
}
return newObj;
};
function loadImageFromRUBE(imageJso, world, loadedBodies)
{
var image = makeClone(imageJso);
if ( image.hasOwnProperty('body') && image.body >= 0 )
image.body = loadedBodies[image.body];//change index to the actual body
else
image.body = null;
image.center = new b2Vec2();
image.center.SetV( getVectorValue(imageJso.center) );
return image;
}
//mainly just a convenience for the testbed - uses global 'world' variable
function loadSceneFromRUBE(worldJso) {
return loadSceneIntoWorld(worldJso, world);
}
//load the scene into an already existing world variable
function loadSceneIntoWorld(worldJso, world) {
var success = true;
var loadedBodies = [];
if ( worldJso.hasOwnProperty('body') ) {
for (var i = 0; i < worldJso.body.length; i++) {
var bodyJso = worldJso.body[i];
var body = loadBodyFromRUBE(bodyJso, world);
if ( body )
loadedBodies.push( body );
else
success = false;
}
}
var loadedJoints = [];
if ( worldJso.hasOwnProperty('joint') ) {
for (var i = 0; i < worldJso.joint.length; i++) {
var jointJso = worldJso.joint[i];
var joint = loadJointFromRUBE(jointJso, world, loadedBodies);
if ( joint )
loadedJoints.push( joint );
//else
// success = false;
}
}
var loadedImages = [];
if ( worldJso.hasOwnProperty('image') ) {
for (var i = 0; i < worldJso.image.length; i++) {
var imageJso = worldJso.image[i];
var image = loadImageFromRUBE(imageJso, world, loadedBodies);
if ( image )
loadedImages.push( image );
else
success = false;
}
world.images = loadedImages;
}
return success;
}
//create a world variable and return it if loading succeeds
function loadWorldFromRUBE(worldJso) {
var gravity = new b2Vec2(0,0);
if ( worldJso.hasOwnProperty('gravity') && worldJso.gravity instanceof Object )
gravity.SetV( worldJso.gravity );
var world = new b2World( gravity );
if ( ! loadSceneIntoWorld(worldJso, world) )
return false;
return world;
}
function getNamedBodies(world, name) {
var bodies = [];
for (b = world.m_bodyList; b; b = b.m_next) {
if ( b.name == name )
bodies.push(b);
}
return bodies;
}
function getNamedFixtures(world, name) {
var fixtures = [];
for (b = world.m_bodyList; b; b = b.m_next) {
for (f = b.m_fixtureList; f; f = f.m_next) {
if ( f.name == name )
fixtures.push(f);
}
}
return fixtures;
}
function getNamedJoints(world, name) {
var joints = [];
for (j = world.m_jointList; j; j = j.m_next) {
if ( j.name == name )
joints.push(j);
}
return joints;
}
function getNamedImages(world, name) {
var images = [];
for (i = 0; i < world.images.length; i++) {
if ( world.images[i].name == name )
images.push(world.images[i].name);
}
return images;
}
//custom properties
function getBodiesByCustomProperty(world, propertyType, propertyName, valueToMatch) {
var bodies = [];
for (b = world.m_bodyList; b; b = b.m_next) {
if ( ! b.hasOwnProperty('customProperties') )
continue;
for (var i = 0; i < b.customProperties.length; i++) {
if ( ! b.customProperties[i].hasOwnProperty("name") )
continue;
if ( ! b.customProperties[i].hasOwnProperty(propertyType) )
continue;
if ( b.customProperties[i].name == propertyName &&
b.customProperties[i][propertyType] == valueToMatch)
bodies.push(b);
}
}
return bodies;
}
function hasCustomProperty(item, propertyType, propertyName) {
if ( !item.hasOwnProperty('customProperties') )
return false;
for (var i = 0; i < item.customProperties.length; i++) {
if ( ! item.customProperties[i].hasOwnProperty("name") )
continue;
if ( ! item.customProperties[i].hasOwnProperty(propertyType) )
continue;
return true;
}
return false;
}
function getCustomProperty(item, propertyType, propertyName, defaultValue) {
if ( !item.hasOwnProperty('customProperties') )
return defaultValue;
for (var i = 0; i < item.customProperties.length; i++) {
if ( ! item.customProperties[i].hasOwnProperty("name") )
continue;
if ( ! item.customProperties[i].hasOwnProperty(propertyType) )
continue;
if ( item.customProperties[i].name == propertyName )
return item.customProperties[i][propertyType];
}
return defaultValue;
}

File diff suppressed because it is too large Load diff

View file

@ -1,40 +0,0 @@
var ragdoll = function() {
//constructor
}
ragdoll.prototype.setNiceViewCenter = function() {
//called once when the user changes to this test from another test
PTM = 70;
setViewCenterWorld( new b2Vec2(0, 1), true );
}
ragdoll.prototype.setup = function() {
//set up the Box2D scene here - the world is already created
var c = document.getElementById('canvas');
var ctx = c.getContext("2d");
if(ctx) {
ctx.imageSmoothingEnabled = false;
ctx.mozImageSmoothingEnabled = false;
ctx.webkitImageSmoothingEnabled = false;
}
setTimeout(function(){
document.getElementById('drawShapesCheck').checked = false;
updateWorldFromDebugDrawCheckboxes();
}, 10);
if ( loadSceneFromRUBE(ragdoll_scene) ) //jack_scene is defined in jack-min.js
console.log("RUBE scene loaded successfully.");
else
console.log("Failed to load RUBE scene");
doAfterLoading();
}
ragdoll.prototype.getComments = function(canvas, evt) {
return "Created in R.U.B.E editor. Pull the latch to the side to open the box.";
}

View file

@ -1,830 +0,0 @@
//Having to type 'Box2D.' in front of everything makes porting
//existing C++ code a pain in the butt. This function can be used
//to make everything in the Box2D namespace available without
//needing to do that.
/*function using(ns, pattern) {
if (pattern == undefined) {
// import all
for (var name in ns) {
//console.log(this[name]);
this[name] = ns[name];
}
} else {
if (typeof(pattern) == 'string') {
pattern = new RegExp(pattern);
}
// import only stuff matching given pattern
for (var name in ns) {
//console.log(name);
if (name.match(pattern)) {
//console.log(ns[name]);
this[name] = ns[name];
}
}
}
}*/
var e_shapeBit = 0x0001;
var e_jointBit = 0x0002;
var e_aabbBit = 0x0004;
var e_pairBit = 0x0008;
var e_centerOfMassBit = 0x0010;
var PTM = 32;
var world = null;
var mouseJointGroundBody;
var canvas;
var context;
var myDebugDraw;
var mouseDownQueryCallback;
var visibleFixturesQueryCallback;
var mouseJoint = null;
var run = true;
var frameTime60 = 0;
var statusUpdateCounter = 0;
var showStats = false;
var mouseDown = false;
var shiftDown = false;
var originTransform;
var mousePosPixel = {
x: 0,
y: 0
};
var prevMousePosPixel = {
x: 0,
y: 0
};
var mousePosWorld = {
x: 0,
y: 0
};
var canvasOffset = {
x: 0,
y: 0
};
var viewCenterPixel = {
x:320,
y:240
};
var viewAABB;
function myRound(val,places) {
var c = 1;
for (var i = 0; i < places; i++)
c *= 10;
return Math.round(val*c)/c;
}
function getWorldPointFromPixelPoint(pixelPoint) {
return {
x: (pixelPoint.x - canvasOffset.x)/PTM,
y: (pixelPoint.y - (canvas.height - canvasOffset.y))/PTM
};
}
function updateMousePos(canvas, evt) {
var rect = canvas.getBoundingClientRect();
mousePosPixel = {
x: evt.clientX - rect.left,
y: canvas.height - (evt.clientY - rect.top)
};
mousePosWorld = getWorldPointFromPixelPoint(mousePosPixel);
}
function setViewCenterWorld(b2vecpos, instantaneous) {
var currentViewCenterWorld = getWorldPointFromPixelPoint( viewCenterPixel );
var toMoveX = b2vecpos.x - currentViewCenterWorld.x;
var toMoveY = b2vecpos.y - currentViewCenterWorld.y;
var fraction = instantaneous ? 1 : 0.25;
canvasOffset.x -= myRound(fraction * toMoveX * PTM, 0);
canvasOffset.y += myRound(fraction * toMoveY * PTM, 0);
}
function onMouseMove(canvas, evt) {
prevMousePosPixel = mousePosPixel;
updateMousePos(canvas, evt);
updateStats();
if ( shiftDown ) {
canvasOffset.x += (mousePosPixel.x - prevMousePosPixel.x);
canvasOffset.y -= (mousePosPixel.y - prevMousePosPixel.y);
draw();
}
else if ( mouseDown && mouseJoint != null ) {
mouseJoint.SetTarget( new b2Vec2(mousePosWorld.x, mousePosWorld.y) );
}
}
var getBodyCB = function(fixture) {
if(fixture.GetBody().GetType() != Box2D.Dynamics.b2BodyDef.b2_staticBody) {
if(fixture.GetShape().TestPoint(fixture.GetBody().GetTransform(), mousePosWorld)) {
selectedBody = fixture.GetBody();
return false;
}
}
return true;
};
function startMouseJoint() {
if ( mouseJoint != null )
return;
// Make a small box.
var aabb = new b2AABB();
var d = 0.001;
aabb.lowerBound.Set(mousePosWorld.x - d, mousePosWorld.y - d);
aabb.upperBound.Set(mousePosWorld.x + d, mousePosWorld.y + d);
// Query the world for overlapping shapes.
mouseDownQueryCallback.m_fixture = null;
mouseDownQueryCallback.m_point.Set(mousePosWorld.x, mousePosWorld.y);
world.QueryAABB(mouseDownQueryCallback, aabb);
if (mouseDownQueryCallback.m_fixture)
{
var body = mouseDownQueryCallback.m_fixture.GetBody();
/*selectedBody = null;
world.QueryAABB(getBodyCB, aabb);
if (selectedBody)
{
var body = selectedBody;*/
var md = new b2MouseJointDef();
md.bodyA = mouseJointGroundBody;
md.bodyB = body;
md.target.Set(mousePosWorld.x, mousePosWorld.y);
md.maxForce = 1000 * body.GetMass();
md.collideConnected = true;
mouseJoint = world.CreateJoint(md);
body.SetAwake(true);
}
}
function onMouseDown(canvas, evt) {
updateMousePos(canvas, evt);
if ( !mouseDown )
startMouseJoint();
mouseDown = true;
updateStats();
}
function onMouseUp(canvas, evt) {
mouseDown = false;
updateMousePos(canvas, evt);
updateStats();
if ( mouseJoint != null ) {
world.DestroyJoint(mouseJoint);
mouseJoint = null;
}
}
function onMouseOut(canvas, evt) {
onMouseUp(canvas,evt);
}
function onKeyDown(canvas, evt) {
//console.log(evt.keyCode);
if ( evt.keyCode == 80 ) {//p
pause();
}
else if ( evt.keyCode == 82 ) {//r
resetScene();
}
else if ( evt.keyCode == 83 ) {//s
step();
}
else if ( evt.keyCode == 88 ) {//x
zoomIn();
}
else if ( evt.keyCode == 90 ) {//z
zoomOut();
}
else if ( evt.keyCode == 37 ) {//left
canvasOffset.x += 32;
}
else if ( evt.keyCode == 39 ) {//right
canvasOffset.x -= 32;
}
else if ( evt.keyCode == 38 ) {//up
canvasOffset.y += 32;
}
else if ( evt.keyCode == 40 ) {//down
canvasOffset.y -= 32;
}
else if ( evt.keyCode == 16 ) {//shift
shiftDown = true;
}
if ( window['currentTest'] && window['currentTest']['onKeyDown'] )
window['currentTest']['onKeyDown'](canvas, evt);
draw();
}
function onKeyUp(canvas, evt) {
if ( evt.keyCode == 16 ) {//shift
shiftDown = false;
}
if ( window['currentTest'] && window['currentTest']['onKeyUp'] )
window['currentTest']['onKeyUp'](canvas, evt);
}
function zoomIn() {
var currentViewCenterWorld = getWorldPointFromPixelPoint( viewCenterPixel );
PTM *= 1.1;
var newViewCenterWorld = getWorldPointFromPixelPoint( viewCenterPixel );
canvasOffset.x += (newViewCenterWorld.x-currentViewCenterWorld.x) * PTM;
canvasOffset.y -= (newViewCenterWorld.y-currentViewCenterWorld.y) * PTM;
draw();
}
function zoomOut() {
var currentViewCenterWorld = getWorldPointFromPixelPoint( viewCenterPixel );
PTM /= 1.1;
var newViewCenterWorld = getWorldPointFromPixelPoint( viewCenterPixel );
canvasOffset.x += (newViewCenterWorld.x-currentViewCenterWorld.x) * PTM;
canvasOffset.y -= (newViewCenterWorld.y-currentViewCenterWorld.y) * PTM;
draw();
}
function updateDebugDrawCheckboxesFromWorld() {
var flags = myDebugDraw.GetFlags();
document.getElementById('drawShapesCheck').checked = (( flags & e_shapeBit ) != 0);
document.getElementById('drawJointsCheck').checked = (( flags & e_jointBit ) != 0);
document.getElementById('drawAABBsCheck').checked = (( flags & e_aabbBit ) != 0);
//document.getElementById('drawPairsCheck').checked = (( flags & e_pairBit ) != 0);
document.getElementById('drawTransformsCheck').checked = (( flags & e_centerOfMassBit ) != 0);
}
function updateWorldFromDebugDrawCheckboxes() {
var flags = 0;
if ( document.getElementById('drawShapesCheck').checked )
flags |= e_shapeBit;
if ( document.getElementById('drawJointsCheck').checked )
flags |= e_jointBit;
if ( document.getElementById('drawAABBsCheck').checked )
flags |= e_aabbBit;
/*if ( document.getElementById('drawPairsCheck').checked )
flags |= e_pairBit;*/
if ( document.getElementById('drawTransformsCheck').checked )
flags |= e_centerOfMassBit;
myDebugDraw.SetFlags( flags );
}
function updateContinuousRefreshStatus() {
showStats = ( document.getElementById('showStatsCheck').checked );
if ( !showStats ) {
var fbSpan = document.getElementById('feedbackSpan');
fbSpan.innerHTML = "";
}
else
updateStats();
}
function init() {
canvas = document.getElementById("canvas");
context = canvas.getContext( '2d' );
canvasOffset.x = canvas.width/2;
canvasOffset.y = canvas.height/2;
canvas.addEventListener('mousemove', function(evt) {
onMouseMove(canvas,evt);
}, false);
canvas.addEventListener('mousedown', function(evt) {
onMouseDown(canvas,evt);
}, false);
canvas.addEventListener('mouseup', function(evt) {
onMouseUp(canvas,evt);
}, false);
canvas.addEventListener('mouseout', function(evt) {
onMouseOut(canvas,evt);
}, false);
canvas.addEventListener('keydown', function(evt) {
onKeyDown(canvas,evt);
}, false);
canvas.addEventListener('keyup', function(evt) {
onKeyUp(canvas,evt);
}, false);
myDebugDraw = new b2DebugDraw();
myDebugDraw.SetSprite(document.getElementById("canvas").getContext("2d"));
myDebugDraw.SetDrawScale(1.0);
myDebugDraw.SetFillAlpha(0.5);
myDebugDraw.SetLineThickness(1.0);
myDebugDraw.SetXFormScale(0.25);
myDebugDraw.SetFlags(b2DebugDraw.e_shapeBit /*| b2DebugDraw.e_jointBit*/);
originTransform = new b2Transform();
var MouseDownQueryCallback = function() {
this.m_fixture = null;
this.m_point = new b2Vec2();
}
MouseDownQueryCallback.prototype.ReportFixture = function(fixture) {
if(fixture.GetBody().GetType() == 2) { //dynamic bodies only
if ( fixture.TestPoint(this.m_point) ) {
this.m_fixture = fixture;
return false;
}
}
return true;
};
mouseDownQueryCallback = new MouseDownQueryCallback();
var VisibleFixturesQueryCallback = function() {
this.m_fixtures = [];
}
VisibleFixturesQueryCallback.prototype.ReportFixture = function(fixture) {
this.m_fixtures.push(fixture);
return true;
};
viewAABB = new b2AABB();
visibleFixturesQueryCallback = new VisibleFixturesQueryCallback();
}
function changeTest() {
resetScene();
if ( window['currentTest'] && window['currentTest']['setNiceViewCenter'] )
window['currentTest']['setNiceViewCenter']();
updateDebugDrawCheckboxesFromWorld();
draw();
}
function createWorld() {
var sceneInfoDiv = document.getElementById('sceneinfo');
var commentsDiv = document.getElementById('testcomments');
sceneInfoDiv.innerHTML = "Loading...";
commentsDiv.innerHTML = "";
if ( world != null )
//Box2D.destroy(world);
world = null;
world = new b2World( new b2Vec2(0.0, -10.0) );
//world = new Box2D.Dynamics.b2World(new Box2D.Common.Math.b2Vec2(0, 9.8) /* gravity */, true /* allowSleep */);
world.SetDebugDraw(myDebugDraw);
mouseJointGroundBody = world.CreateBody( new b2BodyDef() );
var e = document.getElementById("testSelection");
var v = e.options[e.selectedIndex].value;
eval( "window['currentTest']= new "+v+"();" );
window['currentTest']['setup']();
}
function getWorldInfo() {
var numBodies = 0;
var numFixtures = 0;
var numJoints = 0;
for (b = world.m_bodyList; b; b = b.m_next) {
numBodies++;
for (f = b.m_fixtureList; f; f = f.m_next)
numFixtures++;
}
for (j = world.m_jointList; j; j = j.m_next)
numJoints++;
return ""+numBodies+" bodies, "+numFixtures+" fixtures, "+numJoints+" joints";
}
var resettingScene = false;
function resetScene() {
resettingScene = true;
createWorld();
draw();
}
//the RUBE scenes are loaded via jQuery post, so the draw() call above usually
//does not catch them. Call this at the end of the post function.
function doAfterLoading() {
if ( world.images ) {
for (var i = 0; i < world.images.length; i++) {
var imageObj = new Image();
imageObj.src = world.images[i].file;
world.images[i].imageObj = imageObj;
}
}
var sceneInfoDiv = document.getElementById('sceneinfo');
sceneInfoDiv.innerHTML = "Scene info: "+getWorldInfo();;
var comments = "";
if ( window['currentTest']['getComments'] )
comments = window['currentTest']['getComments']();
var commentsDiv = document.getElementById('testcomments');
commentsDiv.innerHTML = "About: "+comments;
resettingScene = false;
draw();
}
function step(timestamp) {
if ( resettingScene )
return;
if ( window['currentTest'] && window['currentTest']['step'] )
window['currentTest']['step']();
if ( ! showStats ) {
world.Step(1/60, 10, 6);
draw();
//logBodyPositions();
return;
}
var current = Date.now();
world.Step(1/60, 10, 6);
var frametime = (Date.now() - current);
frameTime60 = frameTime60 * (59/60) + frametime * (1/60);
draw();
statusUpdateCounter++;
if ( statusUpdateCounter > 20 ) {
updateStats();
statusUpdateCounter = 0;
}
}
function setColorFromBodyType(color, b) {
if (b.IsActive() == false)
color.Set(0.5, 0.5, 0.3);
else if (b.GetType() == b2_staticBody)
color.Set(0.5, 0.9, 0.5);
else if (b.GetType() == b2_kinematicBody)
color.Set(0.5, 0.5, 0.9);
else if (b.IsAwake() == false)
color.Set(0.6, 0.6, 0.6);
else
color.Set(0.9, 0.7, 0.7);
}
//for drawing polygons as one path
function drawLinePolygon(poly, xf) {
var vertexCount = parseInt(poly.GetVertexCount());
var localVertices = poly.GetVertices();
var vertices = new Vector(vertexCount);
for (var i = 0; i < vertexCount; ++i) {
vertices[i] = b2Math.MulX(xf, localVertices[i]);
}
var drawScale = myDebugDraw.m_drawScale;
context.moveTo(vertices[0].x * drawScale, vertices[0].y * drawScale);
for (var i = 1; i < vertexCount; i++) {
context.lineTo(vertices[i].x * drawScale, vertices[i].y * drawScale);
}
context.lineTo(vertices[0].x * drawScale, vertices[0].y * drawScale);
}
function draw() {
//black background
context.fillStyle = 'rgb(0,0,0)';
context.fillRect( 0, 0, canvas.width, canvas.height );
context.save();
context.translate(canvasOffset.x, canvasOffset.y);
context.scale(1,-1);
context.scale(PTM,PTM);
context.lineWidth /= PTM;
//draw images
context.save();
context.scale(1,-1);
if ( world.images ) {
for (var i = 0; i < world.images.length; i++) {
var imageObj = world.images[i].imageObj;
context.save();
if ( world.images[i].body ) {
//body position in world
var bodyPos = world.images[i].body.GetPosition();
context.translate(bodyPos.x, -bodyPos.y);
context.rotate(-world.images[i].body.GetAngle());
//image position in body
var imageLocalCenter = world.images[i].center;
context.translate(imageLocalCenter.x, -imageLocalCenter.y);
context.rotate(-world.images[i].angle);
}
var ratio = 1 / imageObj.height;
ratio *= world.images[i].scale;
context.scale(ratio, ratio);
context.translate(-imageObj.width / 2, -imageObj.height / 2);
context.drawImage(imageObj, 0, 0);
context.restore();
}
}
context.restore();
myDebugDraw.DrawTransform(originTransform);
var flags = myDebugDraw.GetFlags();
myDebugDraw.SetFlags(flags & ~e_shapeBit);
world.DrawDebugData();
myDebugDraw.SetFlags(flags);
if (( flags & e_shapeBit ) != 0) {
//query the world for visible fixtures
var currentViewCenterWorld = getWorldPointFromPixelPoint( viewCenterPixel );
var viewHalfwidth = 0.5 * canvas.width / PTM;
var viewHalfheight = 0.5 * canvas.height / PTM;
viewAABB.lowerBound.Set(currentViewCenterWorld.x - viewHalfwidth, currentViewCenterWorld.y - viewHalfheight);
viewAABB.upperBound.Set(currentViewCenterWorld.x + viewHalfwidth, currentViewCenterWorld.y + viewHalfheight);
visibleFixturesQueryCallback.m_fixtures = [];
world.QueryAABB(visibleFixturesQueryCallback, viewAABB);
var f, b, xf, s;
var color = new b2Color(0, 0, 0);
var circleFixtures = [];
var polygonFixtures = [];
var staticPolygonFixtures = [];
var kinematicPolygonFixtures = [];
var dynamicPolygonFixtures = [];
for (var i = 0; i < visibleFixturesQueryCallback.m_fixtures.length; i++) {
f = visibleFixturesQueryCallback.m_fixtures[i];
s = f.GetShape();
if ( s.GetType() == b2Shape.e_circleShape ) {
circleFixtures.push(f);
}
else if ( s.GetType() == b2Shape.e_polygonShape ) {
polygonFixtures.push(f);
}
}
for (var i = 0; i < circleFixtures.length; i++) {
f = circleFixtures[i];
s = f.GetShape();
b = f.GetBody();
xf = b.GetTransform();
setColorFromBodyType(color, b);
world.DrawShape(s, xf, color);
}
for (var i = 0; i < polygonFixtures.length; i++) {
f = polygonFixtures[i];
b = f.GetBody();
if (b.GetType() == b2_staticBody)
staticPolygonFixtures.push(f);
else if (b.GetType() == b2_kinematicBody)
kinematicPolygonFixtures.push(f);
else
dynamicPolygonFixtures.push(f);
}
context.strokeStyle = "rgb(128,230,128)";
context.beginPath();//draw all static polygons as one path
for (var i = 0; i < staticPolygonFixtures.length; i++) {
f = staticPolygonFixtures[i];
s = f.GetShape();
b = f.GetBody();
xf = b.GetTransform();
//world.DrawShape(s, xf, color);
drawLinePolygon(s, xf);
}
context.closePath();
context.stroke();
context.strokeStyle = "rgb(128,128,230)";
context.beginPath();//draw all kinematic polygons as one path
for (var i = 0; i < kinematicPolygonFixtures.length; i++) {
f = kinematicPolygonFixtures[i];
s = f.GetShape();
b = f.GetBody();
xf = b.GetTransform();
//world.DrawShape(s, xf, color);
drawLinePolygon(s, xf);
}
context.closePath();
context.stroke();
context.strokeStyle = "rgb(230,178,178)";
context.beginPath();//draw all dynamic polygons as one path
for (var i = 0; i < dynamicPolygonFixtures.length; i++) {
f = dynamicPolygonFixtures[i];
s = f.GetShape();
b = f.GetBody();
xf = b.GetTransform();
//world.DrawShape(s, xf, color);
drawLinePolygon(s, xf);
}
context.closePath();
context.stroke();
}
if ( mouseJoint != null ) {
//mouse joint is not drawn with regular joints in debug draw
var p1 = mouseJoint.GetAnchorB();
var p2 = mouseJoint.GetTarget();
context.strokeStyle = 'rgb(204,204,204)';
context.beginPath();
context.moveTo(p1.x,p1.y);
context.lineTo(p2.x,p2.y);
context.stroke();
}
context.restore();
}
function updateStats() {
if ( ! showStats )
return;
var currentViewCenterWorld = getWorldPointFromPixelPoint( viewCenterPixel );
var fbSpan = document.getElementById('feedbackSpan');
fbSpan.innerHTML =
"Status: "+(run?'running':'paused') +
"<br>Physics step time (average of last 60 steps): "+myRound(frameTime60,2)+"ms" +
//"<br>Mouse down: "+mouseDown +
"<br>PTM: "+myRound(PTM,2) +
"<br>View center: "+myRound(currentViewCenterWorld.x,3)+", "+myRound(currentViewCenterWorld.y,3) +
//"<br>Canvas offset: "+myRound(canvasOffset.x,0)+", "+myRound(canvasOffset.y,0) +
"<br>Mouse pos (pixel): "+mousePosPixel.x+", "+mousePosPixel.y +
"<br>Mouse pos (world): "+myRound(mousePosWorld.x,3)+", "+myRound(mousePosWorld.y,3);
}
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
})();
function animate() {
if ( run )
requestAnimFrame( animate );
step();
}
function pause() {
run = !run;
if (run)
animate();
updateStats();
}
//console.log(A.a);
//console.log(Box2D.Dynamics);
//console.log(Box2D.Dynamics.b2BodyDef);
var b2CircleShape = Box2D.Collision.Shapes.b2CircleShape,
b2EdgeChainDef = Box2D.Collision.Shapes.b2EdgeChainDef,
b2EdgeShape = Box2D.Collision.Shapes.b2EdgeShape,
b2MassData = Box2D.Collision.Shapes.b2MassData,
b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape,
b2Shape = Box2D.Collision.Shapes.b2Shape,
b2CircleContact = Box2D.Dynamics.Contacts.b2CircleContact,
b2Contact = Box2D.Dynamics.Contacts.b2Contact,
b2ContactConstraint = Box2D.Dynamics.Contacts.b2ContactConstraint,
b2ContactConstraintPoint = Box2D.Dynamics.Contacts.b2ContactConstraintPoint,
b2ContactEdge = Box2D.Dynamics.Contacts.b2ContactEdge,
b2ContactFactory = Box2D.Dynamics.Contacts.b2ContactFactory,
b2ContactRegister = Box2D.Dynamics.Contacts.b2ContactRegister,
b2ContactResult = Box2D.Dynamics.Contacts.b2ContactResult,
b2ContactSolver = Box2D.Dynamics.Contacts.b2ContactSolver,
b2EdgeAndCircleContact = Box2D.Dynamics.Contacts.b2EdgeAndCircleContact,
b2NullContact = Box2D.Dynamics.Contacts.b2NullContact,
b2PolyAndCircleContact = Box2D.Dynamics.Contacts.b2PolyAndCircleContact,
b2PolyAndEdgeContact = Box2D.Dynamics.Contacts.b2PolyAndEdgeContact,
b2PolygonContact = Box2D.Dynamics.Contacts.b2PolygonContact,
b2PositionSolverManifold = Box2D.Dynamics.Contacts.b2PositionSolverManifold,
b2Body = Box2D.Dynamics.b2Body,
b2_staticBody = Box2D.Dynamics.b2Body.b2_staticBody,
b2_kinematicBody = Box2D.Dynamics.b2Body.b2_kinematicBody,
b2_dynamicBody = Box2D.Dynamics.b2Body.b2_dynamicBody,
b2BodyDef = Box2D.Dynamics.b2BodyDef,
b2ContactFilter = Box2D.Dynamics.b2ContactFilter,
b2ContactImpulse = Box2D.Dynamics.b2ContactImpulse,
b2ContactListener = Box2D.Dynamics.b2ContactListener,
b2ContactManager = Box2D.Dynamics.b2ContactManager,
b2DebugDraw = Box2D.Dynamics.b2DebugDraw,
b2DestructionListener = Box2D.Dynamics.b2DestructionListener,
b2FilterData = Box2D.Dynamics.b2FilterData,
b2Fixture = Box2D.Dynamics.b2Fixture,
b2FixtureDef = Box2D.Dynamics.b2FixtureDef,
b2Island = Box2D.Dynamics.b2Island,
b2TimeStep = Box2D.Dynamics.b2TimeStep,
b2World = Box2D.Dynamics.b2World,
b2Color = Box2D.Common.b2Color,
b2internal = Box2D.Common.b2internal,
b2Settings = Box2D.Common.b2Settings,
b2Mat22 = Box2D.Common.Math.b2Mat22,
b2Mat33 = Box2D.Common.Math.b2Mat33,
b2Math = Box2D.Common.Math.b2Math,
b2Sweep = Box2D.Common.Math.b2Sweep,
b2Transform = Box2D.Common.Math.b2Transform,
b2Vec2 = Box2D.Common.Math.b2Vec2,
b2Vec3 = Box2D.Common.Math.b2Vec3,
b2AABB = Box2D.Collision.b2AABB,
b2Bound = Box2D.Collision.b2Bound,
b2BoundValues = Box2D.Collision.b2BoundValues,
b2Collision = Box2D.Collision.b2Collision,
b2ContactID = Box2D.Collision.b2ContactID,
b2ContactPoint = Box2D.Collision.b2ContactPoint,
b2Distance = Box2D.Collision.b2Distance,
b2DistanceInput = Box2D.Collision.b2DistanceInput,
b2DistanceOutput = Box2D.Collision.b2DistanceOutput,
b2DistanceProxy = Box2D.Collision.b2DistanceProxy,
b2DynamicTree = Box2D.Collision.b2DynamicTree,
b2DynamicTreeBroadPhase = Box2D.Collision.b2DynamicTreeBroadPhase,
b2DynamicTreeNode = Box2D.Collision.b2DynamicTreeNode,
b2DynamicTreePair = Box2D.Collision.b2DynamicTreePair,
b2Manifold = Box2D.Collision.b2Manifold,
b2ManifoldPoint = Box2D.Collision.b2ManifoldPoint,
b2Point = Box2D.Collision.b2Point,
b2RayCastInput = Box2D.Collision.b2RayCastInput,
b2RayCastOutput = Box2D.Collision.b2RayCastOutput,
b2Segment = Box2D.Collision.b2Segment,
b2SeparationFunction = Box2D.Collision.b2SeparationFunction,
b2Simplex = Box2D.Collision.b2Simplex,
b2SimplexCache = Box2D.Collision.b2SimplexCache,
b2SimplexVertex = Box2D.Collision.b2SimplexVertex,
b2TimeOfImpact = Box2D.Collision.b2TimeOfImpact,
b2TOIInput = Box2D.Collision.b2TOIInput,
b2WorldManifold = Box2D.Collision.b2WorldManifold,
ClipVertex = Box2D.Collision.ClipVertex,
Features = Box2D.Collision.Features,
IBroadPhase = Box2D.Collision.IBroadPhase,
b2Joint = Box2D.Dynamics.Joints.b2Joint,
b2JointDef = Box2D.Dynamics.Joints.b2JointDef,
b2JointEdge = Box2D.Dynamics.Joints.b2JointEdge,
b2LineJoint = Box2D.Dynamics.Joints.b2LineJoint,
b2LineJointDef = Box2D.Dynamics.Joints.b2LineJointDef,
b2MouseJoint = Box2D.Dynamics.Joints.b2MouseJoint,
b2MouseJointDef = Box2D.Dynamics.Joints.b2MouseJointDef,
b2PrismaticJoint = Box2D.Dynamics.Joints.b2PrismaticJoint,
b2PrismaticJointDef = Box2D.Dynamics.Joints.b2PrismaticJointDef,
b2PulleyJoint = Box2D.Dynamics.Joints.b2PulleyJoint,
b2PulleyJointDef = Box2D.Dynamics.Joints.b2PulleyJointDef,
b2RevoluteJoint = Box2D.Dynamics.Joints.b2RevoluteJoint,
b2RevoluteJointDef = Box2D.Dynamics.Joints.b2RevoluteJointDef,
b2WeldJoint = Box2D.Dynamics.Joints.b2WeldJoint,
b2WeldJointDef = Box2D.Dynamics.Joints.b2WeldJointDef,
b2DistanceJoint = Box2D.Dynamics.Joints.b2DistanceJoint,
b2DistanceJointDef = Box2D.Dynamics.Joints.b2DistanceJointDef,
b2FrictionJoint = Box2D.Dynamics.Joints.b2FrictionJoint,
b2FrictionJointDef = Box2D.Dynamics.Joints.b2FrictionJointDef;
window['onload'] = function doOnload() {
/*
using(Box2D.Common, "b2.+");
using(Box2D.Common.Math, "b2.+");
using(Box2D.Collision, "b2.+");
using(Box2D.Collision.Shapes, "b2.+");
using(Box2D.Dynamics, "b2.+");
using(Box2D.Dynamics.Joints, "b2.+");
using(Box2D.Dynamics.b2Body, "b2.+");//b2_dynamicBody etc
*/
init();
changeTest();
animate();
}
//these need to be kept global for closure advanced optimization
window['currentTest'] = null;
//window['Box2D'] = Box2D;
/*
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
function ttt(ns, recurse) {
if ( typeof recurse === 'undefined' ) recurse = true;
var parts = ns.split(".");
var base = "window";
for (i=0;i<parts.length;i++)
base += "['"+parts[i]+"']";
//if ( ns.endsWith('prototype') )
// recurse = false;
for (var name in eval(ns)) {
console.log(base+"['"+name+"'] = "+ns+"."+name+";");
//if ( typeof eval(ns+"."+name) == 'function' ) {
if ( recurse )
ttt(ns+"."+name+".prototype", true);
//}
}
}
//ttt('Box2D.Collision');
//ttt('Box2D.Collision.Shapes');
//ttt('Box2D.Common');
//ttt('Box2D.Common.Math');
//ttt('Box2D.Dynamics');
//ttt('Box2D.Dynamics.Contacts');
//ttt('Box2D.Dynamics.Joints');
*/

View file

@ -1 +0,0 @@
../static