UPulleys.pas
上传用户:zkjn0718
上传日期:2021-01-01
资源大小:776k
文件大小:2k
源码类别:

Delphi/CppBuilder

开发平台:

Delphi

  1. unit UPulleys;
  2. interface
  3. {$I ......SourcePhysics2D.inc}
  4. uses
  5.    UMain, UPhysics2DTypes, UPhysics2D, SysUtils;
  6. type
  7.    TPulleys = class(TTester)
  8.    public
  9.       m_joint1: Tb2PulleyJoint;
  10.       constructor Create; override;
  11.       procedure Step(var settings: TSettings; timeStep: Float); override;
  12.    end;
  13. implementation
  14. { TPulleys }
  15. constructor TPulleys.Create;
  16. var
  17.    ground: Tb2Body;
  18.    bd: Tb2BodyDef;
  19.    sd: Tb2PolygonDef;
  20.    body1, body2: Tb2Body;
  21.    pulleyDef: Tb2PulleyJointDef;
  22.    b, y, L: Float;
  23. begin
  24.    inherited;
  25.    begin
  26.       sd := Tb2PolygonDef.Create;
  27.       sd.SetAsBox(50.0, 10.0);
  28.       bd := Tb2BodyDef.Create;
  29.       {$IFDEF OP_OVERLOAD}
  30.       bd.position.SetValue(0.0, -10.0);
  31.       {$ELSE}
  32.       SetValue(bd.position, 0.0, -10.0);
  33.       {$ENDIF}
  34.       ground := m_world.CreateBody(bd);
  35.       ground.CreateShape(sd);
  36.    end;
  37.    begin
  38.       b := 4.0;
  39.       y := 16.0;
  40.       L := 12.0;
  41.       sd := Tb2PolygonDef.Create;
  42.       sd.SetAsBox(2, b);
  43.       sd.density := 5.0;
  44.       bd := Tb2BodyDef.Create;
  45.       {$IFDEF OP_OVERLOAD}
  46.       bd.position.SetValue(-10.0, y);
  47.       {$ELSE}
  48.       SetValue(bd.position, -10.0, y);
  49.       {$ENDIF}
  50.       body1 := m_world.CreateBody(bd, False);
  51.       body1.CreateShape(sd, False);
  52.       body1.SetMassFromShapes;
  53.       {$IFDEF OP_OVERLOAD}
  54.       bd.position.SetValue(10.0, y);
  55.       {$ELSE}
  56.       SetValue(bd.position, 10.0, y);
  57.       {$ENDIF}
  58.       body2 := m_world.CreateBody(bd);
  59.       body2.CreateShape(sd);
  60.       body2.SetMassFromShapes;
  61.       pulleyDef := Tb2PulleyJointDef.Create;
  62.       pulleyDef.Initialize(body1, body2, MakeVector(-10.0, y + b + L),
  63.          MakeVector(10.0, y + b + L), MakeVector(-10.0, y + b), MakeVector(10.0, y + b), 2.0);
  64.       m_joint1 := Tb2PulleyJoint(m_world.CreateJoint(pulleyDef));
  65.    end;
  66. end;
  67. procedure TPulleys.Step(var settings: TSettings; timeStep: Float);
  68. var
  69.    L: Float;
  70. begin
  71.    inherited;
  72.    L := m_joint1.GetLength1 + m_joint1.GetRatio * m_joint1.GetLength2;
  73.    DrawText(Format('L1 + %4.2f * L2 = %4.2f', [m_joint1.GetRatio, L]));
  74. end;
  75. initialization
  76.    RegisterTestEntry('Pulleys', TPulleys);
  77. end.