UDominos.pas
上传用户:zkjn0718
上传日期:2021-01-01
资源大小:776k
文件大小:6k
- unit UDominos;
- interface
- {$I ......SourcePhysics2D.inc}
- uses
- UMain, UPhysics2DTypes, UPhysics2D, SysUtils;
- type
- TDominos = class(TTester)
- public
- constructor Create; override;
- end;
- implementation
- { TDominos }
- constructor TDominos.Create;
- var
- i: Integer;
- b1, b2, b3, b4, b5, b6, b7, ground, body: Tb2Body;
- sd: Tb2PolygonDef;
- bd: Tb2BodyDef;
- jd: Tb2RevoluteJointDef;
- djd: Tb2DistanceJointDef;
- d: TVector2;
- cd: Tb2CircleDef;
- 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}
- b1 := m_world.CreateBody(bd);
- b1.CreateShape(sd);
- end;
- begin
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(6.0, 0.25);
- bd := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(-1.5, 10.0);
- {$ELSE}
- SetValue(bd.position, -1.5, 10.0);
- {$ENDIF}
- ground := m_world.CreateBody(bd);
- ground.CreateShape(sd);
- end;
- begin
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(0.1, 1.0);
- sd.density := 20.0;
- sd.friction := 0.1;
- bd := Tb2BodyDef.Create;
- for i := 0 to 9 do
- begin
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(-6.0 + 1.0 * i, 11.25);
- {$ELSE}
- SetValue(bd.position, -6.0 + 1.0 * i, 11.25);
- {$ENDIF}
- body := m_world.CreateBody(bd, False);
- body.CreateShape(sd, False);
- body.SetMassFromShapes;
- end;
- sd.Free;
- bd.Free;
- end;
- begin
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(7.0, 0.25, b2Vec2_zero, 0.3);
- bd := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(1.0, 6.0);
- {$ELSE}
- SetValue(bd.position, 1.0, 6.0);
- {$ENDIF}
- ground := m_world.CreateBody(bd);
- ground.CreateShape(sd);
- end;
- begin
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(0.25, 1.5);
- bd := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(-7.0, 4.0);
- {$ELSE}
- SetValue(bd.position, -7.0, 4.0);
- {$ENDIF}
- b2 := m_world.CreateBody(bd);
- b2.CreateShape(sd);
- end;
- begin
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(6.0, 0.125);
- sd.density := 10.0;
- bd := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(-0.9, 1.0);
- {$ELSE}
- SetValue(bd.position, -0.9, 1.0);
- {$ENDIF}
- bd.angle := -0.15;
- b3 := m_world.CreateBody(bd);
- b3.CreateShape(sd);
- b3.SetMassFromShapes;
- end;
- jd := Tb2RevoluteJointDef.Create;
- jd.Initialize(b1, b3, MakeVector(-2.0, 1.0));
- jd.collideConnected := True;
- m_world.CreateJoint(jd, False);
- begin
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(0.25, 0.25);
- sd.density := 10.0;
- bd := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(-10.0, 15.0);
- {$ELSE}
- SetValue(bd.position, -10.0, 15.0);
- {$ENDIF}
- b4 := m_world.CreateBody(bd);
- b4.CreateShape(sd);
- b4.SetMassFromShapes;
- end;
- jd.Initialize(b2, b4, MakeVector(-7.0, 15.0));
- m_world.CreateJoint(jd, False);
- begin
- bd := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(6.5, 3.0);
- {$ELSE}
- SetValue(bd.position, 6.5, 3.0);
- {$ENDIF}
- b5 := m_world.CreateBody(bd);
- sd := Tb2PolygonDef.Create;
- sd.density := 10.0;
- sd.friction := 0.1;
- sd.SetAsBox(1.0, 0.1, MakeVector(0.0, -0.9), 0.0);
- b5.CreateShape(sd, False);
- sd.SetAsBox(0.1, 1.0, MakeVector(-0.9, 0.0), 0.0);
- b5.CreateShape(sd, False);
- sd.SetAsBox(0.1, 1.0, MakeVector(0.9, 0.0), 0.0);
- b5.CreateShape(sd);
- b5.SetMassFromShapes;
- end;
- jd.Initialize(b1, b5, MakeVector(6.0, 2.0));
- m_world.CreateJoint(jd, False);
- begin
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(1.0, 0.1);
- sd.density := 30.0;
- sd.friction := 0.2;
- bd := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(6.5, 4.1);
- {$ELSE}
- SetValue(bd.position, 6.5, 4.1);
- {$ENDIF}
- b6 := m_world.CreateBody(bd);
- b6.CreateShape(sd);
- b6.SetMassFromShapes;
- end;
- jd.Initialize(b5, b6, MakeVector(7.5, 4.0));
- m_world.CreateJoint(jd);
- begin
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(0.1, 1.0);
- sd.density := 10.0;
- bd := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(7.4, 1.0);
- {$ELSE}
- SetValue(bd.position, 7.4, 1.0);
- {$ENDIF}
- b7 := m_world.CreateBody(bd);
- b7.CreateShape(sd);
- b7.SetMassFromShapes;
- end;
- djd := Tb2DistanceJointDef.Create;
- djd.body1 := b3;
- djd.body2 := b7;
- {$IFDEF OP_OVERLOAD}
- djd.localAnchor1.SetValue(6.0, 0.0);
- djd.localAnchor2.SetValue(0.0, -1.0);
- d := djd.body2.GetWorldPoint(djd.localAnchor2) - djd.body1.GetWorldPoint(djd.localAnchor1);
- djd.length := d.Length;
- {$ELSE}
- SetValue(djd.localAnchor1, 6.0, 0.0);
- SetValue(djd.localAnchor2, 0.0, -1.0);
- d := Subtract(djd.body2.GetWorldPoint(djd.localAnchor2), djd.body1.GetWorldPoint(djd.localAnchor1));
- djd.length := Length(d);
- {$ENDIF}
- m_world.CreateJoint(djd);
- begin
- cd := Tb2CircleDef.Create;
- cd.radius := 0.2;
- cd.density := 10.0;
- bd := Tb2BodyDef.Create;
- for i := 0 to 3 do
- begin
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(5.9 + 2.0 * cd.radius * i, 2.4);
- {$ELSE}
- SetValue(bd.position, 5.9 + 2.0 * cd.radius * i, 2.4);
- {$ENDIF}
- body := m_world.CreateBody(bd, False);
- body.CreateShape(cd, False);
- body.SetMassFromShapes;
- end;
- cd.Free;
- bd.Free;
- end;
- end;
- initialization
- RegisterTestEntry('Dominos', TDominos);
- end.