From 11c642fd7a277687b80b755fadc22317285ae5c0 Mon Sep 17 00:00:00 2001 From: Jeena Paradies Date: Sun, 22 Jul 2012 02:52:43 +0200 Subject: [PATCH] fixed client physics engine --- app/Game/Client/GameController.js | 2 +- app/Game/Client/Physics/Engine.js | 52 +++++++++++++++++++++++++++++++ app/Game/Core/Physics/Engine.js | 2 +- 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 app/Game/Client/Physics/Engine.js diff --git a/app/Game/Client/GameController.js b/app/Game/Client/GameController.js index b48b883..74234a7 100755 --- a/app/Game/Client/GameController.js +++ b/app/Game/Client/GameController.js @@ -1,6 +1,6 @@ define([ "Game/Core/GameController", - "Game/Core/Physics/Engine", + "Game/Client/Physics/Engine", "Game/Client/View/ViewController", "Game/Client/Control/KeyboardController", "Lib/Utilities/RequestAnimFrame" diff --git a/app/Game/Client/Physics/Engine.js b/app/Game/Client/Physics/Engine.js new file mode 100644 index 0000000..7767e54 --- /dev/null +++ b/app/Game/Client/Physics/Engine.js @@ -0,0 +1,52 @@ +define([ + "Game/Core/Physics/Engine", + "Game/Config/Settings", + "Game/Client/View/DomController", + "Lib/Vendor/Box2D" +], + +function(Parent, Settings, DomController, Box2D) { + + function Engine () { + Parent.call(this); + + if(Settings.DEBUG_MODE) { + this.setupDebugDraw(); + } + } + + Engine.prototype.setupDebugDraw = function() { + //var debugSprite = Settings.DEBUG_DRAW_CANVAS_SPRITE; + var debugSprite = Dom.getDebugCanvas().getContext("2d"); + + // set debug draw + var debugDraw = new Box2D.Dynamics.b2DebugDraw(); + + debugDraw.SetSprite(debugSprite); + debugDraw.SetDrawScale(Settings.RATIO); + debugDraw.SetFillAlpha(0.5); + debugDraw.SetLineThickness(1.0); + + 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(debugDraw); + this.world.SetWarmStarting(true); + } + + + Engine.prototype.update = function() { + Parent.prototype.update.call(this); + + this.world.DrawDebugData(); + } + + return Engine; +}) \ No newline at end of file diff --git a/app/Game/Core/Physics/Engine.js b/app/Game/Core/Physics/Engine.js index f5323eb..85121c3 100755 --- a/app/Game/Core/Physics/Engine.js +++ b/app/Game/Core/Physics/Engine.js @@ -33,4 +33,4 @@ function(Settings, Box2D, CollisionDetector) { } return Engine; -}) \ No newline at end of file +}); \ No newline at end of file