So what's the best Physics Lib for B3D these days?

Blitz3D Forums/Blitz3D Programming/So what's the best Physics Lib for B3D these days?

What's everyone using? Newton, Tokamak, ODE? Pros, cons?

Since I'm tired of waiting on Max3D, I figure I'll just have to crank up B3D again and do the best I can.

IMHO PhysX is currently the best thing there is. It's benchmarked and supposedly is the faster. It's possibly the one with the most features, from what I read from the PhysX site. You should go in the Userlib and check out the PhysX thread.

From what I read, Tokamak is overly complicated.

I've use Newton for a couple of months. You can do a LOT of stuff in newton, but it's a little clumsy sometimes when you have big scenes and lots of polygons to do collision tests with. I've had numerous problems with big models (50K tris) where some tris from the level wouldn't properly collide with the player model. But you can do seriously neat things with Newton.

Anyone else have any input?

I wish someone had made a small 3d physics lib in B3D. Something for cars and the basic forces and rotation etc using blitz collision...

Verlet is somehow slow for pratical use, although I saw a decent example here but no source available.

For 3rd party thing, yes, PhysX is the best, if you want a mid quality, go JV-ODE or EasyTOK, a bit cheapr.


I wish someone had made a small 3d physics lib in B3D. Something for cars and the basic forces and rotation etc using blitz collision...



Verlet is definately not slow - I've had 50+ vehicles running solidly at 50fps and all done in blitz :

http://www.blitzbasic.com/Community/posts.php?topic=62881#703522

I may still release the source once my current project is finished. I guess that doesn't help much!

Stevie

@Stevie G - that would be great!

Im giving my vote to newton, i find it the best for my needs and i think Leadwerks also feels it's the best. He had many reasons for it, hopefully he can post here with them.

Well, the "decent example" is exactly Stevie G's post.... currently the BEST verlet usage I saw in the Blitz community.

I don't know if the source will be available finally, but the game is very good, I hope the game can be finished.

I saw a benchmark table in the plugins sections, if speed isn't the consideration, PhysX can do many plus things like cloth/force field without hardware.

well..from the testing i did a long while ago on my
800mhz machine - tokamak was way quicker.. things
may have changed..but im inclined to think that some of
these wrappers may have a part to play when it comes
to benchmarking - "easytok" implies a significant level
of abstraction...typically this results in less control, and
more calls.. though i could be very wrong.. ;) :p

I would love to license StevieG's verlet source or use it if he makes it open source. Some really great things, in addition to what StevieG has already done, could be created with that verlet lib IMHO.

I personally like Tokamak - I can't say whether it's quicker or slower than the others, having only used ODE ages ago when I made that original wrapper, which was I suspect very slow compared to current systems, but Tokamak seems to me to be much more stable - I've never once managed to break the Tokamak simulation, but with ODE I managed it frequently. Again up-to-date ODE systems may well be much more stable.

Also, as I've said before (many times) Tokamak also has a really nice friction system that works well for car wheels, whereas ODE does not. I know people dispute this point but I've yet to see an ODE driving sim or demo that matches what I've managed easily(ish) in Tokamak in SRX.

Judging only from the demos Newton appears to suffer the same grip-spin problems as ODE when simulating a vehicle.

Stevie G's vertlet stuff is amazing, esp. with hundreds of little vehicles whizzing around.

@Vorderman: In your opinion, what's the best Tokamak wrapper to use in Blitz3D these days?

From the headings in the B3D help section it's the "Tokamak command set by Bot Builder", and the decls file is just called Tokamak.decls.

I've been using it for a good few years, SRX uses it, and it has always worked perfectly with good low-level access where required.

I like Toka, same system as vordermans using. I'ma gread ODE fan too, and JV-ODE is pretty awesome.

When using toka I was able to merge it with network code almost seamlessly. doing that with ODE was a little tougher.

Out of both ODE scores the best, but toka was so much easier and quicker to use, and at the time, more stable too- though I know ODE recently got a large stability/speed boost.

Vorderman and Cygnus: Tokamak is up to version 1.0.3 now and it's open source. Is there a way to benefit from this and/or maybe we could write a new wrapper or something.

Also Vorderman: Could you post a quick and dirty demo using your Tokamak that has a few cubs falling and bouncing off each other/the ground?

I don't have any simple programs around but I do have this Ragdoll source code program that I posted ages ago - the .ZIP file you need is very nicely being hosted by Blitzsupport, link is at the bottom of the page.

http://blitzbasic.com/Community/posts.php?topic=47234#525147

I'm actually having some great success with that source code Vorderman, thanks a bunch. I also had a hard time getting the ground to do collisions, probably because of my inexperience with Tokamak though.

It seems to me you just assign a collisionID to a rigidbody and then set the collisionresponse you want....but it's not quite working that way. :(

Press the Up Arrow to spawn a cube.

Here's the source:
;Tokamak Test


Graphics3D 1024,768,32,1
SetBuffer BackBuffer()

SeedRnd MilliSecs()

Global camera = CreateCamera()
PositionEntity camera,0,20,-20
RotateEntity camera,40,0,0
light = CreateLight()
RotateEntity light,0,0,45

;TOKAMAK ENVIRONMENT SETUP
TOKSIM_SetRigidBodiesCount(500)
TOKSIM_SetGeometriesCount(500)



TOKSIM_CreateSimulator(0,-9.8,0)
;TOKSIM_SetOverlappedPairsCount(50000)
;TOKSIM_SetGeometriesCount(50000)
TOKSIM_SetCollisionResponse(1,2,1)


Global TCube

Type TCube
	Field mesh
	Field TOK_RB
