Tokamak-c (Windows/Linux 32/64-bit) Tue Oct 17

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-c (Windows/Linux 32/64-bit) Tue Oct 17

Post by D.J.Peters »

Tokamak is a small C++ physics rigidbody library for games. (without any graphic engine)

Tokamak-c is an C wrapper I wrote completely new.

I'm sure nobody will learn or use it however I share all my work here since 2005 :-)

Joshy

My youtube tokamak playlist: https://www.youtube.com/watch?v=FUQwghB ... 0812CA9448

Download: tokamak-c.zip Tue Oct 17

Codeblocks project: tokamak-c-src.zip

Tokamak in action rendered with the modern Horde3D engine for FreeBASIC.
Image
Last edited by D.J.Peters on Oct 12, 2022 18:36, edited 10 times in total.
Jack
Posts: 6
Joined: Aug 26, 2005 23:40

Re: Tokamak-c (Windows/Linux 32/64-bit)

Post by Jack »

hi Joshy
that looks really good, thanks for sharing. :-)
St_W
Posts: 1626
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Tokamak-c (Windows/Linux 32/64-bit)

Post by St_W »

Thank you for sharing it, maybe its helpful for somebody now or in the future. I probably wont need it, though - at least I haven't yet in the past. Haven't you shared some other physics engine in the past?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Tokamak-c (Windows/Linux 32/64-bit)

Post by D.J.Peters »

Added some commands and a simple OpenGL preview renderer.

The renderer can render some of Tokamak classes: neAnimatedBody, neRigidBody, neSensor and the neTriangleMesh = Terrain.

Joshy
JohnK
Posts: 279
Joined: Sep 01, 2005 5:20
Location: Earth, usually
Contact:

Re: Tokamak-c (Windows/Linux 32/64-bit)

Post by JohnK »

compiling on windows 10, 64 bit
I copy
libtokamak-c-64.dll.a
libtokamak-c-32.dll.a
To \FreeBASIC-1.05.0-win64\lib\win64

I keep these files in the C:\FreeBASIC-1.05.0-win64\tokamak-c folder
tokamak-c-64.dll
tokamak-c-32.dll


my build error is
C:\FreeBASIC-1.05.0-win64\fbc -s console "test01.bas"
C:\FreeBASIC-1.05.0-win64\bin\win64\ld.exe: skipping incompatible C:\FreeBASIC-1.05.0-win64\lib\win64/libtokamak-c-32.dll.a when searching for -ltokamak-c-32
C:\FreeBASIC-1.05.0-win64\bin\win64\ld.exe: skipping incompatible ./tokamak-c-32.dll when searching for -ltokamak-c-32
C:\FreeBASIC-1.05.0-win64\bin\win64\ld.exe: skipping incompatible C:\FreeBASIC-1.05.0-win64\lib\win64/libtokamak-c-32.dll.a when searching for -ltokamak-c-32
C:\FreeBASIC-1.05.0-win64\bin\win64\ld.exe: skipping incompatible ./tokamak-c-32.dll when searching for -ltokamak-c-32
C:\FreeBASIC-1.05.0-win64\bin\win64\ld.exe: cannot find -ltokamak-c-32


I feel so stupid, why is this not compiling?
St_W
Posts: 1626
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Tokamak-c (Windows/Linux 32/64-bit)

Post by St_W »

There seems to be a small error in the header; it wants to import the 32-bit library although you are using 64-bit FreeBasic.

In tokamak-c.bi change

Code: Select all

#Ifndef __FB_WIN64__
#Inclib "tokamak-c-32"  
#else
#inclib "tokamak-c-64"  
#EndIf
to

Code: Select all

#Ifndef __FB_64BIT__
#Inclib "tokamak-c-32"  
#else
#inclib "tokamak-c-64"  
#EndIf
I don't think __FB_WIN64__ is a valid symbol defined by the compiler; at least it's not listed here: http://freebasic.net/wiki/wikka.php?wak ... gDddefines
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Tokamak-c (Windows/Linux 32/64-bit)

Post by D.J.Peters »

Thank you for testing It's fixed now.
I tested it on 4 boxes Win XP 32-bit / Windows 10 64-bit and Linux Slackware 32-bit / Linux Ubuntu 64-bit.

test02.bas are new and was fun a small challenge !
Normally you can shot 4 spheres near bottom of the wall and it will break
but the challenge are "how to destroy it slowly" :-)

There is a problem with the lib if I compile it with -O2
capsule capsule collision becomes error this version is compiles with -O0 (no optimation)
the error are gone but it's slow.

Last two days I study the complete tokamak C++ code and fixed some small bugs.
I understand currently 70% of all the stuff but the rest are a big secret or challenge for me.

If I find the problem I will recompile it with -O2 and make a new upload.

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

Re: Tokamak-c (Windows/Linux 32/64-bit) Jan 19, 2017

Post by D.J.Peters »

Code: Select all

#include once "rendering.bi"
const MAX_CUBES   = 30*30
dim as neSimulatorSizeInfo SizeInfo
with SizeInfo
  .rigidBodiesCount     = MAX_CUBES + 1 ' one sphere
  .animatedBodiesCount  = 1
  .geometriesCount      = .rigidBodiesCount + .animatedBodiesCount
  .overlappedPairsCount = (.geometriesCount*(.geometriesCount-1))/2
end with
var sim = CreateSimulator(SizeInfo)

var grd = CreateAnimatedBodyBox(sim,1000,2,1000)
AnimatedBodySetPosition(grd,0,-2,0)

const as integer SQR_CUBES = sqr(MAX_CUBES)
dim as neRigidBody ptr cubes(MAX_CUBES-1)
for i as integer = 0 to MAX_CUBES-1
  cubes(i) = CreateRigidBodyCube(sim,1,1)
  var col = i  \  SQR_CUBES
  var row = i mod SQR_CUBES
  RigidBodySetPosition(cubes(i),(-SQR_CUBES\2) + col + (row and 1)*0.5,-.5+row*1.01,50)
  RigidbodySetLinearDamping (cubes(i),.5)
  RigidbodySetAngularDamping(cubes(i),.5)
next

dim as RENDERER gfx
glLoadIdentity()
LookAt(0,40,-5, 0,30,20, 0,1,0)

var n=0
var flag=true
while flag=true
  n=0
  flag=false
  for i as integer = 1 to 30
    SimulatorAdvance(sim)
  next  
  gfx.cls
  gfx.render(grd)
  for i as integer = 0 to MAX_CUBES-1
    if RigidBodyIsIdle(cubes(i))=false then n+=1:flag=true
    gfx.render(cubes(i))
  next
  gfx.Swapbuffers
  windowtitle "build a wall of stacking bricks please wait until all bricks becomes resting ! ... " & n 
wend
for i as integer = 0 to MAX_CUBES-1
  RigidbodySetLinearDamping (cubes(i),0.01)
  RigidbodySetAngularDamping(cubes(i),0.01)
next

var sphere = CreateRigidBodySphere(sim,1,1000)
RigidBodySetPosition(sphere,0,SQR_CUBES\4,60)

dim as neV3 spherepos,heightpos,boxpos
dim as neV3 cannon
dim as integer frame
windowtitle "OK"
while inkey()="" 
  SimulatorAdvance(sim,1/100)
  if frame mod 3=0 then
    gfx.cls
    gfx.render(grd)
    gfx.render(sphere)
    heightpos.y=0
    for i as integer = 0 to MAX_CUBES-1
      if RigidBodyIsIdle(cubes(i)) then
        boxpos=RigidBodyGetPositionV3(cubes(i))
        if boxpos.y>heightpos.y then heightpos=boxpos
      end if
      gfx.render(cubes(i))
    next  
    gfx.Swapbuffers
  end if
  
  spherepos = RigidBodyGetPositionV3(sphere)
  if spherepos.z>55 then
    for i as integer = 0 to MAX_CUBES-1
      if RigidBodyIsIdle(cubes(i)) then
        boxpos=RigidBodyGetPositionV3(cubes(i))
        if boxpos.y>heightpos.y then heightpos=boxpos
      end if
    next  
    spherepos.x=0 : spherepos.y=heightpos.y/2 :  spherepos.z=0
    heightpos.x-=spherepos.x : heightpos.y-=spherepos.y : heightpos.z-=spherepos.z
    heightpos.x+=(rnd-rnd)*0.1:heightpos.y+=(rnd-rnd)*0.1
    V3Normalize(heightpos)
    heightpos.x*=60 : heightpos.y*=60 : heightpos.z*=60
    RigidBodySetPosition(sphere,0,spherepos.y+4,0)
    RigidBodySetVelocity(sphere,heightpos)
  end if  

  sleep 10
  frame+=1
wend
DestroySimulator(sim)
JohnK
Posts: 279
Joined: Sep 01, 2005 5:20
Location: Earth, usually
Contact:

Re: Tokamak-c (Windows/Linux 32/64-bit) Jan 19, 2017

Post by JohnK »

Very cool. I had to realize that commenting out the Sleep 10 and if frame mod 2=0 then... statements will make the simulation go faster on this slow laptop.

I assume complex bodies are made by adding triangles to neTriangleMesh object.

Great job DJ !
integer
Posts: 408
Joined: Feb 01, 2007 16:54
Location: usa

Re: Tokamak-c (Windows/Linux 32/64-bit)

Post by integer »

