unit uLegs;

interface

uses uGlobal;

function model_legs_biped(Params: array of variant): variant; stdcall;
function model_legs_biped_physic(Params: array of variant): variant; stdcall;

implementation

function model_legs_biped(Params: array of variant): variant; stdcall;
var
  P, R, S: array of Double;

  //Base
  Model: integer;
  BaseRoot, Leg1Root, Leg1Up, Leg1Down, Foot1, Leg2Root, Leg2Up, Leg2Down, Foot2: integer;
begin
  SetLength(P, 3);
  SetLength(R, 3);
  SetLength(S, 3);
  P[0]:=0;  P[1]:=0;  P[2]:=0;
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  S[0]:=1;  S[1]:=1;  S[2]:=1;

  //Init POA-Animated Object
  Result:=call('POAAdd',[]);
  call('POAFrames',[Result, 9]);

  P[0]:=0;  P[1]:=0;  P[2]:=0;
  BaseRoot:=call('POAObjectAdd',[Result, otRoot, P,R,S]);
  //exit;
  P[0]:=0;  P[1]:=0;  P[2]:=3;
  Leg1Root:=call('POAObjectAdd',[Result, otRoot, P,R,S]);
  call('glObjectParent', [call('poaObjectID', [Result, Leg1Root]), call('poaObjectID', [Result, BaseRoot])]);

  P[0]:=0;  P[1]:=0;  P[2]:=0;
  Leg1UP:=call('POAObjectAdd',[Result, otRoot, P,R,S]);
  call('glObjectParent', [call('poaObjectID', [Result, Leg1UP]), call('poaObjectID', [Result, Leg1Root])]);

  P[0]:=0;  P[1]:=-5;  P[2]:=0;
  Leg1Down:=call('POAObjectAdd',[Result, otRoot, P,R,S]);
  call('glObjectParent', [call('poaObjectID', [Result, Leg1Down]), call('poaObjectID', [Result, Leg1UP])]);

  P[0]:=0;  P[1]:=-7;  P[2]:=0;
  Foot1:=call('POAObjectAdd',[Result, otRoot, P,R,S]);
  call('glObjectParent', [call('poaObjectID', [Result, Foot1]), call('poaObjectID', [Result, Leg1Down])]);

  P[0]:=0;  P[1]:=0;  P[2]:=-3;
  Leg2Root:=call('POAObjectAdd',[Result, otRoot, P,R,S]);
  call('glObjectParent', [call('poaObjectID', [Result, Leg2Root]), call('poaObjectID', [Result, BaseRoot])]);

  P[0]:=0;  P[1]:=0;  P[2]:=0;
  Leg2UP:=call('POAObjectAdd',[Result, otRoot, P,R,S]);
  call('glObjectParent', [call('poaObjectID', [Result, Leg2UP]), call('poaObjectID', [Result, Leg2Root])]);

  P[0]:=0;  P[1]:=-5;  P[2]:=0;
  Leg2Down:=call('POAObjectAdd',[Result, otRoot, P,R,S]);
  call('glObjectParent', [call('poaObjectID', [Result, Leg2Down]), call('poaObjectID', [Result, Leg2UP])]);

  P[0]:=0;  P[1]:=-7;  P[2]:=0;
  Foot2:=call('POAObjectAdd',[Result, otRoot, P,R,S]);
  call('glObjectParent', [call('poaObjectID', [Result, Foot2]), call('poaObjectID', [Result, Leg2Down])]);

  ///====================

  P[0]:=0;  P[1]:=0;  P[2]:=0;
  R[0]:=0;  R[1]:=0;  R[2]:=90;
  S[0]:=0.1;  S[1]:=0.1;  S[2]:=0.1;

  Model:=call('POAObjectAdd',[Result, otModel, P,R,S, 'data/models/leg_base.3ds']);
  call('glObjectParent', [call('poaObjectID', [Result, Model]), call('poaObjectID', [Result, BaseRoot])]);

  ///====================

  P[0]:=0;  P[1]:=0;  P[2]:=0;
  R[0]:=-90;  R[1]:=0;  R[2]:=0;
  S[0]:=0.1;  S[1]:=0.1;  S[2]:=0.1;

  Model:=call('POAObjectAdd',[Result, otModel, P,R,S, 'data/models/leg_part1.3ds']);
  call('glObjectParent', [call('poaObjectID', [Result, Model]), call('poaObjectID', [Result, Leg1Up])]);

  Model:=call('POAObjectAdd',[Result, otModel, P,R,S, 'data/models/leg_part2.3ds']);
  call('glObjectParent', [call('poaObjectID', [Result, Model]), call('poaObjectID', [Result, Leg1Down])]);

  R[0]:=180;  R[1]:=0;  R[2]:=-90;
  Model:=call('POAObjectAdd',[Result, otModel, P,R,S, 'data/models/leg_foot.3ds']);
  call('glObjectParent', [call('poaObjectID', [Result, Model]), call('poaObjectID', [Result, Foot1])]);

  ///====================

  P[0]:=0;  P[1]:=0;  P[2]:=0;
  R[0]:=-90;  R[1]:=0;  R[2]:=0;
  S[0]:=0.1;  S[1]:=0.1;  S[2]:=0.1;

  Model:=call('POAObjectAdd',[Result, otModel, P,R,S, 'data/models/leg_part1.3ds']);
  call('glObjectParent', [call('poaObjectID', [Result, Model]), call('poaObjectID', [Result, Leg2Up])]);

  Model:=call('POAObjectAdd',[Result, otModel, P,R,S, 'data/models/leg_part2.3ds']);
  call('glObjectParent', [call('poaObjectID', [Result, Model]), call('poaObjectID', [Result, Leg2Down])]);

  R[0]:=180;  R[1]:=0;  R[2]:=-90;
  Model:=call('POAObjectAdd',[Result, otModel, P,R,S, 'data/models/leg_foot.3ds']);
  call('glObjectParent', [call('poaObjectID', [Result, Model]), call('poaObjectID', [Result, Foot2])]);

  //====================================

  call('POAReset',[Result]);

  P[0]:=0;  P[1]:=0;  P[2]:=0;
  S[0]:=1;  S[1]:=1;  S[2]:=1;

  R[0]:=0;  R[1]:=0;  R[2]:=-8;
  call('poaTransformAdd', [Result, 1, BaseRoot, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 1, Leg1Up, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 1, Leg1Down, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 1, Foot1, P,R,S]);

  R[0]:=0;  R[1]:=0;  R[2]:=3;
  call('poaTransformAdd', [Result, 2, BaseRoot, P,R,S]);
  R[0]:=35;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 2, Leg1Up, P,R,S]);
  R[0]:=35;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 2, Leg1Down, P,R,S]);
  R[0]:=30;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 2, Foot1, P,R,S]);

  R[0]:=0;  R[1]:=0;  R[2]:=8;
  call('poaTransformAdd', [Result, 3, BaseRoot, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 3, Leg1Up, P,R,S]);
  R[0]:=80;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 3, Leg1Down, P,R,S]);
  R[0]:=45;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 3, Foot1, P,R,S]);

  R[0]:=0;  R[1]:=0;  R[2]:=-3;
  call('poaTransformAdd', [Result, 4, BaseRoot, P,R,S]);
  R[0]:=-45;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 4, Leg1Up, P,R,S]);
  R[0]:=90;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 4, Leg1Down, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 4, Foot1, P,R,S]);

  //

  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 3, Leg2Up, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 3, Leg2Down, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 3, Foot2, P,R,S]);

  R[0]:=35;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 4, Leg2Up, P,R,S]);
  R[0]:=35;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 4, Leg2Down, P,R,S]);
  R[0]:=30;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 4, Foot2, P,R,S]);

  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 1, Leg2Up, P,R,S]);
  R[0]:=80;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 1, Leg2Down, P,R,S]);
  R[0]:=45;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 1, Foot2, P,R,S]);

  R[0]:=-45;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 2, Leg2Up, P,R,S]);
  R[0]:=90;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 2, Leg2Down, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 2, Foot2, P,R,S]);

  //BACKTIME

  R[0]:=0;  R[1]:=0;  R[2]:=-8;
  call('poaTransformAdd', [Result, 8, BaseRoot, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 8, Leg1Up, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 8, Leg1Down, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 8, Foot1, P,R,S]);

  R[0]:=0;  R[1]:=0;  R[2]:=3;
  call('poaTransformAdd', [Result, 7, BaseRoot, P,R,S]);
  R[0]:=35;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 7, Leg1Up, P,R,S]);
  R[0]:=35;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 7, Leg1Down, P,R,S]);
  R[0]:=30;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 7, Foot1, P,R,S]);

  R[0]:=0;  R[1]:=0;  R[2]:=8;
  call('poaTransformAdd', [Result, 6, BaseRoot, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 6, Leg1Up, P,R,S]);
  R[0]:=80;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 6, Leg1Down, P,R,S]);
  R[0]:=45;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 6, Foot1, P,R,S]);

  R[0]:=0;  R[1]:=0;  R[2]:=-3;
  call('poaTransformAdd', [Result, 5, BaseRoot, P,R,S]);
  R[0]:=-45;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 5, Leg1Up, P,R,S]);
  R[0]:=90;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 5, Leg1Down, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 5, Foot1, P,R,S]);

  //

  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 6, Leg2Up, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 6, Leg2Down, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 6, Foot2, P,R,S]);

  R[0]:=35;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 5, Leg2Up, P,R,S]);
  R[0]:=35;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 5, Leg2Down, P,R,S]);
  R[0]:=30;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 5, Foot2, P,R,S]);

  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 8, Leg2Up, P,R,S]);
  R[0]:=80;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 8, Leg2Down, P,R,S]);
  R[0]:=45;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 8, Foot2, P,R,S]);

  R[0]:=-45;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 7, Leg2Up, P,R,S]);
  R[0]:=90;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 7, Leg2Down, P,R,S]);
  R[0]:=0;  R[1]:=0;  R[2]:=0;
  call('poaTransformAdd', [Result, 7, Foot2, P,R,S]);

  call('poaFrameStart', [Result, 1]);
  call('poaFrameEnd', [Result, 4]);
