|  | 
 
 What is Blitz-Tokamak?Blitz Tokamak is a Blitz friendly wrapper written by Sweenie for the excellent Tokamak physics DLL.You need the blitz wrapper from here http://www.freewebs.com/sweenie/ and the Tokamak DLL from here http://www.tokamakphysics.com/ The Tokamak DLL needs to go into your system folder OR your application/source folder. What can I do with Blitz-Tokamak?You can create tons of things using blitz-tokamak for physics. It's features include:
 What are all the TOK*** beginings on all the commands?These beginnings divide all the commands up into sections:
 How do I write a blitz-tokamak program?This is obviously a more complex subject, and the focus of this tutorial.The first thing to do is to set up the simulator like this: This sets it up - and gives the vector to use as gravity. In this case, the gravity is down in the y direction by 10. When setting these values keep in mind that the greater your gravity, and the greater the time step(covered later), the more likely objects will have errors, and go through meshs or other objects. This is why you should use blitz picking commands instead of tokamak for fast moving bullets etc. Now, Tokamak is slightly limited by the fact that it has to know how many various objects you will have before you actually start up the simulation. You can set the following things: 
 This sets up the simulator with the appropriate amounts of memory. As you can see, I didn't use TOKSIM_SetOverlappedPairsCount, as the total number of rigid bodies is only 105, not much different from 100, so the default value will be fine. I'm assuming you have some knowledge of blitz3d. Here is the scene setup: Now, we'll set up the animated body for the ground. In this case, it never actually moves. Tokab_Create creates an animated body and returns its handle. Tokab_AddBox adds a box to the animated body. The parameters are AnimatedBody, Width, Height, Depth. Tokab_SetPosition sets the position of the animated body. The parameters are AnimatedBody, X, Y, Z. Here is the rest of the animated bodies setup: This creates all the walls Next, we create a rigid box. The Arrays are used to store the handle of the Rigid Body, and the handles of the 3d representation. The Rigid Body is created with the TOKRB_Create command which returns a handle. The command TOKRB_AddBox adds a box to the rigid body. The parameters are the diminsions of the box. Note that the dimensions are twice that off the values in scaleentity because Blitz primitives are 2 units in each dimension. This command does return a handle to a geometry, however, at this point no geometric modifications are being made so it is unnessesary. The next command sets the position of the rigid body. TOKRB_SetLinearDamping and TOKRB_SetAngularDamping set the linear dampening and angular damping respectivly. These can be thought of as air friction, or just to correct problems. Basically, all it means is that over time, an object will be slowed down linearly or angularly based upon how fast it is going. TOKRB_SetMass sets the mass of the object. The greater the mass, the less SetForce or other objects affect it. TOKRB_SetBoxInertiaTensor sets the inertia tensor of an object. If you only have one geometry in your mesh, use this command, except with the specified object. The other parameters are the dimensions. So if your geometry was a sphere, you would use TOKRB_SetSphereInertiaTensor Now, instead of only creating one, we'll create a bunch of them randomly placed with random velocities. The TOKRB_SetVelocity and TOKRB_SetTorque commands obviously sets the linear and angular velocity of the rigid body. Now, we'll write the skeleton of the main loop: This gives us a scene with the camera moving around and around. you should see what looks like one white box in the middle. Here's where the real fun comes in. this is the point where we add in the tokamak updater into the for...Next Loop The command, TOKSIM_Advance, advances the physics simulation. The first parameter is the time step. A larger time step makes things go faster, a smaller one makes it go slower. This is useful for slow mo fx, etc. The second parameter sets the number of sub steps, which allow for more accurate processing of physics. This code: Positions and rotates the 3d representations of the objects onto the tokamak rigid bodies. The code: Gives all the objects a random spinning and moving velocity. The command TOKRB_ApplyImpulse2 applies an impulse at a location other than the center of the object, producing both movement and rotation. Finally, we destroy the simulator and end the program. Here is all the code for the demo. If it does not work, check to see if v04 of sweenie's wrapper are in your userlibs directory and the tokamak dll is either in the program directory or the windows/system32 folder. For a printable copy of this article, please click HERE. 
 This site is Copyright© 2000-2004, BlitzCoder. All rights reserved.   |