New to Tokamak

Blitz3D Forums/Blitz3D Userlibs/New to Tokamak

Steven Noyce(Posted 2006) [#1]
I am new to tokamak. I have tried a few things but none of them seem to work.

First of all, why doesn't this work?
Graphics3D 640,480
SetBuffer BackBuffer()

tok_setupphysics(2,0,0,-1,0)

light=CreateLight()

camera=CreateCamera()
PositionEntity camera,0,3,-10

TOKSIM_SetMaterial(1,.1,.5)

sphere=CreateSphere()
PositionEntity sphere,0,5,0
tok_sphere=TOKRB_Create()
TOKGEOM_SetMaterialIndex(tok_sphere,1)
TOKRB_AddSphere(tok_sphere,1)
TOKRB_SetPosition(tok_sphere,0,5,0)

bowl=CreateSphere()
ScaleEntity bowl,5,.1,5
tok_bowl=TOKRB_Create()
TOKGEOM_SetMaterialIndex(tok_bowl,1)
TOKRB_AddBox(tok_bowl,5,1,5)

While Not KeyDown(1)

PositionEntity sphere,TOKRB_GetX(tok_sphere),TOKRB_GetY(tok_sphere),TOKRB_GetZ(tok_sphere)

TOKSIM_Advance .02,1
UpdateWorld
RenderWorld
Flip
Wend
End
TOKSIM_DestroySimulator()

Function TOK_SetUpPhysics(rigids,anims,gx#,gy#,gz#)
	TOKSIM_SetRigidBodiesCount rigids
	TOKSIM_SetAnimatedBodiesCount anims
	TOKSIM_SetGeometriesCount rigids+anims
	TOKSIM_SetOverlappedPairsCount ((rigids+anims)*((rigids+anims)-1))/2   
	TOKSIM_CreateSimulator(gx,gy,gz)
End Function

Also, any advice on tokomak in general would be very helpful.

Please post any useful ideas!


Sweenie(Posted 2006) [#2]
Uhmm??
It does work.
I'll guess you want the sphere to collide with the bowl?
Well, it won't since the bowl is falling as well.
Try making the bowl an AnimatedBody instead...
tok_bowl=TOKAB_Create()
TOKAB_AddBox(tok_bowl,5,1,5)


Steven Noyce(Posted 2006) [#3]
Thanks!
Are animated bodies not affected by gravity?
What are all of the differences between rigid and animated bodies?


Sweenie(Posted 2006) [#4]
This confuses many.
A Tokamak Rigid Body is dynamic and is affected by forces.
A Tokamak Animated Body is static and thus not affected by forces.
I suppose Animated means that the user will have to animate it, which isn't recommended by the way since that will cause undesired behaviours.
Other physics APIs just use the term Rigid Body and let a RigidBody be static if it's mass is equal to 0.


Steven Noyce(Posted 2006) [#5]
So if you wanted to move something, you would want to make it a rigid body, not an animated body?

That seems a little bit backwards to me, but whatever.


Vorderman(Posted 2006) [#6]
I think I'm using animated bodies for the network cars in SRX - they're positioned each net update and therefore the player's local rigid-body car can hit them.

Seems to work OK, and far better than any other method I've found to do net collisions.


Steven Noyce(Posted 2006) [#7]
If I wanted things to collide with a ground mesh, with lots of hills and other phisical features, how could I set this up in tokamak?

All I have seen are commands for convex bodies, but a terrain like mesh would be concave, wouldn't it?


Sweenie(Posted 2006) [#8]
You can provide Tokamak with a static mesh using the TOKSIM_SetStaticMesh function.

You can see an example on how to use it in this bb code...
http://www.svenberra.net/TokaRally.bb
Look for the MakeTokCollider function in the code...

If you want to compile and run the sample above you'll need these files...
www.svenberra.net/tokamakrally.zip


Steven Noyce(Posted 2006) [#9]
First off, what if you want to have separate planets or asteroids that you want to move and land on with tokamak physics? Is that even remotely possible?

Next, how do you get the time to put into the TOKSIM_Advance command?

And finally, what is the best way to move an entity forward (like moveentity 0,0,1 in blitz)?


Sweenie(Posted 2006) [#10]
a. depends on what you mean with separate planets and asteroids.
"Fullsize" planets won't work for any existing physicsengine, but if you meant isolated islands of polygon data than that should work with tokamak.
The triangles of the static mesh doesn't need to be connected. You can't move them though.

b. the easy way, just get the elapsed time since the last frame. Get the time at the start of the frame using millisecs() and get the time at the end of the frame. The elapsed time is the endtime - starttime. Note though that Tokamak want the time in seconds so you have to divide the milliseconds by 1000 first.

The better way is do decouple the physicsupdate from the renderupdates and update the physics at a fixed rate.
That will make sure the simulation is stable at all times but is a bit trickier to implement.

Check the castledemo in the samples archive, that demo also uses tweening which will make the bodies move smoother. The castledemo locks the updaterate to 30 FPS, make it at least 60 for better physicsperformance.

c) The correct way is to apply forces to the body.
The easier way is to directly set it's velocity.
The forbidden way is to directly set it's position.
Also, tokamak works with global coordinates so if you want a body to move where it's pointing you'll have to transform the force vectors first.
See the TransformVector function.


Steven Noyce(Posted 2006) [#11]
I am confused, what TransformVector function are you talking about? Where can I find it?


Sweenie(Posted 2006) [#12]
Sorry, it's name is TFormVector and is a part of the Blitz3D commandset.

Use it like this...
TFormVector 0,0,8, SpaceShip,0

This transforms the local vector 0,0,8 (In this case, the spaceship's local space) into Global(world) space.

Fetch the resulting vectors from TFormedX(), TFormedY() and TFormedZ() and apply them as a force to the spaceship.
This would make the space move like it has a thruster in the back, given that your spaceship is aligned along the z-axis.


Steven Noyce(Posted 2006) [#13]
Thanks! That is a cool way to do it.