Jump to content
  • Advertisement
Sign in to follow this  

Need a kick in the pants to get started using Newton GD

This topic is 3773 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I;ve been having problems understanding the "tutorials" that come with newton GD. The tutorial applications use Glut, and lots of polymorphism, and I find them confusing. I got round a similar problem with ODE by creating my own physics demo. The first prototype was a single box falling from the sky, with its transformation matrix being dumped to the command prompt.
class physics_demo{
	NewtonWorld* nWorld;
	NewtonBody* boxBody;
	NewtonBody* floorBody; 
	void update(float fps);
	//add an anvil to the simulation.	

	nWorld = NewtonCreate (PhysicsAlloc, PhysicsFree);
	NewtonCollision* collision;	

	// create the box to fall from the sky
	collision = NewtonCreateBox (nWorld, 10, 10, 10, NULL); 
	boxBody = NewtonCreateBody (nWorld, collision);
	NewtonBodySetMassMatrix (boxBody, 1.0f, 1.0f, 1.0f, 1.0f);
	NewtonReleaseCollision (nWorld, collision);	
	dMatrix location (GetIdentityMatrix());
	// set the transformation for the floor
	NewtonBodySetMatrix (boxBody, &location[0][0]);	//create a block to hit the floor		

void physics_demo::update(float fps)
	NewtonUpdate (nWorld, 1.0f / 30.0f);
	dMatrix position;
	for(int x=0; x<4; x++)
	for(int y=0; y<4; y++){
	NewtonBodyGetMatrix(boxBody, &position[0][0]);
	for(int x=0; x<4; x++){
	for(int y=0; y<4; y++){

My problem, is that when I do this I get an identity matrix on each frame. The box I have created does not fall, and I have no idea how to add gravity to the Newton simulation. Searching for "gravity" in Newton.h returns nothing that looks like it sets the gravity. What am I missing? Also, I'm not sure of what function to use to set a callback for when a collision occurs. I've seen in the callback demos that you have to add materials and then add a collision callback for each material. Is there a simpler way? Thanks.

Share this post

Link to post
Share on other sites
You haven't set SetForceAndTorque callback.
That is the place where you apply gravitation force, so currently your box is floating in zero-g space, therefore you get identity matrix all the time.

Check Newton tutorial 2 for example of this.

Share this post

Link to post
Share on other sites
To be honest, I really don't understand the Tutorials. My problem is that the code is full of references to the graphics system, and I'm having a hard time distinguishing between the two. It would be easier if there was an abstract renderer.

If I say that on the Newton forums, it gets deleted. Its also their policy to delete ANYTHING that might start a flame war, including references to ODE. Otherwise, I would post the code I used for ODE and ask how to do this in Newton.

Anyway, how do I set a callback for ANY collision with ANY object?


[update: edited for accuracy]

[Edited by - speciesUnknown on February 26, 2008 4:10:24 AM]

Share this post

Link to post
Share on other sites
Hehe, I know what you mean. Newton tutorials are quite complex and documentation is full of typos & mistakes, which makes picking this API up quite a challenge.

But, I think that setting that kind of callback is complicated... Only thing that I found from API is NewtonMaterialSetCollisionCallback where you can set callback when that kind of material collides.

Check the tutorial 4, file Material.cpp, seems that this should be done something like this:
// Get the default material ID
int defaultID = NewtonMaterialGetDefaultGroupID (nWorld);
// Set callback for the situation when default materials collide
NewtonMaterialSetCollisionCallback (nWorld, defaultID, defaultID, &userData, GenericContactBegin, GenericContactProcess, GenericContactEnd);

Where those last three arguments are the callback functions:
int GenericContactBegin(const NewtonMaterial*, const NewtonBody*, const NewtonBody*)

So that would work if you don't specify your own materials, and if you do, then you must specify those same callbacks for every material collision.

In Newton it seems that you normally have one material for player, several for environment and also own materials for projectiles, etc. Although, I might be wrong in this one, haven't gone that far yet :)

Share this post

Link to post
Share on other sites
Materials are a versatile system, however I would rather manage that stuff myself and have the option of attaching a collision callback to the body rather to the material. I started off with bullet, and learned enough to get a demo app working, and found the tutorials confusing because they were so convoluted. However, bullet kept crashing with failed assertions. So I tried ODE, and again the tutorials were convoluted, using a "demo" class, a subclass for each demo, and the demo subclass used subclassed primitives which doubled as graphics and physics primitives. I abandoned ODE because I couldn't get a stable simulation and everything vibrated for several seconds when it got the slightest touch. So now I'm using Newton.

[update: edited for accuracy, sorry guys]

[Edited by - speciesUnknown on February 26, 2008 4:00:51 AM]

Share this post

Link to post
Share on other sites
speciesUnknown, you may want to check out the newton forums, and especially the FAQ there, specifically this topic about the materials:


On the other 3 points you wrote let me answer some of them, i frequent the newton forum regularly, and i feel you got some wrong impressions about newton forums:

1. not all such topics get deleted, but topics that are written rude with "threats of switching to other engines because newton doesn't have some X feature" and making or asking for specific comparisons then the topic may get deleted, since the purpose of newton forum is not about benchmarks and comparisons, it is only about Newton, and how to use Newton.

2. there are already callbacks and functionalty for this, the material interface handles this, all you have to do is set up 1 material and a callback for when that material collides with itself, then if you use that material everywhere you are basically receiving all the collisions between all bodies...

3. the new version of newton is going to have better demos, but the code is not convoluted, if you cannot understand it, then perhaps you should learn more about c++ first.

Also, about your question on gravity in newton:

Newton does not use any magic or other special functionality to handle gravity, gravity in newton is not any different than any other forces that get applied to the physical bodies, if you wish to have "objects with gravity", then you will simply have to add the gravity force to those objects in the torqueforce callback.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!