UVaryingRestitution.pas
上传用户:zkjn0718
上传日期:2021-01-01
资源大小:776k
文件大小:1k
源码类别:
Delphi/CppBuilder
开发平台:
Delphi
- unit UVaryingRestitution;
- interface
- {$I ......SourcePhysics2D.inc}
- uses
- UMain, UPhysics2DTypes, UPhysics2D, SysUtils;
- type
- TVaryingRestitution = class(TTester)
- public
- constructor Create; override;
- end;
- implementation
- { TVaryingRestitution }
- constructor TVaryingRestitution.Create;
- const
- restitution: array[0..6] of Single = (0.0, 0.1, 0.3, 0.5, 0.75, 0.9, 1.0);
- var
- i: Integer;
- sd: Tb2PolygonDef;
- bd: Tb2BodyDef;
- ground: Tb2Body;
- cd: Tb2CircleDef;
- body: Tb2Body;
- 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;
- cd := Tb2CircleDef.Create;
- cd.radius := 1.0;
- cd.density := 1.0;
- bd := Tb2BodyDef.Create;
- for i := 0 to 6 do
- begin
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(-10.0 + 3.0 * i, 20.0);
- {$ELSE}
- SetValue(bd.position, -10.0 + 3.0 * i, 20.0);
- {$ENDIF}
- body := m_world.CreateBody(bd, False);
- cd.restitution := restitution[i];
- body.CreateShape(cd, False);
- body.SetMassFromShapes;
- end;
- cd.Free;
- bd.Free;
- end;
- initialization
- RegisterTestEntry('Varying Restitution', TVaryingRestitution);
- end.