├── .gitattributes
├── .gitignore
├── README.md
├── assets
├── info.ai
├── info.html
├── warning.ai
└── warning.html
├── build
└── js
│ ├── app
│ ├── FpsDisplay.js
│ ├── FpsDisplay.js.map
│ ├── Main.js
│ ├── Main.js.map
│ ├── Ticker.js
│ └── Ticker.js.map
│ ├── demos
│ ├── Basic.js
│ ├── Basic.js.map
│ ├── Constraints.js
│ ├── Constraints.js.map
│ ├── Ragdolls.js
│ ├── Ragdolls.js.map
│ ├── Stress.js
│ ├── Stress.js.map
│ ├── _template.js
│ └── _template.js.map
│ ├── engines
│ ├── Box2dWebDemo.js
│ ├── Box2dWebDemo.js.map
│ ├── DemoEngineBase.js
│ ├── DemoEngineBase.js.map
│ ├── MatterDemo.js
│ ├── MatterDemo.js.map
│ ├── NapeDemo.js
│ ├── NapeDemo.js.map
│ ├── P2JsDemo.js
│ ├── P2JsDemo.js.map
│ ├── PhysicsJsDemo.js
│ └── PhysicsJsDemo.js.map
│ ├── overlay
│ ├── Overlay.js
│ └── Overlay.js.map
│ └── utils
│ ├── Utils.js
│ └── Utils.js.map
├── css
└── main.css
├── index.html
├── lib
├── box2dweb
│ ├── box2dweb.d.ts
│ ├── box2dweb.max.js
│ └── box2dweb.min.js
├── createjs-lib.d.ts
├── dat-gui.d.ts
├── dat.gui.min.js
├── easeljs-0.8.2.combined.js
├── easeljs.d.ts
├── jquery-3.1.1.min.js
├── jquery.d.ts
├── matter-js
│ ├── matter-js.d.ts
│ ├── matter.js
│ └── matter.min.js
├── nape
│ ├── debugDraw
│ │ ├── nape-debug-draw.d.ts
│ │ ├── nape-debug-draw.max.js
│ │ └── nape-debug-draw.min.js
│ ├── nape.d.ts
│ ├── nape.max.js
│ └── nape.min.js
├── p2js
│ ├── p2.d.ts
│ └── p2.js
├── physicsjs
│ ├── physicsjs-full.js
│ ├── physicsjs-full.min.js
│ └── physicsjs.d.ts
├── pixi.js
│ └── pixi.js.d.ts
└── tweenjs.d.ts
└── src
├── app
├── FpsDisplay.ts
├── Main.ts
└── Ticker.ts
├── demos
├── Basic.ts
├── Constraints.ts
├── Ragdolls.ts
├── Stress.ts
└── _template.ts
├── engines
├── Box2dWebDemo.ts
├── DemoEngineBase.ts
├── MatterDemo.ts
├── NapeDemo.ts
├── P2JsDemo.ts
└── PhysicsJsDemo.ts
├── overlay
└── Overlay.ts
└── utils
└── Utils.ts
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # Windows shortcuts
18 | *.lnk
19 |
20 | # =========================
21 | # Operating System Files
22 | # =========================
23 |
24 | # OSX
25 | # =========================
26 |
27 | .DS_Store
28 | .AppleDouble
29 | .LSOverride
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear in the root of a volume
35 | .DocumentRevisions-V100
36 | .fseventsd
37 | .Spotlight-V100
38 | .TemporaryItems
39 | .Trashes
40 | .VolumeIcon.icns
41 |
42 | # Directories potentially created on remote AFP share
43 | .AppleDB
44 | .AppleDesktop
45 | Network Trash Folder
46 | Temporary Items
47 | .apdisk
48 | .idea/*
49 | src/**/*.js.map
50 | src/**/*.js
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Javascript Physics Library Tests
2 |
3 | A small application used to test, compare and benchmark various physics libraries for Javascript.
4 | View it online here: https://cmann1.github.io/Javascript-Physics-Library-Tests/
5 |
6 | So far there are three different demos for each library;
7 | I've tried to keep the demos as similar as possible across engines to allow them to be easily compared.
8 |
9 | ## Demos
10 | - **Basic** - Randomly creates simple bodies.
11 | - **Constraints** - Compares similar constraints available in each engine.
12 | - **Ragdoll** - How well does each engine handle rag dolls?
13 | - **Stress** - Creates a large number of bodies - a good way to measure the performance of each engine.
14 |
15 | A lot of these tests have been adapted from the Nape and Box2DFlash websites.
16 |
17 | ## Libraries
18 | - **Nape** - http://napephys.com/
19 | - Complete with lots of features
20 | - Possibly the best performance and accuracy in stress test
21 | - Very large file size
22 | - Ported from AS3/Haxe
23 | - Lacks an organised Javascript port
24 | - Updated within the last year or two _(as of Nov 2016)_
25 | - **Box2DWeb** - https://github.com/hecht-software/box2dweb
26 | - Complete
27 | - Good performance on the stress test - similar to Nape
28 | - Ported from C++/AS3
29 | - Last updated one or two years ago _(as of Nov 2016)_
30 | - **p2.js** - http://schteppe.github.io/p2.js/
31 | - Complete
32 | - Poor performance on the stress test
33 | - Updated within the last few months _(as of Nov 2016)_
34 | - **Matter.js** - http://brm.io/matter-js/
35 | - Incomplete - lacks support for many constraints
36 | - Poor performance on the stress test
37 | - Updated recently _(as of Nov 2016)_
38 | - **PhysicsJs** http://wellcaffeinated.net/PhysicsJS/
39 | - Incomplete - lacks support for many constraints
40 | - Cannot handle the stress test
41 | - Seems like it was last updated 2 years ago _(as of Nov 2016)_
42 |
--------------------------------------------------------------------------------
/assets/info.ai:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmann1/Javascript-Physics-Library-Tests/a05ba335fba9299941fe3b07671b3352ff7d70da/assets/info.ai
--------------------------------------------------------------------------------
/assets/info.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | info
10 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/assets/warning.ai:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmann1/Javascript-Physics-Library-Tests/a05ba335fba9299941fe3b07671b3352ff7d70da/assets/warning.ai
--------------------------------------------------------------------------------
/assets/warning.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | warning
10 |
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/build/js/app/FpsDisplay.js:
--------------------------------------------------------------------------------
1 | ///
2 | var app;
3 | (function (app) {
4 | var Fps;
5 | (function (Fps) {
6 | var CSS = "\n#fps-display{\n\tleft: 10px; top: 10px;\n\tpadding: 2px 4px;\n\tposition: absolute;\n\tz-index: 100;\n\n\tbackground-color: #999;\n\tborder-radius: 3px;\n\tcolor: #FFF;\n\tcursor: default;\n\tfont: bold 11px/14px 'Helvetica Neue', Helvetica, Arial, sans-serif;\n\ttext-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);\n\tvertical-align: baseline;\n\twhite-space: nowrap;\n\tuser-select: none;\n}";
7 | var Display = (function () {
8 | function Display(fpsCallback) {
9 | var _this = this;
10 | if (fpsCallback === void 0) { fpsCallback = null; }
11 | this.onTimer = function () {
12 | if (_this.fpsCallback) {
13 | _this.$fpsText.text(_this.fpsCallback().toFixed(1));
14 | }
15 | };
16 | this.fpsCallback = fpsCallback;
17 | this.$fps = $('00 fps
');
18 | this.$fpsText = this.$fps.find('.text');
19 | document.body.appendChild(this.$fps[0]);
20 | var head = document.head || document.getElementsByTagName('head')[0];
21 | var style = document.createElement('style');
22 | style.type = 'text/css';
23 | if (style.styleSheet) {
24 | style.styleSheet.cssText = CSS;
25 | }
26 | else {
27 | style.appendChild(document.createTextNode(CSS));
28 | }
29 | head.appendChild(style);
30 | setInterval(this.onTimer, 500);
31 | }
32 | return Display;
33 | }());
34 | Fps.Display = Display;
35 | })(Fps = app.Fps || (app.Fps = {}));
36 | })(app || (app = {}));
37 | //# sourceMappingURL=FpsDisplay.js.map
--------------------------------------------------------------------------------
/build/js/app/FpsDisplay.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"FpsDisplay.js","sourceRoot":"","sources":["../../../src/app/FpsDisplay.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAE5C,IAAU,GAAG,CA6DZ;AA7DD,WAAU,GAAG;IAAC,IAAA,GAAG,CA6DhB;IA7Da,WAAA,GAAG,EACjB,CAAC;QACA,IAAM,GAAG,GAAG,oYAgBX,CAAC;QAEF;YAOC,iBAAY,WAA+B;gBAP5C,iBAwCC;gBAjCY,2BAA+B,GAA/B,kBAA+B;gBAyB3C,YAAO,GAAG;oBAET,EAAE,CAAA,CAAC,KAAI,CAAC,WAAW,CAAC,CACpB,CAAC;wBACA,KAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;oBACnD,CAAC;gBACF,CAAC,CAAA;gBA7BA,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;gBAC/B,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,8DAA8D,CAAC,CAAC;gBAC9E,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACxC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBAExC,IAAI,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBACrE,IAAI,KAAK,GAAO,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;gBAChD,KAAK,CAAC,IAAI,GAAG,UAAU,CAAC;gBAExB,EAAE,CAAA,CAAC,KAAK,CAAC,UAAU,CAAC,CACpB,CAAC;oBACA,KAAK,CAAC,UAAU,CAAC,OAAO,GAAG,GAAG,CAAC;gBAChC,CAAC;gBACD,IAAI,CACJ,CAAC;oBACA,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;gBACjD,CAAC;gBAED,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;gBAExB,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAChC,CAAC;YAUF,cAAC;QAAD,CAAC,AAxCD,IAwCC;QAxCY,WAAO,UAwCnB,CAAA;IACF,CAAC,EA7Da,GAAG,GAAH,OAAG,KAAH,OAAG,QA6DhB;AAAD,CAAC,EA7DS,GAAG,KAAH,GAAG,QA6DZ"}
--------------------------------------------------------------------------------
/build/js/app/Main.js:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 | ///
6 | ///
7 | ///
8 | ///
9 | ///
10 | ///
11 | var app;
12 | (function (app) {
13 | var Ticker = app.ticker.Ticker;
14 | var NapeDemo = engines.NapeDemo;
15 | var P2JsDemo = engines.P2JsDemo;
16 | var MatterDemo = engines.MatterDemo;
17 | var PhysicsJsDemo = engines.PhysicsJsDemo;
18 | var Box2dWebDemo = engines.Box2dWebDemo;
19 | var Main = (function () {
20 | function Main() {
21 | var _this = this;
22 | this.engines = [];
23 | this.engineIndex = -1;
24 | this.currentDemo = 0;
25 | this.mouseX = 0;
26 | this.mouseY = 0;
27 | this.canvasRightMouseDown = false;
28 | this._enableDrawing = true;
29 | this.velocityIterations = 10;
30 | this.positionIterations = 10;
31 | /*
32 | *** Events
33 | */
34 | this.onVelIterationsChange = function (value) {
35 | _this.currentEngine.velocityIterations = _this.velocityIterations = value;
36 | };
37 | this.onPosIterationsChange = function (value) {
38 | _this.currentEngine.positionIterations = _this.positionIterations = value;
39 | };
40 | this.onCanvasMouseDown = function (event) {
41 | _this.currentEngine.handleMouseDown(event);
42 | if (event.button == 2) {
43 | _this.canvasRightMouseDown = true;
44 | }
45 | };
46 | this.onCanvasMouseUp = function (event) {
47 | _this.currentEngine.handleMouseUp(event);
48 | };
49 | this.onWindowBlur = function () {
50 | _this.ticker.stop();
51 | };
52 | this.onWindowFocus = function () {
53 | _this.ticker.start();
54 | };
55 | this.onWindowContextMenu = function (event) {
56 | if (_this.canvasRightMouseDown || event.target == _this.canvas) {
57 | _this.canvasRightMouseDown = false;
58 | event.preventDefault();
59 | return false;
60 | }
61 | };
62 | this.onWindowLoad = function () {
63 | _this.$canvas = $('#renderCanvas');
64 | _this.canvas = _this.$canvas[0];
65 | _this.$canvas.on('mousedown', _this.onCanvasMouseDown);
66 | _this.canvas.width = Main.CANVAS_WIDTH;
67 | _this.canvas.height = Main.CANVAS_HEIGHT;
68 | _this.fpsDisplay = new app.Fps.Display(_this.ticker.getFps);
69 | _this.initGui();
70 | _this.$engineDisplay = $('#engine-display');
71 | _this.$engineText = _this.$engineDisplay.find('.engine');
72 | _this.$demoText = _this.$engineDisplay.find('.demo');
73 | var frameRate = 60;
74 | _this.engines.push(new NapeDemo(_this.canvas, frameRate));
75 | _this.engines.push(new Box2dWebDemo(_this.canvas, frameRate));
76 | _this.engines.push(new P2JsDemo(_this.canvas, frameRate));
77 | _this.engines.push(new MatterDemo(_this.canvas, frameRate));
78 | _this.engines.push(new PhysicsJsDemo(_this.canvas, frameRate));
79 | _this.loadEngine(0);
80 | // this.loadEngine(this.engines.length - 1);
81 | $(window)
82 | .on('focus', _this.onWindowFocus)
83 | .on('blur', _this.onWindowBlur)
84 | .on('mousemove', _this.onWindowMouseMove)
85 | .on('mouseup', _this.onCanvasMouseUp)
86 | .on('contextmenu', _this.onWindowContextMenu)
87 | .focus();
88 | _this.ticker.start();
89 | };
90 | this.onWindowMouseMove = function (event) {
91 | var offset = _this.$canvas.offset();
92 | _this.mouseX = _this.currentEngine.mouseX = event.pageX - offset.left;
93 | _this.mouseY = _this.currentEngine.mouseY = event.pageY - offset.top;
94 | };
95 | window.addEventListener('DOMContentLoaded', this.onWindowLoad);
96 | this.ticker = new Ticker();
97 | }
98 | Main.prototype.initGui = function () {
99 | var buttons = [];
100 | var gui = new dat.GUI();
101 | var prevEngine = gui.add(this, 'prevEngine');
102 | var nextEngine = gui.add(this, 'nextEngine');
103 | var prevDemo = gui.add(this, 'prevDemo');
104 | var nextDemo = gui.add(this, 'nextDemo');
105 | buttons.push(gui.add(this, 'restart'));
106 | gui.add(this, 'enableDrawing');
107 | prevEngine.name('◀ prevEngine');
108 | nextEngine.name('nextEngine ▶');
109 | prevDemo.name('◀ prevDemo');
110 | nextDemo.name('nextDemo ▶');
111 | this.velIterations = gui.add(this, 'velocityIterations', 1, 50);
112 | this.posIterations = gui.add(this, 'positionIterations', 1, 50);
113 | this.velIterations.onFinishChange(this.onVelIterationsChange);
114 | this.posIterations.onFinishChange(this.onPosIterationsChange);
115 | $([
116 | prevEngine.domElement.parentNode.parentNode,
117 | nextEngine.domElement.parentNode.parentNode,
118 | prevDemo.domElement.parentNode.parentNode,
119 | nextDemo.domElement.parentNode.parentNode
120 | ])
121 | .addClass('dgui-two-column-btn dg-button-row');
122 | for (var _i = 0, buttons_1 = buttons; _i < buttons_1.length; _i++) {
123 | var button = buttons_1[_i];
124 | $(button.domElement.parentNode.parentNode).addClass('dg-button-row');
125 | }
126 | };
127 | Main.prototype.loadEngine = function (index) {
128 | if (index < 0)
129 | index = this.engines.length - 1;
130 | else if (index >= this.engines.length)
131 | index = 0;
132 | if (index == this.engineIndex) {
133 | return;
134 | }
135 | if (this.currentEngine) {
136 | this.currentEngine.clear();
137 | this.ticker.tickCallback = null;
138 | }
139 | this.engineIndex = index;
140 | this.currentEngine = this.engines[index];
141 | this.currentEngine.mouseX = this.mouseX;
142 | this.currentEngine.mouseY = this.mouseY;
143 | this.currentEngine.enableDrawing = this.enableDrawing;
144 | this.currentEngine.loadDemo(Main.DEMO_NAMES[this.currentDemo]);
145 | this.ticker.tickCallback = this.currentEngine.run;
146 | this.updateEngineDisplay();
147 | this.updateIterations();
148 | };
149 | Main.prototype.loadDemo = function (index) {
150 | if (index >= Main.DEMO_NAMES.length)
151 | index = 0;
152 | else if (index < 0)
153 | index = Main.DEMO_NAMES.length - 1;
154 | this.currentDemo = index;
155 | this.currentEngine.loadDemo(Main.DEMO_NAMES[this.currentDemo]);
156 | this.updateEngineDisplay();
157 | this.updateIterations();
158 | };
159 | Main.prototype.prevEngine = function () {
160 | this.loadEngine(this.engineIndex - 1);
161 | };
162 | Main.prototype.nextEngine = function () {
163 | this.loadEngine(this.engineIndex + 1);
164 | };
165 | Main.prototype.prevDemo = function () {
166 | this.loadDemo(this.currentDemo - 1);
167 | };
168 | Main.prototype.nextDemo = function () {
169 | this.loadDemo(this.currentDemo + 1);
170 | };
171 | Object.defineProperty(Main.prototype, "enableDrawing", {
172 | get: function () {
173 | return this._enableDrawing;
174 | },
175 | set: function (value) {
176 | this._enableDrawing = value;
177 | this.currentEngine.enableDrawing = value;
178 | },
179 | enumerable: true,
180 | configurable: true
181 | });
182 | Main.prototype.restart = function () {
183 | this.loadDemo(this.currentDemo);
184 | };
185 | Main.prototype.updateEngineDisplay = function () {
186 | var engineName = this.currentEngine.name;
187 | this.$engineText.text(engineName + " (" + (this.engineIndex + 1) + "/" + this.engines.length + ")");
188 | this.$demoText.text(Main.DEMO_NAMES[this.currentDemo] + " (" + (this.currentDemo + 1) + "/" + Main.DEMO_NAMES.length + ")");
189 | // this.$engineDisplay.stop(true).show().css('opacity', 1).delay(2000).animate(
190 | // { opacity: 0},
191 | // { delay: 250, complete: () => {this.$engineDisplay.hide()}});
192 | };
193 | Main.prototype.updateIterations = function () {
194 | this.velocityIterations = this.currentEngine.velocityIterations;
195 | this.positionIterations = this.currentEngine.positionIterations;
196 | this.velIterations.updateDisplay();
197 | this.posIterations.updateDisplay();
198 | };
199 | Main.CANVAS_WIDTH = 800;
200 | Main.CANVAS_HEIGHT = 600;
201 | Main.DEMO_NAMES = [
202 | 'Basic',
203 | 'Constraints',
204 | 'Ragdolls',
205 | 'Stress',
206 | ];
207 | return Main;
208 | }());
209 | app.Main = Main;
210 | //noinspection JSUnusedLocalSymbols
211 | app.main = new Main();
212 | })(app || (app = {}));
213 | //# sourceMappingURL=Main.js.map
--------------------------------------------------------------------------------
/build/js/app/Main.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"Main.js","sourceRoot":"","sources":["../../../src/app/Main.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,6CAA6C;AAC7C,oCAAoC;AACpC,gCAAgC;AAChC,mDAAmD;AACnD,6CAA6C;AAC7C,6CAA6C;AAC7C,+CAA+C;AAC/C,kDAAkD;AAClD,iDAAiD;AAEjD,IAAU,GAAG,CAmSZ;AAnSD,WAAU,GAAG,EACb,CAAC;IAEA,IAAO,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;IAElC,IAAO,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IACnC,IAAO,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IACnC,IAAO,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACvC,IAAO,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAC7C,IAAO,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAI3C;QAqCC;YArCD,iBAiRC;YA9PQ,YAAO,GAAoB,EAAE,CAAC;YAC9B,gBAAW,GAAG,CAAC,CAAC,CAAC;YAEjB,gBAAW,GAAU,CAAC,CAAC;YAIvB,WAAM,GAAU,CAAC,CAAC;YAClB,WAAM,GAAU,CAAC,CAAC;YAClB,yBAAoB,GAAG,KAAK,CAAC;YAE7B,mBAAc,GAAW,IAAI,CAAC;YAC9B,uBAAkB,GAAG,EAAE,CAAC;YACxB,uBAAkB,GAAG,EAAE,CAAC;YAkJhC;;eAEG;YAEK,0BAAqB,GAAG,UAAC,KAAK;gBAErC,KAAI,CAAC,aAAa,CAAC,kBAAkB,GAAG,KAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC;YACzE,CAAC,CAAC;YAEM,0BAAqB,GAAG,UAAC,KAAK;gBAErC,KAAI,CAAC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AC,WAAW,GAAC,CAAC,UAAI,IAAI,CAAC,OAAO,CAAC,MAAM,MAAG,CAAC,CAAC;YACtF,IAAI,CAAC,SAAS,CAAC,IAAI,CAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,WAAK,IAAI,CAAC,WAAW,GAAC,CAAC,UAAI,IAAI,CAAC,UAAU,CAAC,MAAM,MAAG,CAAC,CAAC;YAE9G,+EAA+E;YAC/E,kBAAkB;YAClB,iEAAiE;QAClE,CAAC;QAEO,+BAAgB,GAAxB;YAEC,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC;YAChE,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC;YAChE,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC;YACnC,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC;QACpC,CAAC;QA9KuB,iBAAY,GAAG,GAAG,CAAC;QACnB,kBAAa,GAAG,GAAG,CAAC;QAEpB,eAAU,GAAG;YACpC,OAAO;YACP,aAAa;YACb,UAAU;YACV,QAAQ;SACR,CAAC;QAuQH,WAAC;IAAD,CAAC,AAjRD,IAiRC;IAjRY,QAAI,OAiRhB,CAAA;IAED,mCAAmC;IACxB,QAAI,GAAG,IAAI,IAAI,EAAE,CAAC;AAE9B,CAAC,EAnSS,GAAG,KAAH,GAAG,QAmSZ"}
--------------------------------------------------------------------------------
/build/js/app/Ticker.js:
--------------------------------------------------------------------------------
1 | var app;
2 | (function (app) {
3 | var ticker;
4 | (function (ticker) {
5 | var Ticker = (function () {
6 | function Ticker(runner, targetFps) {
7 | var _this = this;
8 | if (runner === void 0) { runner = null; }
9 | if (targetFps === void 0) { targetFps = 60; }
10 | this.isRunning = false;
11 | this.measuredFps = 0;
12 | this.frameCount = 0;
13 | this.frameCountPrevTime = 0;
14 | this.getFps = function () {
15 | return _this.isRunning
16 | ? (_this.currentTime != _this.frameCountPrevTime ? _this.frameCount / ((_this.currentTime - _this.frameCountPrevTime) / 1000) : _this.measuredFps)
17 | : 0;
18 | };
19 | this.run = function (time) {
20 | if (!_this.isRunning)
21 | return;
22 | requestAnimationFrame(_this.run);
23 | _this.currentTime = time;
24 | var elapsedTime = time - _this.previousTime;
25 | if (elapsedTime > _this.fpsInterval) {
26 | _this.previousTime = time - (elapsedTime % _this.fpsInterval);
27 | _this._tickCallback(elapsedTime * 0.001, time);
28 | // Update/measure the fps every 1 second
29 | _this.frameCount++;
30 | if (time - _this.frameCountPrevTime >= 1000) {
31 | _this.measuredFps = _this.frameCount / ((_this.currentTime - _this.frameCountPrevTime) / 1000);
32 | _this.frameCountPrevTime = time;
33 | _this.frameCount = 0;
34 | }
35 | }
36 | };
37 | this.targetFps = targetFps;
38 | this.tickCallback = runner;
39 | }
40 | Ticker.EMPTY_RUNNER = function (deltatTime) { };
41 | ;
42 | Object.defineProperty(Ticker.prototype, "tickCallback", {
43 | get: function () {
44 | return this._tickCallback;
45 | },
46 | set: function (callback) {
47 | if (!callback)
48 | callback = Ticker.EMPTY_RUNNER;
49 | this._tickCallback = callback;
50 | },
51 | enumerable: true,
52 | configurable: true
53 | });
54 | Object.defineProperty(Ticker.prototype, "targetFps", {
55 | get: function () {
56 | return this._targetFps;
57 | },
58 | set: function (newTargetFps) {
59 | if (isNaN(newTargetFps))
60 | newTargetFps = 60;
61 | else if (newTargetFps < 0)
62 | newTargetFps = 0;
63 | this._targetFps = newTargetFps;
64 | this.fpsInterval = 1000 / newTargetFps;
65 | },
66 | enumerable: true,
67 | configurable: true
68 | });
69 | Ticker.prototype.start = function () {
70 | this.isRunning = true;
71 | this.frameCountPrevTime = 0;
72 | this.frameCount = 0;
73 | this.previousTime = this.frameCountPrevTime = performance.now();
74 | this.run(this.previousTime);
75 | };
76 | Ticker.prototype.stop = function () {
77 | this.isRunning = false;
78 | };
79 | return Ticker;
80 | }());
81 | ticker.Ticker = Ticker;
82 | })(ticker = app.ticker || (app.ticker = {}));
83 | })(app || (app = {}));
84 | //# sourceMappingURL=Ticker.js.map
--------------------------------------------------------------------------------
/build/js/app/Ticker.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"Ticker.js","sourceRoot":"","sources":["../../../src/app/Ticker.ts"],"names":[],"mappings":"AAAA,IAAU,GAAG,CA6GZ;AA7GD,WAAU,GAAG;IAAC,IAAA,MAAM,CA6GnB;IA7Ga,WAAA,MAAM,EACpB,CAAC;QAOA;YAiBC,gBAAY,MAA0B,EAAE,SAAqB;gBAjB9D,iBAmGC;gBAlFY,sBAA0B,GAA1B,aAA0B;gBAAE,yBAAqB,GAArB,cAAqB;gBARnD,cAAS,GAAG,KAAK,CAAC;gBAIlB,gBAAW,GAAG,CAAC,CAAC;gBAChB,eAAU,GAAG,CAAC,CAAC;gBACf,uBAAkB,GAAG,CAAC,CAAC;gBAmCjC,WAAM,GAAG;oBAER,MAAM,CAAC,KAAI,CAAC,SAAS;0BAClB,CAAC,KAAI,CAAC,WAAW,IAAI,KAAI,CAAC,kBAAkB,GAAG,KAAI,CAAC,UAAU,GAAG,CAAC,CAAC,KAAI,CAAC,WAAW,GAAG,KAAI,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAAC,GAAG,KAAI,CAAC,WAAW,CAAC;0BAC1I,CAAC,CAAC;gBACN,CAAC,CAAC;gBAiBM,QAAG,GAAG,UAAC,IAAI;oBAElB,EAAE,CAAA,CAAC,CAAC,KAAI,CAAC,SAAS,CAAC;wBAClB,MAAM,CAAC;oBAER,qBAAqB,CAAC,KAAI,CAAC,GAAG,CAAC,CAAC;oBAEhC,KAAI,CAAC,WAAW,GAAG,IAAI,CAAC;oBACxB,IAAI,WAAW,GAAG,IAAI,GAAG,KAAI,CAAC,YAAY,CAAC;oBAE3C,EAAE,CAAA,CAAC,WAAW,GAAG,KAAI,CAAC,WAAW,CAAC,CAClC,CAAC;wBACA,KAAI,CAAC,YAAY,GAAG,IAAI,GAAG,CAAC,WAAW,GAAG,KA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AI,CAAC,UAAU,GAAG,YAAY,CAAC;oBAC/B,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,YAAY,CAAC;gBACxC,CAAC;;;eAVA;YAmBD,sBAAK,GAAL;gBAEC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;gBAEtB,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC;gBAC5B,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;gBACpB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;gBAChE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAC7B,CAAC;YAED,qBAAI,GAAJ;gBAEC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;YACxB,CAAC;YA6BF,aAAC;QAAD,CAAC,AAnGD,IAmGC;QAnGY,aAAM,SAmGlB,CAAA;IAEF,CAAC,EA7Ga,MAAM,GAAN,UAAM,KAAN,UAAM,QA6GnB;AAAD,CAAC,EA7GS,GAAG,KAAH,GAAG,QA6GZ"}
--------------------------------------------------------------------------------
/build/js/demos/Basic.js:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 | ///
6 | ///
7 | var demos;
8 | (function (demos) {
9 | var DemoEngineBase = engines.DemoEngineBase;
10 | var VertFormat = engines.VertFormat;
11 | var VELOCITY_ITERATIONS = 10;
12 | var POSITION_ITERATIONS = 10;
13 | var napeDemo;
14 | (function (napeDemo) {
15 | var Body = nape.phys.Body;
16 | var Circle = nape.shape.Circle;
17 | var Polygon = nape.shape.Polygon;
18 | engines.NapeDemo.prototype.loadDemoBasic = function () {
19 | this.velocityIterations = VELOCITY_ITERATIONS;
20 | this.positionIterations = POSITION_ITERATIONS;
21 | this.space.gravity.setxy(0, 0);
22 | // Generate some random objects!
23 | for (var i = 0; i < 100; i++) {
24 | var body = new Body();
25 | // Add random one of either a Circle, Box or Pentagon.
26 | if (Math.random() < 0.33) {
27 | body.shapes.add(new Circle(20));
28 | }
29 | else if (Math.random() < 0.5) {
30 | body.shapes.add(new Polygon(Polygon.box(40, 40)));
31 | }
32 | else {
33 | body.shapes.add(new Polygon(Polygon.regular(20, 20, 5)));
34 | }
35 | // Set to random position on stage and add to Space.
36 | body.position.setxy(Math.random() * this.stageWidth, Math.random() * this.stageHeight);
37 | body.space = this.space;
38 | }
39 | };
40 | })(napeDemo || (napeDemo = {}));
41 | var box2dWebDemo;
42 | (function (box2dWebDemo) {
43 | var b2Vec2 = Box2D.Common.Math.b2Vec2;
44 | var b2BodyDef = Box2D.Dynamics.b2BodyDef;
45 | var b2FixtureDef = Box2D.Dynamics.b2FixtureDef;
46 | var b2Body = Box2D.Dynamics.b2Body;
47 | var b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape;
48 | var b2CircleShape = Box2D.Collision.Shapes.b2CircleShape;
49 | engines.Box2dWebDemo.prototype.loadDemoBasic = function () {
50 | var WORLD_SCALE = this.worldScale;
51 | this.velocityIterations = VELOCITY_ITERATIONS;
52 | this.positionIterations = POSITION_ITERATIONS;
53 | this.world.SetGravity(new b2Vec2(0, 0));
54 | var bodyDef = new b2BodyDef();
55 | var fixDef = new b2FixtureDef();
56 | bodyDef.type = b2Body.b2_dynamicBody;
57 | fixDef.density = 1.0;
58 | fixDef.friction = 0.3;
59 | // Generate some random objects!
60 | for (var i = 0; i < 100; i++) {
61 | bodyDef.position.Set(Math.random() * this.stageWidth * WORLD_SCALE, Math.random() * this.stageHeight * WORLD_SCALE);
62 | var body = this.world.CreateBody(bodyDef);
63 | // Add random one of either a Circle, Box or Pentagon.
64 | if (Math.random() < 0.33) {
65 | fixDef.shape = new b2CircleShape(20 * WORLD_SCALE);
66 | }
67 | else if (Math.random() < 0.5) {
68 | fixDef.shape = b2PolygonShape.AsBox(40 * WORLD_SCALE * 0.5, 40 * WORLD_SCALE * 0.5);
69 | }
70 | else {
71 | fixDef.shape = b2PolygonShape.AsVector(DemoEngineBase.Regular(20 * WORLD_SCALE, 20 * WORLD_SCALE, 5, 0, VertFormat.Vector, b2Vec2));
72 | }
73 | body.CreateFixture(fixDef);
74 | }
75 | };
76 | })(box2dWebDemo || (box2dWebDemo = {}));
77 | var p2JsDemo;
78 | (function (p2JsDemo) {
79 | var Body = p2.Body;
80 | var Circle = p2.Circle;
81 | var Box = p2.Box;
82 | var Convex = p2.Convex;
83 | engines.P2JsDemo.prototype.loadDemoBasic = function () {
84 | var WORLD_SCALE = this.worldScale;
85 | this.velocityIterations = VELOCITY_ITERATIONS;
86 | this.positionIterations = POSITION_ITERATIONS;
87 | this.world.gravity = [0, 0];
88 | // Generate some random objects!
89 | for (var i = 0; i < 100; i++) {
90 | var body = new Body({ mass: 1 });
91 | // Add random one of either a Circle, Box or Pentagon.
92 | if (Math.random() < 0.33) {
93 | body.addShape(new Circle({ radius: 20 * WORLD_SCALE }));
94 | }
95 | else if (Math.random() < 0.5) {
96 | body.addShape(new Box({ width: 40 * WORLD_SCALE, height: 40 * WORLD_SCALE }));
97 | }
98 | else {
99 | body.addShape(new Convex({ vertices: DemoEngineBase.Regular(20 * WORLD_SCALE, 20 * WORLD_SCALE, 5) }));
100 | }
101 | // Set to random position on stage and add to Space.
102 | body.position = [Math.random() * this.stageWidth * WORLD_SCALE, Math.random() * this.stageHeight * WORLD_SCALE];
103 | this.world.addBody(body);
104 | }
105 | };
106 | })(p2JsDemo || (p2JsDemo = {}));
107 | var matterDemo;
108 | (function (matterDemo) {
109 | var Bodies = Matter.Bodies;
110 | var World = Matter.World;
111 | engines.MatterDemo.prototype.loadDemoBasic = function () {
112 | this.velocityIterations = VELOCITY_ITERATIONS;
113 | this.positionIterations = POSITION_ITERATIONS;
114 | this.world.gravity.x = 0;
115 | this.world.gravity.y = 0;
116 | // Generate some random objects!
117 | for (var i = 0; i < 100; i++) {
118 | var body;
119 | var x = Math.random() * this.stageWidth, y = Math.random() * this.stageHeight;
120 | // Add random one of either a Circle, Box or Pentagon.
121 | if (Math.random() < 0.33) {
122 | body = Bodies.circle(x, y, 20);
123 | }
124 | else if (Math.random() < 0.5) {
125 | body = Bodies.rectangle(x, y, 40, 40);
126 | }
127 | else {
128 | body = Bodies.polygon(x, y, 5, 20);
129 | }
130 | World.add(this.world, body);
131 | }
132 | };
133 | })(matterDemo || (matterDemo = {}));
134 | var physicsJsDemo;
135 | (function (physicsJsDemo) {
136 | engines.PhysicsJsDemo.prototype.loadDemoBasic = function () {
137 | this.gravity.setAcceleration({ x: 0, y: 0 });
138 | var bodies = this.bodies;
139 | // Generate some random objects!
140 | for (var i = 0; i < 100; i++) {
141 | var body;
142 | var x = Math.random() * this.stageWidth, y = Math.random() * this.stageHeight;
143 | // Add random one of either a Circle, Box or Pentagon.
144 | if (Math.random() < 0.33) {
145 | bodies.push(Physics.body('circle', {
146 | x: x,
147 | y: y,
148 | radius: 20
149 | }));
150 | }
151 | else if (Math.random() < 0.5) {
152 | bodies.push(Physics.body('rectangle', {
153 | x: x,
154 | y: y,
155 | width: 40,
156 | height: 40
157 | }));
158 | }
159 | else {
160 | bodies.push(Physics.body('convex-polygon', {
161 | x: x,
162 | y: y,
163 | vertices: DemoEngineBase.Regular(20, 20, 5, 0, VertFormat.Vector)
164 | }));
165 | }
166 | }
167 | this.world.add(this.bodies);
168 | };
169 | })(physicsJsDemo || (physicsJsDemo = {}));
170 | })(demos || (demos = {}));
171 | //# sourceMappingURL=Basic.js.map
--------------------------------------------------------------------------------
/build/js/demos/Basic.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"Basic.js","sourceRoot":"","sources":["../../../src/demos/Basic.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,6CAA6C;AAC7C,6CAA6C;AAC7C,+CAA+C;AAC/C,kDAAkD;AAClD,iDAAiD;AAEjD,IAAU,KAAK,CAyMd;AAzMD,WAAU,KAAK,EACf,CAAC;IAEA,IAAO,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAC/C,IAAO,UAAU,GAAG,OAAO,CAA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Ragdolls.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"Ragdolls.js","sourceRoot":"","sources":["../../../src/demos/Ragdolls.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,mDAAmD;AACnD,6CAA6C;AAC7C,6CAA6C;AAC7C,+CAA+C;AAC/C,kDAAkD;AAClD,iDAAiD;AAEjD;;;;GAIG;AAEH,IAAU,KAAK,CAsYd;AAtYD,WAAU,KAAK,EACf,CAAC;IAKA,IAAM,mBAAmB,GAAG,EAAE,CAAC;IAC/B,IAAM,mBAAmB,GAAG,EAAE,CAAC;IAE/B;QAEC,IAAM,SAAS,GAAG,GAAG,CAAC;QACtB,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC;IAC/F,CAAC;IAED,IAAM,YAAY,GAAO;QACxB,MAAM,EAAE;YACP,EAAC,EAAE,EAAE,MAAM;gBACV,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;gBACZ,KAAK,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,MAAM,EAAE,IAAI;oBACZ,OAAO,EAAE,GAAG;oBACZ,QAAQ,EAAE,GAAG;oBACb,WAAW,EAAE,GAAG;iBAChB;gBACD,OAAO,EAAE,cAAc;aACvB;YACD,EAAC,EAAE,EAAE,QAAQ;gBACZ,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;gBACZ,KAAK,EAAE;oBACN,IAAI,EAAE,KAAK;oBACX,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE;oBACrB,OAAO,EAAE,GAAG;oBACZ,QAAQ,EAAE,GAAG;oBACb,WAAW,EAAE,GAAG;iBAChB;aACD;YACD,EAAC,EAAE,EAAE,QAAQ;gBACZ,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CA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AgB,GAAG;YAElD,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAC,CAAC,CAAC;YAChD,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,6EAA6E;YAE7G,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,EAAE,IAAI,CAAC,WAAW,GAAG,EAAE,EAAE,kDAAkD,EAAE,EAAC,MAAM,EAAE,QAAQ,EAAC,CAAC,CAAA;QACpI,CAAC,CAAC;IACH,CAAC,EATS,aAAa,KAAb,aAAa,QAStB;AAEF,CAAC,EAtYS,KAAK,KAAL,KAAK,QAsYd"}
--------------------------------------------------------------------------------
/build/js/demos/Stress.js:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 | ///
6 | ///
7 | var demos;
8 | (function (demos) {
9 | var VELOCITY_ITERATIONS = 35;
10 | var POSITION_ITERATIONS = 10;
11 | var napeDemo;
12 | (function (napeDemo) {
13 | var Body = nape.phys.Body;
14 | var Polygon = nape.shape.Polygon;
15 | engines.NapeDemo.prototype.loadDemoStress = function () {
16 | this.velocityIterations = VELOCITY_ITERATIONS;
17 | this.positionIterations = POSITION_ITERATIONS;
18 | this.space.gravity.setxy(0, 600);
19 | var boxWidth = 10;
20 | var boxHeight = 14;
21 | var pyramidHeight = 40; //820 blocks
22 | for (var y = 1; y <= pyramidHeight; y++) {
23 | for (var x = 0; x < y; x++) {
24 | var block = new Body();
25 | // We initialise the blocks to be slightly overlapping so that
26 | // all contact points will be created in very first step before the blocks
27 | // begin to fall.
28 | block.position.x = (this.stageWidth / 2) - boxWidth * ((y - 1) / 2 - x) * 0.99;
29 | block.position.y = this.stageHeight - boxHeight * (pyramidHeight - y + 0.5) * 0.99;
30 | block.shapes.add(new Polygon(Polygon.box(boxWidth, boxHeight)));
31 | block.space = this.space;
32 | }
33 | }
34 | };
35 | })(napeDemo || (napeDemo = {}));
36 | var box2dWebDemo;
37 | (function (box2dWebDemo) {
38 | var b2Body = Box2D.Dynamics.b2Body;
39 | var b2Vec2 = Box2D.Common.Math.b2Vec2;
40 | var b2BodyDef = Box2D.Dynamics.b2BodyDef;
41 | var b2FixtureDef = Box2D.Dynamics.b2FixtureDef;
42 | var b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape;
43 | engines.Box2dWebDemo.prototype.loadDemoStress = function () {
44 | var WORLD_SCALE = this.worldScale;
45 | this.velocityIterations = VELOCITY_ITERATIONS;
46 | this.positionIterations = POSITION_ITERATIONS;
47 | this.world.SetGravity(new b2Vec2(0, 9.82));
48 | var sw = this.stageWidth;
49 | var sh = this.stageHeight;
50 | var boxWidth = 10;
51 | var boxHeight = 14;
52 | var bw = boxWidth * WORLD_SCALE * 0.5;
53 | var bh = boxHeight * WORLD_SCALE * 0.5;
54 | var pyramidHeight = 40; //820 blocks
55 | var bodyDef = new b2BodyDef();
56 | var fixDef = new b2FixtureDef();
57 | bodyDef.type = b2Body.b2_dynamicBody;
58 | fixDef.density = 1.0;
59 | fixDef.friction = 0.9;
60 | for (var y = 1; y <= pyramidHeight; y++) {
61 | for (var x = 0; x < y; x++) {
62 | // We initialise the blocks to be slightly overlapping so that
63 | // all contact points will be created in very first step before the blocks
64 | // begin to fall.
65 | bodyDef.position.Set(((sw / 2) - boxWidth * ((y - 1) / 2 - x) * 0.99) * WORLD_SCALE, (sh - boxHeight * (pyramidHeight - y + 0.5) * 0.99) * WORLD_SCALE);
66 | var body = this.world.CreateBody(bodyDef);
67 | fixDef.shape = b2PolygonShape.AsBox(bw, bh);
68 | body.CreateFixture(fixDef);
69 | }
70 | }
71 | };
72 | })(box2dWebDemo || (box2dWebDemo = {}));
73 | var p2JsDemo;
74 | (function (p2JsDemo) {
75 | var Body = p2.Body;
76 | var Box = p2.Box;
77 | engines.P2JsDemo.prototype.loadDemoStress = function () {
78 | var WORLD_SCALE = this.worldScale;
79 | this.velocityIterations = VELOCITY_ITERATIONS;
80 | this.positionIterations = POSITION_ITERATIONS;
81 | this.world.gravity = [0, 100 * WORLD_SCALE];
82 | var sw = this.stageWidth;
83 | var sh = this.stageHeight;
84 | var boxWidth = 10;
85 | var boxHeight = 14;
86 | var bw = boxWidth * WORLD_SCALE;
87 | var bh = boxHeight * WORLD_SCALE;
88 | var pyramidHeight = 40; //820 blocks
89 | for (var y = 1; y <= pyramidHeight; y++) {
90 | for (var x = 0; x < y; x++) {
91 | var block = new Body({ mass: 1 });
92 | // We initialise the blocks to be slightly overlapping so that
93 | // all contact points will be created in very first step before the blocks
94 | // begin to fall.
95 | block.position[0] = ((sw / 2) - boxWidth * ((y - 1) / 2 - x) * 0.99) * WORLD_SCALE;
96 | block.position[1] = (sh - boxHeight * (pyramidHeight - y + 0.5) * 0.99) * WORLD_SCALE;
97 | block.addShape(new Box({ width: bw, height: bh }));
98 | this.world.addBody(block);
99 | }
100 | }
101 | };
102 | })(p2JsDemo || (p2JsDemo = {}));
103 | var matterDemo;
104 | (function (matterDemo) {
105 | var Bodies = Matter.Bodies;
106 | var World = Matter.World;
107 | engines.MatterDemo.prototype.loadDemoStress = function () {
108 | this.engine.enableSleeping = false;
109 | this.velocityIterations = VELOCITY_ITERATIONS;
110 | this.positionIterations = POSITION_ITERATIONS;
111 | this.world.gravity.x = 0;
112 | this.world.gravity.y = 0.5;
113 | var boxWidth = 10;
114 | var boxHeight = 14;
115 | var pyramidHeight = 40; //820 blocks
116 | for (var y = 1; y <= pyramidHeight; y++) {
117 | for (var x = 0; x < y; x++) {
118 | // We initialise the blocks to be slightly overlapping so that
119 | // all contact points will be created in very first step before the blocks
120 | // begin to fall.
121 | var block = Bodies.rectangle((this.stageWidth / 2) - boxWidth * ((y - 1) / 2 - x) * 0.99, this.stageHeight - boxHeight * (pyramidHeight - y + 0.5) * 0.99, boxWidth, boxHeight);
122 | World.add(this.world, block);
123 | }
124 | }
125 | };
126 | })(matterDemo || (matterDemo = {}));
127 | var physicsJsDemo;
128 | (function (physicsJsDemo) {
129 | engines.PhysicsJsDemo.prototype.loadDemoStress = function () {
130 | this.gravity.setAcceleration({ x: 0, y: 0.0004 });
131 | var bodies = this.bodies;
132 | var boxWidth = 10;
133 | var boxHeight = 14;
134 | var pyramidHeight = 24; // < Cannot handle more
135 | for (var y = 1; y <= pyramidHeight; y++) {
136 | for (var x = 0; x < y; x++) {
137 | // We initialise the blocks to be slightly overlapping so that
138 | // all contact points will be created in very first step before the blocks
139 | // begin to fall.
140 | bodies.push(Physics.body('rectangle', {
141 | x: (this.stageWidth / 2) - boxWidth * ((y - 1) / 2 - x) * 0.99,
142 | y: this.stageHeight - boxHeight * (pyramidHeight - y + 0.5) * 0.99,
143 | width: boxWidth,
144 | height: boxHeight,
145 | restitution: 0.3
146 | }));
147 | }
148 | }
149 | this.world.add(this.bodies);
150 | this.addWarning(this.stageWidth / 2, 20, 'Fewer bodies added due\nto poor performance');
151 | };
152 | })(physicsJsDemo || (physicsJsDemo = {}));
153 | })(demos || (demos = {}));
154 | //# sourceMappingURL=Stress.js.map
--------------------------------------------------------------------------------
/build/js/demos/Stress.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"Stress.js","sourceRoot":"","sources":["../../../src/demos/Stress.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,6CAA6C;AAC7C,6CAA6C;AAC7C,+CAA+C;AAC/C,kDAAkD;AAClD,iDAAiD;AAEjD,IAAU,KAAK,CAwLd;AAxLD,WAAU,KAAK,EACf,CAAC;IAEA,IAAM,mBAAmB,GAAG,EAAE,CAAC;IAC/B,IAAM,mBAAmB,GAAG,EAAE,CAAC;IAE/B,IAAU,QAAQ,CA2BjB;IA3BD,WAAU,QAAQ,EAClB,CAAC;QACA,IAAO,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAC7B,IAAO,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;QAEpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,cAAc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AAC,WAAW,GAAG,SAAS,GAAC,CAAC,aAAa,GAAG,CAAC,GAAG,GAAG,CAAC,GAAC,IAAI;wBAC9D,KAAK,EAAE,QAAQ;wBACf,MAAM,EAAE,SAAS;wBACjB,WAAW,EAAE,GAAG;qBAChB,CAAC,CAAC,CAAC;gBACL,CAAC;YACF,CAAC;YAED,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAE5B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,EAAE,EAAE,EAAE,6CAA6C,CAAC,CAAC;QACzF,CAAC,CAAC;IACH,CAAC,EA9BS,aAAa,KAAb,aAAa,QA8BtB;AAEF,CAAC,EAxLS,KAAK,KAAL,KAAK,QAwLd"}
--------------------------------------------------------------------------------
/build/js/demos/_template.js:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 | ///
6 | ///
7 | var demos;
8 | (function (demos) {
9 | var VELOCITY_ITERATIONS = 10;
10 | var POSITION_ITERATIONS = 10;
11 | var napeDemo;
12 | (function (napeDemo) {
13 | engines.NapeDemo.prototype.loadDemoXX = function () {
14 | };
15 | })(napeDemo || (napeDemo = {}));
16 | var box2dWebDemo;
17 | (function (box2dWebDemo) {
18 | engines.Box2dWebDemo.prototype.loadDemoXX = function () {
19 | };
20 | })(box2dWebDemo || (box2dWebDemo = {}));
21 | var p2JsDemo;
22 | (function (p2JsDemo) {
23 | engines.P2JsDemo.prototype.loadDemoXX = function () {
24 | };
25 | })(p2JsDemo || (p2JsDemo = {}));
26 | var matterDemo;
27 | (function (matterDemo) {
28 | engines.MatterDemo.prototype.loadDemoXX = function () {
29 | };
30 | })(matterDemo || (matterDemo = {}));
31 | var physicsJsDemo;
32 | (function (physicsJsDemo) {
33 | engines.PhysicsJsDemo.prototype.loadDemoXX = function () {
34 | };
35 | })(physicsJsDemo || (physicsJsDemo = {}));
36 | })(demos || (demos = {}));
37 | //# sourceMappingURL=_template.js.map
--------------------------------------------------------------------------------
/build/js/demos/_template.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"_template.js","sourceRoot":"","sources":["../../../src/demos/_template.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,6CAA6C;AAC7C,6CAA6C;AAC7C,+CAA+C;AAC/C,kDAAkD;AAClD,iDAAiD;AAEjD,IAAU,KAAK,CAyDd;AAzDD,WAAU,KAAK,EACf,CAAC;IAKA,IAAM,mBAAmB,GAAG,EAAE,CAAC;IAC/B,IAAM,mBAAmB,GAAG,EAAE,CAAC;IAE/B,IAAU,QAAQ,CAQjB;IARD,WAAU,QAAQ,EAClB,CAAC;QAGA,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,GAAG;QAGxC,CAAC,CAAC;IACH,CAAC,EARS,QAAQ,KAAR,QAAQ,QAQjB;IAED,IAAU,YAAY,CAQrB;IARD,WAAU,YAAY,EACtB,CAAC;QAGA,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,UAAU,GAAG;QAG5C,CAAC,CAAC;IACH,CAAC,EARS,YAAY,KAAZ,YAAY,QAQrB;IAED,IAAU,QAAQ,CAQjB;IARD,WAAU,QAAQ,EAClB,CAAC;QAGA,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,GAAG;QAGxC,CAAC,CAAC;IACH,CAAC,EARS,QAAQ,KAAR,QAAQ,QAQjB;IAED,IAAU,UAAU,CAQnB;IARD,WAAU,UAAU,EACpB,CAAC;QAGA,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,GAAG;QAG1C,CAAC,CAAC;IACH,CAAC,EARS,UAAU,KAAV,UAAU,QAQnB;IAED,IAAU,aAAa,CAMtB;IAND,WAAU,aAAa,EACvB,CAAC;QACA,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,UAAU,GAAG;QAG7C,CAAC,CAAC;IACH,CAAC,EANS,aAAa,KAAb,aAAa,QAMtB;AAEF,CAAC,EAzDS,KAAK,KAAL,KAAK,QAyDd"}
--------------------------------------------------------------------------------
/build/js/engines/DemoEngineBase.js:
--------------------------------------------------------------------------------
1 | ///
2 | var engines;
3 | (function (engines) {
4 | var Overlay = overlay.Overlay;
5 | var OverlayIcons = overlay.OverlayIcons;
6 | (function (VertFormat) {
7 | VertFormat[VertFormat["Array"] = 0] = "Array";
8 | VertFormat[VertFormat["Vector"] = 1] = "Vector";
9 | })(engines.VertFormat || (engines.VertFormat = {}));
10 | var VertFormat = engines.VertFormat;
11 | (function (MouseAction) {
12 | MouseAction[MouseAction["Idle"] = 0] = "Idle";
13 | MouseAction[MouseAction["Handled"] = 1] = "Handled";
14 | })(engines.MouseAction || (engines.MouseAction = {}));
15 | var MouseAction = engines.MouseAction;
16 | var DemoEngineBase = (function () {
17 | function DemoEngineBase(canvas, frameRate) {
18 | var _this = this;
19 | this.name = 'INVALID';
20 | this._velocityIterations = 10;
21 | this._positionIterations = 10;
22 | this.mouseX = 0;
23 | this.mouseY = 0;
24 | /**
25 | * The scale used when rendering to convert from world coordinates to pixels.
26 | * Do not modify directly, instead use setDrawScale()
27 | * @type {number}
28 | */
29 | this.drawScale = 1;
30 | /**
31 | * Used to convert from pixels to world coordinates.
32 | * It's useful when creating demos for multiple engines to specify all units in pixels multiplied by worldScale so that the same values
33 | * can be used for all engines.
34 | * Automatically calculated during setWorldScale(). Equals 1 / drawScale.
35 | * @type {number}
36 | */
37 | this.worldScale = 1;
38 | this._enableDrawing = true;
39 | this.autoClearCanvas = false;
40 | this.mousePressed = false;
41 | /**
42 | * Runs this demo. Demos must not override this method and use runInternal instead.
43 | * @param deltaTime
44 | * @param timestamp
45 | */
46 | this.run = function (deltaTime, timestamp) {
47 | _this.runInternal(deltaTime, timestamp);
48 | if (_this._enableDrawing) {
49 | _this.renderOverlays();
50 | }
51 | };
52 | this.canvas = canvas;
53 | this.context = this.canvas.getContext('2d');
54 | this.stageWidth = canvas.width;
55 | this.stageHeight = canvas.height;
56 | this.frameRate = frameRate;
57 | this.frameRateInterval = 1 / frameRate;
58 | Overlay.bounds.set(0, 0, this.stageWidth, this.stageHeight);
59 | this.setup();
60 | }
61 | /**
62 | * super.clear() is required for all Demos overriding this method
63 | */
64 | DemoEngineBase.prototype.clear = function () {
65 | this.overlays = [];
66 | this.demoMouseDownHook = null;
67 | };
68 | DemoEngineBase.prototype.clearCanvas = function () {
69 | this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
70 | };
71 | DemoEngineBase.prototype.loadDemo = function (name) {
72 | this.clear();
73 | var demoFunc = this['loadDemo' + name];
74 | if (demoFunc) {
75 | demoFunc.call(this);
76 | }
77 | else {
78 | this.addWarning(this.stageWidth / 2, 20, "Cannot find \"" + name + "\" demo for \"" + this.name + "\" engine");
79 | }
80 | };
81 | DemoEngineBase.prototype.renderOverlays = function () {
82 | var context = this.context;
83 | for (var _i = 0, _a = this.overlays; _i < _a.length; _i++) {
84 | var overlay_1 = _a[_i];
85 | overlay_1.render(context);
86 | }
87 | };
88 | DemoEngineBase.prototype.setDrawScale = function (newScale) {
89 | this.drawScale = newScale;
90 | this.worldScale = 1 / newScale;
91 | };
92 | Object.defineProperty(DemoEngineBase.prototype, "enableDrawing", {
93 | /*
94 | *** Getters, Setters
95 | */
96 | get: function () {
97 | return this._enableDrawing;
98 | },
99 | set: function (value) {
100 | this._enableDrawing = value;
101 | if (!value) {
102 | if (this.autoClearCanvas) {
103 | this.clearCanvas();
104 | }
105 | this.onDisableDrawing();
106 | }
107 | },
108 | enumerable: true,
109 | configurable: true
110 | });
111 | Object.defineProperty(DemoEngineBase.prototype, "positionIterations", {
112 | get: function () {
113 | return this._positionIterations;
114 | },
115 | set: function (value) {
116 | if (this._positionIterations == value)
117 | return;
118 | this._positionIterations = value;
119 | this.onPositionIterationsUpdate(value);
120 | },
121 | enumerable: true,
122 | configurable: true
123 | });
124 | Object.defineProperty(DemoEngineBase.prototype, "velocityIterations", {
125 | get: function () {
126 | return this._velocityIterations;
127 | },
128 | set: function (value) {
129 | if (this._velocityIterations == value)
130 | return;
131 | this._velocityIterations = value;
132 | this.onVelocityIterationsUpdate(value);
133 | },
134 | enumerable: true,
135 | configurable: true
136 | });
137 | /*
138 | *** Utility Methods
139 | */
140 | DemoEngineBase.prototype.addOverlay = function (x, y, message, icon, options) {
141 | if (icon === void 0) { icon = null; }
142 | this.overlays.push(new Overlay(x, y, message, icon, options));
143 | return this.overlays[this.overlays.length - 1];
144 | };
145 | DemoEngineBase.prototype.addWarning = function (x, y, message, options) {
146 | this.overlays.push(new Overlay(x, y, message, OverlayIcons.Warning, options));
147 | return this.overlays[this.overlays.length - 1];
148 | };
149 | DemoEngineBase.prototype.addInfo = function (x, y, message, options) {
150 | this.overlays.push(new Overlay(x, y, message, OverlayIcons.Info, options));
151 | return this.overlays[this.overlays.length - 1];
152 | };
153 | DemoEngineBase.Box = function (x, y, w, h, format, VertexClass) {
154 | if (format === void 0) { format = VertFormat.Array; }
155 | if (VertexClass === void 0) { VertexClass = null; }
156 | var vertices = [];
157 | var useArray = format == VertFormat.Array;
158 | var hw = w / 2;
159 | var hh = h / 2;
160 | var boxVertices = [
161 | x + hw, y + hh,
162 | x - hw, y + hh,
163 | x - hw, y - hh,
164 | x + hw, y - hh
165 | ];
166 | for (var a = 0; a < 8; a += 2) {
167 | var x_1 = boxVertices[a];
168 | var y_1 = boxVertices[a + 1];
169 | if (VertexClass)
170 | vertices.push(new VertexClass(x_1, y_1));
171 | else
172 | vertices.push(useArray ? [x_1, y_1] : { x: x_1, y: y_1 });
173 | }
174 | return vertices;
175 | };
176 | DemoEngineBase.Regular = function (xRadius, yRadius, edgeCount, angleOffset, format, VertexClass) {
177 | if (angleOffset === void 0) { angleOffset = 0; }
178 | if (format === void 0) { format = VertFormat.Array; }
179 | if (VertexClass === void 0) { VertexClass = null; }
180 | var vertices = [];
181 | var useArray = format == VertFormat.Array;
182 | for (var a = 0; a < edgeCount; a++) {
183 | var x = xRadius * Math.cos(angleOffset + 2 * Math.PI * (a / edgeCount));
184 | var y = yRadius * Math.sin(angleOffset + 2 * Math.PI * (a / edgeCount));
185 | if (VertexClass)
186 | vertices.push(new VertexClass(x, y));
187 | else
188 | vertices.push(useArray ? [x, y] : { x: x, y: y });
189 | }
190 | return vertices;
191 | };
192 | DemoEngineBase.drawCircle = function (context, x, y, radius) {
193 | context.moveTo(x, y);
194 | context.arc(x, y, radius, 0, 2 * Math.PI, false);
195 | };
196 | /*
197 | *** Events
198 | */
199 | DemoEngineBase.prototype.onDisableDrawing = function () { };
200 | DemoEngineBase.prototype.onPositionIterationsUpdate = function (iterations) { };
201 | DemoEngineBase.prototype.onVelocityIterationsUpdate = function (iterations) { };
202 | DemoEngineBase.prototype.handleMouseDown = function (event) {
203 | this.mousePressed = true;
204 | this.onMouseDown();
205 | if (this.demoMouseDownHook && this.mouseAction == MouseAction.Idle)
206 | this.demoMouseDownHook();
207 | };
208 | DemoEngineBase.prototype.handleMouseUp = function (event) {
209 | this.mousePressed = false;
210 | this.onMouseUp();
211 | if (this.demoMouseUpHook && this.mouseAction == MouseAction.Idle)
212 | this.demoMouseUpHook();
213 | this.mouseAction = MouseAction.Idle;
214 | };
215 | DemoEngineBase.prototype.onMouseDown = function () { };
216 | DemoEngineBase.prototype.onMouseUp = function () { };
217 | return DemoEngineBase;
218 | }());
219 | engines.DemoEngineBase = DemoEngineBase;
220 | })(engines || (engines = {}));
221 | //# sourceMappingURL=DemoEngineBase.js.map
--------------------------------------------------------------------------------
/build/js/engines/DemoEngineBase.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"DemoEngineBase.js","sourceRoot":"","sources":["../../../src/engines/DemoEngineBase.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAE5C,IAAU,OAAO,CA0UhB;AA1UD,WAAU,OAAO,EACjB,CAAC;IAEA,IAAO,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,IAAO,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAI3C,WAAY,UAAU;QAErB,6CAAK,CAAA;QAC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AAW,CAAC,IAAI,CAAC;gBACjE,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC3B,CAAC;QACD,sCAAa,GAAb,UAAc,KAAM;YAEnB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;YAC1B,IAAI,CAAC,SAAS,EAAE,CAAC;YAEjB,EAAE,CAAA,CAAC,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,IAAI,CAAC;gBAC/D,IAAI,CAAC,eAAe,EAAE,CAAC;YAExB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC,IAAI,CAAC;QACrC,CAAC;QAES,oCAAW,GAArB,cAA0B,CAAC;QACjB,kCAAS,GAAnB,cAAwB,CAAC;QAE1B,qBAAC;IAAD,CAAC,AA/SD,IA+SC;IA/SqB,sBAAc,iBA+SnC,CAAA;AAEF,CAAC,EA1US,OAAO,KAAP,OAAO,QA0UhB"}
--------------------------------------------------------------------------------
/build/js/engines/MatterDemo.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"MatterDemo.js","sourceRoot":"","sources":["../../../src/engines/MatterDemo.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,yDAAyD;;;;;;AAEzD,IAAU,OAAO,CA2ThB;AA3TD,WAAU,OAAO,EACjB,CAAC;IAEA,IAAO,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,IAAO,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,IAAO,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IAC5B,IAAO,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,IAAO,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IAC1B,IAAO,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;IAChD,IAAO,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IAMtC,IAAO,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,IAAO,KAAK,GAAG,MAAM,CAA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C,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YACzC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;YAC5B,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;YAE5B,MAAM,CAAC,GAAG,CAAC;QACZ,CAAC;QAED;;WAEG;QAEO,+CAA0B,GAApC,UAAqC,UAAiB;YAErD,IAAI,CAAC,MAAM,CAAC,kBAAkB,GAAG,UAAU,CAAC;QAC7C,CAAC;QAES,+CAA0B,GAApC,UAAqC,UAAiB;YAErD,IAAI,CAAC,MAAM,CAAC,kBAAkB,GAAG,UAAU,CAAC;QAC7C,CAAC;QAEF,iBAAC;IAAD,CAAC,AAtSD,CAAgC,sBAAc,GAsS7C;IAtSY,kBAAU,aAsStB,CAAA;AAEF,CAAC,EA3TS,OAAO,KAAP,OAAO,QA2ThB"}
--------------------------------------------------------------------------------
/build/js/engines/NapeDemo.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"NapeDemo.js","sourceRoot":"","sources":["../../../src/engines/NapeDemo.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,6CAA6C;AAC7C,+CAA+C;AAC/C,oEAAoE;;;;;;AAEpE,IAAU,OAAO,CA4ThB;AA5TD,WAAU,OAAO,EACjB,CAAC;IACA,IAAO,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IAC7B,IAAO,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;IAChC,IAAO,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC9B,IAAO,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;IACzC,IAAO,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IAC7B,IAAO,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ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AE,CAAC;QACtB,CAAC;;QAED,4BAAS,GAAT;YAEC,gDAAgD;YAChD,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,KAAK,CAAC;QAC/B,CAAC;;QAEF,eAAC;IAAD,CAAC,AAnSD,CAA8B,sBAAc,GAmS3C;IAnSY,gBAAQ,WAmSpB,CAAA;AACF,CAAC,EA5TS,OAAO,KAAP,OAAO,QA4ThB"}
--------------------------------------------------------------------------------
/build/js/engines/PhysicsJsDemo.js:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | var __extends = (this && this.__extends) || function (d, b) {
4 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
5 | function __() { this.constructor = d; }
6 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
7 | };
8 | var engines;
9 | (function (engines) {
10 | var PhysicsJsDemo = (function (_super) {
11 | __extends(PhysicsJsDemo, _super);
12 | function PhysicsJsDemo() {
13 | _super.apply(this, arguments);
14 | this.name = 'PhysicsJs';
15 | }
16 | PhysicsJsDemo.prototype.setup = function () {
17 | var _this = this;
18 | _super.prototype.clear.call(this);
19 | this.autoClearCanvas = true;
20 | this.bodies = [];
21 | Physics({
22 | timestep: this.frameRateInterval * 1000
23 | }, function (world) {
24 | _this.world = world;
25 | _this.renderer = Physics.renderer('canvas', {
26 | el: 'renderCanvas',
27 | autoResize: false,
28 | width: _this.canvas.width,
29 | height: _this.canvas.height
30 | });
31 | _this.gravity = Physics.behavior('constant-acceleration');
32 | world.add([
33 | _this.renderer,
34 | _this.gravity,
35 | Physics.behavior('body-impulse-response'),
36 | Physics.behavior('body-collision-detection'),
37 | Physics.behavior('sweep-prune'),
38 | Physics.behavior('interactive', { el: _this.canvas }),
39 | Physics.behavior('edge-collision-detection', {
40 | aabb: Physics.aabb(0, 0, _this.stageWidth, _this.stageHeight),
41 | restitution: 0.05
42 | }),
43 | _this.constraints = Physics.behavior('verlet-constraints', {
44 | iterations: 3
45 | })
46 | ]);
47 | world.on('interact:grab', _this.onBodyGrab.bind(_this));
48 | });
49 | };
50 | PhysicsJsDemo.prototype.clear = function () {
51 | _super.prototype.clear.call(this);
52 | this.clearCanvas();
53 | if (this.bodies.length) {
54 | this.world.remove(this.bodies);
55 | this.bodies = [];
56 | }
57 | this.constraints.drop();
58 | };
59 | PhysicsJsDemo.prototype.loadDemo = function (name) {
60 | _super.prototype.loadDemo.call(this, name);
61 | };
62 | PhysicsJsDemo.prototype.runInternal = function (deltaTime, timestamp) {
63 | this.world.step(timestamp);
64 | if (this._enableDrawing) {
65 | this.world.render();
66 | }
67 | };
68 | ;
69 | /*
70 | *** Utility Methods
71 | */
72 | PhysicsJsDemo.prototype.pinBody = function (body, pinned) {
73 | return body;
74 | };
75 | PhysicsJsDemo.prototype.createBody = function (x, y, shape, pinned) {
76 | throw new Error('PhysicsJs does not have the concept of shapes. createBody method not supported.');
77 | };
78 | PhysicsJsDemo.prototype.createBox = function (x, y, width, height, pinned) {
79 | var body = this.pinBody(Physics.body('rectangle', {
80 | x: x,
81 | y: y,
82 | width: width * 2,
83 | height: height * 2,
84 | restitution: 0.3
85 | }), pinned);
86 | this.bodies.push(body);
87 | return body;
88 | };
89 | PhysicsJsDemo.prototype.createCircle = function (x, y, radius, pinned) {
90 | var body = this.pinBody(Physics.body('circle', {
91 | x: x,
92 | y: y,
93 | radius: radius,
94 | restitution: 0.3
95 | }), pinned);
96 | this.bodies.push(body);
97 | return body;
98 | };
99 | PhysicsJsDemo.prototype.createFromData = function (x, y, data) {
100 | var WORLD_SCALE = this.worldScale;
101 | var DEG2RAD = 1 / (180 / Math.PI);
102 | var bodiesData = data.bodies;
103 | var jointsData = data.joints;
104 | var bodyRegistry = {};
105 | var bodies = [];
106 | x *= WORLD_SCALE;
107 | y *= WORLD_SCALE;
108 | if (bodiesData)
109 | for (var _i = 0, bodiesData_1 = bodiesData; _i < bodiesData_1.length; _i++) {
110 | var bodyData = bodiesData_1[_i];
111 | if (!bodyData.shape) {
112 | continue;
113 | }
114 | var bodyType = void 0;
115 | var options = {
116 | x: x + bodyData.x * WORLD_SCALE,
117 | y: y + bodyData.y * WORLD_SCALE
118 | };
119 | if (bodyData.type === undefined || bodyData.type === 'dynamic')
120 | options.treatment = 'dynamic';
121 | else if (bodyData.type === 'static')
122 | options.treatment = 'static';
123 | else if (bodyData.type === 'kinematic')
124 | options.treatment = 'kinematic';
125 | var shapeData = bodyData.shape;
126 | var shapeType = shapeData.type;
127 | if (shapeType === 'box') {
128 | bodyType = 'rectangle';
129 | options.width = shapeData.width * WORLD_SCALE;
130 | options.height = shapeData.height * WORLD_SCALE;
131 | }
132 | else if (shapeType === 'circle') {
133 | bodyType = 'circle';
134 | options.radius = shapeData.radius * WORLD_SCALE;
135 | }
136 | else
137 | console.error("Unsupported shape type \"" + shapeType + "\"");
138 | // if(shapeData.density !== undefined)
139 | // options.density = shapeData.density;
140 | if (shapeData.friction !== undefined)
141 | options.cof = shapeData.friction;
142 | if (shapeData.restitution !== undefined)
143 | options.restitution = shapeData.restitution;
144 | var body = Physics.body(bodyType, options);
145 | this.bodies.push(body);
146 | bodies.push(body);
147 | if (bodyData.id !== undefined) {
148 | bodyRegistry[bodyData.id] = body;
149 | }
150 | if (bodyData.impulse) {
151 | var impulse = void 0;
152 | if (bodyData.impulse.hasOwnProperty('x') && bodyData.impulse.hasOwnProperty('y')) {
153 | impulse = bodyData.impulse;
154 | }
155 | else if (bodyData.impulse instanceof Array) {
156 | impulse = { x: bodyData.impulse[0], y: bodyData.impulse[1] };
157 | }
158 | else if (bodyData.impulse instanceof Function) {
159 | var impulseData = bodyData.impulse();
160 | impulse = { x: impulseData[0], y: impulseData[1] };
161 | }
162 | if (impulse)
163 | body.applyForce({ x: impulse.x / 10000 * WORLD_SCALE, y: impulse.y / 10000 * WORLD_SCALE });
164 | }
165 | }
166 | this.world.add(bodies);
167 | if (jointsData)
168 | for (var _a = 0, jointsData_1 = jointsData; _a < jointsData_1.length; _a++) {
169 | var jointData = jointsData_1[_a];
170 | var type = jointData.type;
171 | var body1 = bodyRegistry[jointData.body1];
172 | var body2 = bodyRegistry[jointData.body2];
173 | if (!body1 || !body2) {
174 | console.error("Cannot find body with id \"" + (!body1 ? jointData.body1 : jointData.body2) + "\"");
175 | continue;
176 | }
177 | if (type == 'revolute') {
178 | this.constraints.distanceConstraint(body1, body2);
179 | }
180 | else {
181 | console.error("Unsupported joint type \"" + type + "\"");
182 | }
183 | }
184 | };
185 | /*
186 | *** Events
187 | */
188 | PhysicsJsDemo.prototype.onBodyGrab = function (data) {
189 | this.mouseAction = engines.MouseAction.Handled;
190 | };
191 | return PhysicsJsDemo;
192 | }(engines.DemoEngineBase));
193 | engines.PhysicsJsDemo = PhysicsJsDemo;
194 | })(engines || (engines = {}));
195 | //# sourceMappingURL=PhysicsJsDemo.js.map
--------------------------------------------------------------------------------
/build/js/engines/PhysicsJsDemo.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"PhysicsJsDemo.js","sourceRoot":"","sources":["../../../src/engines/PhysicsJsDemo.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,yDAAyD;;;;;;AAEzD,IAAU,OAAO,CA0PhB;AA1PD,WAAU,OAAO,EACjB,CAAC;IAEA;QAAmC,iCAAc;QAAjD;YAAmC,8BAAc;YAGzC,SAAI,GAAU,WAAW,CAAC;QAkPlC,CAAC;QA1OA,6BAAK,GAAL;YAAA,iBAyCC;YAvCA,gBAAK,CAAC,KAAK,WAAE,CAAC;YAEd,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;YAC5B,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;YAEjB,OAAO,CACN;gBACC,QAAQ,EAAE,IAAI,CAAC,iBAAiB,GAAG,IAAI;aACvC,EACD,UAAC,KAAkB;gBAElB,KAAI,CAAC,KAAK,GAAG,KAAK,CAAC;gBACnB,KAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE;oBAC1C,EAAE,EAAE,cAAc;oBAClB,UAAU,EA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------------------------------------------
/build/js/utils/Utils.js:
--------------------------------------------------------------------------------
1 | var utils;
2 | (function (utils) {
3 | function applyDefaults(input, defaults) {
4 | for (var attr in defaults) {
5 | if (defaults.hasOwnProperty(attr) && !input.hasOwnProperty(attr))
6 | input[attr] = defaults[attr];
7 | }
8 | return input;
9 | }
10 | utils.applyDefaults = applyDefaults;
11 | })(utils || (utils = {}));
12 | //# sourceMappingURL=Utils.js.map
--------------------------------------------------------------------------------
/build/js/utils/Utils.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/utils/Utils.ts"],"names":[],"mappings":"AAAA,IAAU,KAAK,CAcd;AAdD,WAAU,KAAK,EACf,CAAC;IAEA,uBAAiC,KAAO,EAAE,QAAU;QAEnD,GAAG,CAAA,CAAC,IAAI,IAAI,IAAI,QAAQ,CAAC,CACzB,CAAC;YACA,EAAE,CAAA,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;gBAC/D,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QAED,MAAM,CAAC,KAAK,CAAC;IACd,CAAC;IATe,mBAAa,gBAS5B,CAAA;AAEF,CAAC,EAdS,KAAK,KAAL,KAAK,QAcd"}
--------------------------------------------------------------------------------
/css/main.css:
--------------------------------------------------------------------------------
1 | html, body{
2 | background: #272727;
3 | overflow: hidden;
4 | width: 100%;
5 | height: 100%;
6 | margin: 0;
7 | padding: 0;
8 | }
9 |
10 | #canvas-wrap{
11 | position: absolute;
12 | left: 0;
13 | top: 0;
14 | bottom: 0;
15 | right: 0;
16 |
17 | display: flex;
18 | justify-content: center;
19 | align-items: center;
20 | }
21 | #renderCanvas{
22 | border: 1px solid #191919;
23 | display: block;
24 | position: relative !important;
25 |
26 | touch-action: none;
27 | }
28 |
29 | div.dg.ac{
30 | z-index: 100 !important;
31 | }
32 | .dg li.dgui-two-column-btn{
33 | width: 50%;
34 | box-sizing: border-box;
35 | float: left;
36 | clear: none;
37 | }
38 | .dg li.dgui-two-column-btn span.property-name{
39 | width: auto;
40 | }
41 | .dg li.cr.dg-button-row.dgui-two-column-btn:nth-child(even) div{
42 | border-left: none;
43 | }
44 |
45 | #engine-display{
46 | /*position: absolute;*/
47 | /*left: 50%;*/
48 | /*top: 10px;*/
49 | /*text-shadow: 1px 1px 0px #000;*/
50 | /*color: #FFF;*/
51 | /*font-size: 30px;*/
52 |
53 | position: absolute;
54 | left: 10px;
55 | top: 35px;
56 | text-shadow: 1px 1px 0 #000;
57 | color: #FFF;
58 | font-size: 20px;
59 | z-index: 100;
60 | }
61 | #engine-display .inner{
62 | /*margin-left: -50%;*/
63 | }
64 | #engine-display .engine{
65 |
66 | }
67 | #engine-display .demo{
68 |
69 | }
70 |
71 | .dg li.cr.dg-button-row {
72 | border: none;
73 | padding: 0;
74 | user-select: none;
75 | }
76 | .dg li.cr.dg-button-row > div span.property-name{
77 | width: auto;
78 | float: none;
79 | display: block;
80 | text-transform: capitalize;
81 | text-align: center;
82 | }
83 | .dg li.cr.dg-button-row > div {
84 | -moz-box-shadow:inset 0px 1px 0px 0px #5e5e5e;
85 | -webkit-box-shadow:inset 0px 1px 0px 0px #5e5e5e;
86 | box-shadow:inset 0px 1px 0px 0px #5e5e5e;
87 | background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #303030), color-stop(1, #1a1a1a));
88 | background:-moz-linear-gradient(top, #303030 5%, #1a1a1a 100%);
89 | background:-webkit-linear-gradient(top, #303030 5%, #1a1a1a 100%);
90 | background:-o-linear-gradient(top, #303030 5%, #1a1a1a 100%);
91 | background:-ms-linear-gradient(top, #303030 5%, #1a1a1a 100%);
92 | background:linear-gradient(to bottom, #303030 5%, #1a1a1a 100%);
93 | filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#303030', endColorstr='#1a1a1a',GradientType=0);
94 | background-color:#303030;
95 | border:1px solid #000000;
96 |
97 | /*display:inline-block;*/
98 | cursor:pointer;
99 | color:#ffffff;
100 | font-family: Arial, serif;
101 | /*font-size:13px;*/
102 | /*font-weight:bold;*/
103 | padding:0 12px;
104 | /*padding:6px 12px;*/
105 | text-decoration:none;
106 |
107 | box-sizing: border-box;
108 | height: 27px;
109 | }
110 | .dg li.cr.dg-button-row > div:hover {
111 | background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #1a1a1a), color-stop(1, #303030));
112 | background:-moz-linear-gradient(top, #1a1a1a 5%, #303030 100%);
113 | background:-webkit-linear-gradient(top, #1a1a1a 5%, #303030 100%);
114 | background:-o-linear-gradient(top, #1a1a1a 5%, #303030 100%);
115 | background:-ms-linear-gradient(top, #1a1a1a 5%, #303030 100%);
116 | background:linear-gradient(to bottom, #1a1a1a 5%, #303030 100%);
117 | filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#1a1a1a', endColorstr='#303030',GradientType=0);
118 | background-color:#1a1a1a;
119 | }
120 | .dg li.cr.dg-button-row > div:active {
121 | position:relative;
122 | top:1px;
123 | }
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Javascript Physics Libraries
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | Engine: Nape
57 |
58 |
59 | Demo: Basic
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/lib/createjs-lib.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for CreateJS
2 | // Project: http://www.createjs.com/
3 | // Definitions by: Pedro Ferreira , Chris Smith , Satoru Kimura
4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5 |
6 | /*
7 | Copyright (c) 2012 Pedro Ferreira
8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 | */
12 | // Common class and methods for CreateJS.
13 | // Library documentation : http://www.createjs.com/Docs/EaselJS/modules/EaselJS.html
14 | // Library documentation : http://www.createjs.com/Docs/PreloadJS/modules/PreloadJS.html
15 | // Library documentation : http://www.createjs.com/Docs/SoundJS/modules/SoundJS.html
16 | // Library documentation : http://www.createjs.com/Docs/TweenJS/modules/TweenJS.html
17 |
18 |
19 | declare namespace createjs {
20 | export class Event {
21 | constructor(type: string, bubbles: boolean, cancelable: boolean);
22 |
23 | // properties
24 | bubbles: boolean;
25 | cancelable: boolean;
26 | currentTarget: any; // It is 'Object' type officially, but 'any' is easier to use.
27 | defaultPrevented: boolean;
28 | eventPhase: number;
29 | immediatePropagationStopped: boolean;
30 | propagationStopped: boolean;
31 | removed: boolean;
32 | target: any; // It is 'Object' type officially, but 'any' is easier to use.
33 | timeStamp: number;
34 | type: string;
35 |
36 | // other event payloads
37 | data: any;
38 | delta: number;
39 | error: string;
40 | id: string;
41 | item: any;
42 | loaded: number;
43 | name: string;
44 | next: string;
45 | params: any;
46 | paused: boolean;
47 | progress: number;
48 | rawResult: any;
49 | result: any;
50 | runTime: number;
51 | src: string;
52 | time: number;
53 | total: number;
54 |
55 | // methods
56 | clone(): Event;
57 | preventDefault(): void;
58 | remove(): void;
59 | set(props: Object): Event;
60 | stopImmediatePropagation(): void;
61 | stopPropagation(): void;
62 | toString(): string;
63 | }
64 |
65 | export class EventDispatcher {
66 | constructor();
67 |
68 | // methods
69 | addEventListener(type: string, listener: (eventObj: Object) => boolean, useCapture?: boolean): Function;
70 | addEventListener(type: string, listener: (eventObj: Object) => void, useCapture?: boolean): Function;
71 | addEventListener(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, useCapture?: boolean): Object;
72 | addEventListener(type: string, listener: { handleEvent: (eventObj: Object) => void; }, useCapture?: boolean): Object;
73 | dispatchEvent(eventObj: Object, target?: Object): boolean;
74 | dispatchEvent(eventObj: string, target?: Object): boolean;
75 | dispatchEvent(eventObj: Event, target?: Object): boolean;
76 | hasEventListener(type: string): boolean;
77 | static initialize(target: Object): void;
78 | off(type: string, listener: (eventObj: Object) => boolean, useCapture?: boolean): void;
79 | off(type: string, listener: (eventObj: Object) => void, useCapture?: boolean): void;
80 | off(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, useCapture?: boolean): void;
81 | off(type: string, listener: { handleEvent: (eventObj: Object) => void; }, useCapture?: boolean): void;
82 | off(type: string, listener: Function, useCapture?: boolean): void; // It is necessary for "arguments.callee"
83 | on(type: string, listener: (eventObj: Object) => boolean, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Function;
84 | on(type: string, listener: (eventObj: Object) => void, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Function;
85 | on(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Object;
86 | on(type: string, listener: { handleEvent: (eventObj: Object) => void; }, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Object;
87 | removeAllEventListeners(type?: string): void;
88 | removeEventListener(type: string, listener: (eventObj: Object) => boolean, useCapture?: boolean): void;
89 | removeEventListener(type: string, listener: (eventObj: Object) => void, useCapture?: boolean): void;
90 | removeEventListener(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, useCapture?: boolean): void;
91 | removeEventListener(type: string, listener: { handleEvent: (eventObj: Object) => void; }, useCapture?: boolean): void;
92 | removeEventListener(type: string, listener: Function, useCapture?: boolean): void; // It is necessary for "arguments.callee"
93 | toString(): string;
94 | willTrigger(type: string): boolean;
95 | }
96 |
97 | export function extend(subclass: () => any, superclass: () => any): () => any; // returns the subclass prototype
98 | export function indexOf(array: any[], searchElement: Object): number;
99 | export function promote(subclass: () => any, prefix: string): () => any;
100 |
101 | export function proxy(method: (eventObj: Object) => boolean, scope: Object, ...arg: any[]): (eventObj: Object) => any;
102 | export function proxy(method: (eventObj: Object) => void, scope: Object, ...arg: any[]): (eventObj: Object) => any;
103 | export function proxy(method: { handleEvent: (eventObj: Object) => boolean; }, scope: Object, ...arg: any[]): (eventObj: Object) => any;
104 | export function proxy(method: { handleEvent: (eventObj: Object) => void; }, scope: Object, ...arg: any[]): (eventObj: Object) => any;
105 | }
106 |
--------------------------------------------------------------------------------
/lib/dat-gui.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for dat.GUI v0.5
2 | // Project: https://github.com/dataarts/dat.gui
3 | // Definitions by: Satoru Kimura
4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5 |
6 | declare namespace dat {
7 | export class GUI {
8 | constructor(option?: GUIParams);
9 |
10 | __controllers: GUIController[];
11 | __folders: GUI[];
12 | domElement: HTMLElement;
13 |
14 | add(target: Object, propName:string): GUIController;
15 | add(target: Object, propName:string, min: number, max: number): GUIController;
16 | add(target: Object, propName:string, status: boolean): GUIController;
17 | add(target: Object, propName:string, items:string[]): GUIController;
18 | add(target: Object, propName:string, items:number[]): GUIController;
19 | add(target: Object, propName:string, items:Object): GUIController;
20 |
21 | addColor(target: Object, propName:string): GUIController;
22 | addColor(target: Object, propName:string, color: string): GUIController;
23 | addColor(target: Object, propName:string, rgba: number[]): GUIController; // rgb or rgba
24 | addColor(target: Object, propName:string, hsv:{h:number; s:number; v:number}): GUIController;
25 |
26 | addFolder(propName:string): GUI;
27 |
28 | close(): void;
29 | open(): void;
30 | remember(target: Object): void;
31 | }
32 |
33 | export interface GUIParams{
34 | autoPlace?: boolean;
35 | closed?: boolean;
36 | load?: any;
37 | name?: string;
38 | preset?: string;
39 | width?: number;
40 | }
41 |
42 | export class GUIController {
43 | destroy(): void;
44 | fire(): GUIController;
45 | getValue(): any;
46 | isModified(): boolean;
47 | listen(): GUIController;
48 | min(n: number): GUIController;
49 | remove(target: GUIController): void;
50 | setValue(value: any): GUIController;
51 | step(n: number): GUIController;
52 | updateDisplay(): void;
53 |
54 | onChange: (value?: any) => void;
55 | onFinishChange: (value?: any) => void;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/lib/physicsjs/physicsjs.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | type Vectorish = {x:number, y:number};
4 | type AABB = {
5 | x: Number, // the x coord of the center point
6 | y: Number, // the y coord of the center point
7 | hw: Number, // the half-width
8 | hh: Number, // the half-height
9 | };
10 |
11 | interface PhysicsWorld
12 | {
13 | add(things:any):PhysicsWorld;
14 | addBehavior(behavior:any):PhysicsWorld;
15 | addBody(body:any):PhysicsWorld;
16 | destroy():void;
17 | find(rules:any):any;
18 | findOne(rules:any):any;
19 | getBehaviors():any;
20 | getBodies():any;
21 | has(thing:any):boolean;
22 | integrator(integrator?:any):any;
23 | isPaused():boolean;
24 | options(cfg:Object):Object;
25 | pause():PhysicsWorld;
26 | remove(things:any):PhysicsWorld;
27 | removeBehavior(behavior:any):PhysicsWorld;
28 | removeBody(body:any):PhysicsWorld;
29 | render():PhysicsWorld;
30 | renderer(renderer?:any):any;
31 | step(now?:number):PhysicsWorld;
32 | timestep(dt?:number):any;
33 | unpause():PhysicsWorld;
34 | wakeUpAll():PhysicsWorld;
35 | warp(warp?:number):any;
36 | on(key:string, cb:Function);
37 | }
38 |
39 | interface PhysicsBody
40 | {
41 | treatment:'dynamic'|'kinematic'|'static';
42 | addChild(body:PhysicsBody):PhysicsBody;
43 | applyForce(force:Vectorish, p?):PhysicsBody;
44 | clear():PhysicsBody;
45 | }
46 |
47 | interface PhysicsRenderer
48 | {
49 | el:any;
50 | width:number;
51 | height:number;
52 | stage:Object;
53 | }
54 |
55 | interface CanvasRenderer extends PhysicsRenderer
56 | {
57 |
58 | }
59 |
60 | interface PixiRenderer extends PhysicsRenderer
61 | {
62 | attach(data:Object):PixiRenderer;
63 | centerAnchor(view:PIXI.DisplayObject):void;
64 | createCircle(x:number, y:number, r:number, styles:Object):PIXI.Graphics;
65 | createDisplay(type:string, options?:Object):PIXI.DisplayObject;
66 | createLine(from:number, to:number, styles:Object):PIXI.Graphics;
67 | createPolygon(verts:any, styles:Object):PIXI.Graphics;
68 | createRect(x:number, y:number, r:number, styles:Object):PIXI.Graphics;
69 | detach(data:PIXI.Graphics|Object):PixiRenderer;
70 | drawBody(body:PhysicsBody, view:PIXI.DisplayObject):void;
71 | loadSpriteSheets(assetsToLoad:any, callback:Function):PixiRenderer;
72 | setStyles(graphics:PIXI.Graphics, styles:Object):PIXI.Graphics;
73 | createView(geometry:any, styles:Object):any;
74 | drawBody(body:Object, view:Object):any;
75 | drawMeta(meta:any):void;
76 | render(bodies:any, meta:Object):PixiRenderer;
77 | resize(width?:number, height?:number):PixiRenderer;
78 | setWorld(world:PhysicsWorld):PixiRenderer;
79 | }
80 |
81 | interface PhysicsBehavior
82 | {
83 | applyTo(object:any):any;
84 | setAcceleration(vec:any):void;
85 | }
86 |
87 | interface PhysicsVerletConstraintsBehavior extends PhysicsBehavior
88 | {
89 | angleConstraint(bodyA:PhysicsBody, bodyB:PhysicsBody, bodyC:PhysicsBody, stiffness?:number, targetAngle?:number):any;
90 | distanceConstraint(bodyA:PhysicsBody, bodyB:PhysicsBody, stiffness?:number, targetLength?:number):any;
91 | drop():PhysicsVerletConstraintsBehavior;
92 | getConstraints():any;
93 | remove(constraintData:any):PhysicsVerletConstraintsBehavior;
94 | resolve():void;
95 | resolveAngleConstraints(coef:number):void;
96 | resolveDistanceConstraints(coef:number):void;
97 | shuffleConstraints():void;
98 | }
99 |
100 | interface PhysicsUtil
101 | {
102 | ticker:{
103 | on:(cb:Function) => void
104 | };
105 | }
106 |
107 | interface PhysicsEngine
108 | {
109 | util:PhysicsUtil;
110 | (cb:(world:PhysicsWorld) => void):any;
111 | (options:any, cb:(world:PhysicsWorld) => void):any;
112 | body(name:string, options?:Object):PhysicsBody;
113 | renderer(name:string, options?:Object):CanvasRenderer|PixiRenderer;
114 | behavior(name:string, options?:Object):PhysicsBehavior;
115 | vector(x:number, y:number);
116 |
117 | aabb(minX, minY, maxX, maxY):AABB;
118 | aabb(pt1:Vectorish, pt2:Vectorish):AABB;
119 | aabb(width, height, pt?:Vectorish):AABB;
120 | }
121 |
122 |
123 | declare var Physics:PhysicsEngine;
124 |
--------------------------------------------------------------------------------
/lib/tweenjs.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for TweenJS 0.6.0
2 | // Project: http://www.createjs.com/#!/TweenJS
3 | // Definitions by: Pedro Ferreira , Chris Smith
4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5 |
6 | /*
7 | Copyright (c) 2012 Pedro Ferreira
8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 | */
12 |
13 | // Library documentation : http://www.createjs.com/Docs/TweenJS/modules/TweenJS.html
14 |
15 | ///
16 |
17 | declare namespace createjs {
18 | export class CSSPlugin {
19 | constructor();
20 |
21 | // properties
22 | static cssSuffixMap: Object;
23 |
24 | // methods
25 | static install(): void;
26 | }
27 |
28 | export class Ease {
29 | // methods
30 | static backIn: (amount: number) => number;
31 | static backInOut: (amount: number) => number;
32 | static backOut: (amount: number) => number;
33 | static bounceIn: (amount: number) => number;
34 | static bounceInOut: (amount: number) => number;
35 | static bounceOut: (amount: number) => number;
36 | static circIn: (amount: number) => number;
37 | static circInOut: (amount: number) => number;
38 | static circOut: (amount: number) => number;
39 | static cubicIn: (amount: number) => number;
40 | static cubicInOut: (amount: number) => number;
41 | static cubicOut: (amount: number) => number;
42 | static elasticIn: (amount: number) => number;
43 | static elasticInOut: (amount: number) => number;
44 | static elasticOut: (amount: number) => number;
45 | static get(amount: number): (amount: number) => number;
46 | static getBackIn(amount: number): (amount: number) => number;
47 | static getBackInOut(amount: number): (amount: number) => number;
48 | static getBackOut(amount: number): (amount: number) => number;
49 | static getElasticIn(amplitude: number, period: number): (amount: number) => number;
50 | static getElasticInOut(amplitude: number, period: number): (amount: number) => number;
51 | static getElasticOut(amplitude: number, period: number): (amount: number) => number;
52 | static getPowIn(pow: number): (amount: number) => number;
53 | static getPowInOut(pow: number): (amount: number) => number;
54 | static getPowOut(pow: number): (amount: number) => number;
55 | static linear: (amount: number) => number;
56 | static none: (amount: number) => number; // same as linear
57 | static quadIn: (amount: number) => number;
58 | static quadInOut: (amount: number) => number;
59 | static quadOut: (amount: number) => number;
60 | static quartIn: (amount: number) => number;
61 | static quartInOut: (amount: number) => number;
62 | static quartOut: (amount: number) => number;
63 | static quintIn: (amount: number) => number;
64 | static quintInOut: (amount: number) => number;
65 | static quintOut: (amount: number) => number;
66 | static sineIn: (amount: number) => number;
67 | static sineInOut: (amount: number) => number;
68 | static sineOut: (amount: number) => number;
69 | }
70 |
71 | export class MotionGuidePlugin {
72 | constructor();
73 |
74 | //methods
75 | static install(): Object;
76 | }
77 |
78 | /*
79 | NOTE: It is commented out because it conflicts with SamplePlugin Class of PreloadJS.
80 | this class is mainly for documentation purposes.
81 | http://www.createjs.com/Docs/TweenJS/classes/SamplePlugin.html
82 | */
83 | /*
84 | export class SamplePlugin {
85 | constructor();
86 |
87 | // properties
88 | static priority: any;
89 |
90 | //methods
91 | static init(tween: Tween, prop: string, value: any): any;
92 | static step(tween: Tween, prop: string, startValue: any, injectProps: Object, endValue: any): void;
93 | static install(): void;
94 | static tween(tween: Tween, prop: string, value: any, startValues: Object, endValues: Object, ratio: number, wait: boolean, end: boolean): any;
95 | }
96 | */
97 |
98 | export class Timeline extends EventDispatcher {
99 | constructor (tweens: Tween[], labels: Object, props: Object);
100 |
101 | // properties
102 | duration: number;
103 | ignoreGlobalPause: boolean;
104 | loop: boolean;
105 | position: Object;
106 |
107 | // methods
108 | addLabel(label: string, position: number): void;
109 | addTween(...tween: Tween[]): void;
110 | getCurrentLabel(): string;
111 | getLabels(): Object[];
112 | gotoAndPlay(positionOrLabel: string | number): void;
113 | gotoAndStop(positionOrLabel: string | number): void;
114 | removeTween(...tween: Tween[]): void;
115 | resolve(positionOrLabel: string | number): number;
116 | setLabels(o: Object): void;
117 | setPaused(value: boolean): void;
118 | setPosition(value: number, actionsMode?: number): boolean;
119 | tick(delta: number): void;
120 | updateDuration(): void;
121 | }
122 |
123 |
124 | export class Tween extends EventDispatcher {
125 | constructor(target: Object, props?: Object, pluginData?: Object);
126 |
127 | // properties
128 | duration: number;
129 | static IGNORE: Object;
130 | ignoreGlobalPause: boolean;
131 | static LOOP: number;
132 | loop: boolean;
133 | static NONE: number;
134 | onChange: Function; // deprecated
135 | passive: boolean;
136 | pluginData: Object;
137 | position: number;
138 | static REVERSE: number;
139 | target: Object;
140 |
141 | // methods
142 | call(callback: (tweenObject: Tween) => any, params?: any[], scope?: Object): Tween; // when 'params' isn't given, the callback receives a tweenObject
143 | call(callback: (...params: any[]) => any, params?: any[], scope?: Object): Tween; // otherwise, it receives the params only
144 | static get(target: Object, props?: Object, pluginData?: Object, override?: boolean): Tween;
145 | static hasActiveTweens(target?: Object): boolean;
146 | static installPlugin(plugin: Object, properties: any[]): void;
147 | pause(tween: Tween): Tween;
148 | play(tween: Tween): Tween;
149 | static removeAllTweens(): void;
150 | static removeTweens(target: Object): void;
151 | set(props: Object, target?: Object): Tween;
152 | setPaused(value: boolean): Tween;
153 | setPosition(value: number, actionsMode: number): boolean;
154 | static tick(delta: number, paused: boolean): void;
155 | tick(delta: number): void;
156 | to(props: Object, duration?: number, ease?: (t: number) => number): Tween;
157 | wait(duration: number, passive?: boolean): Tween;
158 |
159 | }
160 |
161 | export class TweenJS {
162 | // properties
163 | static buildDate: string;
164 | static version: string;
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/src/app/FpsDisplay.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | namespace app.Fps
4 | {
5 | const CSS = `
6 | #fps-display{
7 | left: 10px; top: 10px;
8 | padding: 2px 4px;
9 | position: absolute;
10 | z-index: 100;
11 |
12 | background-color: #999;
13 | border-radius: 3px;
14 | color: #FFF;
15 | cursor: default;
16 | font: bold 11px/14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
17 | text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
18 | vertical-align: baseline;
19 | white-space: nowrap;
20 | user-select: none;
21 | }`;
22 |
23 | export class Display
24 | {
25 | private $fps:JQuery;
26 | private $fpsText:JQuery;
27 |
28 | public fpsCallback:() => number;
29 |
30 | constructor(fpsCallback:() => number = null)
31 | {
32 | this.fpsCallback = fpsCallback;
33 | this.$fps = $('00 fps
');
34 | this.$fpsText = this.$fps.find('.text');
35 | document.body.appendChild(this.$fps[0]);
36 |
37 | var head = document.head || document.getElementsByTagName('head')[0];
38 | var style:any = document.createElement('style');
39 | style.type = 'text/css';
40 |
41 | if(style.styleSheet)
42 | {
43 | style.styleSheet.cssText = CSS;
44 | }
45 | else
46 | {
47 | style.appendChild(document.createTextNode(CSS));
48 | }
49 |
50 | head.appendChild(style);
51 |
52 | setInterval(this.onTimer, 500);
53 | }
54 |
55 | onTimer = () =>
56 | {
57 | if(this.fpsCallback)
58 | {
59 | this.$fpsText.text(this.fpsCallback().toFixed(1));
60 | }
61 | }
62 |
63 | }
64 | }
--------------------------------------------------------------------------------
/src/app/Main.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 | ///
6 | ///
7 | ///
8 | ///
9 | ///
10 | ///
11 |
12 | namespace app
13 | {
14 |
15 | import Ticker = app.ticker.Ticker;
16 | import DemoEngineBase = engines.DemoEngineBase;
17 | import NapeDemo = engines.NapeDemo;
18 | import P2JsDemo = engines.P2JsDemo;
19 | import MatterDemo = engines.MatterDemo;
20 | import PhysicsJsDemo = engines.PhysicsJsDemo;
21 | import Box2dWebDemo = engines.Box2dWebDemo;
22 |
23 | import GUIController = dat.GUIController;
24 |
25 | export class Main
26 | {
27 | private static readonly CANVAS_WIDTH = 800;
28 | private static readonly CANVAS_HEIGHT = 600;
29 |
30 | private static readonly DEMO_NAMES = [
31 | 'Basic',
32 | 'Constraints',
33 | 'Ragdolls',
34 | 'Stress',
35 | ];
36 |
37 | private $canvas:JQuery;
38 | private canvas:HTMLCanvasElement;
39 | private fpsDisplay:Fps.Display;
40 |
41 | private $engineDisplay;
42 | private $engineText;
43 | private $demoText;
44 | private engines:DemoEngineBase[] = [];
45 | private engineIndex = -1;
46 | private currentEngine:DemoEngineBase;
47 | private currentDemo:number = 0;
48 |
49 | private ticker:Ticker;
50 |
51 | private mouseX:number = 0;
52 | private mouseY:number = 0;
53 | private canvasRightMouseDown = false;
54 |
55 | private _enableDrawing:boolean = true;
56 | private velocityIterations = 10;
57 | private positionIterations = 10;
58 |
59 | velIterations:GUIController;
60 | posIterations:GUIController;
61 |
62 | constructor()
63 | {
64 | window.addEventListener('DOMContentLoaded', this.onWindowLoad);
65 | this.ticker = new Ticker();
66 | }
67 |
68 | private initGui()
69 | {
70 | var buttons = [];
71 |
72 | var gui = new dat.GUI();
73 | var prevEngine = gui.add(this, 'prevEngine');
74 | var nextEngine = gui.add(this, 'nextEngine');
75 | var prevDemo = gui.add(this, 'prevDemo');
76 | var nextDemo = gui.add(this, 'nextDemo');
77 | buttons.push(gui.add(this, 'restart'));
78 | gui.add(this, 'enableDrawing');
79 |
80 | prevEngine.name('◀ prevEngine');
81 | nextEngine.name('nextEngine ▶');
82 | prevDemo.name('◀ prevDemo');
83 | nextDemo.name('nextDemo ▶');
84 |
85 | this.velIterations = gui.add(this, 'velocityIterations', 1, 50);
86 | this.posIterations = gui.add(this, 'positionIterations', 1, 50);
87 | this.velIterations.onFinishChange(this.onVelIterationsChange);
88 | this.posIterations.onFinishChange(this.onPosIterationsChange);
89 |
90 | $([
91 | prevEngine.domElement.parentNode.parentNode,
92 | nextEngine.domElement.parentNode.parentNode,
93 | prevDemo.domElement.parentNode.parentNode,
94 | nextDemo.domElement.parentNode.parentNode
95 | ])
96 | .addClass('dgui-two-column-btn dg-button-row');
97 |
98 | for(let button of buttons)
99 | {
100 | $(button.domElement.parentNode.parentNode).addClass('dg-button-row');
101 | }
102 | }
103 |
104 | private loadEngine(index)
105 | {
106 | if(index < 0)
107 | index = this.engines.length - 1;
108 | else if(index >= this.engines.length)
109 | index = 0;
110 |
111 | if(index == this.engineIndex)
112 | {
113 | return;
114 | }
115 |
116 | if(this.currentEngine)
117 | {
118 | this.currentEngine.clear();
119 | this.ticker.tickCallback = null;
120 | }
121 |
122 | this.engineIndex = index;
123 | this.currentEngine = this.engines[index];
124 |
125 | this.currentEngine.mouseX = this.mouseX;
126 | this.currentEngine.mouseY = this.mouseY;
127 |
128 | this.currentEngine.enableDrawing = this.enableDrawing;
129 | this.currentEngine.loadDemo(Main.DEMO_NAMES[this.currentDemo]);
130 | this.ticker.tickCallback = this.currentEngine.run;
131 |
132 | this.updateEngineDisplay();
133 | this.updateIterations();
134 | }
135 |
136 | private loadDemo(index)
137 | {
138 | if(index >= Main.DEMO_NAMES.length)
139 | index = 0;
140 | else if(index < 0)
141 | index = Main.DEMO_NAMES.length - 1;
142 |
143 | this.currentDemo = index;
144 | this.currentEngine.loadDemo(Main.DEMO_NAMES[this.currentDemo]);
145 |
146 | this.updateEngineDisplay();
147 | this.updateIterations();
148 | }
149 |
150 | private prevEngine()
151 | {
152 | this.loadEngine(this.engineIndex - 1);
153 | }
154 | private nextEngine()
155 | {
156 | this.loadEngine(this.engineIndex + 1);
157 | }
158 |
159 | private prevDemo()
160 | {
161 | this.loadDemo(this.currentDemo - 1);
162 | }
163 | private nextDemo()
164 | {
165 | this.loadDemo(this.currentDemo + 1);
166 | }
167 |
168 | get enableDrawing():boolean
169 | {
170 | return this._enableDrawing;
171 | }
172 | set enableDrawing(value:boolean)
173 | {
174 | this._enableDrawing = value;
175 | this.currentEngine.enableDrawing = value;
176 | }
177 |
178 | private restart()
179 | {
180 | this.loadDemo(this.currentDemo);
181 | }
182 |
183 | private updateEngineDisplay()
184 | {
185 | var engineName = this.currentEngine.name;
186 |
187 | this.$engineText.text(`${engineName} (${this.engineIndex+1}/${this.engines.length})`);
188 | this.$demoText.text(`${Main.DEMO_NAMES[this.currentDemo]} (${this.currentDemo+1}/${Main.DEMO_NAMES.length})`);
189 |
190 | // this.$engineDisplay.stop(true).show().css('opacity', 1).delay(2000).animate(
191 | // { opacity: 0},
192 | // { delay: 250, complete: () => {this.$engineDisplay.hide()}});
193 | }
194 |
195 | private updateIterations()
196 | {
197 | this.velocityIterations = this.currentEngine.velocityIterations;
198 | this.positionIterations = this.currentEngine.positionIterations;
199 | this.velIterations.updateDisplay();
200 | this.posIterations.updateDisplay();
201 | }
202 |
203 | /*
204 | *** Events
205 | */
206 |
207 | private onVelIterationsChange = (value) =>
208 | {
209 | this.currentEngine.velocityIterations = this.velocityIterations = value;
210 | };
211 |
212 | private onPosIterationsChange = (value) =>
213 | {
214 | this.currentEngine.positionIterations = this.positionIterations = value;
215 | };
216 |
217 | private onCanvasMouseDown = (event) =>
218 | {
219 | this.currentEngine.handleMouseDown(event);
220 |
221 | if(event.button == 2)
222 | {
223 | this.canvasRightMouseDown = true;
224 | }
225 | };
226 |
227 | private onCanvasMouseUp = (event) =>
228 | {
229 | this.currentEngine.handleMouseUp(event);
230 | };
231 |
232 | private onWindowBlur = () =>
233 | {
234 | this.ticker.stop();
235 | };
236 |
237 | private onWindowFocus = () =>
238 | {
239 | this.ticker.start();
240 | };
241 |
242 | private onWindowContextMenu = (event) =>
243 | {
244 | if(this.canvasRightMouseDown || event.target == this.canvas)
245 | {
246 | this.canvasRightMouseDown = false;
247 | event.preventDefault();
248 | return false;
249 | }
250 | };
251 |
252 | private onWindowLoad = () =>
253 | {
254 | this.$canvas = $('#renderCanvas');
255 | this.canvas = this.$canvas[0];
256 | this.$canvas.on('mousedown', this.onCanvasMouseDown);
257 | this.canvas.width = Main.CANVAS_WIDTH;
258 | this.canvas.height = Main.CANVAS_HEIGHT;
259 |
260 | this.fpsDisplay = new Fps.Display(this.ticker.getFps);
261 |
262 | this.initGui();
263 |
264 | this.$engineDisplay = $('#engine-display');
265 | this.$engineText = this.$engineDisplay.find('.engine');
266 | this.$demoText = this.$engineDisplay.find('.demo');
267 |
268 | const frameRate = 60;
269 | this.engines.push(new NapeDemo(this.canvas, frameRate));
270 | this.engines.push(new Box2dWebDemo(this.canvas, frameRate));
271 | this.engines.push(new P2JsDemo(this.canvas, frameRate));
272 | this.engines.push(new MatterDemo(this.canvas, frameRate));
273 | this.engines.push(new PhysicsJsDemo(this.canvas, frameRate));
274 | this.loadEngine(0);
275 | // this.loadEngine(this.engines.length - 1);
276 |
277 | $(window)
278 | .on('focus', this.onWindowFocus)
279 | .on('blur', this.onWindowBlur)
280 | .on('mousemove', this.onWindowMouseMove)
281 | .on('mouseup', this.onCanvasMouseUp)
282 | .on('contextmenu', this.onWindowContextMenu)
283 | .focus();
284 |
285 | this.ticker.start();
286 | };
287 |
288 | private onWindowMouseMove = (event) =>
289 | {
290 | var offset = this.$canvas.offset();
291 | this.mouseX = this.currentEngine.mouseX = event.pageX - offset.left;
292 | this.mouseY = this.currentEngine.mouseY = event.pageY - offset.top;
293 | };
294 |
295 | /*
296 | *** Utility Methods
297 | */
298 | }
299 |
300 | //noinspection JSUnusedLocalSymbols
301 | export var main = new Main();
302 |
303 | }
--------------------------------------------------------------------------------
/src/app/Ticker.ts:
--------------------------------------------------------------------------------
1 | namespace app.ticker
2 | {
3 |
4 | export interface TickCallback{
5 | // The delta time in seconds
6 | (deltaTime:number, timestamp:number):void
7 | }
8 |
9 | export class Ticker
10 | {
11 | protected static EMPTY_RUNNER(deltatTime:number){};
12 |
13 | protected _tickCallback:TickCallback;
14 | protected _targetFps:number;
15 | // The required amount of time between frames in milliseconds
16 | protected fpsInterval;
17 |
18 | protected isRunning = false;
19 | protected previousTime;
20 | protected currentTime;
21 |
22 | protected measuredFps = 0;
23 | protected frameCount = 0;
24 | protected frameCountPrevTime = 0;
25 |
26 | constructor(runner:TickCallback = null, targetFps:number = 60)
27 | {
28 | this.targetFps = targetFps;
29 | this.tickCallback = runner;
30 | }
31 |
32 | get tickCallback():TickCallback
33 | {
34 | return this._tickCallback;
35 | }
36 | set tickCallback(callback:TickCallback)
37 | {
38 | if(!callback)
39 | callback = Ticker.EMPTY_RUNNER;
40 |
41 | this._tickCallback = callback;
42 | }
43 |
44 | get targetFps():number
45 | {
46 | return this._targetFps;
47 | }
48 | set targetFps(newTargetFps)
49 | {
50 | if(isNaN(newTargetFps))
51 | newTargetFps = 60;
52 | else if(newTargetFps < 0)
53 | newTargetFps = 0;
54 |
55 | this._targetFps = newTargetFps;
56 | this.fpsInterval = 1000 / newTargetFps;
57 | }
58 |
59 | getFps = ():number =>
60 | {
61 | return this.isRunning
62 | ? (this.currentTime != this.frameCountPrevTime ? this.frameCount / ((this.currentTime - this.frameCountPrevTime) / 1000) : this.measuredFps)
63 | : 0;
64 | };
65 |
66 | start()
67 | {
68 | this.isRunning = true;
69 |
70 | this.frameCountPrevTime = 0;
71 | this.frameCount = 0;
72 | this.previousTime = this.frameCountPrevTime = performance.now();
73 | this.run(this.previousTime);
74 | }
75 |
76 | stop()
77 | {
78 | this.isRunning = false;
79 | }
80 |
81 | private run = (time) =>
82 | {
83 | if(!this.isRunning)
84 | return;
85 |
86 | requestAnimationFrame(this.run);
87 |
88 | this.currentTime = time;
89 | let elapsedTime = time - this.previousTime;
90 |
91 | if(elapsedTime > this.fpsInterval)
92 | {
93 | this.previousTime = time - (elapsedTime % this.fpsInterval);
94 |
95 | this._tickCallback(elapsedTime * 0.001, time);
96 |
97 | // Update/measure the fps every 1 second
98 | this.frameCount++;
99 | if(time - this.frameCountPrevTime >= 1000)
100 | {
101 | this.measuredFps = this.frameCount / ((this.currentTime - this.frameCountPrevTime) / 1000);
102 | this.frameCountPrevTime = time;
103 | this.frameCount = 0;
104 | }
105 | }
106 | }
107 |
108 | }
109 |
110 | }
--------------------------------------------------------------------------------
/src/demos/Basic.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 | ///
6 | ///
7 |
8 | namespace demos
9 | {
10 |
11 | import DemoEngineBase = engines.DemoEngineBase;
12 | import VertFormat = engines.VertFormat;
13 |
14 | const VELOCITY_ITERATIONS = 10;
15 | const POSITION_ITERATIONS = 10;
16 |
17 | namespace napeDemo
18 | {
19 | import Body = nape.phys.Body;
20 | import Circle = nape.shape.Circle;
21 | import Polygon = nape.shape.Polygon;
22 |
23 | engines.NapeDemo.prototype.loadDemoBasic = function()
24 | {
25 | this.velocityIterations = VELOCITY_ITERATIONS;
26 | this.positionIterations = POSITION_ITERATIONS;
27 | this.space.gravity.setxy(0, 0);
28 |
29 | // Generate some random objects!
30 | for (var i:number = 0; i < 100; i++) {
31 | var body:Body = new Body();
32 |
33 | // Add random one of either a Circle, Box or Pentagon.
34 | if (Math.random() < 0.33) {
35 | body.shapes.add(new Circle(20));
36 | }
37 | else if (Math.random() < 0.5) {
38 | body.shapes.add(new Polygon(Polygon.box(40, 40)));
39 | }
40 | else {
41 | body.shapes.add(new Polygon(Polygon.regular(20, 20, 5)));
42 | }
43 |
44 | // Set to random position on stage and add to Space.
45 | body.position.setxy(Math.random() * this.stageWidth, Math.random() * this.stageHeight);
46 | body.space = this.space;
47 | }
48 | };
49 | }
50 |
51 | namespace box2dWebDemo
52 | {
53 | import b2Vec2 = Box2D.Common.Math.b2Vec2;
54 | import b2BodyDef = Box2D.Dynamics.b2BodyDef;
55 | import b2FixtureDef = Box2D.Dynamics.b2FixtureDef;
56 | import b2Body = Box2D.Dynamics.b2Body;
57 | import b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape;
58 | import b2CircleShape = Box2D.Collision.Shapes.b2CircleShape;
59 |
60 | engines.Box2dWebDemo.prototype.loadDemoBasic = function()
61 | {
62 | const WORLD_SCALE = this.worldScale;
63 |
64 | this.velocityIterations = VELOCITY_ITERATIONS;
65 | this.positionIterations = POSITION_ITERATIONS;
66 | this.world.SetGravity(new b2Vec2(0, 0));
67 |
68 | var bodyDef:b2BodyDef = new b2BodyDef();
69 | var fixDef:b2FixtureDef = new b2FixtureDef();
70 |
71 | bodyDef.type = b2Body.b2_dynamicBody;
72 | fixDef.density = 1.0;
73 | fixDef.friction = 0.3;
74 |
75 | // Generate some random objects!
76 | for (var i:number = 0; i < 100; i++) {
77 | bodyDef.position.Set(Math.random() * this.stageWidth * WORLD_SCALE, Math.random() * this.stageHeight * WORLD_SCALE);
78 |
79 | let body:b2Body = this.world.CreateBody(bodyDef);
80 |
81 | // Add random one of either a Circle, Box or Pentagon.
82 | if (Math.random() < 0.33) {
83 | fixDef.shape = new b2CircleShape(20 * WORLD_SCALE);
84 | }
85 | else if (Math.random() < 0.5) {
86 | fixDef.shape = b2PolygonShape.AsBox(40 * WORLD_SCALE * 0.5, 40 * WORLD_SCALE * 0.5);
87 | }
88 | else {
89 | fixDef.shape = b2PolygonShape.AsVector(DemoEngineBase.Regular(20 * WORLD_SCALE, 20 * WORLD_SCALE, 5, 0, VertFormat.Vector, b2Vec2));
90 | }
91 |
92 | body.CreateFixture(fixDef);
93 | }
94 | };
95 | }
96 |
97 | namespace p2JsDemo
98 | {
99 | import Body = p2.Body;
100 | import Circle = p2.Circle;
101 | import Box = p2.Box;
102 | import Convex = p2.Convex;
103 |
104 | engines.P2JsDemo.prototype.loadDemoBasic = function()
105 | {
106 | const WORLD_SCALE = this.worldScale;
107 |
108 | this.velocityIterations = VELOCITY_ITERATIONS;
109 | this.positionIterations = POSITION_ITERATIONS;
110 | this.world.gravity = [0, 0];
111 |
112 | // Generate some random objects!
113 | for (var i:number = 0; i < 100; i++) {
114 | var body:Body = new Body({ mass: 1});
115 |
116 | // Add random one of either a Circle, Box or Pentagon.
117 | if (Math.random() < 0.33) {
118 | body.addShape(new Circle({radius: 20 * WORLD_SCALE}));
119 | }
120 | else if (Math.random() < 0.5) {
121 | body.addShape(new Box({width: 40 * WORLD_SCALE, height: 40 * WORLD_SCALE}));
122 | }
123 | else {
124 | body.addShape(new Convex({vertices: DemoEngineBase.Regular(20 * WORLD_SCALE, 20 * WORLD_SCALE, 5)}));
125 | }
126 |
127 | // Set to random position on stage and add to Space.
128 | body.position = [Math.random() * this.stageWidth * WORLD_SCALE, Math.random() * this.stageHeight * WORLD_SCALE];
129 | this.world.addBody(body);
130 | }
131 | }
132 | }
133 |
134 | namespace matterDemo
135 | {
136 | import Body = Matter.Body;
137 | import Bodies = Matter.Bodies;
138 | import World = Matter.World;
139 |
140 | engines.MatterDemo.prototype.loadDemoBasic = function()
141 | {
142 | this.velocityIterations = VELOCITY_ITERATIONS;
143 | this.positionIterations = POSITION_ITERATIONS;
144 | this.world.gravity.x = 0;
145 | this.world.gravity.y = 0;
146 |
147 | // Generate some random objects!
148 | for (var i:number = 0; i < 100; i++) {
149 | var body:Body;
150 | const x = Math.random() * this.stageWidth, y = Math.random() * this.stageHeight;
151 |
152 | // Add random one of either a Circle, Box or Pentagon.
153 | if (Math.random() < 0.33) {
154 | body = Bodies.circle(x, y, 20);
155 | }
156 | else if (Math.random() < 0.5) {
157 | body = Bodies.rectangle(x, y, 40, 40);
158 | }
159 | else {
160 | body = Bodies.polygon(x, y, 5, 20);
161 | }
162 |
163 | World.add(this.world, body);
164 | }
165 | };
166 | }
167 |
168 | namespace physicsJsDemo
169 | {
170 | engines.PhysicsJsDemo.prototype.loadDemoBasic = function()
171 | {
172 | this.gravity.setAcceleration({x: 0, y: 0});
173 | const bodies = this.bodies;
174 |
175 | // Generate some random objects!
176 | for (var i:number = 0; i < 100; i++) {
177 | var body;
178 | var x = Math.random() * this.stageWidth, y = Math.random() * this.stageHeight;
179 |
180 | // Add random one of either a Circle, Box or Pentagon.
181 | if (Math.random() < 0.33) {
182 | bodies.push(Physics.body('circle', {
183 | x: x,
184 | y: y,
185 | radius: 20
186 | }));
187 | }
188 | else if (Math.random() < 0.5) {
189 | bodies.push(Physics.body('rectangle', {
190 | x: x,
191 | y: y,
192 | width: 40,
193 | height: 40
194 | }));
195 | }
196 | else {
197 | bodies.push(Physics.body('convex-polygon', {
198 | x: x,
199 | y: y,
200 | vertices: DemoEngineBase.Regular(20, 20, 5, 0, VertFormat.Vector)
201 | }));
202 | }
203 | }
204 |
205 | this.world.add(this.bodies);
206 | };
207 | }
208 |
209 | }
--------------------------------------------------------------------------------
/src/demos/Stress.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 | ///
6 | ///
7 |
8 | namespace demos
9 | {
10 |
11 | const VELOCITY_ITERATIONS = 35;
12 | const POSITION_ITERATIONS = 10;
13 |
14 | namespace napeDemo
15 | {
16 | import Body = nape.phys.Body;
17 | import Polygon = nape.shape.Polygon;
18 |
19 | engines.NapeDemo.prototype.loadDemoStress = function()
20 | {
21 | this.velocityIterations = VELOCITY_ITERATIONS;
22 | this.positionIterations = POSITION_ITERATIONS;
23 | this.space.gravity.setxy(0, 600);
24 |
25 | var boxWidth:number = 10;
26 | var boxHeight:number = 14;
27 | var pyramidHeight:number = 40; //820 blocks
28 |
29 | for (var y:number = 1; y <= pyramidHeight; y++) {
30 | for (var x:number = 0; x < y; x++) {
31 | var block:Body = new Body();
32 | // We initialise the blocks to be slightly overlapping so that
33 | // all contact points will be created in very first step before the blocks
34 | // begin to fall.
35 | block.position.x = (this.stageWidth/2) - boxWidth*((y-1)/2 - x)*0.99;
36 | block.position.y = this.stageHeight - boxHeight*(pyramidHeight - y + 0.5)*0.99;
37 | block.shapes.add(new Polygon(Polygon.box(boxWidth, boxHeight)));
38 | block.space = this.space;
39 | }}
40 | };
41 | }
42 |
43 | namespace box2dWebDemo
44 | {
45 | import b2Body = Box2D.Dynamics.b2Body;
46 | import b2Vec2 = Box2D.Common.Math.b2Vec2;
47 | import b2BodyDef = Box2D.Dynamics.b2BodyDef;
48 | import b2FixtureDef = Box2D.Dynamics.b2FixtureDef;
49 | import b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape;
50 |
51 | engines.Box2dWebDemo.prototype.loadDemoStress = function()
52 | {
53 | const WORLD_SCALE = this.worldScale;
54 |
55 | this.velocityIterations = VELOCITY_ITERATIONS;
56 | this.positionIterations = POSITION_ITERATIONS;
57 | this.world.SetGravity(new b2Vec2(0, 9.82));
58 |
59 | const sw = this.stageWidth;
60 | const sh = this.stageHeight;
61 | const boxWidth:number = 10;
62 | const boxHeight:number = 14;
63 | const bw:number = boxWidth * WORLD_SCALE * 0.5;
64 | const bh:number = boxHeight * WORLD_SCALE * 0.5;
65 | var pyramidHeight:number = 40; //820 blocks
66 |
67 | var bodyDef:b2BodyDef = new b2BodyDef();
68 | var fixDef:b2FixtureDef = new b2FixtureDef();
69 |
70 | bodyDef.type = b2Body.b2_dynamicBody;
71 | fixDef.density = 1.0;
72 | fixDef.friction = 0.9;
73 |
74 | for (var y:number = 1; y <= pyramidHeight; y++) {
75 | for (var x:number = 0; x < y; x++) {
76 | // We initialise the blocks to be slightly overlapping so that
77 | // all contact points will be created in very first step before the blocks
78 | // begin to fall.
79 | bodyDef.position.Set(
80 | ((sw/2) - boxWidth*((y-1)/2 - x)*0.99) * WORLD_SCALE,
81 | (sh - boxHeight*(pyramidHeight - y + 0.5)*0.99) * WORLD_SCALE
82 | );
83 |
84 | let body:b2Body = this.world.CreateBody(bodyDef);
85 | fixDef.shape = b2PolygonShape.AsBox(bw, bh);
86 | body.CreateFixture(fixDef);
87 | }
88 | }
89 | };
90 | }
91 |
92 | namespace p2JsDemo
93 | {
94 | import Body = p2.Body;
95 | import Box = p2.Box;
96 |
97 | engines.P2JsDemo.prototype.loadDemoStress = function()
98 | {
99 | const WORLD_SCALE = this.worldScale;
100 |
101 | this.velocityIterations = VELOCITY_ITERATIONS;
102 | this.positionIterations = POSITION_ITERATIONS;
103 | this.world.gravity = [0, 100 * WORLD_SCALE];
104 |
105 | const sw = this.stageWidth;
106 | const sh = this.stageHeight;
107 | const boxWidth:number = 10;
108 | const boxHeight:number = 14;
109 | const bw:number = boxWidth * WORLD_SCALE;
110 | const bh:number = boxHeight * WORLD_SCALE;
111 | var pyramidHeight:number = 40; //820 blocks
112 |
113 | for (var y:number = 1; y <= pyramidHeight; y++) {
114 | for (var x:number = 0; x < y; x++) {
115 | var block:Body = new Body({ mass: 1});
116 | // We initialise the blocks to be slightly overlapping so that
117 | // all contact points will be created in very first step before the blocks
118 | // begin to fall.
119 | block.position[0] = ((sw/2) - boxWidth*((y-1)/2 - x)*0.99) * WORLD_SCALE;
120 | block.position[1] = (sh - boxHeight*(pyramidHeight - y + 0.5)*0.99) * WORLD_SCALE;
121 | block.addShape(new Box({width: bw, height: bh}));
122 | this.world.addBody(block);
123 | }}
124 | };
125 | }
126 |
127 | namespace matterDemo
128 | {
129 | import Body = Matter.Body;
130 | import Bodies = Matter.Bodies;
131 | import World = Matter.World;
132 |
133 | engines.MatterDemo.prototype.loadDemoStress = function()
134 | {
135 | this.engine.enableSleeping = false;
136 | this.velocityIterations = VELOCITY_ITERATIONS;
137 | this.positionIterations = POSITION_ITERATIONS;
138 | this.world.gravity.x = 0;
139 | this.world.gravity.y = 0.5;
140 |
141 | var boxWidth:number = 10;
142 | var boxHeight:number = 14;
143 | var pyramidHeight:number = 40; //820 blocks
144 |
145 | for (var y:number = 1; y <= pyramidHeight; y++) {
146 | for (var x:number = 0; x < y; x++) {
147 | // We initialise the blocks to be slightly overlapping so that
148 | // all contact points will be created in very first step before the blocks
149 | // begin to fall.
150 | var block:Body = Bodies.rectangle(
151 | (this.stageWidth/2) - boxWidth*((y-1)/2 - x)*0.99,
152 | this.stageHeight - boxHeight*(pyramidHeight - y + 0.5)*0.99,
153 | boxWidth,
154 | boxHeight);
155 | World.add(this.world, block);
156 | }}
157 | };
158 | }
159 |
160 | namespace physicsJsDemo
161 | {
162 | engines.PhysicsJsDemo.prototype.loadDemoStress = function()
163 | {
164 | this.gravity.setAcceleration({x: 0, y: 0.0004});
165 | const bodies = this.bodies;
166 |
167 | var boxWidth:number = 10;
168 | var boxHeight:number = 14;
169 | var pyramidHeight:number = 24; // < Cannot handle more
170 |
171 | for (var y:number = 1; y <= pyramidHeight; y++) {
172 | for (var x:number = 0; x < y; x++) {
173 | // We initialise the blocks to be slightly overlapping so that
174 | // all contact points will be created in very first step before the blocks
175 | // begin to fall.
176 | bodies.push(Physics.body('rectangle', {
177 | x: (this.stageWidth/2) - boxWidth*((y-1)/2 - x)*0.99,
178 | y: this.stageHeight - boxHeight*(pyramidHeight - y + 0.5)*0.99,
179 | width: boxWidth,
180 | height: boxHeight,
181 | restitution: 0.3
182 | }));
183 | }
184 | }
185 |
186 | this.world.add(this.bodies);
187 |
188 | this.addWarning(this.stageWidth / 2, 20, 'Fewer bodies added due\nto poor performance');
189 | };
190 | }
191 |
192 | }
--------------------------------------------------------------------------------
/src/demos/_template.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 | ///
6 | ///
7 |
8 | namespace demos
9 | {
10 |
11 | import DemoEngineBase = engines.DemoEngineBase;
12 | import VertFormat = engines.VertFormat;
13 |
14 | const VELOCITY_ITERATIONS = 10;
15 | const POSITION_ITERATIONS = 10;
16 |
17 | namespace napeDemo
18 | {
19 | import Body = nape.phys.Body;
20 |
21 | engines.NapeDemo.prototype.loadDemoXX = function()
22 | {
23 |
24 | };
25 | }
26 |
27 | namespace box2dWebDemo
28 | {
29 | import b2Body = Box2D.Dynamics.b2Body;
30 |
31 | engines.Box2dWebDemo.prototype.loadDemoXX = function()
32 | {
33 |
34 | };
35 | }
36 |
37 | namespace p2JsDemo
38 | {
39 | import Body = p2.Body;
40 |
41 | engines.P2JsDemo.prototype.loadDemoXX = function()
42 | {
43 |
44 | };
45 | }
46 |
47 | namespace matterDemo
48 | {
49 | import Body = Matter.Body;
50 |
51 | engines.MatterDemo.prototype.loadDemoXX = function()
52 | {
53 |
54 | };
55 | }
56 |
57 | namespace physicsJsDemo
58 | {
59 | engines.PhysicsJsDemo.prototype.loadDemoXX = function()
60 | {
61 |
62 | };
63 | }
64 |
65 | }
--------------------------------------------------------------------------------
/src/engines/DemoEngineBase.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | namespace engines
4 | {
5 |
6 | import Overlay = overlay.Overlay;
7 | import OverlayIcons = overlay.OverlayIcons;
8 | import OverlayOptions = overlay.OverlayOptions;
9 | import OverlayIconDef = overlay.OverlayIcons.OverlayIconDef;
10 |
11 | export enum VertFormat
12 | {
13 | Array,
14 | Vector
15 | }
16 |
17 | export enum MouseAction
18 | {
19 | Idle,
20 | Handled
21 | }
22 |
23 | export interface IVertex
24 | {
25 | new (x:number, y:number);
26 | }
27 |
28 | export abstract class DemoEngineBase
29 | {
30 |
31 | public name:string = 'INVALID';
32 |
33 | protected canvas:HTMLCanvasElement;
34 | protected context:CanvasRenderingContext2D;
35 | protected stageWidth:number;
36 | protected stageHeight:number;
37 | protected frameRate:number;
38 | protected frameRateInterval:number;
39 |
40 | protected _velocityIterations = 10;
41 | protected _positionIterations = 10;
42 |
43 | public mouseX:number = 0;
44 | public mouseY:number = 0;
45 |
46 | /**
47 | * The scale used when rendering to convert from world coordinates to pixels.
48 | * Do not modify directly, instead use setDrawScale()
49 | * @type {number}
50 | */
51 | protected drawScale = 1;
52 | /**
53 | * Used to convert from pixels to world coordinates.
54 | * It's useful when creating demos for multiple engines to specify all units in pixels multiplied by worldScale so that the same values
55 | * can be used for all engines.
56 | * Automatically calculated during setWorldScale(). Equals 1 / drawScale.
57 | * @type {number}
58 | */
59 | protected worldScale = 1;
60 |
61 | protected _enableDrawing:boolean = true;
62 | protected autoClearCanvas = false;
63 |
64 | protected overlays:Overlay[];
65 |
66 | protected demoMouseDownHook:() => void;
67 | protected demoMouseUpHook:() => void;
68 | protected mouseAction:MouseAction;
69 | protected mousePressed = false;
70 |
71 | constructor(canvas:HTMLCanvasElement, frameRate:number)
72 | {
73 | this.canvas = canvas;
74 | this.context = this.canvas.getContext('2d');
75 | this.stageWidth = canvas.width;
76 | this.stageHeight = canvas.height;
77 |
78 | this.frameRate = frameRate;
79 | this.frameRateInterval = 1 / frameRate;
80 |
81 | Overlay.bounds.set(0, 0, this.stageWidth, this.stageHeight);
82 |
83 | this.setup();
84 | }
85 |
86 | abstract setup();
87 |
88 | /**
89 | * super.clear() is required for all Demos overriding this method
90 | */
91 | clear()
92 | {
93 | this.overlays = [];
94 | this.demoMouseDownHook = null;
95 | }
96 |
97 | public clearCanvas()
98 | {
99 | this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
100 | }
101 |
102 | loadDemo(name:string)
103 | {
104 | this.clear();
105 |
106 | let demoFunc = this['loadDemo' + name];
107 | if(demoFunc)
108 | {
109 | demoFunc.call(this);
110 | }
111 | else
112 | {
113 | this.addWarning(this.stageWidth / 2, 20, `Cannot find "${name}" demo for "${this.name}" engine`);
114 | }
115 | }
116 |
117 | loadDemoCommon:(...args) => void;
118 | loadDemoBasic:() => void;
119 | loadDemoStress:() => void;
120 | loadDemoConstraints:() => void;
121 | loadDemoRagdolls:() => void;
122 |
123 | /**
124 | * Runs this demo. Demos must not override this method and use runInternal instead.
125 | * @param deltaTime
126 | * @param timestamp
127 | */
128 | run = (deltaTime:number, timestamp:number) =>
129 | {
130 | this.runInternal(deltaTime, timestamp);
131 |
132 | if(this._enableDrawing)
133 | {
134 | this.renderOverlays();
135 | }
136 | };
137 |
138 | protected abstract runInternal(deltaTime:number, timestamp:number);
139 |
140 | protected renderOverlays()
141 | {
142 | const context = this.context;
143 |
144 | for(let overlay of this.overlays)
145 | {
146 | overlay.render(context);
147 | }
148 | }
149 |
150 | protected setDrawScale(newScale)
151 | {
152 | this.drawScale = newScale;
153 | this.worldScale = 1 / newScale;
154 | }
155 |
156 | /*
157 | *** Getters, Setters
158 | */
159 |
160 | public get enableDrawing():boolean
161 | {
162 | return this._enableDrawing;
163 | }
164 |
165 | public set enableDrawing(value:boolean)
166 | {
167 | this._enableDrawing = value;
168 |
169 | if(!value)
170 | {
171 | if(this.autoClearCanvas)
172 | {
173 | this.clearCanvas();
174 | }
175 |
176 | this.onDisableDrawing();
177 | }
178 | }
179 |
180 | get positionIterations():number
181 | {
182 | return this._positionIterations;
183 | }
184 | set positionIterations(value:number)
185 | {
186 | if(this._positionIterations == value)
187 | return;
188 |
189 | this._positionIterations = value;
190 | this.onPositionIterationsUpdate(value);
191 | }
192 |
193 | get velocityIterations():number
194 | {
195 | return this._velocityIterations;
196 | }
197 | set velocityIterations(value:number)
198 | {
199 | if(this._velocityIterations == value)
200 | return;
201 |
202 | this._velocityIterations = value;
203 | this.onVelocityIterationsUpdate(value);
204 | }
205 |
206 | /*
207 | *** Utility Methods
208 | */
209 |
210 | public addOverlay(x, y, message:string, icon:OverlayIconDef = null, options?:OverlayOptions)
211 | {
212 | this.overlays.push(new Overlay(x, y, message, icon, options));
213 | return this.overlays[this.overlays.length - 1];
214 | }
215 | public addWarning(x, y, message:string, options?:OverlayOptions)
216 | {
217 | this.overlays.push(new Overlay(x, y, message, OverlayIcons.Warning, options));
218 | return this.overlays[this.overlays.length - 1];
219 | }
220 | public addInfo(x, y, message:string, options?:OverlayOptions)
221 | {
222 | this.overlays.push(new Overlay(x, y, message, OverlayIcons.Info, options));
223 | return this.overlays[this.overlays.length - 1];
224 | }
225 |
226 | /**
227 | * Utility to pin a body.
228 | */
229 | protected abstract pinBody(body:T, pinned?:Boolean):T;
230 | /**
231 | * Utility to create a (optionally) pinned body with the given shape
232 | */
233 | protected abstract createBody(x:number, y:number, shape:any, pinned?:boolean):T;
234 | /**
235 | * Box utility.
236 | */
237 | protected abstract createBox(x:number, y:number, width:number, height:number, pinned?:boolean):T;
238 | /**
239 | * Circle utility.
240 | */
241 | protected abstract createCircle(x:number, y:number, radius:number, pinned?:boolean):T;
242 |
243 | protected abstract createFromData(x:number, y:number, data:any);
244 |
245 | static Box(x, y, w, h, format:VertFormat = VertFormat.Array, VertexClass:IVertex = null):Array|{x:number, y:number}|any>
246 | {
247 | var vertices = [];
248 | const useArray = format == VertFormat.Array;
249 |
250 | const hw = w / 2;
251 | const hh = h / 2;
252 |
253 | const boxVertices = [
254 | x + hw, y + hh,
255 | x - hw, y + hh,
256 | x - hw, y - hh,
257 | x + hw, y - hh
258 | ];
259 |
260 | for(let a = 0; a < 8; a += 2)
261 | {
262 | let x = boxVertices[a];
263 | let y = boxVertices[a + 1];
264 |
265 | if(VertexClass)
266 | vertices.push(new VertexClass(x, y));
267 | else
268 | vertices.push(useArray ? [x, y] : {x: x, y:y});
269 | }
270 |
271 | return vertices;
272 | }
273 |
274 | static Regular(xRadius, yRadius, edgeCount, angleOffset = 0, format:VertFormat = VertFormat.Array, VertexClass:IVertex = null):Array|{x:number, y:number}|any>
275 | {
276 | var vertices = [];
277 | const useArray = format == VertFormat.Array;
278 |
279 | for(let a = 0; a < edgeCount; a++)
280 | {
281 | let x = xRadius * Math.cos(angleOffset + 2 * Math.PI * (a / edgeCount));
282 | let y = yRadius * Math.sin(angleOffset + 2 * Math.PI * (a / edgeCount));
283 |
284 | if(VertexClass)
285 | vertices.push(new VertexClass(x, y));
286 | else
287 | vertices.push(useArray ? [x, y] : {x: x, y:y});
288 | }
289 |
290 | return vertices;
291 | }
292 |
293 | static drawCircle(context:CanvasRenderingContext2D, x, y, radius)
294 | {
295 | context.moveTo(x, y);
296 | context.arc(x, y, radius, 0, 2 * Math.PI, false);
297 | }
298 |
299 | /*
300 | *** Events
301 | */
302 |
303 | protected onDisableDrawing() { }
304 |
305 | protected onPositionIterationsUpdate(iterations:number) { }
306 |
307 | protected onVelocityIterationsUpdate(iterations:number) { }
308 |
309 | handleMouseDown(event?)
310 | {
311 | this.mousePressed = true;
312 | this.onMouseDown();
313 |
314 | if(this.demoMouseDownHook && this.mouseAction == MouseAction.Idle)
315 | this.demoMouseDownHook();
316 | }
317 | handleMouseUp(event?)
318 | {
319 | this.mousePressed = false;
320 | this.onMouseUp();
321 |
322 | if(this.demoMouseUpHook && this.mouseAction == MouseAction.Idle)
323 | this.demoMouseUpHook();
324 |
325 | this.mouseAction = MouseAction.Idle;
326 | }
327 |
328 | protected onMouseDown() { }
329 | protected onMouseUp() { }
330 |
331 | }
332 |
333 | }
--------------------------------------------------------------------------------
/src/engines/MatterDemo.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
4 | namespace engines
5 | {
6 |
7 | import Engine = Matter.Engine;
8 | import Render = Matter.Render;
9 | import World = Matter.World;
10 | import Bodies = Matter.Bodies;
11 | import Body = Matter.Body;
12 | import MouseConstraint = Matter.MouseConstraint;
13 | import Constraint = Matter.Constraint;
14 | import Composite = Matter.Composite;
15 | import Bounds = Matter.Bounds;
16 | import Detector = Matter.Detector;
17 | import Vertices = Matter.Vertices;
18 | import Sleeping = Matter.Sleeping;
19 | import Events = Matter.Events;
20 | import Mouse = Matter.Mouse;
21 | import Vector = Matter.Vector;
22 |
23 | export class MatterDemo extends DemoEngineBase
24 | {
25 |
26 | public name:string = 'Matter';
27 |
28 | protected engine:Engine;
29 | protected world:World;
30 | protected render:Render;
31 |
32 | protected simulationTime:number = 0;
33 | protected elapsedTime:number = 0;
34 | protected frameRateIntervalMs:number;
35 |
36 | protected mouseConstraint:MouseConstraint;
37 | protected groundBody:Body;
38 |
39 | protected mousePressed = false;
40 |
41 | setup()
42 | {
43 | super.clear();
44 |
45 | this.engine = Engine.create({
46 | enableSleeping: true
47 | });
48 | this.world = this.engine.world;
49 | this.render = Render.create({
50 | canvas: this.canvas,
51 | engine: this.engine,
52 | options: {
53 | showAngleIndicator: true,
54 | }
55 | });
56 |
57 | const w = this.stageWidth;
58 | const h = this.stageHeight;
59 | const hw = w / 2;
60 | const hh = h / 2;
61 | const t = 200;
62 | const ht = t/2;
63 |
64 | var top = Bodies.rectangle(hw, -ht, w+t, t);
65 | var bot = Bodies.rectangle(hw, h+ht, w+t, t);
66 | var lef = Bodies.rectangle(-ht, hh, t, h+t);
67 | var rig = Bodies.rectangle(w+ht, hh, t, h+t);
68 | this.groundBody = Body.create({parts: [top, bot, lef, rig], isStatic: true});
69 |
70 | this.mouseConstraint = MouseConstraint.create(this.engine, {
71 | mouse: Mouse.create(this.canvas)
72 | });
73 | this.mouseConstraint.constraint.stiffness = 0.75;
74 | (this.mouseConstraint.constraint as any).angularStiffness = 0;
75 |
76 | this.frameRateIntervalMs = 1000 / this.frameRate;
77 | this.autoClearCanvas = true;
78 | }
79 |
80 | clear()
81 | {
82 | super.clear();
83 |
84 | this.simulationTime = 0;
85 | this.elapsedTime = 0;
86 | this.engine.enableSleeping = true;
87 | World.clear(this.world, false);
88 | }
89 |
90 | loadDemo(name:string)
91 | {
92 | super.loadDemo(name);
93 |
94 | World.add(this.world, this.groundBody);
95 | World.addConstraint(this.world, this.mouseConstraint.constraint);
96 | }
97 |
98 | protected runInternal(deltaTime:number, timestamp:number)
99 | {
100 | if(deltaTime > 0.05)
101 | {
102 | deltaTime = 0.05;
103 | }
104 |
105 | this.simulationTime += deltaTime;
106 |
107 | if(this.mousePressed)
108 | {
109 | if(this.mouseConstraint.body)
110 | {
111 | this.mouseAction = MouseAction.Handled;
112 | }
113 | }
114 |
115 | // Keep on stepping forward by fixed time step until amount of time
116 | // needed has been simulated.
117 | while(this.elapsedTime < this.simulationTime)
118 | {
119 | Engine.update(this.engine, this.frameRateIntervalMs);
120 | this.elapsedTime += this.frameRateInterval;
121 | }
122 |
123 | Events.trigger(this.engine, 'tick', {
124 | timestamp: this.simulationTime * 1000
125 | });
126 |
127 | if(this._enableDrawing)
128 | {
129 | Render.world(this.render);
130 | }
131 | };
132 |
133 | /*
134 | *** Utility Methods
135 | */
136 |
137 | protected pinBody(body:Body, pinned?:Boolean):Body
138 | {
139 | if(pinned)
140 | {
141 | var joint = Constraint.create({
142 | bodyB: body,
143 | // pointA: Vector.create(0,0),
144 | pointA: Vector.clone(body.position),
145 | });
146 | World.add(this.world, joint);
147 | }
148 |
149 | return body;
150 | }
151 | protected createBody(x:number, y:number, shape:any, pinned?:boolean)
152 | {
153 | throw new Error('MatterJs does not have the concept of shapes. createBody method not supported.');
154 | }
155 | protected createBox(x:number, y:number, width:number, height:number, pinned?:boolean)
156 | {
157 | var body = this.pinBody(Bodies.rectangle(x, y, width * 2, height * 2), pinned);
158 | World.add(this.world, body);
159 | return body;
160 | }
161 | protected createCircle(x:number, y:number, radius:number, pinned?:boolean)
162 | {
163 | var body = this.pinBody(Bodies.circle(x, y, radius), pinned);
164 | World.add(this.world, body);
165 | return body;
166 | }
167 |
168 | protected createFromData(x:number, y:number, data:any)
169 | {
170 | const WORLD_SCALE = this.worldScale;
171 | const DEG2RAD = 1 / (180 / Math.PI);
172 |
173 | const bodiesData = data.bodies;
174 | const jointsData = data.joints;
175 | const bodyRegistry:{[id:string]:Body} = {};
176 |
177 | // x *= WORLD_SCALE;
178 | // y *= WORLD_SCALE;
179 |
180 | if(bodiesData)
181 | for(let bodyData of bodiesData)
182 | {
183 | let isStatic:boolean;
184 | let px = x + bodyData.x;
185 | let py = y + bodyData.y;
186 | let body;
187 |
188 | if(!bodyData.shape) continue;
189 |
190 | if(bodyData.type === undefined || bodyData.type === 'dynamic')
191 | isStatic = false;
192 | else if(bodyData.type === 'static')
193 | isStatic = true;
194 | else if(bodyData.type === 'kinematic')
195 | isStatic = false;
196 |
197 | const shapeData = bodyData.shape;
198 | const shapeType = shapeData.type;
199 | const options = {isStatic: isStatic};
200 |
201 | if(shapeType === 'box')
202 | body = Bodies.rectangle(px, py, shapeData.width, shapeData.height, options);
203 | else if(shapeType === 'circle')
204 | body = Bodies.circle(px, py, shapeData.radius, options);
205 | else
206 | console.error(`Unsupported shape type "${shapeType}"`);
207 |
208 | if(shapeData.density !== undefined)
209 | body.density = shapeData.density;
210 | if(shapeData.friction !== undefined)
211 | body.friction = shapeData.friction;
212 | if(shapeData.restitution !== undefined)
213 | body.restitution = shapeData.restitution;
214 |
215 | World.add(this.world, body);
216 | if(bodyData.id !== undefined)
217 | {
218 | bodyRegistry[bodyData.id] = body;
219 | }
220 |
221 | if(bodyData.impulse)
222 | {
223 | let impulse:Vector;
224 |
225 | if(bodyData.impulse.hasOwnProperty('x') && bodyData.impulse.hasOwnProperty('y'))
226 | {
227 | impulse = bodyData.impulse;
228 | }
229 | else if(bodyData.impulse instanceof Array)
230 | {
231 | impulse = Vector.create(bodyData.impulse[0], bodyData.impulse[1]);
232 | }
233 | else if(bodyData.impulse instanceof Function)
234 | {
235 | let impulseData = bodyData.impulse();
236 | impulse = Vector.create(impulseData[0], impulseData[1]);
237 | }
238 |
239 | if(impulse)
240 | Body.applyForce(body, Vector.create(px, py), Vector.create(impulse.x / 10000, impulse.y / 10000));
241 | }
242 | }
243 |
244 | if(jointsData)
245 | for(let jointData of jointsData)
246 | {
247 | const type = jointData.type;
248 | const body1 = bodyRegistry[jointData.body1];
249 | const body2 = bodyRegistry[jointData.body2];
250 |
251 | if(!body1 || !body2)
252 | {
253 | console.error(`Cannot find body with id "${!body1 ? jointData.body1 : jointData.body2}"`);
254 | continue;
255 | }
256 |
257 | if(type == 'revolute')
258 | {
259 | var worldPivot = Vector.create(x + jointData.worldAnchorX, y + jointData.worldAnchorY);
260 | var joint = Constraint.create({
261 | bodyA: body1,
262 | bodyB: body2,
263 | pointA: MatterDemo.globalToLocal(body1, worldPivot),
264 | pointB: MatterDemo.globalToLocal(body2, worldPivot),
265 | stiffness: 0.1,
266 | length: 2
267 | });
268 | World.add(this.world, joint);
269 |
270 | // if(jointData.lowerLimit != undefined || jointData.upperLimit != undefined)
271 | // {
272 | // jointDef.enableLimit = true;
273 | // if(jointData.lowerLimit != undefined)
274 | // jointDef.lowerAngle = jointData.lowerLimit * DEG2RAD;
275 | // if(jointData.upperLimit != undefined)
276 | // jointDef.upperAngle = jointData.upperLimit * DEG2RAD;
277 | // }
278 | }
279 | else
280 | {
281 | console.error(`Unsupported joint type "${type}"`);
282 | }
283 | }
284 | }
285 |
286 | public static globalToLocal(body:Body, worldPoint:Vector, out:Vector = null)
287 | {
288 | if(!out)
289 | {
290 | out = Vector.create();
291 | }
292 |
293 | const sin = Math.sin(-body.angle);
294 | const cos = Math.cos(-body.angle);
295 | const x = worldPoint.x - body.position.x;
296 | const y = worldPoint.y - body.position.y;
297 | out.x = (x * cos - y * sin);
298 | out.y = (x * sin + y * cos);
299 |
300 | return out;
301 | }
302 |
303 | /*
304 | *** Events
305 | */
306 |
307 | protected onPositionIterationsUpdate(iterations:number)
308 | {
309 | this.engine.positionIterations = iterations;
310 | }
311 |
312 | protected onVelocityIterationsUpdate(iterations:number)
313 | {
314 | this.engine.velocityIterations = iterations;
315 | }
316 |
317 | }
318 |
319 | }
--------------------------------------------------------------------------------
/src/engines/NapeDemo.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 |
6 | namespace engines
7 | {
8 | import Vec2 = nape.geom.Vec2;
9 | import Space = nape.space.Space;
10 | import Stage = createjs.Stage;
11 | import ShapeDebug = nape.util.ShapeDebug;
12 | import Body = nape.phys.Body;
13 | import BodyType = nape.phys.BodyType;
14 | import Polygon = nape.shape.Polygon;
15 | import Circle = nape.shape.Circle;
16 | import BodyList = nape.phys.BodyList;
17 |
18 | import Constraint = nape.constraint.Constraint;
19 | import PivotJoint = nape.constraint.PivotJoint;
20 | import WeldJoint = nape.constraint.WeldJoint;
21 | import DistanceJoint = nape.constraint.DistanceJoint;
22 | import LineJoint = nape.constraint.LineJoint;
23 | import PulleyJoint = nape.constraint.PulleyJoint;
24 | import AngleJoint = nape.constraint.AngleJoint;
25 | import MotorJoint = nape.constraint.MotorJoint;
26 |
27 | import Overlay = overlay.Overlay;
28 | import Material = nape.phys.Material;
29 |
30 | export class NapeDemo extends DemoEngineBase
31 | {
32 | public name:string = 'Nape';
33 |
34 | protected stage:Stage;
35 | protected space:Space;
36 | protected debug:ShapeDebug;
37 |
38 | protected simulationTime:number = 0;
39 |
40 | protected handJoint:PivotJoint;
41 |
42 | setup()
43 | {
44 | this.space = new Space();
45 |
46 | var debug = this.debug = new ShapeDebug(2000, 2000);
47 | debug.thickness = 1;
48 | debug.drawBodies = true;
49 | debug.drawConstraints = true;
50 |
51 | this.stage = new Stage(this.canvas);
52 | this.stage.addChild(this.debug.display);
53 | }
54 |
55 | clear()
56 | {
57 | super.clear();
58 |
59 | this.simulationTime = 0;
60 | this.handJoint = null;
61 | this.space.clear();
62 | this.debug.clear();
63 | this.stage.update();
64 | }
65 |
66 | loadDemo(name:string)
67 | {
68 | super.loadDemo(name);
69 |
70 | const t = 200;
71 | const t2 = t * 2;
72 | var border:Body = new Body(BodyType.STATIC);
73 | border.shapes.add(new Polygon(Polygon.rect(-t, -t, this.stageWidth + t2, t)));
74 | border.shapes.add(new Polygon(Polygon.rect(-t, this.stageHeight, this.stageWidth + t2, t)));
75 | border.shapes.add(new Polygon(Polygon.rect(-t, -t, t, this.stageHeight + t2)));
76 | border.shapes.add(new Polygon(Polygon.rect(this.stageWidth, -t, t, this.stageHeight + t2)));
77 | border.space = this.space;
78 |
79 | this.handJoint = new PivotJoint(this.space.world, null, Vec2.weak(0,0), Vec2.weak(0,0));
80 | this.handJoint.space = this.space;
81 | this.handJoint.active = false;
82 | this.handJoint.stiff = false;
83 | }
84 |
85 | protected runInternal(deltaTime:number, timestamp:number)
86 | {
87 | if(deltaTime > 0.05)
88 | {
89 | deltaTime = 0.05;
90 | }
91 |
92 | this.simulationTime += deltaTime;
93 |
94 | if(this.handJoint.active)
95 | {
96 | this.handJoint.anchor1.setxy(this.mouseX, this.mouseY);
97 | }
98 |
99 | // Keep on stepping forward by fixed time step until amount of time
100 | // needed has been simulated.
101 | while(this.space.elapsedTime < this.simulationTime)
102 | {
103 | this.space.step(this.frameRateInterval, this._velocityIterations, this._positionIterations);
104 | }
105 |
106 | if(this._enableDrawing)
107 | {
108 | this.debug.clear();
109 | this.debug.draw(this.space);
110 | this.debug.flush();
111 | this.stage.update();
112 | }
113 | };
114 |
115 | /*
116 | *** Utility Methods
117 | */
118 |
119 | protected pinBody(body:Body, pinned?:Boolean):Body
120 | {
121 | if (pinned) {
122 | var pin:PivotJoint = new PivotJoint(
123 | this.space.world, body,
124 | body.position,
125 | Vec2.weak(0,0)
126 | );
127 | pin.space = this.space;
128 | }
129 |
130 | return body;
131 | }
132 | protected createBody(x:number, y:number, shape:any, pinned?:boolean):Body
133 | {
134 | var body:Body = new Body();
135 | body.position.setxy(x, y);
136 | body.shapes.add(shape);
137 | body.space = this.space;
138 |
139 | return this.pinBody(body, pinned);
140 | }
141 | protected createBox(x:number, y:number, width:number, height:number, pinned?:boolean):Body
142 | {
143 | return this.createBody(x, y, new Polygon(Polygon.box(width*2, height*2)), pinned);
144 | }
145 | protected createCircle(x:number, y:number, radius:number, pinned?:boolean):Body
146 | {
147 | return this.createBody(x, y, new Circle(radius), pinned);
148 | }
149 |
150 | protected createFromData(x:number, y:number, data:any)
151 | {
152 | const DEG2RAD = 1 / (180 / Math.PI);
153 |
154 | const bodiesData = data.bodies;
155 | const jointsData = data.joints;
156 | const bodyRegistry:{[id:string]:Body} = {};
157 |
158 | if(bodiesData)
159 | for(let bodyData of bodiesData)
160 | {
161 | let body:Body;
162 |
163 | if(bodyData.type === undefined || bodyData.type === 'dynamic')
164 | body = new Body(BodyType.DYNAMIC);
165 | else if(bodyData.type === 'static')
166 | body = new Body(BodyType.STATIC);
167 | else if(bodyData.type === 'kinematic')
168 | body = new Body(BodyType.KINEMATIC);
169 |
170 | if(bodyData.shape)
171 | {
172 | const shapeData = bodyData.shape;
173 | const shapeType = shapeData.type;
174 |
175 | if(shapeType === 'box')
176 | body.shapes.add(new Polygon(Polygon.box(shapeData.width, shapeData.height)));
177 | else if(shapeType === 'circle')
178 | body.shapes.add(new Circle(shapeData.radius));
179 | else
180 | console.error(`Unsupported shape type "${shapeType}"`);
181 |
182 | let mat = new Material();
183 |
184 | if(shapeData.density !== undefined)
185 | mat.density = shapeData.density;
186 | if(shapeData.friction !== undefined)
187 | mat.dynamicFriction = shapeData.friction;
188 | if(shapeData.restitution !== undefined)
189 | mat.elasticity = shapeData.restitution;
190 | }
191 |
192 | body.position.setxy(x + bodyData.x, y + bodyData.y);
193 | body.space = this.space;
194 | if(bodyData.id !== undefined)
195 | {
196 | bodyRegistry[bodyData.id] = body;
197 | }
198 |
199 | if(bodyData.impulse)
200 | {
201 | let impulse:Vec2;
202 |
203 | if(bodyData.impulse instanceof Vec2)
204 | {
205 | impulse = bodyData.impulse;
206 | }
207 | if(bodyData.impulse instanceof Array)
208 | {
209 | impulse = bodyData.impulse;
210 | }
211 | else if(bodyData.impulse.hasOwnProperty('x') && bodyData.impulse.hasOwnProperty('y'))
212 | {
213 | impulse = Vec2.weak(bodyData.impulse.x, bodyData.impulse.y);
214 | }
215 | else if(bodyData.impulse instanceof Function)
216 | {
217 | let impulseData = bodyData.impulse();
218 | impulse = Vec2.weak(impulseData[0], impulseData[1]);
219 | }
220 |
221 | if(impulse)
222 | body.applyImpulse(impulse);
223 | }
224 | }
225 |
226 | if(jointsData)
227 | for(let jointData of jointsData)
228 | {
229 | const type = jointData.type;
230 | const body1 = bodyRegistry[jointData.body1];
231 | const body2 = bodyRegistry[jointData.body2];
232 |
233 | if(!body1 || !body2)
234 | {
235 | console.error(`Cannot find body with id "${!body1 ? jointData.body1 : jointData.body2}"`);
236 | continue;
237 | }
238 |
239 | if(type == 'revolute')
240 | {
241 | var pivotPoint:Vec2 = Vec2.get(x + jointData.worldAnchorX, y + jointData.worldAnchorY);
242 | var pivotJoint = new PivotJoint(
243 | body1, body2,
244 | body1.worldPointToLocal(pivotPoint, true),
245 | body2.worldPointToLocal(pivotPoint, true)
246 | );
247 |
248 | pivotJoint.ignore = jointData.collideConnected != undefined ? jointData.collideConnected : true;
249 | pivotJoint.space = this.space;
250 |
251 | if(jointData.lowerLimit != undefined || jointData.upperLimit != undefined)
252 | {
253 | let angleJoint = new AngleJoint(body1, body2,
254 | jointData.lowerLimit != undefined ? jointData.lowerLimit * DEG2RAD : -Number.MAX_VALUE,
255 | jointData.upperLimit != undefined ? jointData.upperLimit * DEG2RAD : Number.MAX_VALUE);
256 | angleJoint.debugDraw = false;
257 | angleJoint.space = this.space;
258 | }
259 |
260 | pivotPoint.dispose();
261 | }
262 | else
263 | {
264 | console.error(`Unsupported joint type "${type}"`);
265 | }
266 | }
267 | }
268 |
269 | /*
270 | *** Events
271 | */
272 |
273 | protected onDisableDrawing()
274 | {
275 | this.debug.clear();
276 | this.stage.update();
277 | }
278 |
279 | onMouseDown()
280 | {
281 | // Allocate a Vec2 from object pool.
282 | var mousePoint:Vec2 = Vec2.get(this.mouseX, this.mouseY, false);
283 |
284 | // Determine the set of Body's which are intersecting mouse point.
285 | // And search for any 'dynamic' type Body to begin dragging.
286 | var bodies:BodyList = this.space.bodiesUnderPoint(mousePoint);
287 | for (var i:number = 0; i < bodies.length; i++) {
288 | var body:Body = bodies.at(i);
289 |
290 | if (!body.isDynamic()) {
291 | continue;
292 | }
293 |
294 | // Configure hand joint to drag this body.
295 | // We initialise the anchor point on this body so that
296 | // constraint is satisfied.
297 | //
298 | // The second argument of worldPointToLocal means we get back
299 | // a 'weak' Vec2 which will be automatically sent back to object
300 | // pool when setting the handJoint's anchor2 property.
301 | this.handJoint.body2 = body;
302 | this.handJoint.anchor2.set(body.worldPointToLocal(mousePoint, true));
303 |
304 | // Enable hand joint!
305 | this.handJoint.active = true;
306 | this.mouseAction = MouseAction.Handled;
307 |
308 | break;
309 | }
310 |
311 | // Release Vec2 back to object pool.
312 | mousePoint.dispose();
313 | };
314 |
315 | onMouseUp()
316 | {
317 | // Disable hand joint (if not already disabled).
318 | this.handJoint.active = false;
319 | };
320 |
321 | }
322 | }
--------------------------------------------------------------------------------
/src/engines/PhysicsJsDemo.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
4 | namespace engines
5 | {
6 |
7 | export class PhysicsJsDemo extends DemoEngineBase
8 | {
9 |
10 | public name:string = 'PhysicsJs';
11 |
12 | world:PhysicsWorld;
13 | gravity;
14 | renderer:CanvasRenderer;
15 | bodies:PhysicsBody[];
16 | constraints:PhysicsVerletConstraintsBehavior;
17 |
18 | setup()
19 | {
20 | super.clear();
21 |
22 | this.autoClearCanvas = true;
23 | this.bodies = [];
24 |
25 | Physics(
26 | {
27 | timestep: this.frameRateInterval * 1000
28 | },
29 | (world:PhysicsWorld) =>
30 | {
31 | this.world = world;
32 | this.renderer = Physics.renderer('canvas', {
33 | el: 'renderCanvas', // id of the canvas element
34 | autoResize: false,
35 | width: this.canvas.width,
36 | height: this.canvas.height
37 | });
38 | this.gravity = Physics.behavior('constant-acceleration');
39 |
40 | world.add([
41 | this.renderer,
42 | this.gravity,
43 | Physics.behavior('body-impulse-response'),
44 | Physics.behavior('body-collision-detection'),
45 | Physics.behavior('sweep-prune'),
46 | Physics.behavior('interactive', { el: this.canvas }),
47 | Physics.behavior('edge-collision-detection', {
48 | aabb: Physics.aabb(0, 0, this.stageWidth, this.stageHeight),
49 | restitution: 0.05
50 | }),
51 | this.constraints = Physics.behavior('verlet-constraints', {
52 | iterations: 3
53 | })
54 | ]);
55 |
56 | world.on('interact:grab', this.onBodyGrab.bind(this));
57 | }
58 | );
59 | }
60 |
61 | clear()
62 | {
63 | super.clear();
64 | this.clearCanvas();
65 |
66 | if(this.bodies.length)
67 | {
68 | this.world.remove(this.bodies);
69 | this.bodies = [];
70 | }
71 |
72 | this.constraints.drop();
73 | }
74 |
75 | loadDemo(name:string)
76 | {
77 | super.loadDemo(name);
78 | }
79 |
80 | protected runInternal(deltaTime:number, timestamp:number)
81 | {
82 | this.world.step(timestamp);
83 |
84 | if(this._enableDrawing)
85 | {
86 | this.world.render();
87 | }
88 | };
89 |
90 | /*
91 | *** Utility Methods
92 | */
93 |
94 | protected pinBody(body:PhysicsBody, pinned?:Boolean):PhysicsBody
95 | {
96 | return body;
97 | }
98 | protected createBody(x:number, y:number, shape:any, pinned?:boolean)
99 | {
100 | throw new Error('PhysicsJs does not have the concept of shapes. createBody method not supported.');
101 | }
102 | protected createBox(x:number, y:number, width:number, height:number, pinned?:boolean)
103 | {
104 | var body = this.pinBody(Physics.body('rectangle', {
105 | x: x,
106 | y: y,
107 | width: width * 2,
108 | height: height * 2,
109 | restitution: 0.3
110 | }), pinned);
111 | this.bodies.push(body);
112 |
113 | return body;
114 | }
115 | protected createCircle(x:number, y:number, radius:number, pinned?:boolean)
116 | {
117 | var body = this.pinBody(Physics.body('circle', {
118 | x: x,
119 | y: y,
120 | radius: radius,
121 | restitution: 0.3
122 | }), pinned);
123 | this.bodies.push(body);
124 |
125 | return body;
126 | }
127 |
128 | protected createFromData(x:number, y:number, data:any)
129 | {
130 | const WORLD_SCALE = this.worldScale;
131 | const DEG2RAD = 1 / (180 / Math.PI);
132 |
133 | const bodiesData = data.bodies;
134 | const jointsData = data.joints;
135 | const bodyRegistry:{[id:string]:PhysicsBody} = {};
136 | const bodies = [];
137 |
138 | x *= WORLD_SCALE;
139 | y *= WORLD_SCALE;
140 |
141 | if(bodiesData)
142 | for(let bodyData of bodiesData)
143 | {
144 | if(!bodyData.shape)
145 | {
146 | continue;
147 | }
148 |
149 | let bodyType:string;
150 | let options:any = {
151 | x: x + bodyData.x * WORLD_SCALE,
152 | y: y + bodyData.y * WORLD_SCALE
153 | };
154 |
155 | if(bodyData.type === undefined || bodyData.type === 'dynamic')
156 | options.treatment = 'dynamic';
157 | else if(bodyData.type === 'static')
158 | options.treatment = 'static';
159 | else if(bodyData.type === 'kinematic')
160 | options.treatment = 'kinematic';
161 |
162 | const shapeData = bodyData.shape;
163 | const shapeType = shapeData.type;
164 |
165 | if(shapeType === 'box')
166 | {
167 | bodyType = 'rectangle';
168 | options.width = shapeData.width * WORLD_SCALE;
169 | options.height = shapeData.height * WORLD_SCALE;
170 | }
171 | else if(shapeType === 'circle')
172 | {
173 | bodyType = 'circle';
174 | options.radius = shapeData.radius * WORLD_SCALE;
175 | }
176 | else
177 | console.error(`Unsupported shape type "${shapeType}"`);
178 |
179 | // if(shapeData.density !== undefined)
180 | // options.density = shapeData.density;
181 | if(shapeData.friction !== undefined)
182 | options.cof = shapeData.friction;
183 | if(shapeData.restitution !== undefined)
184 | options.restitution = shapeData.restitution;
185 |
186 | var body:PhysicsBody = Physics.body(bodyType, options);
187 | this.bodies.push(body);
188 | bodies.push(body);
189 | if(bodyData.id !== undefined)
190 | {
191 | bodyRegistry[bodyData.id] = body;
192 | }
193 |
194 | if(bodyData.impulse)
195 | {
196 | let impulse:{x,y};
197 |
198 | if(bodyData.impulse.hasOwnProperty('x') && bodyData.impulse.hasOwnProperty('y'))
199 | {
200 | impulse = bodyData.impulse;
201 | }
202 | else if(bodyData.impulse instanceof Array)
203 | {
204 | impulse = {x: bodyData.impulse[0], y: bodyData.impulse[1]};
205 | }
206 | else if(bodyData.impulse instanceof Function)
207 | {
208 | let impulseData = bodyData.impulse();
209 | impulse = {x: impulseData[0], y: impulseData[1]};
210 | }
211 |
212 | if(impulse)
213 | body.applyForce({x: impulse.x / 10000 * WORLD_SCALE, y: impulse.y / 10000 * WORLD_SCALE});
214 | }
215 | }
216 |
217 | this.world.add(bodies);
218 |
219 | if(jointsData)
220 | for(let jointData of jointsData)
221 | {
222 | const type = jointData.type;
223 | const body1 = bodyRegistry[jointData.body1];
224 | const body2 = bodyRegistry[jointData.body2];
225 |
226 | if(!body1 || !body2)
227 | {
228 | console.error(`Cannot find body with id "${!body1 ? jointData.body1 : jointData.body2}"`);
229 | continue;
230 | }
231 |
232 | if(type == 'revolute')
233 | {
234 | this.constraints.distanceConstraint(body1, body2);
235 | }
236 | else
237 | {
238 | console.error(`Unsupported joint type "${type}"`);
239 | }
240 | }
241 | }
242 |
243 | /*
244 | *** Events
245 | */
246 |
247 | protected onBodyGrab(data)
248 | {
249 | this.mouseAction = MouseAction.Handled;
250 | }
251 |
252 | }
253 |
254 | }
--------------------------------------------------------------------------------
/src/utils/Utils.ts:
--------------------------------------------------------------------------------
1 | namespace utils
2 | {
3 |
4 | export function applyDefaults(input:T, defaults:T):T
5 | {
6 | for(var attr in defaults)
7 | {
8 | if(defaults.hasOwnProperty(attr) && !input.hasOwnProperty(attr))
9 | input[attr] = defaults[attr];
10 | }
11 |
12 | return input;
13 | }
14 |
15 | }
--------------------------------------------------------------------------------