http://www.newtondynamics.com/wiki/index.php?title=Difference_between_collision_callback_from_newton_1.53&feed=atom&action=historyDifference between collision callback from newton 1.53 - Revision history2024-03-28T13:13:58ZRevision history for this page on the wikiMediaWiki 1.30.2http://www.newtondynamics.com/wiki/index.php?title=Difference_between_collision_callback_from_newton_1.53&diff=117&oldid=prevWikiSysop: 1 revision imported2019-06-10T08:02:10Z<p>1 revision imported</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr style="vertical-align: top;" lang="en-GB">
<td colspan="1" style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: white; color:black; text-align: center;">Revision as of 08:02, 10 June 2019</td>
</tr><tr><td colspan="2" style="text-align: center;" lang="en-GB"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>WikiSysophttp://www.newtondynamics.com/wiki/index.php?title=Difference_between_collision_callback_from_newton_1.53&diff=116&oldid=prevUnknown user at 08:02, 10 June 20192019-06-10T08:02:10Z<p></p>
<p><b>New page</b></p><div>== Description ==<br />
<br />
The [[NewtonMaterialSetCollisionCallback]] callbacks have changed slightly in functionality with newer newton: <br />
<br />
[[NewtonContactBegin]] has been renamed to [[NewtonOnAABBOverlap]], the functionality is identical. <br />
<br />
[[NewtonContactsProcess ]] is now called only once per pair of bodies in a contact, to get actual contacts you must now use a iterator, see below for example. <br />
<br />
[[NewtonContactEnd]] has been removed as it became redundant. if you used this, you only have to move the code to the end of [[NewtonContactsProcess]] callback routine.<br />
<br />
== Porting old code ==<br />
<br />
A usual approach in newton 1.53 was, to store the two bodies that were being processed in [[NewtonContactBegin]] and then for each contact get a call to [[NewtonContactsProcess]].<br />
But in latest newton, there are new functions such as [[NewtonJointGetBody0]] and [[NewtonJointGetBody1]] for this purpose, which you use inside the new [[NewtonContactsProcess]] callback, If you cached the newton body pointers from [[NewtonContactBegin]] callback you should no longer rely on that and use [[NewtonJointGetBody0]] and [[NewtonJointGetBody1]], as these two callbacks may now be called in a different order for many bodies! <br />
<br />
== NewtonContactsProcess ==<br />
<br />
Newton library now calls [[NewtonContactsProcess]] just once for ALL contacts, in parameter it passes you a "contact joint" handle.<br />
To get the actual contacts you have to use [[NewtonContactJointGetFirstContact]] and [[NewtonContactJointGetNextContact]], this enables you to write contact processing in a much more efficient way. <br />
<br />
== Example of a new NewtonContactsProcess callback ==<br />
<br />
This is a simple callback for two "cars", which when hit spawn some spark effects and apply some damage.<br />
<br />
<source lang="pascal"><br />
<br />
function NewtonContactsProcessTest(const contact: PNewtonJoint; timestep: float; threadindex: integer): longint; cdecl;<br />
var<br />
pos, nor: vector;<br />
ImpactForce: single;<br />
TotalDamage: single;<br />
ContactCar0, ContactCar1: Tcar;<br />
material: Pnewtonmaterial;<br />
ThisContact: PNewtonJoint;<br />
begin<br />
<br />
ContactCar0 := NewtonBodyGetUserData(NewtonJointGetBody0(contact));<br />
ContactCar1 := NewtonBodyGetUserData(NewtonJointGetBody1(contact));<br />
<br />
Result := 1;<br />
TotalDamage := 0;<br />
<br />
ThisContact := NewtonContactJointGetFirstContact(contact);<br />
<br />
while ThisContact <> nil do<br />
begin<br />
material := NewtonContactGetMaterial(ThisContact);<br />
<br />
NewtonMaterialGetContactPositionAndNormal(material, @pos, @nor);<br />
<br />
ImpactForce := NewtonMaterialGetContactNormalSpeed(material);<br />
TotalDamage := TotalDamage + ImpactForce;<br />
<br />
if (ImpactForce > 0.3) then<br />
spawnsomesparks(pos);<br />
<br />
if ImpactForce > 3 then begin<br />
ContactCar0.damage(ImpactForce);<br />
ContactCar1.damage(ImpactForce);<br />
end;<br />
<br />
ThisContact := NewtonContactJointGetNextContact(contact, ThisContact);<br />
end;<br />
<br />
<br />
</source><br />
<br />
[[Category:Porting old code from newton 1.53]]</div>Unknown user