Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by D.J.Peters »

Since 2008 there was a fatal bug in the Tokamak Physics SDK V1.05 the author self never found or fixed the bug.
(I found a tiny note somewhere on the net "the slider joint are not implemented" !)

If you connected two rigidbodies with a simple slider joint all primary parameters of the joint and the bodies like the position and orientation was NAN (not a number) !

After one week (really 5 hours x 7 days) of study the complete C++ code line by line (and by commenting out changing some stuff and recompile and tests)
I found the bug :-) (and fixed some other bugs also) and I added velocity damping and the motor to the slider joint)

Why I use tokamak in a game ?
There are many really good and big C/C++ physics libs but I don't like the complexity of this monsters and I feel me like a tiny boy if I don't understand whats going on in this libs.

~10 years ago (i can't remenber) I wrote a C++ Basic4GL tokamak plugin but this task was not possible without to understand how the C++ lib really works.
I found out day by day it looks complex but isn't at all.

For a beginner physics is a complex stuff at all. I know it self ;-)
I added some "step by step" examples (and a tiny but helpful physics debug renderer).
So if you would use physics in you game or demo but you do not know how, give it a try.
If you run in to problems ask, I will do my best to help if I can.

I added for my self and ofcourse for you some important hints in file: "tokamak-c.bi"
(I self read the file more than once to get an better understanding what are possible and how.)

My game will become more and more complexity so I must learn the tokamak SDK itself and like to share it with you.

If you would like to write a game with physics but you don't know what ?

maybe a retro pin ball machine of couse with the right sound also :-) (sound playback can be triggered by optional collision callbacks)

An epic space shooter (don't forget to disable gravity)

A kind of sorting machine (with lots of assembly lines)

A full working construction machine e.g. a crane or excavator ...

Maybe a submarine simulator.

A remote controlled drone (with some flying missions)

A learning neural network that controls a type of single creeping creature or a large swarm of them.!

Or a machine that moves president Trump out the white house ;-)
...

Don't worry about any limitations compared to other big physics packages.

There are only box, sphere, capsule and a triangle mesh terrain as primary collision shapes
but you combine many of them to get a complete new or missing collision shape.

There are no springs or damper but tokamak use sensors, a line with start point length and direction.
If this line sensor collided with any other shape you get the depth of penetration and it's simple to use it as spring/damper also.

The neSensor class is a real powerful tool.
I self will use it in my game for constructing any kind of vehicles with wheels or any other floating platform.

Download binaries and some beginner friendly examples: tokamak-1.2-c.zip Oct 2020
(Ask if you need one more "short" XYZ beginner friendly example I can post it)

Download C++ source code as Codeblocks project: tokamak-1.2-c-src.zip Oct 2020
(I changed many things and never wrote a changelog but all tiny changes are marked with "!!!" and all big changes are marked with "!!!!")

Youtube: Tokamak-1.2-c Playlist.

Youtube: Old Basic4GL Tokamak-1.05-c++ Plugin Playlist.

Joshy
Last edited by D.J.Peters on Oct 12, 2022 18:07, edited 4 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by D.J.Peters »

Example of using the Y-hinge axes as motor.
Let it run and than change the cube mass from 100 KG to 20 KG and see what happens.
Tip: Every force create the same force in opposite direction !

Joshy

Code: Select all

#include "glRenderer.bi" 

' test of:
' JointSetMotor()
' JointMotorEnable()

var gfx = glRenderer()
WindowTitle "file: 64_neJoint_hinge_motor.bas"

var sim = CreateSimulator()

' create a 1000m x 1m x 1000m satatic box as ground
var ground = CreateAnimatedBodyBox(sim,1000,1,1000)
' move it 50cm down top face = ground level 0
AnimatedBodySetPosition(ground,0,-.5,0)

var mass = 100.0
' create a 1m x 1m x 1m 100 KG cube
var cube = CreateRigidBodyCube(sim,1, mass)
' put center 50cm above the ground
RigidBodySetPosition(cube,0.0,.5,0.0)
' disable sleeping
RigidBodySetSleepingParameter(cube,0.0)

' create a 10m x 5cm x 30cm 1KG propeller
var prop = CreateRigidBodyBox(sim,10.0,0.05,0.30, 1)
' put it as little bit above the cube
RigidBodySetPosition(prop,0.0, 1.025, 0.0)
' disable sleeping
RigidBodySetSleepingParameter(prop,0.0)

' connect the cube and propeller with a joint
var joint = SimulatorCreateRigidBodyRigidBodyJoint(sim,cube,prop)
' set the joint as hinge joint
JointSetType(joint, NE_HINGE)
JointSetPositionRotationFrameWorld(joint, 0,1.0,0, 0,0,0)

' set the joint Y-axes as motor 
' 100 = desired velocity, 10 = max force
JointSetMotor(joint,100,10)
' enable the motor
JointMotorEnable(joint,true)
' enable the joint contrain
JointEnable(joint,true)

' disable collision between the cube and the connected propeller
RigidBodySetCollideConnected(cube,false)

var LookFrom = neV3(0,1.7,10)

while inkey()=""
  SimulatorAdvance(sim) ' 60 Hz.
  gfx.Advance()
  var lookAt = RigidBodyGetPositionV3(cube)
  gfx.LookAt(lookFrom,lookAt)
  gfx.Cls
  
  gfx.Render(ground)  

  gfx.GroundShadow(true)
    gfx.Render(cube)
    gfx.Render(prop)
  gfx.GroundShadow(false)
  
  gfx.Render(cube)
  gfx.Render(prop)
  
  gfx.Text(0,0,"fps: " & gfx.fps)
  gfx.Show()
