Using NewtonSceneCollision

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Using NewtonSceneCollision

Postby Bird » Thu Jul 25, 2013 9:17 am

I've created a NewtonSceneCollision body and am trying to interactively use it to push around another dynamic body in the scene. It kinda of works but I'm seeing a lot of penetration when the 2 bodies collide. Here's a demo video

http://hurleyworks.com/media/flash/NewtonSceneCollision/NewtonSceneCollision.html

Is there a way to prevent the penetrations? I have tried setting NewtonBodySetContinuousCollisionMode to 1 but it doesn't help.

-Bird
http://hurleyworks.com/
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: Using NewtonSceneCollision

Postby Julio Jerez » Thu Jul 25, 2013 9:40 am

Scene collision are static compound collision, you can move then but they do no perform physic on other dynamics objects
They can take Collision tree, High field, user high field are also static collision, plus all the other convex shapes.
basically they are an optimization for creating large background scene without having to pollute the high level collision pruner

basically a scene collision is like a city, with streets, buildings, light post, and everything that is static in a city. you can move those object for editing purpose, during that proses the collision is inactive.


if you one to move a complex object you have to use compound collision instead.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Using NewtonSceneCollision

Postby Bird » Thu Jul 25, 2013 10:48 am

Ok, I guess I misunderstood you in another post. I thought that SceneCollisions could be dragged around and interact with dynamic bodies
http://newtondynamics.com/forum/viewtopic.php?f=9&t=7632#p52333

So is there a way in Newton to allow the user controlled body move around in a Newton scene and push dynamic bodies around? This is what KinematicBodies do in Bullet and PhysX and I really hoping to find the same functionality in Newton

-Bird
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: Using NewtonSceneCollision

Postby JoeJ » Thu Jul 25, 2013 1:37 pm

I have not yet used kinematic bodies or scene collision, but i made a interaction model where i can pick up and drag around a dynamic body or compound. It interacts perfectly with other bodies in the scene.

There are two ways to do that:

force / torque method - calculate forces and apply in callback.
This is harder to implement, but may do better on cases where you try to push an object into a wall or similar.

Joint method - use Kinematic Joint from joint lib.
Very easy to implement - may cause jitter when pushing object into walls, but handles multybody problems nicely.

Example: When dragging a ragdoll the force method is too weak, because it will only use mass from the single body you pick.
Joint method works well with this.

Try the joint method first - it's really easy. You can decide if Kinematic Joint should handle rotation too, and you can set max friction which means maximum force to apply.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Using NewtonSceneCollision

Postby Julio Jerez » Thu Jul 25, 2013 2:05 pm

There is also another way to do this. but first let me clrrify something.

There is one big difference betwen newton and all those other engine.
Newton is a real Newtoniam, mcjhanix physics simulator.
By this I mean netwon will calcyate a constatin force to cancel forces along a shared degree of fredom between two rigid bodies.

This force is calculate considering all of the physics propertie to teh body at at the degree of freedon, the point reletive velocity, the point relative poistion
the linear and angular momentum of the two bodies.
The engine is not concenet wj eteh penetrataion distance btewwen the two bodies.

to resolve penetarion ditance newton use a trick tha volate teh laws of newtonian mechanic for a few simulation stape,.
besualclly it resule penetraion by adding a small contact linear velocity that seperte the contacts.

This is in fact wrong, but it is the compromise I have to make in order to get for realtime simulation.
Penetrations are inevitable if we move at descreete time steps. and we nee to reolev them.

you can test this by plasingg two boxes in the scene in deep penetration, you will see that teh engine resolve them by moving one ouside at a constant velocity. Thsi in fact add energy to teh system as long as ther is peneteration by the extra added energy is a fix amount.
To have a system liek thsi yo unee to have a very good solve that calculaet teh actual forces. and tah si what newtpn provide.

All other engine are no real newtonian physical simation engines, tehy are collsion systeme that use impulse to to the to resolve interpentartion.
this is a very, veruy, very big difference.
And impusel is somethong thet teleprost a isnt form position a to position B, in zero time, theis is a unceepatble volation of the laws of physics.
If you do the same test of the deep penetration box yo uwill get an explosion.

Now there are two ways you can solve the problem of intepenetration when you teleprting a statioc body
1- set the velocity on the static body, and afte teh frem reset to to zero, you cna impelment that with a listeners.
you set the teleport velocity in the pre-updart function fo rteh listener the the colllsion system will detect that velocity and when teh body tiche oeth bodey the will react properlly.

2-by making a Material that associate those type of bodies with all other bodies.
then in the contact point you modify the conta velocity by addin the contact velcity at that point form teh statioc body

of the two the first is eassier, and is teh way of core 300, teh secudn is how peopel did in the pass and soudl also work.

