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

Postby klepto2 » Thu Jul 31, 2008 7:49 am

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 Method

End Type


Type 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 Function
End 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
newton.jpg
The tree collisions are all done by the same function shown in the thread.
newton.jpg (115.36 KiB) Viewed 9512 times
klepto2
 
Posts: 8
Joined: Sun Jan 28, 2007 7:31 pm

Re: beta 16, some treecollisions not working

Postby Julio Jerez » Thu Jul 31, 2008 8:33 am

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
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: beta 16, some treecollisions not working

Postby klepto2 » Thu Jul 31, 2008 8:43 am

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

Postby Julio Jerez » Thu Jul 31, 2008 8:57 am

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
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: beta 16, some treecollisions not working

Postby Julio Jerez » Thu Jul 31, 2008 9:07 am

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
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: beta 16, some treecollisions not working

Postby klepto2 » Thu Jul 31, 2008 10:23 am

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

Postby Julio Jerez » Thu Jul 31, 2008 10:28 am

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
teh muthreaded you lead to about 80% gain with two core.
anyway that is a diffrnet problem
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: beta 16, some treecollisions not working

Postby Julio Jerez » Thu Jul 31, 2008 10:30 am

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
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: beta 16, some treecollisions not working

Postby klepto2 » Thu Jul 31, 2008 10:45 am

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

RAR Reuploaded
ZIP

thx in advance
klepto2
 
Posts: 8
Joined: Sun Jan 28, 2007 7:31 pm

Re: beta 16, some treecollisions not working

Postby Julio Jerez » Thu Jul 31, 2008 11:03 am

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
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: beta 16, some treecollisions not working

Postby klepto2 » Thu Jul 31, 2008 11:13 am

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.

Link: New Executable
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

Postby Julio Jerez » Thu Jul 31, 2008 11:20 am

the execultable do nto run. i get a window erro sayon it is not a win32 file.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: beta 16, some treecollisions not working

Postby klepto2 » Thu Jul 31, 2008 11:23 am

could you redownload it.I have just tested it and maybe your download was corrupt.

The filesize should be: 1666560 bytes
klepto2
 
Posts: 8
Joined: Sun Jan 28, 2007 7:31 pm

Re: beta 16, some treecollisions not working

Postby Julio Jerez » Tue Aug 05, 2008 6:40 am

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 tree
BeginFace
for each face
  tringle = face(i)
  scale each face (scale matrix)
  collision->addFace()
end face

body = newtoBoidy (collision)
BodySetMatrix (matrix without scale)


then it will work fine.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: beta 16, some treecollisions not working

Postby klepto2 » Tue Aug 05, 2008 7:13 am

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


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 16 guests