A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Stucuk » Mon Sep 06, 2010 11:28 pm
Is it possible to send 0 as the maxSize so you can call it like the following:
- Code: Select all
NewtonCollisionCollide(World,0,Collision1,@Matrix1[0,0],Collision2,@Matrix2[0,0],Nil,Nil,Nil,0);
Assuming it didn't crash due to trying to assign data to memory that doesn't exist, would the return value be the true number of contacts or just upto maxsize?
-

Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
by Julio Jerez » Tue Sep 07, 2010 11:40 am
I am not sure, There is nothing wrong with sending zero, had you tryied?
I will just do a test because doing teh call, it may save some time.
-
Julio Jerez
- Moderator

-
- Posts: 12452
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Stucuk » Tue Sep 07, 2010 1:07 pm
I havn't tried it because i don't have a test case and its not of major importance. Only reason i am using it is so i can make a Sphere "Grow". ConvexHullModifier isn't for Spheres afaik, so iv wrote code to create a collision thats larger than the current one, then test everything thats within its AABB using the NewtonCollisionCollide and if nothing is colliding to destroy the spheres body and recreate with the new collision. If it is colliding with something then destroy the collision and try again next frame. For a simple "Is it colliding", i don't need the other stuff NewtonCollisionCollide returns but it doesn't seem to be slow when maxSize is 1.
If setting to Zero works all depends on if the return value is the total amount of contacts, or if its the total amount limited to a max of maxSize. If its the latter then with maxSize being 0 it would always return 0.
If anyone is interested in a AABB CollisionCollide which only returns if an object collides with your collision then the code iv used is below (And yes i shouldn't have used Global Variables to store stuff for CollisionCollideInAABB):
- Code: Select all
function CollisionCollide(Collision1,Collision2 : PNewtonCollision; Matrix1,Matrix2 : TMatrix) : Boolean;
var
Contacts,
Normals,
Penetration : TVec3;
begin
if not Assigned(Collision1) or not Assigned(Collision2) then
Result := False
else
Result := NewtonCollisionCollide(World,1,Collision1,@Matrix1[0,0],Collision2,@Matrix2[0,0],@Contacts[0],@Normals[0],@Penetration[0],0) > 0;
end;
function CollisionCollide(Collision : PNewtonCollision; Matrix : TMatrix; Body : PNewtonBody) : Boolean;
var
Collision2 : PNewtonCollision;
Matrix2 : TMatrix;
begin
if not Assigned(Body) then
begin
Result := False;
Exit;
end;
NewtonBodyGetMatrix(Body,@Matrix2[0,0]);
Collision2 := NewtonBodyGetCollision(Body);
Result := CollisionCollide(Collision,Collision2,Matrix,Matrix2);
end;
var
CCInAABB : Boolean;
CCCollision : PNewtonCollision;
CCMatrix : TMatrix;
CCIgnoreBody : PNewtonBody;
CCIgnoreCall : function (Body : PNewtonBody) : Boolean; cdecl;
procedure CollisionCollideBodysInAABB(const Body : PNewtonBody; userData : Pointer ); cdecl;
begin
if not Assigned(CCIgnoreCall) or not CCIgnoreCall(Body) then
CCInAABB := CCInAABB or CollisionCollide(CCCollision,CCMatrix,Body);
end;
function CollisionCollideInAABB(Collision : PNewtonCollision; Matrix : TMatrix; IgnoreCallback : Pointer) : Boolean;
var
Min,Max : TVec3;
begin
CCInAABB := False;
CCCollision := Collision;
CCMatrix := Matrix;
@CCIgnoreCall := IgnoreCallback;
if Assigned(CCCollision) then
begin
NewtonCollisionCalculateAABB(Collision,@Matrix[0,0],@Min[0],@Max[0]);
NewtonWorldForEachBodyInAABBDo(World,@Min[0],@Max[0],@CollisionCollideBodysInAABB,Nil);
end;
Result := CCInAABB;
end;
-

Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 44 guests