Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
physics [2020/05/24 13:25] – [Callbacks] admin | physics [2020/05/24 13:30] – [Example] admin | ||
---|---|---|---|
Line 131: | Line 131: | ||
</ | </ | ||
(available since v0.8.2.1600+) | (available since v0.8.2.1600+) | ||
- | ===== Example ===== | ||
- | For a working physics system you need a TGorillaPhysicsSystem component on your form. | ||
- | |||
- | <file pascal Form1.pas> | ||
- | type | ||
- | TForm1 = class(TForm) | ||
- | GorillaViewport1: | ||
- | Light1: TLight; | ||
- | Dummy1: TDummy; | ||
- | Camera1: TCamera; | ||
- | GorillaPhysicsSystem1: | ||
- | Plane1: TPlane; | ||
- | GorillaCube1: | ||
- | PhysicsTimer1: | ||
- | GorillaSphere1: | ||
- | LightMaterialSource1: | ||
- | LightMaterialSource2: | ||
- | procedure FormCreate(Sender: | ||
- | procedure PhysicsTimer1Timer(Sender: | ||
- | private | ||
- | { Private-Deklarationen } | ||
- | public | ||
- | { Public-Deklarationen } | ||
- | end; | ||
- | |||
- | var | ||
- | Form1: TForm1; | ||
- | |||
- | implementation | ||
- | |||
- | {$R *.fmx} | ||
- | |||
- | uses | ||
- | Gorilla.Physics, | ||
- | | ||
- | procedure TForm1.FormCreate(Sender: | ||
- | var LPrefab : TGorillaColliderSettings; | ||
- | begin | ||
- | // the plane should be a static body, otherwise it will fall in to nothingness | ||
- | LPrefab := TGorillaColliderSettings.Create(TQ3BodyType.eStaticBody); | ||
- | GorillaPhysicsSystem1.AddBoxCollider(Plane1, | ||
- | |||
- | // the cube is a dynamic / moveable body which collides with the plane and sphere | ||
- | LPrefab := TGorillaColliderSettings.Create(TQ3BodyType.eDynamicBody); | ||
- | GorillaPhysicsSystem1.AddBoxCollider(GorillaCube1, | ||
- | |||
- | // the sphere is a dynamic / moveable body which collides with the plane and cube | ||
- | LPrefab := TGorillaColliderSettings.Create(TQ3BodyType.eDynamicBody); | ||
- | GorillaPhysicsSystem1.AddSphereCollider(GorillaSphere1, | ||
- | |||
- | // we activate the physics system | ||
- | GorillaPhysicsSystem1.Active := true; | ||
- | | ||
- | // and we need to activate the physics timer for constant updates | ||
- | PhysicsTimer1.Enabled := true; | ||
- | end; | ||
- | |||
- | procedure TForm1.PhysicsTimer1Timer(Sender: | ||
- | var LDelta : Single; | ||
- | begin | ||
- | // get the delta time => time since the last step() was called | ||
- | LDelta := GorillaPhysicsSystem1.GetDeltaTime(); | ||
- | GorillaPhysicsSystem1.Step(LDelta); | ||
- | GorillaViewport1.Invalidate(); | ||
- | end; | ||
- | </ | ||
===== Callbacks ===== | ===== Callbacks ===== | ||
Line 210: | Line 144: | ||
procedure TUIMainWin.doOnBeginContact(const ABodyA, ABodyB : TQ3Body); | procedure TUIMainWin.doOnBeginContact(const ABodyA, ABodyB : TQ3Body); | ||
begin | begin | ||
+ | if not Assigned(ABodyA.UserDataType) then | ||
+ | Exit; | ||
+ | if not Assigned(ABodyB.UserDataType) then | ||
+ | Exit; | ||
+ | | ||
if TComponent(ABodyA.UserData).Name.Equals(' | if TComponent(ABodyA.UserData).Name.Equals(' | ||
begin | begin | ||
FMX.Types.Log.D(' | FMX.Types.Log.D(' | ||
[TComponent(ABodyA.UserData).Name, | [TComponent(ABodyA.UserData).Name, | ||
+ | end | ||
+ | else | ||
+ | begin | ||
+ | FMX.Types.Log.D('< | ||
+ | [ABodyA.UserDataType^.Name, | ||
end; | end; | ||
end; | end; | ||
Line 227: | Line 171: | ||
* RemoteBodyForce | * RemoteBodyForce | ||
- | By this methods you're able to set a position or rotation explicitly or to apply a force / impulse on a specific element. | + | <file pascal> |
+ | // move cube upwards by impulse | ||
+ | GorillaPhysicsSystem1.RemoteBodyImpulse(GorillaCube1, | ||
+ | </ | ||
+ | |||
+ | By the methods | ||
**__CAUTION: | **__CAUTION: | ||
Next step: [[fmodaudio|FMOD Audio]] | Next step: [[fmodaudio|FMOD Audio]] |