
Newton - Javascript Physics Library - evlapix
https://github.com/hunterloftis/newton
======
dougk16
Haven't looked too much at the API, but right off the bat I would suggest a
more compelling suite of demos, with collision, stacking, etc...I may just be
missing the links.

You're definitely targeting a gaping niche IMO though (same one I'm trying to
fill through a side project). Using Box2D in JavaScript feels like programming
in assembly sometimes.

~~~
swah
Yep, the demo is just non-interactive falling objects, it feels like an
"intro" instead of a physics engine.

~~~
hunterloftis
It is! I'm the author of newton and didn't realize it was going to be
published on hacker news. It's fast and simple but lacks some basic features
I'm rounding out - plus it needs more examples and a test suite.

------
munchor
You really need to submit a single newton.js to GitHub so people can try it
out more easily. (how I did it for my library[1]. Other than that, I've been
using Chipmunk-JS lately and struggling a bit here and there so I very much
look forward to using Newton.

[1]:
[https://github.com/davidgomes/pentagine/blob/master/tools/me...](https://github.com/davidgomes/pentagine/blob/master/tools/merge.rb)

EDIT: Already filled in a pull request, the code looks quite good.

~~~
hunterloftis
Awesome, thanks. What do you mean though by submitting a single newton.js to
github?

------
feistyio
I wish you all the best with your ambitious project ^w^

You should seriously consider employing techniques such as LLJS[1] to avoid
thrashing the GC.

At the very least use typed arrays à la glMatrix[2] rather than a Vector
prototype.

Typed arrays have the added benefit of interoperability with WebGL and
Canvas2D via Function::apply.

\---

[1] [http://mbebenita.github.io/LLJS](http://mbebenita.github.io/LLJS)

[2] [http://glmatrix.net](http://glmatrix.net)

~~~
josephg
Author of ChipmunkJS here. I did some benchmarks moving things to typed arrays
about a year ago, and the change was a wash in my benchmark results. I think
that might not be the case now considering all the optimizations the v8 team
have been making to asmjs-like code.

I did some quick benchmarks using emscripten recently and performance
absolutely blew away my hand-tweaked chipmunk code[3]. Hand optimized,
ChipmunkJS takes 2.8x as long to run the tests. Emscripten compiled chipmunk
is 1.4x, so twice as fast.

That said, the generated code is huge and awful, and the API is terrible. I've
been playing around with porting my library to LLJS recently, but when I
looked at LLJS it hadn't been updated in over a year. Its nice to see that
there were some commits a few months ago, but LLJS needs a lot of work before
its generally usable. I've been doing some stuff manually as a toy - still not
sure where to go with all of this. Bridging from ASMJS to regular javascript
makes your API really hard to use.

\---

[1] [https://github.com/josephg/Chipmunk-
js](https://github.com/josephg/Chipmunk-js)

[2]
[https://docs.google.com/spreadsheet/ccc?key=0Ap2hDnCZnXiVdDV...](https://docs.google.com/spreadsheet/ccc?key=0Ap2hDnCZnXiVdDVFenh2cm5fdUx3WGw0N2szdVotOXc&usp=sharing)
, though this is somewhat hard to read.

[3] [http://josephg.com/blog/chipmunkjs-and-
emscripten](http://josephg.com/blog/chipmunkjs-and-emscripten)

[4] [http://josephg.com/blog/chipmunk-in-asm-
js](http://josephg.com/blog/chipmunk-in-asm-js)

------
angersock
_" Unfortunately, these ports combine the clarity and conciseness of C++ with
the speed of JavaScript."_

This is exactly how I felt using the Box2D port for our swarm project--itself
a port of an ActionScript port of a C++ library.

------
DanielRibeiro
I wonder how it compares to p2.js[1], another recent 2D physics engine, but
created by the same person who created the 3D physics engine Cannon.js[2]

[1] [https://github.com/schteppe/p2.js](https://github.com/schteppe/p2.js)

[2]
[https://github.com/schteppe/cannon.js](https://github.com/schteppe/cannon.js)

~~~
hunterloftis
Thanks for the link, I hadn't seen p2.js.

Here are a few points for comparison:

\- p2.js is significantly more complete than newton

\- p2.js uses a rigid body simulation closer in principle to box2d, while
newton uses a particle-and-constraint based verlet integration

\- newton provides a game loop with separate render/simulate time tracking
(something I feel is missing from existing libs)

------
pstuart
This would be perfect for my idea of a tool for teaching programming to kids:
a small game framework that they can program with a DSL, then teach them to
hack the DSL....

------
coherentpony
I can't find a license.

------
sambeau
This would go really nicely with Snap.svg. Hurry up and finish it, please!

~~~
hunterloftis
On it!

