UPulleys.pas
上传用户:zkjn0718
上传日期:2021-01-01
资源大小:776k
文件大小:2k
- unit UPulleys;
- interface
- {$I ......SourcePhysics2D.inc}
- uses
- UMain, UPhysics2DTypes, UPhysics2D, SysUtils;
- type
- TPulleys = class(TTester)
- public
- m_joint1: Tb2PulleyJoint;
- constructor Create; override;
- procedure Step(var settings: TSettings; timeStep: Float); override;
- end;
- implementation
- { TPulleys }
- constructor TPulleys.Create;
- var
- ground: Tb2Body;
- bd: Tb2BodyDef;
- sd: Tb2PolygonDef;
- body1, body2: Tb2Body;
- pulleyDef: Tb2PulleyJointDef;
- b, y, L: Float;
- begin
- inherited;
- begin
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(50.0, 10.0);
- bd := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(0.0, -10.0);
- {$ELSE}
- SetValue(bd.position, 0.0, -10.0);
- {$ENDIF}
- ground := m_world.CreateBody(bd);
- ground.CreateShape(sd);
- end;
- begin
- b := 4.0;
- y := 16.0;
- L := 12.0;
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(2, b);
- sd.density := 5.0;
- bd := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(-10.0, y);
- {$ELSE}
- SetValue(bd.position, -10.0, y);
- {$ENDIF}
- body1 := m_world.CreateBody(bd, False);
- body1.CreateShape(sd, False);
- body1.SetMassFromShapes;
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(10.0, y);
- {$ELSE}
- SetValue(bd.position, 10.0, y);
- {$ENDIF}
- body2 := m_world.CreateBody(bd);
- body2.CreateShape(sd);
- body2.SetMassFromShapes;
- pulleyDef := Tb2PulleyJointDef.Create;
- pulleyDef.Initialize(body1, body2, MakeVector(-10.0, y + b + L),
- MakeVector(10.0, y + b + L), MakeVector(-10.0, y + b), MakeVector(10.0, y + b), 2.0);
- m_joint1 := Tb2PulleyJoint(m_world.CreateJoint(pulleyDef));
- end;
- end;
- procedure TPulleys.Step(var settings: TSettings; timeStep: Float);
- var
- L: Float;
- begin
- inherited;
- L := m_joint1.GetLength1 + m_joint1.GetRatio * m_joint1.GetLength2;
- DrawText(Format('L1 + %4.2f * L2 = %4.2f', [m_joint1.GetRatio, L]));
- end;
- initialization
- RegisterTestEntry('Pulleys', TPulleys);
- end.