## beta 16, some treecollisions not working

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

### beta 16, some treecollisions not working

Hi,
after fixing the matrix problems and other stuff, I was testing the treecollisions. The first result was very promising because they worked. But after some intensive testing I had some problems. Some coltrees works perfectly, and others really behave curious. In general the curious trees don't work at all, but on some not reproduceable times somewhere a collision is noticed.

Attached Image shows what I mean.

This is my treecollision code:
Code: Select all
`Type TPhysicBody   Field body:Byte Ptr   Field node:Byte Ptr   Field World:TPhysicWorld   Field matrix:Float[16]   Field Mesh:TMesh   Field Volume:Float   Field AABB:TVec3[2]   Field UpdateForce:Float[3]   Field Mass:Float      Method Setup()       Node =  newtonCreateBody(World.World , Body)      NewtonBodySetMatrix(Node , Mesh.Mat.grid)      newtonBodySetUserData(node ,Self)            Volume = NewtonConvexCollisionCalculateVolume(Body)      AABB[0] = New TVec3      AABB[1] = New TVec3      NewtonBodyGetAABB(Node,AABB[0].Pointer(),AABB[1].Pointer())      UpdateForce = [0.0 , 9.81 , 0.0]      World.AddPhysicBody(Self)   End Method      Method Update()      newtonBodyGetMatrix(Node , Mesh.Mat.grid)   End Method      Method SetMass(Mass:Float = 0)      Self.Mass = Mass      Local Massp:Float[3]      Local Inertia:Float[3]      NewtonConvexCollisionCalculateInertialMatrix(body,Inertia,Massp)      NewtonBodySetCentreOfMass(Node,Massp)      newtonBodySetMassMatrix(Node , Mass , inertia[0] , inertia[1], inertia[2])   End Method      Method ApplyImpulse(impactX:Float , ImpactY:Float , ImpactZ:Float , ForceX:Float , ForceY:Float , ForceZ:Float)       NewtonBodyAddImpulse(node , [ForceX , ForceY , ForceZ] , [impactX , impactY , impactZ])    End MethodEnd TypeType TPhysicBodyComplexHull Extends TPhysicBody      Function Create:TPhysicBodyComplexHull (World:TPhysicWorld,Mesh:TMesh,Optimized:Byte)      Local B:TPhysicBodyComplexHull = New TPhysicBodyComplexHull       B.Mesh = Mesh      B.World = World      B.Body = NewtonCreateTreeCollision(World.World)       NewtonTreeCollisionBeginBuild(B.Body)      Local Vector:Float[9]      For   Local Surf:TSurface = EachIn Mesh.surf_List            For Local I:Int = 0 To surf.no_tris-1               Local v0=surf.TriangleVertex(i,2)               Local v1=surf.TriangleVertex(i,1)               Local v2=surf.TriangleVertex(i,0)                              Vector[0] = surf.VertexX(v0)               Vector[1] = surf.VertexY(v0)               Vector[2] = -surf.VertexZ(v0)                              Vector[3] = surf.VertexX(v1)               Vector[4] = surf.VertexY(v1)               Vector[5] = -surf.VertexZ(v1)                              Vector[6] = surf.VertexX(v2)               Vector[7] = surf.VertexY(v2)               Vector[8] = -surf.VertexZ(v2)                              NewtonTreeCollisionAddFace(B.Body,3,Vector,12,0)            Next      Next            If Optimized = True Then          NewtonTreeCollisionEndBuild(B.Body , 1)       Else         NewtonTreeCollisionEndBuild(B.Body , 0)      End If      B.Setup      Return B   End FunctionEnd Type`

another thing I've noticed: If I enable simd instructions then the NewtonUpdate function causes random crashes if I add to many bodys at the same time. Without simd it works fine.

Did I miss something?
Attachments
The tree collisions are all done by the same function shown in the thread.
newton.jpg (115.36 KiB) Viewed 5917 times
klepto2

Posts: 8
Joined: Sun Jan 28, 2007 7:31 pm

### Re: beta 16, some treecollisions not working

try using a single thead, to eleminate the posibility of race condition in call back

I see you are still doing the funny mutiply by -1, you shoud not have to do that.
I beleive the SSE code is correct.
I never had a crash evet with 30 tousan bozes stress test.
Julio Jerez
Moderator

Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: beta 16, some treecollisions not working

Well, it is just running in one thread. Because Blitzmax doesn't support Multithreading. the thing with multiplying -1 is just because of the different z axis behaviour between my Engine and raw openGL. the z values are internally inverted and thas the only way I get correct treecollisions, at least the shape.

But what I don't understand is why do some treecollisions work and others do?
klepto2

Posts: 8
Joined: Sun Jan 28, 2007 7:31 pm

### Re: beta 16, some treecollisions not working

klepto2 wrote:But what I don't understand is why do some treecollisions work and others do?

yes I do nto get that either, it could be a bug, all three collision should work and that prarticular one seems very simple.
Is the wire frame in the image the newton debug collision?

