MAV with Tokamak, maybe a collision problem?

Blitz3D Forums/Blitz3D Userlibs/MAV with Tokamak, maybe a collision problem?

Damien Sturdy(Posted 2005) [#1]
Hi peeps...

Ive just started using tokamak and have it working almost perfectly where ODE would just cough, choke and die...

i have a building, destroyable. Then i have the player who shoots a "cannon" spheres at the model.

All works for a while, but then suddenly when i click "shoot", boom. MAV on "toksim_advance"

WHat ive done is create a system where tokamak runs through a type, and i can "addobject"s to the scene.

Here is my INIT function and related const's:
Const Rigid_Bodies=5000,Animated_Bodies=2
Function Tok_init()
Local tbodies=rigid_bodies+animated_bodies

TOKSIM_SetRigidBodiesCount Rigid_Bodies
TOKSIM_SetAnimatedBodiesCount Animated_Bodies
TOKSIM_SetRigidParticleCount 0
TOKSIM_SetControllersCount 0
TOKSIM_SetGeometriesCount Rigid_bodies+Animated_Bodies ;Assuming each one only has one geometry.  Not true with more complex rigid bodies and animated bodies.
TOKSIM_CreateSimulator(0,-1.8,0)
TOKSIM_SetOverlappedPairsCount(TBodies*(TBodies-1)/2)
;SetGeometriesCount 
End Function



Here is how i create the objects:
b\body=Tokrb_create()
b\mesh=CreateCube()
ScaleMesh b\mesh,.5,.5,.5
ScaleEntity b\mesh,Length,height,width
b\geom=Tokrb_addbox(b\body,Length,height,width)
Tokrb_setmass(b\body,mass)
Tokrb_setposition b\body,x,y,z
PositionEntity b\mesh,x,y,z
TOKRB_SetBoxInertiaTensor b\body,Length,height,width,mass


I have a "life" parameter to all tokamak objects that when reaches 0, the tokamak object is freed as so:

tokrb_free b\body
TOKRB_RemoveGeometry(b\body%,b\Geom) ;Is this needed? error happens with and without.
FreeEntity b\mesh
delete B



heres the code that is executed when the player shoots:

sp.Tok_object=tok_createobject(1,EntityX(camera),EntityY(camera),EntityZ(camera),20,20,20,400):EntityColor sp\mesh,0,0,0:EntityShininess sp\mesh,1
sp\life=-150
TFormVector 0,0,55,camera,0
TOKRB_Setvelocity(sp\body,TFormedX(),TFormedY(),TFormedZ())


The spheres are created by code the same as the cubes above, just using the sphere commands

Are there any bugs i need to know about/avoid? what do i need to add to INIT to stop this from happening?


Sweenie(Posted 2005) [#2]
I don't know of any specific bug when creating new bodies but there definitely is one major bug that causes Tokamak to crash when freeing bodies.
It has something to do with freeing bodies that has been in contact with other bodies during the last timestep.
To prevent this from happening, move the body to free out of "harms way"(move it a long way from the other bodies) then let the simulation advance one timestep and after that it should be ok to release it.
You won't need to remove the geometry, it's handled by tokamak.


Damien Sturdy(Posted 2005) [#3]
Sweenie, thanks for replying. Ahh, so it IS a collision thing.

i accidentally found that thread after hours of looking. The bug still happens, but not as often by doing your technique. I will try moving the object away for 2 frames.

Would just Tokrb_active(body,0) for noe frame also do the job? ive noted that when i disable my bricks they still seem to collide with themselves :/


Or, would i move them to a totally unique place for each object, and tokrb_active 0 them?

Also, the error only ever happened when creating an object, not freeing them. Could/is the bug related to freeing then creating?

Other than this my EasyMak Wrapper is working nicely with it. simple commands to init, create visual objects and update them, rather than the user have to lock a blitzmesh to everything they create and worry about all these things.

Now ive finally gone Toka, i realised just how bad ODE can be.

nice work man.. Wish you could work more on it. :)