A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Bill » Mon Oct 27, 2014 3:19 pm
Hello everyone,
I'm 100% brand new to Newton Dynamics Engine and I'm trying to get started with some basic experimentation, but I'm totally failing! I honestly just don't know where to begin. I've downloaded all the files from the github repository and I've spent a few hours poking around, but I'm getting nowhere. I was hoping to get some basic advice on where to start.
Is there some documentation somewhere that walks a total beginner through how to get started? Here are some of my initial points of confusion:
1) Is there a recommended version of Visual Studio that is most compatible with the library and its tutorial examples? I tried VS2012, but I had a lot of problems getting some of the projects to build. VS2010 seems to be better, but I figured it might not hurt to ask what I should ideally be using.
2) I see a lot of stuff on the Wiki about Newton 2.0 and Newton 1.53. The version I downloaded has a folder called "coreLibrary_300". Is that different than Newton 2.0 and 1.53?
3) In the "applications\tutorialsSDK300" folder of the stuff I downloaded, there are two sub-folders: CNewtonTutorials and NewtonTutorials. What is the difference here? Should I be focused on one or the other as a new user?
4) Can I do anything with the stuff in "applications\tutorialsSDK200", or is it incompatible with my version of Newton?
Basically, I'm just totally lost! Can anyone try to point me in the right direction here?
My goal is to use Newton as the engine for some semi-scientific simulations...I don't plan to initially use it as a game physics engine. As an example, I thought a good learning exercise for me would be to simulate something like to a bunch of colliding billiards balls that are sliding / rolling around on a billiards table. It would be great to have some very basic graphics built-in to my simulation, but it isn't totally necessary. I'm planning to develop on a Windows 8.1 machine using whichever version of Visual Studio is recommended. In terms of my background, I have decent C / C++ skills (but I'm no computer scientist!) and I have pretty good knowledge of physics-related concepts.
Any help on how best to get started with Newton would really be greatly appreciated! Thanks for reading and I look forward to whatever help you can provide.
-
Bill
-
- Posts: 22
- Joined: Mon Oct 27, 2014 9:40 am
by manny » Mon Oct 27, 2014 4:28 pm
Hi there,
I would recommend checking out the demosSandbox. It's the project that is being maintained as both a showcase on the feature and a interactive tutorial. You can find it at: / applications / demosSandbox / projects
1.) The recommended IDE for windows sandbox is vs2012. But the library has build files for vs2013 aswell, but the sandbox projects should be upgradable to vs2013.
2.) newton 3.0 is the current and most up to date version of the library. It is not compatible with previous versions of the API. The wiki has not yet been updated, but the header documentation of newton is excellent and works as a documentation.
3.) I think the tutorial has not yet been updated for newton 3.0, it probably won't, as the sandbox contains a demo scene for nearly every function of the lirary. But I might be wrong here.
4.) see 2.0)
My goal is to use Newton as the engine for some semi-scientific simulations
That's a great choice. Check out the sandbox, it contains everything to get started within minutes.
-
manny
- Site Admin

-
- Posts: 131
- Joined: Tue Feb 11, 2014 6:49 pm
by JoeJ » Mon Oct 27, 2014 4:30 pm
Look there:
http://newtondynamics.com/forum/viewtopic.php?f=9&t=7762&p=53450&hilit=c+code+tutorial#p53450In the middle is a link to a very simple one file example.
You need to build newton.dll (and lib) with the project from github and to include newton.h.
Other parts of the projects (demo sandbox, joint lib...) are not necessary.
After you've got some simulation running, the code in demo sandbox / tutorials will become more helpfull. You also need some 3d gfx then (being able to render boxes should do it for now)
-