wend
DestroySimulator(sim)
Last edited by D.J.Peters on Oct 22, 2020 16:02, edited 3 times in total.
Roland Chastain
Posts: 992
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by Roland Chastain »

Hello! It sounds very interesting. Thank you for sharing.

I tried a first compilation/run test. I cannot run the compiled program: the libray, which is in the same directory, is not found. I will retry tomorrow. Maybe it's too late and my mind is not clear.

[roland@localhost tokamak-1.2-c]$ fbc 02_hello_world_fullscreen.bas
[roland@localhost tokamak-1.2-c]$ ./02_hello_world_fullscreen
./02_hello_world_fullscreen: error while loading shared libraries: libtokamak-1.2-c-64.so: cannot open shared object file: No such file or directory
[roland@localhost tokamak-1.2-c]$ export PATH=/home/roland/Documents/basic/tokamak-1.2-c:$PATH
[roland@localhost tokamak-1.2-c]$ ./02_hello_world_fullscreen
./02_hello_world_fullscreen: error while loading shared libraries: libtokamak-1.2-c-64.so: cannot open shared object file: No such file or directory
[roland@localhost tokamak-1.2-c]$ fbc 02_hello_world_fullscreen.bas -p ./lib/lin
fbc: /lib64/libtinfo.so.5: no version information available (required by fbc)
fbc: Symbol `ospeed' has different size in shared object, consider re-linking
[roland@localhost tokamak-1.2-c]$ ./02_hello_world_fullscreen
./02_hello_world_fullscreen: error while loading shared libraries: libtokamak-1.2-c-64.so: cannot open shared object file: No such file or directory
[roland@localhost tokamak-1.2-c]$
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by D.J.Peters »

@Roland yes on linux libs must be found by the linker you can show where the linker will look for:

echo LD_LIBRARY_PATH
or
echo $LD_LIBRARY_PATH

on many linux distros /usr/lib or /usr/local/lib ...

if you know the path copy or move as root the lib to the lib folder

cd tokamak-1.2-c
sudo cp libtokamak-1.2-c-64.so /usr/lib
****
fbc ./31_neSandbox.bas
./31_neSandbox

Joshy
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by VANYA »

Hi Joshy!

Some examples require renderer.bi file. All other examples work.
Linux 64-bit
Roland Chastain
Posts: 992
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by Roland Chastain »

VANYA wrote:Some examples require renderer.bi file. All other examples work.
Linux 64-bit
Same for me (Linux Mageia).

@Joshy
Thank you for your help about library installation.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by D.J.Peters »

VANYA wrote:Some examples require renderer.bi file. All other examples work.
Thank you for testing
Roland Chastain wrote:Same for me Thank you for your help about library installation.
No problem and thank you for testing.
By the way this is a good example and shows how comfortable fbsound-1.2 is.
No need to install any library :-)

Joshy
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by D.J.Peters »

Ok I fixed the typo download and try again and test all examples please.
(The tokamak-c lib is the same I fixed only the *.bas files)

Thank you.

Joshy
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by VANYA »

D.J.Peters wrote:Ok I fixed the typo download and try again and test all examples please.
(The tokamak-c lib is the same I fixed only the *.bas files)

Thank you.

Joshy
All examples are working now. Thanks!
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by D.J.Peters »

VANYA wrote:All examples are working now. Thanks!
Cool now i'm safe to use tokamak lib in my game :-)

Joshy
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by D.J.Peters »

added: new example to play with in second post.
(Using the y-axes of a hinge joint as motor.)

Joshy
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by D.J.Peters »

I added a Tokamak-1.2-c youtube playlist see first post.
(I will post more videos from time to time)

Joshy

In my personal version of the glRenderer I added:

Code: Select all

declare function BeginVideoStream(byval Filename as zstring ptr, byval frameRate as long = 25, byval Quality as long = 75) as boolean
declare sub EndVideoStream()
Gunslinger
Posts: 103
Joined: Mar 08, 2016 19:10
Location: The Netherlands

Re: Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by Gunslinger »

Thanks Joshy for your hard work. I will give this one a try again.
And i don't think Someone has to understand physics completely to make a game with it.
Kaleidio
Posts: 3
Joined: Jun 07, 2021 11:46

Re: Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by Kaleidio »

Using FreeBASIC compiler 1.08.0

my code, for whatever reason, results in my rigid body getting a really large value when applying gravity, as if Tokamak for whatever reason is returning wrong floating point exponents. it only happens to error when I call SimulatorAdvance() (engine/engine.bas GameEngine.DoPhysics) the object's gravity gives it a huge number instead of a tiny one.

game.bas, gamesrc/objects.bas, engine/objects/entity.bas and engine/physics/physics.bas Engine3DPhysicsDictionary.Physics3DUpdate are the few big files in question here

you can run game.exe to see what the bug looks like. the console shows the weirdly large values in question. it makes the object snap out of existence downward into the abyss.

here's a link to the code

https://drive.google.com/file/d/1xFq8G7 ... sp=sharing

it seems like it's my code at fault but I don't understand how and don't know of any solutions
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Tokamak physics SDK V1.2 (Windows/Linux 32/64-bi)

Post by D.J.Peters »

@Kaleidio sorry I have not the time to study nor check your whole game engine source code !

Post an readable tokamak-c only example that shows me the problem please.

Joshy
Post Reply