-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c80fe7f
Showing
43 changed files
with
11,025 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
// settings | ||
"passfail" : false, // Stop on first error. | ||
"maxerr" : 100, // Maximum error before stopping. | ||
|
||
// dev | ||
"debug" : false, // Allow debugger statements e.g. browser breakpoints. | ||
"devel" : true, // Allow developments statements e.g. `console.log();`. | ||
|
||
// ECMAScript 5 | ||
"es5" : false, // Allow ECMAScript 5 syntax. | ||
"strict" : false, // Require `use strict` pragma in every file. | ||
"globalstrict" : false, // Allow global "use strict" (also enables 'strict'). | ||
|
||
// options | ||
"laxbreak" : true, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons. | ||
|
||
// style | ||
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`. | ||
"noempty" : true, // Prohibit use of empty blocks. | ||
"nonew" : true, // Prohibit use of constructors for side-effects. | ||
"onevar" : false, // Allow only one `var` statement per function. | ||
"plusplus" : false, // Prohibit use of `++` & `--`. | ||
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`. | ||
"trailing" : false, // Prohibit trailing whitespaces. | ||
"white" : false, // Check against strict whitespace and indentation rules. | ||
"indent" : 4 // Specify indentation spacing | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
module.exports = function(grunt) { | ||
grunt.initConfig({ | ||
pkg: grunt.file.readJSON('package.json'), | ||
concat: { | ||
build: { | ||
options: { | ||
process: function(src, filepath) { | ||
return '// Begin ' + filepath + '\n\n' + src + '\n\n; // End ' + filepath + '\n\n'; | ||
} | ||
}, | ||
src: ['src/**/*.js', '!src/module/*'], | ||
dest: 'build/<%= pkg.name %>.js' | ||
}, | ||
pack: { | ||
options: { | ||
banner: '/**\n* <%= pkg.name %>.js <%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %>\n* <%= pkg.homepage %>\n* License: <%= pkg.license %>\n*/\n\n', | ||
}, | ||
src: ['src/module/Intro.js', 'build/<%= pkg.name %>.js', 'src/module/Outro.js'], | ||
dest: 'build/<%= pkg.name %>.js' | ||
} | ||
}, | ||
uglify: { | ||
options: { | ||
banner: '/**\n* <%= pkg.name %>.min.js <%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %>\n* <%= pkg.homepage %>\n* License: <%= pkg.license %>\n*/\n\n', | ||
}, | ||
build: { | ||
src: 'build/<%= pkg.name %>.js', | ||
dest: 'build/<%= pkg.name %>.min.js' | ||
} | ||
}, | ||
copy: { | ||
demo: { | ||
src: 'build/<%= pkg.name %>.js', | ||
dest: 'demo/js/lib/<%= pkg.name %>.js' | ||
} | ||
}, | ||
jshint: { | ||
options: { | ||
jshintrc: '.jshintrc' | ||
}, | ||
all: ['src/**/*.js', '!src/module/*'] | ||
}, | ||
connect: { | ||
watch: { | ||
options: { | ||
port: 9000, | ||
open: 'http://localhost:9000/demo', | ||
livereload: 9001 | ||
} | ||
} | ||
}, | ||
watch: { | ||
options: { | ||
livereload: { | ||
port: 9001 | ||
} | ||
}, | ||
src: { | ||
files: ['src/**/*.js'], | ||
tasks: ['concat', 'uglify', 'copy'] | ||
}, | ||
demo: { | ||
files: ['build/matter.js', 'demo/js/**/*.html', 'demo/js/**/*.js', 'demo/css/**/*.css'] | ||
} | ||
}, | ||
}); | ||
|
||
grunt.loadNpmTasks('grunt-contrib-concat'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-contrib-connect'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-copy'); | ||
|
||
grunt.registerTask('default', ['test', 'concat', 'uglify', 'copy']); | ||
grunt.registerTask('test', ['jshint']); | ||
grunt.registerTask('dev', ['connect:watch', 'watch']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Liam Brummitt | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# Matter.js | ||
|
||
*Matter.js* is a 2D rigid body physics engine for the web written in JavaScript (yes, another) | ||
|
||
[brm.io/matter-js](http://brm.io/matter-js) | ||
|
||
### Demos | ||
|
||
- [Mixed Shapes](http://brm.io/matter-js-demo#mixed) | ||
- [Solid Shapes](http://brm.io/matter-js-demo#mixedSolid) | ||
- [Stack](http://brm.io/matter-js-demo#stack) | ||
- [Circle Stack](http://brm.io/matter-js-demo#circleStack) | ||
- [Pyramid](http://brm.io/matter-js-demo#pyramid) | ||
- [Car](http://brm.io/matter-js-demo#car) | ||
- [Newton's Cradle](http://brm.io/matter-js-demo#newtonsCradle) | ||
- [Restitution](http://brm.io/matter-js-demo#restitution) | ||
- [Friction](http://brm.io/matter-js-demo#friction) | ||
- [Air Friction](http://brm.io/matter-js-demo#airFriction) | ||
- [Reverse Gravity](http://brm.io/matter-js-demo#gravity) | ||
- [Sleeping](http://brm.io/matter-js-demo#sleeping) | ||
- [Grid Broadphase](http://brm.io/matter-js-demo#broadphase) | ||
- [Chains](http://brm.io/matter-js-demo#chains) | ||
- [Ball Pool](http://brm.io/matter-js-demo#ballPool) | ||
- [Wrecking Ball](http://brm.io/matter-js-demo#wreckingBall) | ||
- [Avalanche](http://brm.io/matter-js-demo#avalanche) | ||
- [Beach Balls](http://brm.io/matter-js-demo#beachBalls) | ||
- [Stress 1](http://brm.io/matter-js-demo#stress) | ||
- [Stress 2](http://brm.io/matter-js-demo#stress2) | ||
|
||
### Features | ||
|
||
- Physical properties (mass, area, density etc.) | ||
- Rigid bodies of any convex polygon | ||
- Stable stacking and resting | ||
- Restitution (elastic and inelastic collisions) | ||
- Conservation of momentum | ||
- Friction and resistance | ||
- Constraints | ||
- Gravity | ||
- Composite bodies | ||
- Sleeping and static bodies | ||
- Original JavaScript physics implementation (not a port) | ||
- HTML5 canvas renderer | ||
- Mobile-compatible (touch, scaleable) | ||
- Cross-browser (chrome, firefox, IE8+) | ||
- World state serialisation (requires | ||
[resurrect.js](https://github.com/skeeto/resurrect-js)) | ||
- Built in GUI for testing (requires | ||
[dat.gui.js](http://workshop.chromeexperiments.com/examples/gui/)) | ||
- Time scaling (slow-mo, speed-up) | ||
- Broad-phase, mid-phase and narrow-phase collisions | ||
|
||
### Status | ||
|
||
Matter.js is currently only *alpha* status, so production use should be avoided. | ||
|
||
This engine is the result of [learning game physics](http://brm.io/game-physics-for-beginners/) and getting a bit carried away. | ||
<br>There's no intention to compete with other engines, so I'm not sure yet if it will be developed further. | ||
<br>That said, the engine is reasonably stable and performs well, it's just not feature complete. | ||
|
||
Though if I get time and people are interested, I may continue working on it. | ||
<br>Contributions are also welcome, if you'd like to help. | ||
|
||
### Install | ||
|
||
Download [matter.js](#) or [matter.min.js](#) and include the script in your HTML file: | ||
|
||
<script src="matter.js" type="text/javascript"></script> | ||
|
||
### Usage | ||
|
||
See [Demo.js](#) and [DemoMobile.js](#) for many usage examples. No docs at the moment, sorry. | ||
<br>When loaded, all functions are under the global <code>Matter.*</code> namespace. | ||
|
||
### Implementation | ||
|
||
The technical details for physics nerds and game devs. | ||
<br>This engine is using the following techniques: | ||
|
||
- Time-corrected position Verlet integrator | ||
- Adaptive grid broad-phase detection | ||
- AABB mid-phase detection | ||
- SAT narrow-phase detection | ||
- Iterative sequential impulse solver and position solver | ||
- Resting collisions with resting constraints ala Erin Catto's method | ||
(GDC08) | ||
- Temporal coherence impulse caching and warming | ||
- Collision pairs, contacts and impulses maintained with a pair | ||
manager | ||
- Approximate Coulomb friction model using friction constraints | ||
- Constraints solved with the Gauss-Siedel method | ||
- Semi-variable time step, synced with rendering | ||
- A basic sleeping strategy | ||
- HTML5 canvas renderer | ||
|
||
### References | ||
|
||
See my post on [Game physics for beginners](http://brm.io/game-physics-for-beginners/). | ||
|
||
### License | ||
|
||
Matter.js is licensed under [The MIT License (MIT)](http://opensource.org/licenses/MIT) | ||
<br/>Copyright (c) 2014 Liam Brummitt | ||
|
||
This license is also supplied with the release and source code. | ||
<br/>As stated in the license, absolutely no warranty is provided. | ||
|
||
### Similar Projects | ||
|
||
If you need a more complete engine, check out jswiki's list of [Physics libraries](https://github.com/bebraw/jswiki/wiki/Physics-libraries) |
Oops, something went wrong.