A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by samisaham » Fri Oct 16, 2009 11:20 pm
I am having trouble figuring out how to get the materialPair userdata in the NewtonContactsProcess callback when one of the objects is a trigger volume. Is there a way to do this yet? I am using Newton 2 beta. I tried the following without success:
- Code: Select all
void HandleContactLevel (const NewtonJoint* contactJoint, dFloat timestep, int threadIndex)
{
NewtonMaterial* material;
BUOYANCYDAT* info;
void* contact = NewtonContactJointGetFirstContact (contactJoint);
material = NewtonContactGetMaterial (contact);
info = (BUOYANCYDAT*)NewtonMaterialGetMaterialPairUserData(material);
}
I have been experimenting and searching the forums and tutorials but to no avail. Any help would be much appreciated!
Thanks,
-hanson
-
samisaham
-
- Posts: 15
- Joined: Mon Mar 24, 2008 11:59 am
by samisaham » Mon Oct 26, 2009 10:40 am
This is rather important to me. Is there any way to get the material pair userData for collisions with a trigger volume?
-
samisaham
-
- Posts: 15
- Joined: Mon Mar 24, 2008 11:59 am
by JernejL » Mon Oct 26, 2009 3:23 pm
In newton2 you receive a contactjoint, you need to iterate the contactjoint for all contacts, and use things like NewtonJointGetBody0, NewtonJointGetBody1, NewtonBodyGetMaterialGroupID, NewtonMaterialGetUserData there.
Example code how to use new material callback in newton2 for delphi:
- Code: Select all
function CarHitCar(const contact: PNewtonJoint; timestep: float; threadindex: integer): longint; cdecl;
var
pos, nor: vector;
ImpactForce: single;
TotalDamage: single;
ContactCar0, ContactCar1: Tcar;
material: Pnewtonmaterial;
ThisContact: PNewtonJoint;
begin
ContactCar0 := NewtonBodyGetUserData(NewtonJointGetBody0(contact));
ContactCar1 := NewtonBodyGetUserData(NewtonJointGetBody1(contact));
// use NewtonBodyGetMaterialGroupID and NewtonMaterialGetUserData for both bodies here..
Result := 1;
TotalDamage := 0;
ThisContact := NewtonContactJointGetFirstContact(contact);
while ThisContact <> nil do
begin
material := NewtonContactGetMaterial(ThisContact);
NewtonMaterialGetContactPositionAndNormal(material, @pos, @nor);
ThisContact := NewtonContactJointGetNextContact(contact, ThisContact);
end;
-

JernejL
-
- Posts: 1587
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by samisaham » Mon Oct 26, 2009 6:50 pm
Thanks so much! I finally got it working:
- Code: Select all
const NewtonBody* body0;
const NewtonBody* body1;
BUOYANCYDAT* info;
body0 = NewtonJointGetBody0 (contactJoint);
body1 = NewtonJointGetBody1 (contactJoint);
info = (BUOYANCYDAT*)NewtonMaterialGetUserData(NewtonBodyGetWorld(body0), NewtonBodyGetMaterialGroupID(body0),NewtonBodyGetMaterialGroupID(body1));
I'd think there would be an easier way as there was with the old method, but in any case I'm glad it's working now

Thanks
-Sam Hanson
-
samisaham
-
- Posts: 15
- Joined: Mon Mar 24, 2008 11:59 am
by Carli » Tue Oct 27, 2009 3:18 am
a c++man able to read pascal code???? very rare
-
Carli
-
- Posts: 245
- Joined: Fri Oct 02, 2009 5:28 am
by JernejL » Tue Oct 27, 2009 3:24 am
Carli wrote:a c++man able to read pascal code???? very rare
When you look at details.. the pascal / delphi syntax is not as different from c++ as it appears

-

JernejL
-
- Posts: 1587
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Carli » Tue Oct 27, 2009 4:00 am
i know - that's the reason why i can't understand c++mans who are not able to read pascal (espeacially opengl-commands

)
i love pascal - espeacially the platform-independency of lazarus/freepascal
-
Carli
-
- Posts: 245
- Joined: Fri Oct 02, 2009 5:28 am
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 2 guests