UFixedJoint.pas
上传用户:zkjn0718
上传日期:2021-01-01
资源大小:776k
文件大小:3k
- unit UFixedJoint;
- interface
- {$I ......SourcePhysics2D.inc}
- uses
- UMain, UPhysics2DTypes, UPhysics2D, SysUtils;
- type
- TFixedJoint = class(TTester)
- public
- constructor Create; override;
- end;
- implementation
- { TFixedJoint }
- constructor TFixedJoint.Create;
- var
- bd, bd1, bd2: Tb2BodyDef;
- sd, sd1, sd2: Tb2PolygonDef;
- ground, body1, body2: Tb2Body;
- jd: Tb2FixedJointDef;
- 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
- bd1 := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd1.position.SetValue(1.0, 7.0);
- {$ELSE}
- SetValue(bd1.position, 1.0, 7.0);
- {$ENDIF}
- bd1.angle := 0.7;
- body1 := m_world.CreateBody(bd1);
- sd1 := Tb2PolygonDef.Create;
- sd1.vertexCount := 3;
- {$IFDEF OP_OVERLOAD}
- sd1.vertices[0].SetValue(-2.0, -2.0);
- sd1.vertices[1].SetValue(2.0, -2.0);
- sd1.vertices[2].SetValue(2.0, 2.0);
- {$ELSE}
- SetValue(sd1.vertices[0], -2.0, -2.0);
- SetValue(sd1.vertices[1], 2.0, -2.0);
- SetValue(sd1.vertices[2], 2.0, 2.0);
- {$ENDIF}
- sd1.density := 10.0;
- sd1.friction := 0.2;
- body1.CreateShape(sd1);
- body1.SetMassFromShapes;
- bd2 := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd2.position.SetValue(5.0, 6.0);
- {$ELSE}
- SetValue(bd2.position, 5.0, 6.0);
- {$ENDIF}
- bd2.angle := -0.2;
- body2 := m_world.CreateBody(bd2);
- sd2 := Tb2PolygonDef.Create;
- sd2.SetAsBox(1.0, 2.0);
- sd2.density := 30.0;
- sd2.friction := 0.2;
- body2.CreateShape(sd2);
- body2.SetMassFromShapes;
- jd := Tb2FixedJointDef.Create;
- jd.collideConnected := False;
- jd.Initialize(body1, body2);
- m_world.CreateJoint(jd);
- end;
- begin
- bd1 := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd1.position.SetValue(20, 20);
- {$ELSE}
- SetValue(bd1.position, 20, 20);
- {$ENDIF}
- body1 := m_world.CreateBody(bd1);
- sd1 := Tb2PolygonDef.Create;
- sd1.SetAsBox(2, 2);
- sd1.density := 10.0;
- sd1.friction := 0.5;
- sd1.restitution := 0.0;
- body1.CreateShape(sd1);
- body1.SetMassFromShapes;
- bd2 := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd2.position.SetValue(-5, 10);
- {$ELSE}
- SetValue(bd2.position, -5, 10);
- {$ENDIF}
- body2 := m_world.CreateBody(bd2);
- sd2 := Tb2PolygonDef.Create;
- sd2.SetAsBox(2.0, 2.0);
- sd2.density := 10.0;
- sd2.friction := 0.5;
- sd2.restitution := 0.0;
- body2.CreateShape(sd2);
- body2.SetMassFromShapes;
- jd := Tb2FixedJointDef.Create;
- jd.collideConnected := False;
- jd.Initialize(body1, body2);
- m_world.CreateJoint(jd);
- end;
- end;
- initialization
- RegisterTestEntry('Fixed Joint', TFixedJoint);
- end.