UShapeEditing.pas
上传用户:zkjn0718
上传日期:2021-01-01
资源大小:776k
文件大小:2k
源码类别:
Delphi/CppBuilder
开发平台:
Delphi
- unit UShapeEditing;
- interface
- {$I ......SourcePhysics2D.inc}
- uses
- UMain,
- UPhysics2DTypes,
- UPhysics2D,
- SysUtils,
- OpenGL;
- type
- TShapeEditing = class(TTester)
- public
- m_body: Tb2Body;
- m_shape1, m_shape2: Tb2Shape;
- constructor Create; override;
- procedure Step(var settings: TSettings; timeStep: Float); override;
- procedure Keyboard(key: Byte); override;
- end;
- implementation
- { TDistanceTest }
- constructor TShapeEditing.Create;
- var
- sd: Tb2PolygonDef;
- bd, bodydef: Tb2BodyDef;
- ground: Tb2Body;
- begin
- inherited;
- 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);
- bodydef := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bodydef.position.SetValue(0.0, 10.0);
- {$ELSE}
- SetValue(bodydef.position, 0.0, 10.0);
- {$ENDIF}
- m_body := m_world.CreateBody(bodydef);
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(4.0, 4.0, MakeVector(0.0, 0.0), 0.0);
- sd.density := 10.0;
- m_shape1 := m_body.CreateShape(sd);
- m_body.SetMassFromShapes;
- end;
- procedure TShapeEditing.Step(var settings: TSettings; timeStep: Float);
- begin
- inherited;
- DrawText('Press C create a shape, D destroy a shape.');
- end;
- procedure TShapeEditing.Keyboard(key: Byte);
- var
- sd: Tb2CircleDef;
- begin
- inherited;
- case key of
- 67{C}:
- if not Assigned(m_shape2) then
- begin
- sd := Tb2CircleDef.Create;
- sd.radius := 3.0;
- sd.density := 10.0;
- {$IFDEF OP_OVERLOAD}
- sd.localPosition.SetValue(0.5, -4.0);
- {$ELSE}
- SetValue(sd.localPosition, 0.5, -4.0);
- {$ENDIF}
- m_shape2 := m_body.CreateShape(sd);
- m_body.SetMassFromShapes;
- m_body.WakeUp;
- end;
- 68{D}:
- if Assigned(m_shape2) then
- begin
- m_body.DestroyShape(m_shape2);
- m_shape2 := nil;
- m_body.SetMassFromShapes;
- m_body.WakeUp;
- end;
- end;
- end;
- initialization
- RegisterTestEntry('Shape Editing', TShapeEditing);
- end.