End Type


;TOKAMAK GROUND PLANE
Global ground = CreateCube()
PositionEntity ground,0,0,0
ScaleMesh ground,20,.1,20
ground_TOKRB = TOKRB_Create()
TOKRB_AddBox ground_TOKRB,20,.1,20
TOKRB_SetCollisionID ground_TOKRB,2
;MakeTokCollider( ground )

 

;TOKSIM_SetMaterial 1,10,10 		;ragdoll body parts use this setting
;TOKSIM_SetMaterial 2,0.4,0.15		;tokamak level mesh uses this setting
 

Global total%

Local newTime% = MilliSecs()
Local oldTime% = newTime
Local deltaTime#

While Not KeyHit(1)
Cls

newTime = MilliSecs()
deltaTime = (newTime - oldTime) / 1000.0
oldTime = newTime

If KeyDown(200) Then CreateTCube()

For cube.TCube = Each TCube
	PositionEntity cube\mesh,TOKRB_GetX#(cube\TOK_RB),TOKRB_GetY#(cube\TOK_RB),TOKRB_GetZ#(cube\TOK_RB),True
	RotateEntity cube\mesh,TOKRB_GetPitch#(cube\TOK_RB),TOKRB_GetYaw#(cube\TOK_RB),TOKRB_GetRoll#(cube\TOK_RB),True
Next
	;ADVANCE TOKAMAK SIMULATION
	TOKSIM_Advance(deltaTime,2)

UpdateWorld
RenderWorld

Text 5,5,deltaTime
Text 5,30,total

Flip
Wend

;DESTROY THE TOKAMAK SIMULATION
TOKSIM_DestroySimulator()

End


Function CreateTCube()
	total = total + 1
	cube.TCube = New TCube
	cube\mesh = CreateCube()
	EntityColor cube\mesh,Rand(255),Rand(255),Rand(255)
	ScaleEntity cube\mesh,.5,.5,.5
	PositionEntity cube\mesh,0,10,0
	cube\TOK_RB = TOKRB_Create()
	TOKRB_AddBox cube\TOK_RB,1.0,1.0,1.0
	TOKRB_SetMass cube\TOK_RB,10.0
	TOKRB_SetPosition cube\TOK_RB,EntityX#(cube\mesh),EntityY#(cube\mesh),EntityZ#(cube\mesh)
	;TOKGEOM_SetMaterialIndex cube\TOK_RB,1
	TOKRB_ApplyImpulse cube\TOK_RB, Rnd(-1.0,1.0) , Rnd(1,01) ,Rnd(-1.0,1.0)
	TOKRB_ApplyTwist cube\TOK_RB, Rnd(-5.0,5.0) , Rnd(-5.0,5.0) ,Rnd(-5.0,5.0)
	TOKRB_SetCollisionID cube\TOK_RB,1
End Function

Function MakeTokCollider(mesh)
 scount=CountSurfaces(mesh)
 For ind=1 To scount
  surface=GetSurface(mesh,ind)
  ttltris=ttltris+CountTriangles(surface)
  ttlvert=ttlvert+CountVertices(surface)
 Next
 vertices=CreateBank(16*ttlvert)
 triangles=CreateBank(24*ttltris)
 offsetv=0
 offsett=0
 For ind=1 To scount
  surface = GetSurface(mesh,ind)
  ctr=CountTriangles(surface)
  tric=tric+cvt
  cvt=CountVertices(surface)
  ;fill bank with vertices
  For v=0 To cvt-1
   PokeFloat vertices,offsetv,VertexX#(surface,v)
   PokeFloat vertices,offsetv+4,VertexY#(surface,v)
   PokeFloat vertices,offsetv+8,VertexZ#(surface,v)
   PokeFloat vertices,offsetv+12,0.0
   offsetv=offsetv+16
  Next
  ;fill bank with triangles
  For v=0 To ctr-1
   PokeInt triangles,offsett,tric+TriangleVertex(surface,v,0)
   PokeInt triangles,offsett+4,tric+TriangleVertex(surface,v,1)
   PokeInt triangles,offsett+8,tric+TriangleVertex(surface,v,2)
   PokeInt triangles,offsett+12,2	; Material ID
   PokeInt triangles,offsett+16,0
   PokeInt triangles,offsett+20,0
   offsett=offsett+24
  Next
 Next

 ;Hand over the terrain data to Tokamak
 TOKSIM_SetStaticMesh vertices,ttlvert,triangles,ttltris
 ; Now we can free the banks as Tokamak has copied all data
 FreeBank vertices
 FreeBank triangles
End Function


I see your problem with the ground - try replacing the section in your code that creates the ground (the block under the heading ;TOKAMAK GROUND PLANE) with this:

;TOKAMAK GROUND PLANE
Global abground = TOKAB_Create()
geom = TOKAB_AddBox(abground,100.0,10.0,100.0)
TOKGEOM_SetMaterialIndex geom,1
TOKAB_SetPosition abground,0.0,-5.0,0.0
Global groundplane = CreatePlane()
PositionEntity groundplane,0,0,0


NOTE That I'm using TOKAB (animated body) rather than TOKRB (rigid body) for the ground, this is because animated bodies are fixed in place (they don't have a physical mass, just a collision geometry). If you create a normal rigid body ground it will just fall away into space same as the cubes.

Hope that helps.

Thanks Vorderman. I really like Tokamak but it seems there's not many examples out there, and the BlitzCoder site is gone and I think there were a lot of examples on it.

I'm having a lot of problems getting a basic hinge joint to work. I messed around with it all night last night and had little success. I got the two boxes to link together but I can't get it to be a really tight hinge (like a door).