' file: JointSlider02.bas

' test of: DynamicObjectSetRotationDisabled

' same as JointSlider01.bas but with rotation disabled

#include once "InitGL.bi"

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

sub _AppInit_ constructor
  InitGL()
  PhysicsCreateInstance()
end sub

sub _AppExit_ destructor
  PhysicsDestroyInstance()
end sub


' create a static ground plane
PhysicsAddStaticGround(10)

' create a dynamic cube and add it to the simulation 
dim as DynamicObject ptr cube = DynamicObjectCreateNew()
DynamicObjectInitialiseAsACube cube,  0, 0, 0, 1
DynamicObjectSetPosition       cube, -5, 5,-5
PhysicsAddDynamicObject        cube

DynamicObjectSetRotationDisabled cube,1


' create a fixed joint (connection between world and dynamic object)
dim as PhysicsJoint ptr joint = DynamicObjectAddWorldJoint(cube)
' define the new joint as a slider joint
PhysicsJointInitialiseSlider joint, -5, 7,-5, _ ' position on ObjectA (2m above)
                                    -5, 7,-5, _ ' slider start
                                     5, 3, 5    ' slider end
' render and simualtion loop
dim as TA_Vec3 v3Start,v3End
dim as integer key,frames
while key<>K_ESCAPE andalso key<>K_WINDOW_CLOSE
  key=GetKeyCode()

  ' one step in simulation
  PhysicsUpdate(1.0/75)

  if frames mod 3=0 then
    glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
    glLoadIdentity
    glTranslatef 0,-5,-20
    ' draw all objects (only in debug mode) 
    PhysicsRender()

    glDisable(GL_LIGHTING)
    glBegin(GL_LINES)
      ' draw the line of joint in red
      glColor3f(1,0,0)
      PhysicsJointV3GetSliderPos0 joint,v3Start
      PhysicsJointV3GetSliderPos1 joint,v3End
      glVertex3fv(v3Start) : glVertex3fv(v3End)
      ' draw the connection in blue
      glColor3f(0,0,1)
      v3Start.x=0:v3Start.y=2:v3Start.z=0
      DynamicObjectV3Transform cube,v3Start,v3Start
      v3End.x=0:v3End.y=.5:v3End.z=0
      DynamicObjectV3Transform cube,v3End,v3End
      glVertex3fv(v3Start) : glVertex3fv(v3End)
    glEnd()
    glEnable(GL_LIGHTING)
    flip
  end if
  Sleep(10)
  frames+=1
wend