afte we fix teh oethe bug, I can set up demo to demostrate that if you want.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Using NewtonSceneCollision

Postby JoeJ » Thu Jul 25, 2013 2:31 pm

hmm... that helps me to understand the purpose of kinematic bodies :)
I want to make a moving / rotatig platform for ragdoll to test balancing under harder conditions.
Kinematic body seems ideal for this (also for an animation package like Birds).

Kinematic body has the option to either recieve or not recieve influnce from collision with dynamic bodies?
So could you show both those options in the demo?
Is it also possible to attach a dynamic body using a joint to a kinematic body?
Is it also possible to change state dynamic <-> kinematic body (i assume we can do that ourself by delete / create and copy velocities - but it might be a useful tool function to be in newton)?
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Using NewtonSceneCollision

Postby Bird » Thu Jul 25, 2013 3:10 pm

you can test this by plasingg two boxes in the scene in deep penetration, you will see that teh engine resolve them by moving one ouside at a constant velocity. Thsi in fact add energy to teh system as long as ther is peneteration by the extra added energy is a fix amount.
To have a system liek thsi yo unee to have a very good solve that calculaet teh actual forces. and tah si what newtpn provide.

All other engine are no real newtonian physical simation engines, tehy are collsion systeme that use impulse to to the to resolve interpentartion.
this is a very, veruy, very big difference.
And impusel is somethong thet teleprost a isnt form position a to position B, in zero time, theis is a unceepatble volation of the laws of physics.
If you do the same test of the deep penetration box yo uwill get an explosion


Heh, I'm probably the only guy on the planet that can test that out in 5 minutes.:)

http://hurleyworks.com/media/flash/DeepPenetration/DeepPenetration.html

PhysX exploded like you suggested but Bullet behaves a lot closer to Newton in this case.

Thanks for the explanation. My project supports Bullet, PhysX and Newton. If I wasn't afraid of putting all of my eggs in one basket, I'd drop PhysX and Bullet support in a second.

-Bird
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: Using NewtonSceneCollision

Postby Julio Jerez » Thu Jul 25, 2013 3:44 pm

Oh but beleive physx will explode, but will also explode of all of the physic libraries out there Bullet is the absulte worse physcally, much worse that Physx.
Clip impulse stuff, shok progagatuion way, and position correction are not laws of physics.
The onle reaos they relsuet inteparetray is because they remove enetgry form teyh system.
but it i sthat fact that make the siumation so horrendous. you can not arbiotrarity or base on intuitions remove
energy or momentum from a system unless the force that generate the engery is workless. there is not such thing as a workless impulse.

The only are only two correct newtonian physically correct realtime rigid bodies simulatores, Newton and ODE,
They boeth formatale lagriagian dynamcis solver and solev teh secudn order direncail equation.
the idea the you can clamp impusle here and there is not a law of physics.
that stuff is take from older version of the Havok engine and has proven over and over to generates really bad Game physics.

you may see a gentile behavior in teh box case, but beleive it will fail, all you have to do is place a bunch of them and you will see expose teh explsion.

there are few libraries that do the same kind of stuff Tokamak, Havok, True axis, and bullet but is has never and will even work.

at teh basics level the reason why it fail is that impusle are not forces, force are applied during a period of time, tehr are secudn order quatity, they generate emerging behaviors like centripal and coriolie forces, impulse can never do that.

if you take an impsule and you divided by the mass, you get is a velocity change.
when you apply the velocity change to a point you change the position, you can do that many time and you body look like is moving.

p = p0 + v0 * t + dv * t

if you take a force and you apply that force to a body for a period of time you get a change of velocity and a change of accelation

v = v0 + a * t
p = p0 + v0 * dt + a * t* 2

those two very different values, when the acceleration changed in magnitud and in direction then you get sideways velocity changes that the first metho can never produce because the first method is just a first order diferencial equation, while the secund is a secund order differencial equation.

must people do not know that an dtehr are just happin that teh get collsion and teh objec move aorund, but afte a while ther see teh difference and they get selft bambuzzled by morons selft appointed experts.

If I ever decided to go the route of Impule, believe I can make a psedueo phsyic libarey taht can be abput an order of magnote fater that newto is now.
it is no that I have discarded that idea all together and may use one day for a Inverse Kinematic solver for Character animation, but for now I have too many thing pending to do.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Using NewtonSceneCollision

Postby Bird » Mon Jul 29, 2013 2:37 pm

JoeJ wrote:I have not yet used kinematic bodies or scene collision, but i made a interaction model where i can pick up and drag around a dynamic body or compound. It interacts perfectly with other bodies in the scene.
Joint method - use Kinematic Joint from joint lib.
Very easy to implement - may cause jitter when pushing object into walls, but handles multybody problems nicely.

