A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by wivlaro » Sun Jun 12, 2016 4:50 pm
Hi,
Is there a convenient way to asymmetrically mask off some groups of objects from colliding with each other?
Eg. I have a few static scene colliders, of class A, with which everything can collide. Then I have lots of objects class B and class C.
Say I want class B objects to basically ignore class C, but class C objects should react to class B (i.e. class Bs should be able to push class Cs but not the other way around).
Case in point:
I have some static scene objects (A), I have some game objects (B) and I have some fluff effects (C) (like large, light fog/smoke particles).
I'm imagining I could do something with the material groups to achieve this, but I can't see how. The class C objects would have to be able to get stuck between class A and class B.
Some ideas of mine that are probably flawed:
1. I was thinking of making class C objects just large and super-light so they barely affect class A, but they'd still be solid, unless i shank them on contact with both A & B - seems complicated.
2. Make two NewtonWorlds, one "real" simulation world with just A & B and one "effects" world with A & B as kinematic, manually moved and C as the dynamic objects - seems very inefficient.
3. Is there something I can do in the NewtonMaterialSetCollisionCallbacks?
4. I saw NewtonMaterialSetCollisionCallback which looks promising but can't see any documentation for it.
Anyone have any better ideas? Thanks
-
wivlaro
-
- Posts: 10
- Joined: Sun Jul 21, 2013 5:16 am
by Julio Jerez » Sun Jun 12, 2016 6:41 pm
collision shapes have these methods.
- Code: Select all
void NewtonCollisionSetUserData (const NewtonCollision* const collision, void* const userData);
void* NewtonCollisionGetUserData (const NewtonCollision* const collision);
you can set a pointer to a custom user data that and there you can invent your own strategy for doing contact filter on any collision callback. This is similar to the BodyUser Data.
I do not recommend using Materials, because they are a legacy from 1.5 when the collision graph of Materials call back is based on body vs body collision, it does not offer sufficient resolution for bodies with multi material shapes like terrains, and compound, and collision scenes.
the collision user data pointer put that on the end user hands and you can do it anyway you want.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by wivlaro » Sat Jul 30, 2016 8:11 am
Thanks. How do I make one of the bodies affected by the collision and the other not affected?
-
wivlaro
-
- Posts: 10
- Joined: Sun Jul 21, 2013 5:16 am
by JoeJ » Sat Jul 30, 2016 11:31 am
- Code: Select all
int BodyGetMaterialX (const Body* body)
{
BodyData *data = (BodyData*) BodyGetUserData ((Body*)body);
return data->materialIndex;
}
int GenericOnAABBOverlap (const NewtonMaterial* material, const NewtonBody* body0, const NewtonBody* body1, int threadIndex)
{
if (BodyGetMaterialX (body0)==0 && BodyGetMaterialX (body1)==0) return 0;
return 1;
}
// set the callback somewhere at setup:
NewtonMaterialSetCollisionCallback (world, defMatID, defMatID, GenericOnAABBOverlap, MyGenericContactProcess);
NewtonMaterialSetCallbackUserData (world, defMatID, defMatID, this);
I do it this way, although it is based on body user data, not from collision (I never understood the role of materials).
It may not be the best way - but just to show you this stuff is based an callbacks.
What happens is the callback is called from Newton broadphase when bounding boxes overlap,
and when returning 0 the pair is not further processed (so no exact collision needs to be calculated).
I set also MyGenericContactProcess, where i can do things like overwriting contact velocity or collect exact collision data. I think you can set this to zero if you don't need this.
-
JoeJ
-
- Posts: 1453
- Joined: Tue Dec 21, 2010 6:18 pm
by wivlaro » Sun Jul 31, 2016 8:20 am
Looking at the comments above NewtonMaterialSetCollisionCallback it says
If the function *processCallback* was set, the application receives a callback for every contact found between the two colliding bodies. Here the application can perform fine grain control over the behavior of the collision system. For example, rejecting the contact, making the contact frictionless, applying special effects to the surface etc.
If I use the ProcessContact callback I don't see any API calls that will let me modify the contact joint at all. I just want to have one body carry on as if there was no collision at all, and the other one to be moved by it.
-
wivlaro
-
- Posts: 10
- Joined: Sun Jul 21, 2013 5:16 am
by wivlaro » Sun Jul 31, 2016 8:26 am
Actually I have another idea.
If I add another collidable object attached to the same body.
Static objects - collide with everything. (S)
My dynamic game objects
- one collider that collides the rigid body (G)
- one collider which is set up as a kinematic object and kept at the same position (H)
Dynamic fluff VFX objects with their colliders (V)
Then I only accept collisions between S & G, and separately between S & V and H & V
I think I will try this.
-
wivlaro
-
- Posts: 10
- Joined: Sun Jul 21, 2013 5:16 am
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 12 guests