JoeJ
-
- Posts: 1489
- Joined: Tue Dec 21, 2010 6:18 pm
by Bill » Tue Oct 28, 2014 5:24 pm
manny / JoeJ,
Thank you very much for taking the time to respond. Your answers definitely help to point me in the right direction! I'll start taking a good look at the samples you mentioned.
Regards,
Bill
-
Bill
-
- Posts: 22
- Joined: Mon Oct 27, 2014 9:40 am
by Bill » Fri Oct 31, 2014 3:49 pm
Well, I'm off and running (although running definitely isn't the right word!)...
I've built the Newton library and I've cobbled together a basic example using the resources pointed out above. It's just a ball that bounces against a plane.
I'm to the point where I'm trying to modify this simple example, just to try to teach myself some basics and get comfortable with the way things are done. I'd like to be able to change the coefficient of restitution between my bouncing ball and the plane. I found some stuff in the Wiki that sort of pointed me in the right direction, but I can't seem to quite get there all the way. Here is what I have right now at the top of my main function (I've omitted the rest of main, which just runs the simulation loop, destroys the world, and returns):
- Code: Select all
// create a newton world
NewtonWorld* const world = NewtonCreate ();
// create a static body to serve as the floor.
NewtonBody* const background = CreateBackgroundBody (world);
// Create a material for this body
int myMaterial1 = NewtonMaterialCreateGroupID(world);
NewtonBodySetMaterialGroupID(background, myMaterial1);
NewtonBody* const freeFallBall = CreateFreeFallBall (world);
// Create a material for this body
int myMaterial2 = NewtonMaterialCreateGroupID(world);
NewtonBodySetMaterialGroupID(freeFallBall, myMaterial2);
// Do something here to set the coefficient of restitution for this pair of materials...
Can someone please give me some pointers on how to set the coefficient of restitution for this pair of materials? It seems like maybe it has something to do with NewtonMaterialSetCollisionCallback, but I can't quite figure it out!
Any help is greatly appreciated! Hopefully once I get just a bit further along, I'll get over the hump and stop asking stupid questions like this!
Thanks,
Bill
-
Bill
-
- Posts: 22
- Joined: Mon Oct 27, 2014 9:40 am
by Sweenie » Fri Oct 31, 2014 5:08 pm
Try this function...
NewtonMaterialSetDefaultElasticity
It should set the default restitution for a collision between two material groups.
The callback can be used if you want to controll the behaviour of the collision at the time they collide, for example if you want the restitution to be different based on the impact velocity etc.
-
Sweenie
-
- Posts: 503
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
by JoeJ » Sat Nov 01, 2014 6:39 am
The code below is what i'm using at the moment, but i don't think it's good / fast or the recommended way. (I do not use Newton material system at all here and set the same material to all bodies, but calculate properties at contact time)
It contains some worth reading comments i've copied from the forum to help with softness vs. elasticity confusion.
Also it shows that you can calculate your own material properties depending on what two materials collide - most other engines would just take the average or min/max values like i do here too, but you can also read real world values from a table etc.
I do not know yet how this should be done with newtons build in material system, but it's possible.
- Code: Select all
...
NewtonMaterialSetCollisionCallback (world, defMatID, defMatID, this, GenericOnAABBOverlap, GenericContactProcess); // setup callback
...
static void GenericContactProcess (const NewtonJoint* contactJoint, dFloat timestep, int threadIndex)
{
const NewtonBody* body0 = NewtonJointGetBody0(contactJoint);
const NewtonBody* body1 = NewtonJointGetBody1(contactJoint);
NewtonWorld *world = NewtonBodyGetWorld (body0);
int defMatId = NewtonMaterialGetDefaultGroupID (world);
PhysicsWorld *pworld = (PhysicsWorld*) NewtonMaterialGetUserData (world, defMatId, defMatId); // crude way to get pointers to my custom data
BodyData *data0 = (BodyData*) BodyGetUserData ((Body*)body0);
BodyData *data1 = (BodyData*) BodyGetUserData ((Body*)body1);
Material &mat0 = pworld->materials[data0->materialIndex]; // Material is my own struct
Material &mat1 = pworld->materials[data1->materialIndex];
float staticFriction = min(mat0.staticFriction, mat1.staticFriction);
float dynamicFriction = min(mat0.dynamicFriction, mat1.dynamicFriction);
float restitution = (mat0.restitution + mat1.restitution) * 0.5f;
for (void* contact = NewtonContactJointGetFirstContact (contactJoint); contact;
contact = NewtonContactJointGetNextContact (contactJoint, contact))
{
NewtonMaterial* material = NewtonContactGetMaterial (contact);
NewtonMaterialSetContactFrictionCoef (material, staticFriction, dynamicFriction, 0);
NewtonMaterialSetContactFrictionCoef (material, staticFriction, dynamicFriction, 1);
NewtonMaterialSetContactElasticity (material, restitution); // 1 = bounce forever
//NewtonMaterialSetSurfaceThickness // Thickness is how cloase the collision will be, you can for example set a small sickness value and the shape will not touch.
//NewtonMaterialSetContactSoftness // softness in hwo fast penetration will be resulved (by penaltry force proportinal to the penetration.)
NewtonMaterialSetContactSoftness (material, 0);
/*
softness and elasticity are very different things.
one is a function of penetration distance
and the other is function of relative impact velocity
elasticity is the coeficient of restitution according to the equation of impulse. eleaticity is proportional to the relative velocity of impact at a contact.
softness it there to resolve interpenetration only.
Softness is the penetration coneficient that is use to convert teh interpenetration is disatnce to an inpulse veliocity to recove from penetration,
the velocity is then added to the impact velocity.
in future versions of Newton softness will be eliminated all together.
you can leave the softnes coficient to the default and only work with elaticity.
yes elasticity is what some people call restitution
softeness is a penalty acceleration that is added to the contact point if they penetrate.
it is not propotional to the penetration, instead the penetration is use as a switch to decide if using the softhness or not,
In Newton this parameter is not visual, is is in fact translate to an impulsive force add to the contact point, and it is one of the reason collision can go bad if you set that value to anything too high.
the parameter have not physical explanation other that recover bodies from penetation.
so the physics of it are umpredicatble since I do not have any physcial/mathematical expresion to add it to the engine.
like I said, set it to zero, the engine do recover from penetration graciously by separating the at a constant speed when they penetrate.
*/
}
}
-

JoeJ
-
- Posts: 1489
- Joined: Tue Dec 21, 2010 6:18 pm
by Bill » Mon Nov 03, 2014 11:17 am
Sweenie / JoeJ,
Thanks for the help! I ended up just using NewtonMaterialSetDefaultElasticity for now, as what I'm trying to do is extremely basic at this point. The collision callback stuff looks useful and powerful, once I get myself up to that level of sophistication!
Things are starting to make some sense to me...at least the very basics, that is. I'm going to try to start adding some simple graphics to my example problems using GLUT. Once I get that up and running, I'm sure I'll be back with more beginner questions!
Thanks again,
Bill
-
Bill
-
- Posts: 22
- Joined: Mon Oct 27, 2014 9:40 am
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 1 guest