Newton SDK Notes

Newton is closed-source binary-only library.  Annoying.
On the plus side, there's only one header file, Newton.h, and library, newton.lib/dll.

A closed-source (15MB download) physics API.  Troy uses it.

http://www.newtondynamics.com/
http://www.newtondynamics.com/wiki/index.php5
http://walaber.com/newton_wiki/index.php?title=Main_Page

Collision primitives:
	NewtonCreateSphere
	NewtonCreateBox
	NewtonCreateCylinder
	NewtonCreateCapsule  (cylinder with sphere ends)
	NewtonCreateCone
	NewtonCreateChamferCylinder (cylinder with rounded sides)
	NewtonCreateConvexHull
	NewtonCreateTreeCollision
	NewtonReleaseCollision


Concepts in Newton:
	Collision: know about object shape. Refcounted.  Stored relative to the body's coordinate system.
	Body: know about object location and orientation (rigid body).  Has mass and inertia.
		NewtonCreateBody
		NewtonBodySetMassMatrix
		NewtonBodySetMatrix
		NewtonBodyGetMatrix
		NewtonBodySetOmega
		NewtonBodySetForceAndTorqueCallback
			-> This is where you add forces, like gravity
	
	Overall flow:
		NewtonCreate (create a world)
		NewtonDestroy
	


---------------
Tried it out on a big set of cubes.  It works, sorta.  The default rotational inertia (1.0) is way too huge, so the cubes rotate very slowly.  

Performance is tolerable with 100 objects.

Performance is kinda-sorta with 500 nonintersecting objects (7ms).  Performance dogs out with objects piled up (50ms+).  *Segfault* with 1000 objects in a pile; but I can have 2000+ objects spread out with tolerable performance.
	-> Big piles are bad.

Performance isn't affected by having a mix of cubes and spheres.


-----------------  Robotics ------------

For the robot project, we basically need:
	- Robots, consisting of
		- Body, just a uniform-mass rectangle
		- Wheels/tracks, with high coefficient of friction
	- A terrain, probably represented as a heightfield.  Friction might vary across space.



In the Newton SDK, we've got:

NewtonWorld *w=NewtonCreateWorld(NULL,NULL);

NewtonMaterial* tireMaterial= ...

NewtonCollision *body=NewtonCreateBox(w, x,y,z, NULL);
NewtonCollision *tire=NewtonCreateCyliner(w, radius,thick, matrix);
Square tires also might be a good way to model friction. I think you want NewtonConstraintCreateHinge to attach the tires to the box.  There's also a "NewtonConstraintCreateVehicle".



For the terrain, you can either stare at Tutorial 08 on heightfields and:

NewtonCollision *terrain=NewtonCreateUserMeshCollision(w,
	minCorner,maxcorner,
	meshData,
	meshCollide,meshRayHit,meshDestroy);

It looks *way* easier to just use a NewtonTreeCollisionAddFace, which takes one triangle at a time.  This might be slower than a well-written heightfield UserMesh, though.


Tried this.  AddFace is really easy, and quite fast for a 40x30 face mesh.  It takes about two seconds to set up a 100x100 mesh, but the runtime performance is still pretty good.  A 100x100 mesh gives you 10cm resolution over a 10m area--not perfect, but OK.

100x100: 1.86s setup, 50fps runtime
200x100: 4.25s
200x200: 9.37s setup, 20fps runtime
400x400: 39.9s setup, 7.5fps runtime



Hmmm... I'm getting really weird behavior from NewtonConstraintCreateHinge when I use object-local coordinates.  They work right only when I use world coordinates (like the docs say!).