I have no experience using joints and I couldn't find any example code for a CustomKinematicController except in the Advanced Player demo which is way too complicated for me to understand and in the MousePick code which looks like it's been depreciated. It would be very helpful to see a very simple demo of a Kinematic Joint in action and more basic demos of some of the other types of joints as well. :)

Thanks for the help, Joel!

-Bird
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: Using NewtonSceneCollision

Postby Julio Jerez » Mon Jul 29, 2013 5:26 pm

yes the pick code, is being replaced, I am addind a better one.
give me few days until I completed the bouyancy request than I am working now,
Then I resume with these problems
Basically I am making an impulse based pick system that will not requires attachig a joint, that will be controlled by a cusome controller.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Using NewtonSceneCollision

Postby JoeJ » Mon Jul 29, 2013 6:11 pm

There's some code i used to submit some CCD bugs, which are fixed meanwhile.
But Kinematic Joint is used there. I add some comments.
You can overwrite BasicStacking.cpp from Demo Sandbox with this code to play around.
You may want to set the target posits higher, because i tried to pull the bodies into ground to provoke bugs.

You see this is easy. Same for adding a ball socket for two dynamic bodies.
I remember i had all basic joints working for both bullet & newton,
but the quality difference became quite large here, so i dropped bullet at this point.
Newton makes it also possible to add your own joints without the need to be a math god :)

Code: Select all
/* Copyright (c) <2009> <Newton Game Dynamics>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely
*/

#include <toolbox_stdafx.h>
#include "SkyBox.h"
#include "../DemoEntityManager.h"
#include "../DemoCamera.h"
#include "DemoMesh.h"
#include "PhysicsUtils.h"

#include "CustomKinematicController.h"


static NewtonBody* BuildBox (DemoEntityManager* const scene, dFloat mass, const dVector& origin, const dVector& size)
{
   dMatrix matrix (GetIdentityMatrix());

   // create the shape and visual mesh as a common data to be re used
   NewtonWorld* const world = scene->GetNewton();
   NewtonCollision* const collision = CreateConvexCollision (world, GetIdentityMatrix(), size, _BOX_PRIMITIVE, 0);


   DemoMesh* const geometry = mass
      ? new DemoMesh("DynBox", collision, "smilli.tga", "smilli.tga", "smilli.tga")
      : new DemoMesh("StaticBox", collision, "wood_0.tga", "wood_0.tga", "wood_1.tga");
   
   matrix.m_posit = origin;
   
   NewtonBody *body = CreateSimpleSolid (scene, geometry, mass, matrix, collision, 0);

   // do not forget to release the assets   
   geometry->Release();
   NewtonDestroyCollision (collision);

   return body;
}




void BasicBoxStacks (DemoEntityManager* const scene)
{
   BuildBox (scene, 0.0f, dVector(0,-5,0), dVector (100, 10, 100)); // ground
   
#if 0

   // provoke CCD assert
   
   NewtonBody* body = BuildBox (scene, 10.0f, dVector(0,3,1), dVector (4,4,4));
   NewtonBodySetContinuousCollisionMode (body, 1);
   CustomKinematicController *kj = new CustomKinematicController(body, dVector (0,3,0)); // vector is pin position in local body space
   kj->SetMaxLinearFriction (1000); // 'max force'
   kj->SetTargetPosit (dVector (0,0,0)); // the world space target position. You can animate at runtime - pin position will follow.

#elif 1

   // provoke 'penetration bug'
   
   NewtonBody* body = BuildBox (scene, 1.0f, dVector(0,3,1), dVector (4,4,4));
   CustomKinematicController *kj = new CustomKinematicController(body, dVector (0,3,0));
   dQuaternion q (dVector(1,0,0), 0.7f);
   kj->SetPickMode (1); // also constrain orientation
   kj->SetTargetPosit (dVector (0,0,0));
   kj->SetTargetRotation (q); // world space target orientation... animate this too
   kj->SetMaxLinearFriction (500);
   kj->SetMaxAngularFriction (500); // 'max torque'

#else

   // provoke 'penetration bug' linear only
   
   NewtonBody* body = BuildBox (scene, 1.0f, dVector(0,3,1), dVector (4,4,4));
   CustomKinematicController *kj = new CustomKinematicController(body, dVector (0,3,0));
   kj->SetTargetPosit (dVector (0,-10,0));
   kj->SetMaxLinearFriction (500);

#endif


   // place camera into position
   dQuaternion rot;
   dVector origin (-20.0f, 2.0f, 0.0f, 0.0f);
   scene->SetCameraMatrix(rot, origin);


//   ExportScene (scene->GetNewton(), "../../../media/test1.ngd");
}


User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Using NewtonSceneCollision

Postby Bird » Tue Jul 30, 2013 9:51 am