do you have a test for debugging?
if you have a test can you make so that it has only one body falling in the place the reproduce the bug?

klepto2 wrote:Well, it is just running in one thread. Because Blitzmax doesn't support Multithreading

I heard that before, it is wierd, has you tried?
because I beleive that it should work in mutthreaded mode in blizmax also. even if blith max is not mutthireaded.
you are no making thread in blithmax, the thread are crated a child of the Newton main thread in the DLL.
but that is a different problem.
Julio Jerez
Moderator

Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: beta 16, some treecollisions not working

I noticed something wrong in your set mass funtion

Code: Select all
`   Method SetMass(Mass:Float = 0)      Self.Mass = Mass      Local Massp:Float[3]      Local Inertia:Float[3]      NewtonConvexCollisionCalculateInertialMatrix(body,Inertia,Massp)      NewtonBodySetCentreOfMass(Node,Massp)      newtonBodySetMassMatrix(Node , Mass , inertia[0] , inertia[1], inertia[2])   End Method`

this line is wrong
newtonBodySetMassMatrix(Node , Mass , inertia[0] , inertia[1], inertia[2])

is should be
newtonBodySetMassMatrix(Node , Mass , Mass * inertia[0] , Mass * inertia[1], Mass * inertia[2])

that migh take care of the curios psosition as you call it
please try that fix, it is impostant
Julio Jerez
Moderator

Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: beta 16, some treecollisions not working

thx for the fix with the mass.
I have uploaded a small sample which will create a row of boxes along the bridge if you press the left mouse button.
A hit on F5 will cycle through the viewmodes : 0 - no debug lines, 1 - normal debug lines, 2 - same as 1 but without depthtesting soyou will see the whole mesh.

Test application

I had multithreading already working, but this was with beta 11or 12. With the newer Versions I wasn't able to run it in multithreaded mode. The trick was to disable the GarbageCollector during NewtonUpdate() but this doesn't work anymore.
Also the speedgain was maybe less then 1 or to 2 %. I will investigate the multithreading problem as soosn as my other lib is working.
klepto2

Posts: 8
Joined: Sun Jan 28, 2007 7:31 pm

### Re: beta 16, some treecollisions not working

Ok I will check teh demo.
the mutithreade mode in beta 16 is the same as all beta. teh diffrnectr is the teh lock unlock i spass to the application.
bu teh er are tow funtion to control the look/unloc
anyway that is a diffrnet problem
Julio Jerez
Moderator

Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: beta 16, some treecollisions not working

I get this error unpacking

! C:\temp\newtontest.rar: CRC failed in scene\chaindot3.png. The file is corrupt
! C:\temp\newtontest.rar: Unexpected end of archive
Julio Jerez
Moderator

Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: beta 16, some treecollisions not working

hmm, it works for me. Anyway I reuploaded it and also added a ZIP archiv. Hopefully one of these work.

ZIP

klepto2

Posts: 8
Joined: Sun Jan 28, 2007 7:31 pm

### Re: beta 16, some treecollisions not working

are the debug lin eteh newton debug line or you mesh debug line.

also can you change the demo so that it only place the box that is falling the collision?
It is too hard for me to issolate the bug with so many objects.

I need to write a visual debugge to facilitate debugging this problems.
Julio Jerez
Moderator

Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: beta 16, some treecollisions not working

OK, I have removed the fountain and there is just one box which is falling down to earth.
The debug lines are Newtons debuglines. I have created a not optimized version of the Colltree, but with an optimized one its the same.

Just copy the new exe in the old directory.

[edit:]
Maybe I could serialize the collisiongeometry for you, maybe you're able to test it with your own apps?
klepto2

Posts: 8
Joined: Sun Jan 28, 2007 7:31 pm

### Re: beta 16, some treecollisions not working

the execultable do nto run. i get a window erro sayon it is not a win32 file.
Julio Jerez
Moderator

Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: beta 16, some treecollisions not working

The filesize should be: 1666560 bytes
klepto2

Posts: 8
Joined: Sun Jan 28, 2007 7:31 pm

### Re: beta 16, some treecollisions not working

The problem is that you are setting teh transformation of teh static body with scale into teh matrix. Netwon do not support scale into the body matrix
scale is supported with transform modifier, unfortunally collision trees do not support transform modifier.
if you apply the scale to each face of teh tree as you pass then to the collision tree then the bug will go away. something like this

Code: Select all
`collision = Create Collison treeBeginFacefor each face  tringle = face(i)   scale each face (scale matrix)  collision->addFace()end facebody = newtoBoidy (collision)BodySetMatrix (matrix without scale)`

then it will work fine.
Julio Jerez
Moderator

Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: beta 16, some treecollisions not working

damn, you're right. Because the model loading is done internally I wasn't able to see this. Sorry for this stupid mistake.
I will fix this. thx

again sorry and thx for your valuable time
klepto2

Posts: 8
Joined: Sun Jan 28, 2007 7:31 pm