UVaryingFriction.pas
上传用户:zkjn0718
上传日期:2021-01-01
资源大小:776k
文件大小:2k
源码类别:
Delphi/CppBuilder
开发平台:
Delphi
- unit UVaryingFriction;
- interface
- {$I ......SourcePhysics2D.inc}
- uses
- UMain, UPhysics2DTypes, UPhysics2D, SysUtils;
- type
- TVaryingFriction = class(TTester)
- public
- constructor Create; override;
- end;
- implementation
- { TVaryingFriction }
- constructor TVaryingFriction.Create;
- const
- friction: array[0..4] of Single = (0.75, 0.5, 0.35, 0.1, 0.0);
- var
- i: Integer;
- sd: Tb2PolygonDef;
- bd: Tb2BodyDef;
- body: Tb2Body;
- begin
- inherited;
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(50.0, 20.0);
- bd := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(0.0, -20.0);
- {$ELSE}
- SetValue(bd.position, 0.0, -20.0);
- {$ENDIF}
- m_world.CreateBody(bd, False).CreateShape(sd, False);
- sd.SetAsBox(13.0, 0.25);
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(-4.0, 22.0);
- {$ELSE}
- SetValue(bd.position, -4.0, 22.0);
- {$ENDIF}
- bd.angle := -0.25;
- m_world.CreateBody(bd, False).CreateShape(sd, False);
- sd.SetAsBox(0.25, 1.0);
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(10.5, 19.0);
- {$ELSE}
- SetValue(bd.position, 10.5, 19.0);
- {$ENDIF}
- m_world.CreateBody(bd, False).CreateShape(sd, False);
- sd.SetAsBox(13.0, 0.25);
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(4.0, 14.0);
- {$ELSE}
- SetValue(bd.position, 4.0, 14.0);
- {$ENDIF}
- bd.angle := 0.25;
- m_world.CreateBody(bd, False).CreateShape(sd, False);
- sd.SetAsBox(0.25, 1.0);
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(-10.5, 11.0);
- {$ELSE}
- SetValue(bd.position, -10.5, 11.0);
- {$ENDIF}
- m_world.CreateBody(bd, False).CreateShape(sd, False);
- sd.SetAsBox(13.0, 0.25);
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(-4.0, 6.0);
- {$ELSE}
- SetValue(bd.position, -4.0, 6.0);
- {$ENDIF}
- bd.angle := -0.25;
- m_world.CreateBody(bd, False).CreateShape(sd, False);
- sd.SetAsBox(0.5, 0.5);
- sd.density := 25.0;
- bd.angle := 0.0;
- for i := 0 to 4 do
- begin
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(-15.0 + 4.0 * i, 28.0);
- {$ELSE}
- SetValue(bd.position, -15.0 + 4.0 * i, 28.0);
- {$ENDIF}
- body := m_world.CreateBody(bd, False);
- sd.friction := friction[i];
- body.CreateShape(sd, False);
- body.SetMassFromShapes;
- end;
- bd.Free;
- sd.Free;
- end;
- initialization
- RegisterTestEntry('Varying Friction', TVaryingFriction);
- end.