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