Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
physics [2020/05/24 13:27] – [Callbacks] adminphysics [2020/06/06 15:37] – [Max Contacts] admin
Line 74: Line 74:
 Even if there is no object limit, this will limit your scene indirectly. Even if there is no object limit, this will limit your scene indirectly.
  
 +==== Types of Body ====
  
 +Q3 Physics Engine allows to decide between 3 different body types.
 +
 +^Type ^Description ^
 +|TQ3BodyType.eStaticBody | Static bodies will not be move or influenced by mass and impulses. Use this type for defining a plane / floor.|
 +|TQ3BodyType.eDynamicBody|Dynamic bodies will move, handle forces influenced by mass and impulses. Use this type by default for any kind of physics-engine handled instances.|
 +|TQ3BodyType.eKinematicBody|Kinematic bodies will be moved, but will not be influenced by mass and impulses. Use this type as an alternative to dynamic bodies. |
 ===== Colliders ===== ===== Colliders =====
  
Line 131: Line 138:
 </file> </file>
 (available since v0.8.2.1600+) (available since v0.8.2.1600+)
 +
 +===== Callbacks =====
 +
 +The physics controller provides 2 callback events to interact with the physics world.
 +  * OnBeginContact
 +  * OnEndContact
 +
 +Those callbacks will give you the both colliding elements at this moment of TQ3Body type (Gorilla.Physics.Q3.Body).
 +Each body has an untyped pointer property "UserData", which contains the linked visual component. The type of that link you can request with the property "UserDataType".
 +
 +<file pascal>
 +procedure TUIMainWin.doOnBeginContact(const ABodyA, ABodyB : TQ3Body);
 +begin
 +    if not Assigned(ABodyA.UserDataType) then
 +      Exit;
 +    if not Assigned(ABodyB.UserDataType) then
 +      Exit;      
 +      
 +    if TComponent(ABodyA.UserData).Name.Equals('Cube1') and TComponent(ABodyB.UserData).Name.Equals('Sphere2') then
 +    begin
 +      FMX.Types.Log.D('expected collision between %s <=> %s', 
 +        [TComponent(ABodyA.UserData).Name, TComponent(ABodyB.UserData).Name]);
 +    end
 +    else
 +    begin
 +      FMX.Types.Log.D('<ERROR> unexpected collision between %s <=> %s', 
 +        [ABodyA.UserDataType^.Name, ABodyB.UserDataType^.Name]);
 +    end;
 + end;
 +</file>
 +===== Remote-Control =====
 +
 +As you read above, the physics controller universe is separated from scene universe.
 +But sometimes you need to control elements in physics world.
 +Therefore we've implemented some helper methods.
 +  * RemoteMeshTransform
 +  * RemoteBodyTransform
 +  * RemoteBodyImpulse
 +  * RemoteBodyForce
 +
 +<file pascal>
 +// move cube upwards by impulse
 +GorillaPhysicsSystem1.RemoteBodyImpulse(GorillaCube1, Point3D(0, -1, 0));
 +</file>
 +
 +By the methods above you're able to set a position and/or rotation explicitly, or to apply a force / impulse on a specific element.
 +
 +**__CAUTION:__ By this methods you can influence physical mechanics so heavily, that overstep bounds / limits, which may lead to unexpected behaviour.**
 +
 +
 ===== Example ===== ===== Example =====
 For a working physics system you need a TGorillaPhysicsSystem component on your form. For a working physics system you need a TGorillaPhysicsSystem component on your form.
Line 198: Line 255:
 </file> </file>
  
-===== Callbacks ===== 
- 
-The physics controller provides 2 callback events to interact with the physics world. 
-  * OnBeginContact 
-  * OnEndContact 
- 
-Those callbacks will give you the both colliding elements at this moment of TQ3Body type (Gorilla.Physics.Q3.Body). 
-Each body has an untyped pointer property "UserData", which contains the linked visual component. The type of that link you can request with the property "UserDataType". 
- 
-<file pascal> 
-procedure TUIMainWin.doOnBeginContact(const ABodyA, ABodyB : TQ3Body); 
-begin 
-    if not Assigned(ABodyA.UserDataType) then 
-      Exit; 
-    if not Assigned(ABodyB.UserDataType) then 
-      Exit;       
-       
-    if TComponent(ABodyA.UserData).Name.Equals('Cube1') and TComponent(ABodyB.UserData).Name.Equals('Sphere2') then 
-    begin 
-      FMX.Types.Log.D('expected collision between %s <=> %s',  
-        [TComponent(ABodyA.UserData).Name, TComponent(ABodyB.UserData).Name]); 
-    end 
-    else 
-    begin 
-      FMX.Types.Log.D('<ERROR> unexpected collision between %s <=> %s',  
-        [ABodyA.UserDataType^.Name, ABodyB.UserDataType^.Name]); 
-    end; 
- end; 
-</file> 
-===== Remote-Control ===== 
- 
-As you read above, the physics controller universe is separated from scene universe. 
-But sometimes you need to control elements in physics world. 
-Therefore we've implemented some helper methods. 
-  * RemoteMeshTransform 
-  * RemoteBodyTransform 
-  * RemoteBodyImpulse 
-  * RemoteBodyForce 
- 
-By this methods you're able to set a position or rotation explicitly or to apply a force / impulse on a specific element. 
- 
-**__CAUTION:__ By this methods you can influence physical mechanics so heavily, that overstep bounds / limits, which may lead to unexpected behaviour.** 
  
 Next step: [[fmodaudio|FMOD Audio]] Next step: [[fmodaudio|FMOD Audio]]