end;

function model_legs_biped_physic(Params: array of variant): variant; stdcall;
var
  J: integer;
  Axis, Anchor: array of Double;
begin
  SetLength(Axis, 3);
  SetLength(Anchor, 3);

  Axis[0]:=0; Axis[1]:=0; Axis[2]:=1;
  Anchor[0]:=0; Anchor[1]:=0; Anchor[2]:=0;

  //BaseRoot, Leg1Root, Leg1Up, Leg1Down, Foot1, Leg2Root, Leg2Up, Leg2Down, Foot2
 { call('odeObjectAdd', [call('poaObjectID',[Result, BaseRoot]), ptDynamic, otCube]);
  call('odeObjectAdd', [call('poaObjectID',[Result, Leg1Root]), ptDynamic, otCube]);
  call('odeObjectAdd', [call('poaObjectID',[Result, Leg1Up]), ptDynamic, otCube]);
  call('odeObjectAdd', [call('poaObjectID',[Result, Leg1Down]), ptDynamic, otCube]);
  call('odeObjectAdd', [call('poaObjectID',[Result, Foot1]), ptDynamic, otCube]);
  call('odeObjectAdd', [call('poaObjectID',[Result, Leg2Root]), ptDynamic, otCube]);
  call('odeObjectAdd', [call('poaObjectID',[Result, Leg2Up]), ptDynamic, otCube]);
  call('odeObjectAdd', [call('poaObjectID',[Result, Leg2Down]), ptDynamic, otCube]);
  call('odeObjectAdd', [call('poaObjectID',[Result, Foot2]), ptDynamic, otCube]);}


  {J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], BaseRoot]), ptDynamic, otCube]);
  call('odeObjectParams', [call('poaObjectID',[Params[0], BaseRoot]), J, 6, 1, 6]);
  //J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], Leg1Root]), ptDynamic, otCube]);
  J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], Leg1Up]), ptDynamic, otCube]);

  J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], Leg1Down]), ptDynamic, otCube]);
  J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], Foot1]), ptDynamic, otCube]);

  J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], Leg2Root]), ptDynamic, otCube]);
  J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], Leg2Up]), ptDynamic, otCube]);
  J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], Leg2Down]), ptDynamic, otCube]);
  J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], Foot2]), ptDynamic, otCube]);   }


  {
  J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], BaseRoot]), ptDynamic, otCube]);
  call('odeObjectParams', [call('poaObjectID',[Params[0], BaseRoot]), J, 6, 1, 6]);

  J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], Leg1Up]), ptDynamic, otCube]);
  call('odeObjectParams', [call('poaObjectID',[Params[0], Leg1Up]), J, 1, 4, 0.5]);
  J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], Leg1Down]), ptDynamic, otCube]);
  call('odeObjectParams', [call('poaObjectID',[Params[0], Leg1Down]), J, 0.75, 3, 0.5]);
  J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], Foot1]), ptDynamic, otCube]);
  call('odeObjectParams', [call('poaObjectID',[Params[0], Foot1]), J, 1, 0.5, 1]);

  J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], Leg2Up]), ptDynamic, otCube]);
  call('odeObjectParams', [call('poaObjectID',[Params[0], Leg2Up]), J, 1, 4, 0.5]);
  J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], Leg2Down]), ptDynamic, otCube]);
  call('odeObjectParams', [call('poaObjectID',[Params[0], Leg2Down]), J, 0.75, 3, 0.5]);
  J:=call('odeObjectAdd', [call('poaObjectID',[Params[0], Foot2]), ptDynamic, otCube]);
  call('odeObjectParams', [call('poaObjectID',[Params[0], Foot2]), J, 1, 0.5, 1]);


  J:=call('odeJointAdd', [call('poaObjectID',[Params[0], BaseRoot]),call('poaObjectID',[Params[0], Leg1up])]);
  Anchor[0]:=0; Anchor[1]:=7; Anchor[2]:=0;
  call('odeJointParams', [j, Axis, Anchor]);

  J:=call('odeJointAdd', [call('poaObjectID',[Params[0], BaseRoot]),call('poaObjectID',[Params[0], Leg2up])]);
  Anchor[0]:=0; Anchor[1]:=7; Anchor[2]:=0;
  call('odeJointParams', [j, Axis, Anchor]);
                                                 {
  J:=call('odeJointAdd', [call('poaObjectID',[Params[0], Leg1Root]),call('poaObjectID',[Params[0], Leg1Up])]);
  Anchor[0]:=0; Anchor[1]:=7; Anchor[2]:=0;
  call('odeJointParams', [j, Axis, Anchor]);

  J:=call('odeJointAdd', [call('poaObjectID',[Params[0], Leg2Root]),call('poaObjectID',[Params[0], Leg2Up])]);
  Anchor[0]:=0; Anchor[1]:=7; Anchor[2]:=0;
  call('odeJointParams', [j, Axis, Anchor]);   }

  {J:=call('odeJointAdd', [call('poaObjectID',[Params[0], Leg1Up]),call('poaObjectID',[Params[0], Leg1Down])]);
  Anchor[0]:=0; Anchor[1]:=3; Anchor[2]:=0;
  call('odeJointParams', [j, Axis, Anchor]);

  J:=call('odeJointAdd', [call('poaObjectID',[Params[0], Leg2Up]),call('poaObjectID',[Params[0], Leg2Down])]);
  Anchor[0]:=0; Anchor[1]:=3; Anchor[2]:=0;
  call('odeJointParams', [j, Axis, Anchor]);

  J:=call('odeJointAdd', [call('poaObjectID',[Params[0], Leg1Down]),call('poaObjectID',[Params[0], Foot1])]);
  Anchor[0]:=0; Anchor[1]:=0; Anchor[2]:=0;
  call('odeJointParams', [j, Axis, Anchor]);

  J:=call('odeJointAdd', [call('poaObjectID',[Params[0], Leg2Down]),call('poaObjectID',[Params[0], Foot2])]);
  Anchor[0]:=0; Anchor[1]:=0; Anchor[2]:=0;
  call('odeJointParams', [j, Axis, Anchor]);
   }
end;

end.
