Gorilla.Physics
Unit Gorilla.Physics.pasClasses
- TGorillaContactListener = class ( TQ3ContactListener )
- TGorillaPhysicsColliderPrefab = class ( TCollectionItem )
- TGorillaPhysicsColliderPrefabs = class ( TOwnedCollection )
- TGorillaPhysicsSystem = class ( TGorillaControl )
Records
- record TGorillaColliderSettings
Enumerations
- enum TGorillaPhysicsBodyType = ( eStaticBody, eDynamicBody, eKinematicBody ) ;
- enum TGorillaPhysicsColliderKind = ( ckBox, ckSphere, ckCapsule, ckParticle, ckMesh, ckTerrain ) ;
Constants
TGorillaPhysicsBodyType
Type of body (static, dynamic or kinematic)
Remarks
A body is defined by one of these 3 kinds.
Static bodies will not be move or influenced by mass and impulses. Use this type for defining a plane / floor.
Dynamic bodies will move, handle forces influenced by mass and impulses. Use this type by default for any kind of physics-engine handled instances.
Kinematic bodies will be moved, but will not be influenced by mass and impulses. Use this type as an alternative to dynamic bodies.
Static bodies have no Rigidbody component attached to them, so the physics engine does not consider them to be moving. (Avoid moving these frequently or you'll violate that expectation) Use static colliders for level geometry like the ground and immovable walls, or stationary trigger volumes. Static colliders on their own won't set off trigger/collision messages, unless there's a Rigidbody on the other participant. Dynamic bodies have a Rigidbody component attached to them and their eKinematic flag is not set. These objects move at the whims of physics according to their velocities/angular velocities and the forces/torques and collision impacts exerted on them. The physics engine takes responsibility for resolving their collisions with static, kinematic, and other dynamic objects and rebounding them as needed. Use these for basic physics objects you want to be able to stack & topple and have them behave plausibly with minimal intervention, or for objects that you want to steer in a physics-focused way, like a rocketship. Kinematic bodies have a Rigidbody component with a set eKinematic flag. This tells the physics engine "this object moves, but I'll handle that part" — the kinematic object will process collisions with other rigidbodies, but only dynamic objects will automatically react by bouncing away, and cause messages to be sent. The kinematic object itself won't move except how you tell it to with MovePosition or MoveRotation — its velocity won't automatically integrate each timestep. Use this for objects that you want to control in ways that don't behave like simple physics bodies — like a bipedal character controller or highly custom vehicle controls. Use physics queries like overlap checks and shape casts to scan for collisions preemptively, since they won't stop your object automatically.
TGorillaColliderSettings
Fields
- public _Type :
TQ3BodyType
- public LockRotAxisX :
Boolean
- public LockRotAxisY :
Boolean
- public LockRotAxisZ :
Boolean
- public LockMoveAxisX :
Boolean
- public LockMoveAxisY :
Boolean
- public LockMoveAxisZ :
Boolean
- public LinearDamping :
Single
- public AngularDamping :
Single
- public Slop :
Single
- public AllowSleep :
Boolean
- public Active :
Boolean
- public Data :
TQ3ColliderData
Methods
- public function Create
(
AType :
TQ3BodyType
)
: TGorillaColliderSettings
;
static;
We need a static method here, because scripting is currently not able to call record constructors.
TGorillaContactListener
A ContactListener is a callback instance for collision detection. Use this component to react individually on collision. By default a contact listener is created inside of the physics system.
Ancestors
Members
TGorillaPhysicsColliderPrefab
Ancestors
Members
Fields
- protected FKind :
TGorillaPhysicsColliderKind
- protected FControl :
TControl3D
- protected FSettings :
TGorillaColliderSettings
Methods
- public constructor Create ( Collection : TCollection ) ;
- public destructor Destroy ( ) ;
- protected function GetAngularDamping ( ) : Single ;
- protected procedure SetAngularDamping ( const AValue : Single ) ;
- protected function GetActive ( ) : Boolean ;
- protected procedure SetActive ( const AValue : Boolean ) ;
- protected function GetAllowSleep ( ) : Boolean ;
- protected procedure SetAllowSleep ( const AValue : Boolean ) ;
- protected function GetBodyType ( ) : TQ3BodyType ;
- protected procedure SetBodyType ( const AValue : TQ3BodyType ) ;
- protected function GetDensity ( ) : Single ;
- protected procedure SetDensity ( const AValue : Single ) ;
- protected function GetFriction ( ) : Single ;
- protected procedure SetFriction ( const AValue : Single ) ;
- protected function GetLinearDamping ( ) : Single ;
- protected procedure SetLinearDamping ( const AValue : Single ) ;
- protected function GetLockMoveAxisX ( ) : Boolean ;
- protected procedure SetLockMoveAxisX ( const AValue : Boolean ) ;
- protected function GetLockMoveAxisY ( ) : Boolean ;
- protected procedure SetLockMoveAxisY ( const AValue : Boolean ) ;
- protected function GetLockMoveAxisZ ( ) : Boolean ;
- protected procedure SetLockMoveAxisZ ( const AValue : Boolean ) ;
- protected function GetLockRotAxisX ( ) : Boolean ;
- protected procedure SetLockRotAxisX ( const AValue : Boolean ) ;
- protected function GetLockRotAxisY ( ) : Boolean ;
- protected procedure SetLockRotAxisY ( const AValue : Boolean ) ;
- protected function GetLockRotAxisZ ( ) : Boolean ;
- protected procedure SetLockRotAxisZ ( const AValue : Boolean ) ;
- protected function GetRestitution ( ) : Single ;
- protected procedure SetRestitution ( const AValue : Single ) ;
- protected function GetSensor ( ) : Boolean ;
- protected procedure SetSensor ( const AValue : Boolean ) ;
- protected function GetSlop ( ) : Single ;
- protected procedure SetSlop ( const AValue : Single ) ;
- protected procedure AssignTo ( ADest : TPersistent ) ; override;
- public procedure Notification ( AComponent : TComponent; Operation : TOperation ) ;
Properties
- public Settings : TGorillaColliderSettingsread FSettings
- published Control : TControl3D
- published Kind : TGorillaPhysicsColliderKind
- published BodyType : TQ3BodyType
Set the body type used for collision detection: static, dynamic, kinematic
read GetBodyType
write SetBodyType - published LockRotAxisX : Boolean
- published LockRotAxisY : Boolean
- published LockRotAxisZ : Boolean
- published LockMoveAxisX : Boolean
- published LockMoveAxisY : Boolean
- published LockMoveAxisZ : Boolean
- published LinearDamping : Single
- published AngularDamping : Single
- published Slop : Single
- published AllowSleep : Boolean
- published Active : Boolean
- published Friction : Single
- published Restitution : Single
- published Density : Single
- published Sensor : Boolean
TGorillaPhysicsColliderPrefabs
A designtime helper to pre-register colliders. On physics activation those predefined colliders will be registered.
Ancestors
Members
TGorillaPhysicsSystem
User component for physics computation. The Gorilla physics system uses internally the Q3 Physics Engine.
Ancestors
Members
Fields
- protected FEngine :
TQ3Scene
- protected FListener :
TGorillaContactListener
- protected FColliders :
TGorillaPhysicsColliderPrefabs
- protected FOnBeginContact :
TOnGorillaPhysicsNotifyContact
- protected FOnEndContact :
TOnGorillaPhysicsNotifyContact
Methods
- public constructor Create ( AOwner : TComponent ) ;
- public destructor Destroy ( ) ;
- protected procedure DoOnQ3BodyUpdate ( ASender : TObject; const ACollider : TQ3Collider ) ;
- protected procedure SetColliders ( const AValue : TGorillaPhysicsColliderPrefabs ) ;
- protected function GetActive ( ) : Boolean ;
- protected procedure SetActive ( const AValue : Boolean ) ;
- protected function GetAsync ( ) : Boolean ;
- protected procedure SetAsync ( const AValue : Boolean ) ;
- protected function GetAccuracy ( ) : Integer ;
- protected procedure SetAccuracy ( const AValue : Integer ) ;
- protected function GetOnBeginStep ( ) : TNotifyEvent ;
- protected procedure SetOnBeginStep ( const AValue : TNotifyEvent ) ;
- protected function GetOnEndStep ( ) : TNotifyEvent ;
- protected procedure SetOnEndStep ( const AValue : TNotifyEvent ) ;
- protected function GetOnBeginUpdate ( ) : TNotifyEvent ;
- protected procedure SetOnBeginUpdate ( const AValue : TNotifyEvent ) ;
- protected function GetOnEndUpdate ( ) : TNotifyEvent ;
- protected procedure SetOnEndUpdate ( const AValue : TNotifyEvent ) ;
- protected procedure DoAddBoxCollider ( const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; const AAbsoluteMatrix : TMatrix3D; const ASize : TPoint3D; out ABody : TQ3Body ) ; virtual;
- protected procedure DoAddSphereCollider ( const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; const AAbsoluteMatrix : TMatrix3D; const ARadius : Single; out ABody : TQ3Body ) ; virtual;
- protected procedure DoAddCapsuleCollider ( const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; const AAbsoluteMatrix : TMatrix3D; const ARadius : Single; const AHeight : Single; out ABody : TQ3Body ) ; virtual;
- protected procedure DoAddTerrainCollider ( const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; const AAbsoluteMatrix : TMatrix3D; const AMeshMatrix : TMatrix3D; const ASize : TPoint3D; const AMeshData : TMeshData; out ABody : TQ3Body ) ; virtual;
- protected procedure DoAddMeshCollider ( const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; const AAbsoluteMatrix : TMatrix3D; const AMeshMatrix : TMatrix3D; const ASize : TPoint3D; const AMeshData : TMeshData; out ABody : TQ3Body ) ; virtual;
- protected procedure RegisterColliderPrefabs ( ) ; virtual;
- protected procedure UnregisterColliderPrefabs ( ) ; virtual;
- protected procedure Notification ( AComponent : TComponent; Operation : TOperation ) ; override;
- public procedure Resize3D ( ) ; override;
- public procedure Block
(
)
;
Block physics system externally, if you're working in async mode and interacting with bodies, colliders, ... You need to block, otherwise simulation thread may destroy objects you're about to use.
- public procedure Unblock
(
)
;
After blocking the physics system, you need to unblock it, when you're ready with your work.
- public procedure BlockSystem ( ) ;
- public procedure UnblockSystem ( ) ;
- public procedure LoadFromDefinition
(
const
ADef :
TCustomDef
)
;
override;
LoadFromDefinition not supported for physics system component yet.
- public procedure AddBoxCollider
(
const
AControl :
TControl3D; const
APrefab :
TGorillaColliderSettings
)
;
overload;
Add a box collider for a specific TControl3D instance to the physics system. At first you will need to create a TGorillaColliderSettings structure, where to define the body type (static, dynamic, kinematic)
- public procedure AddSphereCollider
(
const
AControl :
TControl3D; const
APrefab :
TGorillaColliderSettings
)
;
Add a spherical collider for a specific TControl3D instance to the physics system. At first you will need to create a TGorillaColliderSettings structure, where to define the body type (static, dynamic, kinematic)
- public procedure AddCapsuleCollider
(
const
AControl :
TControl3D; const
APrefab :
TGorillaColliderSettings; const
ARadius :
Single; const
AHeight :
Single
)
;
Add a capsule collider for a specific TControl3D instance to the physics system. At first you will need to create a TGorillaColliderSettings structure, where to define the body type (static, dynamic, kinematic)
- public procedure AddParticleCollider
(
const
AData :
Pointer; const
AType :
PTypeInfo; const
APrefab :
TGorillaColliderSettings; const
ATransformation :
TMatrix3D; const
ARadius :
Single; out
ABody :
TQ3Body
)
;
Add a particle collider for a specific pointer value to the physics system. At first you will need to create a TGorillaColliderSettings structure, where to define the body type (static, dynamic, kinematic). Also provide a starting transformation matrix and a radius of the particle. The procedure will return a TQ3Body instance as pointer which should be linked with your particle structure (AParticle). This method is automatically used by the physics particle influencer class.
- public procedure AddTerrainCollider
(
const
AMesh :
TCustomMesh; const
APrefab :
TGorillaColliderSettings
)
;
overload;
Add a terrain collider for a specific TCustomMesh (terrain) instance to the physics system. At first you will need to create a TGorillaColliderSettings structure, where to define the body type (static, dynamic, kinematic). Of course the body type is flexible, but for terrains you should use the static body type.
- public procedure AddTerrainCollider
(
const
ATerrain :
TGorillaMesh; const
APrefab :
TGorillaColliderSettings
)
;
overload;
Add a terrain collider for a specific TGorillaMesh instance to the physics system. At first you will need to create a TGorillaColliderSettings structure where to define the body type (static, dynamic, kinematic). Of course the body type is flexible, but for terrains you should use the static body type.
- public procedure AddMeshCollider
(
const
AMesh :
TCustomMesh; const
APrefab :
TGorillaColliderSettings
)
;
overload;
Add a capsule collider for a specific TCustomMesh instance to the physics system. At first you will need to create a TGorillaColliderSettings structure where to define the body type (static, dynamic, kinematic)
- public procedure AddMeshCollider
(
const
AMesh :
TGorillaMesh; const
APrefab :
TGorillaColliderSettings
)
;
overload;
Add a capsule collider for a specific TGorillaMesh instance to the physics system. At first you will need to create a TGorillaColliderSettings structure where to define the body type (static, dynamic, kinematic)
- public procedure RemoveCollider
(
const
AMesh :
TControl3D
)
;
overload;
Remove an existing collider for a specific TControl3D object. The method will automatically request the TQ3Body and remove it from physics system.
- public procedure RemoveCollider
(
const
ABody :
TQ3Body
)
;
overload;
Remove an existing collider. The method expects the specific body instance to be removed. This method will be used by the particle system. But of course you can use this method in case you handled the TQ3Body instances anywhere else.
- public procedure RemoteMeshTransform
(
const
ACtrl :
TControl3D
)
;
overload;
The method allows to modify position and rotation for a specific TControl3D in the physics system from external. This may be useful when there are external influences the physics system do not know of.
- public procedure RemoteBodyTransform
(
const
ABody :
TQ3Body; const
ATranslation :
TPoint3D; const
ARotationAngle :
TPoint3D
)
;
overload;
The method allows to modify position and rotation for a specific TQ3Body in the physics system from external by a translation and rotation value. This may be useful when there are external influences the physics system do not know of.
- public procedure RemoteBodyTransform
(
const
ACtrl :
TControl3D; const
ATranslation :
TPoint3D; const
ARotationAngle :
TPoint3D
)
;
overload;
The method allows to modify position and rotation for a specific control in the physics system from external by a translation and rotation value. This may be useful when there are external influences the physics system do not know of.
- public procedure RemoteBodyImpulse
(
const
ABody :
TQ3Body; const
AImpulse :
TPoint3D
)
;
overload;
Applies an impulse on a specific body. Use this method to push a physics controlled body, f.e. for third person models.
- public procedure RemoteBodyImpulse
(
const
ACtrl :
TControl3D; const
AImpulse :
TPoint3D
)
;
overload;
Applies an impulse on a specific control. Use this method to push a physics controlled body, f.e. for third person models.
- public procedure RemoteBodyForce
(
const
ABody :
TQ3Body; const
AForce :
TPoint3D; const
ADirect :
Boolean
=
False
)
;
overload;
Applies a force on a specific body. Use this method to push a physics controlled body, f.e. for third person models.
- public procedure RemoteBodyForce
(
const
ACtrl :
TControl3D; const
AForce :
TPoint3D; const
ADirect :
Boolean
=
False
)
;
overload;
Applies a force on a specific control. Use this method to push a physics controlled body, f.e. for third person models.
- public procedure RemoteBodyVelocity
(
const
ABody :
TQ3Body; const
AVelocity :
TPoint3D; const
ADirect :
Boolean
=
True
)
;
overload;
Set body velocity directly. Use this method to move the body, f.e. for first/third person controller.
- public procedure RemoteBodyVelocity
(
const
ACtrl :
TControl3D; const
AVelocity :
TPoint3D; const
ADirect :
Boolean
=
True
)
;
overload;
Set control velocity directly. Use this method to move the control, f.e. for first/third person controller.
- public procedure RemoteBodyAngularVelocity
(
const
ABody :
TQ3Body; const
AVelocity :
TPoint3D
)
;
overload;
Set body angular velocity directly. Use this method to rotate the body, f.e. for first/third person controller.
- public procedure RemoteBodyAngularVelocity
(
const
ACtrl :
TControl3D; const
AVelocity :
TPoint3D
)
;
overload;
Set control angular velocity directly. Use this method to rotate the control, f.e. for first/third person controller.
- public function GetDeltaTime
(
)
: Single
;
Returns the delta time, which is the time since the last step. The value returned is computed in milliseconds.
- public procedure Step
(
)
;
Use this method to execute physics calculation. We recommend to use a 33ms interval, f.e. by a TTimer component. Submit the deltatime since the last step.
Properties
- public Engine : TQ3Scene
TGorillaPhysicsEngine is just a wrapper component. This property is the currently available internal physics engine. At the current development state we provide physics by the Q3 physics engine.
read FEngine - published Active : Boolean
- published Async : Boolean
- published Accuracy : Integer
Get or set physics computation accuracy. A value between 1 and 25 is valid. The higher the value, the more accurate. But by increasing this value, more iterations per step are need, which reduces performance. The default value is set to 10.
read GetAccuracy
write SetAccuracy - published Colliders : TGorillaPhysicsColliderPrefabs
Provides a collection of predefined colliders. Apply a TGorillaPhysicsColliderPrefab at designtime and it will be registered on activation.
read FColliders
write SetColliders