UBridge.pas
上传用户:zkjn0718
上传日期:2021-01-01
资源大小:776k
文件大小:2k
- unit UBridge;
- interface
- {$I ......SourcePhysics2D.inc}
- uses
- UMain, UPhysics2DTypes, UPhysics2D, SysUtils;
- type
- TBridge = class(TTester)
- public
- constructor Create; override;
- end;
- implementation
- { TBridge }
- constructor TBridge.Create;
- const
- numPlanks = 30;
- var
- i: Integer;
- ground, prevBody, body: Tb2Body;
- sd: Tb2PolygonDef;
- bd: Tb2BodyDef;
- jd: Tb2RevoluteJointDef;
- 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
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(0.5, 0.125);
- sd.density := 20.0;
- sd.friction := 0.2;
- jd := Tb2RevoluteJointDef.Create;
- prevBody := ground;
- bd := Tb2BodyDef.Create;
- for i := 0 to numPlanks - 1 do
- begin
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(-14.5 + 1.0 * i, 5.0);
- {$ELSE}
- SetValue(bd.position, -14.5 + 1.0 * i, 5.0);
- {$ENDIF}
- body := m_world.CreateBody(bd, False);
- body.CreateShape(sd, False);
- body.SetMassFromShapes;
- jd.Initialize(prevBody, body, MakeVector(-15.0 + 1.0 * i, 5.0));
- m_world.CreateJoint(jd, False);
- prevBody := body;
- end;
- bd.Free;
- sd.Free;
- jd.Initialize(prevBody, ground, MakeVector(-15.0 + 1.0 * numPlanks, 5.0));
- m_world.CreateJoint(jd);
- end;
- end;
- initialization
- RegisterTestEntry('Bridge', TBridge);
- end.