Thanks for that Joel, I've got it working now. Do you know if clients are responsible for deleting the joint pointers or is that handled automagically inside Newton?

I'm still seeing penetration problems with the Kinematic Joint though.
http://hurleyworks.com/media/flash/KinematicJoint/KinematicJoint.html

-Bird
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: Using NewtonSceneCollision

Postby Julio Jerez » Tue Jul 30, 2013 10:39 am

wait until I make a better picking function that will calculate the impulses better.
That will be next week, after I get over the stuff I am doing now.

I will complete the scaling, for compound by change the interface for taking a local scalex, scaley, scalez, top take a general matrix
this will support both global and local scale with having to do that Asshat solution that I try last week.
the I will do that picking function
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Using NewtonSceneCollision

Postby JoeJ » Tue Jul 30, 2013 11:38 am

Bird wrote:I'm still seeing penetration problems with the Kinematic Joint though.


Ignoring the discussion what is the best picking method, there seems to be someting you need to fix for proper joint usage.
Looking the video i see a ball running at high framerate and a box with joint looking like low framerate.
What i assume is this:

The user picking is updated at low frequency, this leads to large positianl differences of the joint target.
The box has low mass, the joint has large friction - so it moves the box with relative huge forces to hit the target in one frame.
Because CCD is off, newton misses collisions.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Using NewtonSceneCollision

Postby Bird » Tue Jul 30, 2013 3:04 pm

The user picking is updated at low frequency, this leads to large positianl differences of the joint target.
The box has low mass, the joint has large friction - so it moves the box with relative huge forces to hit the target in one frame.
Because CCD is off, newton misses collisions.

Thanks, I hadn't thought of that but I don't think that's what's happening. Below is a debug slice just before the ball penetrates the box. I made a Newton Listener for updating the Kinematic target matrix and it gets called 8 times cause I'm using 8 substeps.

The user mouse events happen at least once before each physics update and the differences in the box position are less than half of the diameter of the ball on each frame. I have tried with CCD on and off and it has no effect and tried various combinations of mass and friction and they don't seem to make any difference.

Thanks for the help!

-Bird

Code: Select all
[Log:0:] D: **** MOUSE MOVE EVENT: User moves joint to ( 3.34465, 0.75, -2.36852 )
[Log:0:] D: -------------------NewtonEngine::advancePhysics
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.34372, 0.75, -2.36759 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.34307, 0.75, -2.36694 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.34261, 0.75, -2.36648 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.34229, 0.749999, -2.36616 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.34207, 0.749999, -2.36594 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.34191, 0.749999, -2.36579 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.34181, 0.749999, -2.36568 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.34173, 0.749999, -2.3656 )
[Log:0:] D: **** MOUSE MOVE EVENT: User moves joint to ( 3.47005, 0.749999, -2.75931 )
[Log:0:] D: -------------------NewtonEngine::advancePhysics
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.46912, 0.749999, -2.75838 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.46846, 0.749999, -2.75772 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.46801, 0.749999, -2.75727 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.46769, 0.749998, -2.75695 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.46747, 0.749998, -2.75673 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.46731, 0.749998, -2.75657 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.4672, 0.749998, -2.75646 )
{Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.46713, 0.749998, -2.75639 )
[Log:0:] D: **** MOUSE MOVE EVENT: User moves joint to ( 3.60917, 0.749999, -3.19286 )
[Log:0:] D: -------------------NewtonEngine::advancePhysics
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.60824, 0.749999, -3.19193 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.60759, 0.749998, -3.19128 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.60714, 0.749998, -3.19083 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.60682, 0.749998, -3.19051 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.6066, 0.749998, -3.19028 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.60644, 0.749998, -3.19013 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.60633, 0.749998, -3.19002 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.60626, 0.749998, -3.18994 )
[Log:0:] D: **** MOUSE MOVE EVENT: User moves joint to ( 3.69394, 0.75, -3.45704 )
[Log:0:] D: -------------------NewtonEngine::advancePhysics
[Log:0:] D:  *** Contact with ball***
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.69304, 0.75, -3.45591 )
[Log:0:] D:  *** Contact with ball***
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.6924, 0.75, -3.45513 )
[Log:0:] D:  *** Contact with ball***
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.69196, 0.75, -3.45458 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.69165, 0.75, -3.45419 )
[Log:0:] D:  *** Contact with ball***
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.69143, 0.75, -3.45392 )
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.69128, 0.75, -3.45373 )
[Log:0:] D:  *** Contact with ball***
[Log:0:] D: AppListener::postUpdate: Kinematic Joint sets target to( 3.69117, 0.75, -3.4536 )
[Log:0:] D: **** MOUSE MOVE EVENT: User moves joint to ( 3.79654, 0.75, -3.93414 )
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron