#include once "InitGL.bi"

#define USEDEBUG ' "optional" enable debug rendering and error report in file "debug.txt"
#include once "TrueAxis.bi"

InitGL()
PhysicsCreateInstance()

' create a dynamic box (1m x 3m x 0.2m)
dim as DynamicObject ptr box = DynamicObjectCreateNew()
DynamicObjectInitialiseAsABox(box,0,0,0, 1,3,0.2)
DynamicObjectSetPosition(box,0,10,0)
DynamicObjectSetRotationD(box,0,0,15) ' pitch, yaw, roll in "D"egree
' add the box to the simulation
PhysicsAddDynamicObject box

' create a static XZ plane Y=0 (5m x 5m)
PhysicsAddStaticGround(5)


dim as integer  frames
dim as KeyCodes key

' render and simulation loop
while key<>K_ESCAPE andalso key<>K_WINDOW_CLOSE
  key=GetKeyCode()
  ' one step in simulation (75Hz.)
  PhysicsUpdate(1.0/75.0)
  ' render every third physics frame (25Hz.)
  if frames mod 3=0 then
    glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
    glLoadIdentity
    glTranslatef 0,-2,-15
    ' draw all objects (only in debug mode) 
    PhysicsRender()
    ' sometimes usefull also
    'PhysicsRenderBoundingBoxes() 
    flip
  end if
  Sleep(10) ' time sharing
  frames+=1
wend