D.J.Peters wrote:...
I tested it on 4 boxes Win XP 32-bit / Windows 10 64-bit and Linux Slackware 32-bit / Linux Ubuntu 64-bit.
...
Joshy
on my Win xp 32
The "physictest01.bas" compiles ok, however at run time:
error: h3dInit() !

normally my screen resolution is 1280x1024.
Through the control panel screen res changed to: 1024x768 -- same error message at run time.

What program modifications should be made to avoid the run time error?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Tokamak-c (Windows/Linux 32/64-bit) Jan 19, 2017

Post by D.J.Peters »

@integer I tested my latest version of tokamak here
but you talk about a problem with Horde3D engine it's here here: http://www.freebasic.net/forum/viewtopi ... 14&t=23969

if h3dInit() fails it means you don't have a working OpenGL 2.x gfx card ?

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

Re: Tokamak-c (Windows/Linux 32/64-bit) Jan 19, 2017

Post by D.J.Peters »

Does anyone knows how to calculate the Inertia Tensor for a combined volume ?

Here are I combine 4 boxes and one sphere in the center but I don't know how to get the tensor for this kind of object.

Is it the sum of 4 box and 1 sphere inertia tensor or the sum/5 or a multiply of 5 inertia tensor matrixes ?

Joshy

Code: Select all

#include once "rendering.bi"

const as f32 MASS = 100
function CreateCombinedRigidBody(sim as neSimulator ptr) as neRigidBody ptr
  var rb = SimulatorCreateRigidBody(sim)
  var g0 = RigidBodyAddGeometry(rb)
  var g1 = RigidBodyAddGeometry(rb)
  var g2 = RigidBodyAddGeometry(rb)
  var g3 = RigidBodyAddGeometry(rb)
  var g4 = RigidBodyAddGeometry(rb)
  
  var p0 = neV3(0,0,0)
  var p1 = neV3(-1,0,-1)
  var p2 = neV3(-1,0, 1)
  var p3 = neV3( 1,0, 1)
  var p4 = neV3( 1,0,-1)
  var zero = neV3()
  GeometrySetSphereDiameter(g0,1.5) : GeometrySetPositionRotationV3(g0,p0,zero)
  GeometrySetBoxSize(g1,1,1,1) : GeometrySetPositionRotationV3(g1,p1, zero)
  GeometrySetBoxSize(g2,1,1,1) : GeometrySetPositionRotationV3(g2,p2, zero)
  GeometrySetBoxSize(g3,1,1,1) : GeometrySetPositionRotationV3(g3,p3, zero)
  GeometrySetBoxSize(g4,1,1,1) : GeometrySetPositionRotationV3(g4,p4, zero)
  RigidBodyUpdateBoundingInfo(rb)
  return rb
end function  
'
' main
'
var sim = CreateSimulator()

var ground = CreateAnimatedBodyBox(sim,500,2,500)
AnimatedBodySetPosition(ground,0,-1,0) ' make top face at zero (ground)

var rb1 = CreateCombinedRigidBody(sim)
RigidBodySetInertiaTensor(rb1,neSphereInertiaTensor(3, MASS*5))
RigidBodySetMass(rb1,MASS*5)
RigidBodyUpdateBoundingInfo(rb1)
RigidBodySetPositionRotation(rb1,-3,1.75,0, 120,0,0)

var rb2 = CreateCombinedRigidBody(sim)
RigidBodySetInertiaTensor(rb2,neBoxInertiaTensor(3,1.5,3,MASS*5))
RigidBodySetMass(rb2,MASS*5)
RigidBodyUpdateBoundingInfo(rb2)
RigidBodySetPositionRotation(rb2, 3,1.75,0, 120,0,0)

dim as RENDERER gfx
dim as integer frame
windowtitle "sleepinmg: " & RigidBodyGetSleepingParameter(rb1)
while inkey()=""
  SimulatorAdvance(sim) ' 60 Hz.
  if frame mod 2=0 then ' 30 Hz.
    gfx.cls
    glLoadIdentity()
    glTransLatef(0,-4,-20) 
    gfx.render(ground)
    gfx.render(rb1)
    gfx.render(rb2)
    gfx.Swapbuffers
  else
    sleep(10) ' don't use all CPU cycles
  end if

  frame+=1
wend
DestroySimulator(sim)
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: Tokamak-c (Windows/Linux 32/64-bit) Jan 26, 2017

Post by ike »

I'm sure nobody will learn or use it however I share all my work here since 2005 :-)
We use your work DJ! Let's say I use your FLTK lib on almost everyday base
But I have nothing to say or ask, I didnot find any bug or so ..
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Tokamak-c (Windows/Linux 32/64-bit) Jan 26, 2017

Post by D.J.Peters »

fixed a bug for 64-bit

Joshy
Post Reply