Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
1.0.0:physics [2023/03/16 08:54] – [Remote-Control] admin | 1.0.0:physics [2023/03/16 09:21] – [ColliderSettings / ColliderPrefab] admin | ||
---|---|---|---|
Line 116: | Line 116: | ||
On collider registration you push starting transformation information and shape data to the physics world: | On collider registration you push starting transformation information and shape data to the physics world: | ||
- | * AddBoxCollider() | + | ^Method^ |
- | | + | |procedure |
- | | + | |procedure |
- | | + | |procedure |
- | | + | |procedure |
- | | + | |procedure |
+ | |procedure AddTerrainCollider(const ATerrain : TGorillaMesh; | ||
+ | |procedure | ||
+ | |procedure AddMeshCollider(const AMesh : TGorillaMesh; | ||
From there on the physics controller will compute transformation based on its own universe. | From there on the physics controller will compute transformation based on its own universe. | ||
Line 131: | Line 134: | ||
Derived components of **TControl3D**, | Derived components of **TControl3D**, | ||
+ | |||
+ | ==== ColliderSettings / ColliderPrefab ==== | ||
+ | |||
+ | Registering a collider for a 3D object expects collider settings (TGorillaColliderSettings) or a collider prefab (TGorillaPhysicsColliderPrefab). | ||
+ | |||
+ | The collider prefab is a collection item for design time usage. It will automatically register a collider settings (TGorillaColliderSettings) for you when the physics system getting started. | ||
+ | |||
+ | While the collider settings (TGorillaColliderSettings) is the core structure for collider registration. | ||
+ | |||
+ | It gives you a number of possible settings: | ||
+ | |||
+ | ^Property ^Description^ | ||
+ | |_Type|TGorillaPhysicsBodyType (TQ3BodyType.eStaticBody, | ||
+ | |LockRotAxisX|Locked rotation on the x axis.| | ||
+ | |LockRotAxisY|Locked rotation on the y axis.| | ||
+ | |LockRotAxisZ|Locked rotation on the z axis.| | ||
+ | |LockMoveAxisX|Locked translation on the x axis.| | ||
+ | |LockMoveAxisY|Locked translation on the y axis.| | ||
+ | |LockMoveAxisZ|Locked translation on the z axis.| | ||
+ | |LinearDamping|Linear Damping controls how much the physics body or constraint resists translation.| | ||
+ | |AngularDamping|Angular Damping controls how much they resist rotating. | | ||
+ | |Slop|Additional slop value, which will be added to the computed penetration depth on collision.| | ||
+ | |AllowSubColliders|If a object hierarchy is provided as control, it will try to add the same kind of collider for all sub-elements. Caution: This may produce unexpected behaviour especially on dynamic colliders.| | ||
+ | |AllowSleep|Allows a body to go in sleeping mode and save resources. By default TRUE.| | ||
+ | |Active|Is body enabled for physics computation.| | ||
+ | |Data|Setup colliderdata: | ||
+ | |Data.Friction|Friction is a force between two surfaces that are sliding, or trying to slide, across each other. For example, when you try to push a book along the floor, friction makes this difficult. Friction always works in the direction opposite to the direction in which the object is moving, or trying to move.| | ||
+ | |Data.Restitution|The coefficient of restitution is a measure of how much kinetic energy remains after the collision of two bodies. Its value ranges from 0 to 1.| | ||
+ | |Data.Density|It is the mass of a material substance per unit volume.| | ||
+ | |Data.Sensor|A sensor is a device that detects and responds to some type of input from the physical environment.| | ||
===== Threading ===== | ===== Threading ===== | ||
Line 224: | Line 257: | ||
**__CAUTION: | **__CAUTION: | ||
+ | |||
**__WARNING: | **__WARNING: | ||
===== Example ===== | ===== Example ===== | ||
+ | |||
+ | ==== Runtime Integration ==== | ||
+ | |||
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 295: | Line 332: | ||
end; | end; | ||
</ | </ | ||
+ | |||
+ | ==== Override Collider-Registration ==== | ||
+ | |||
+ | Default collider registration methods only support TControl3D objects. | ||
+ | But it is sometimes needed to register other types of objects for colliders, like a virtual instance of a mesh. | ||
+ | |||
+ | Writing a helper class gives you access to the protected internal registration methods which are unspecified by type: | ||
+ | ^Method ^ | ||
+ | |procedure DoAddBoxCollider(const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; | ||
+ | |procedure DoAddSphereCollider(const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; | ||
+ | |procedure DoAddCapsuleCollider(const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; | ||
+ | |procedure DoAddTerrainCollider(const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; | ||
+ | |procedure DoAddMeshCollider(const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; | ||
+ | |||
+ | <file pascal> | ||
+ | type | ||
+ | /// < | ||
+ | /// Create a helper class to access protected methods for adding colliders. | ||
+ | /// Default methods only handle TControl3D instances, but we | ||
+ | /// want to add colliders dynamically for our virtual instances (TGorillaMeshInstance). | ||
+ | /// </ | ||
+ | TGorillaPhysicsHelper = class helper for TGorillaPhysicsSystem | ||
+ | public | ||
+ | procedure AddInstanceCollider(const ATemplate : TMeshDef; | ||
+ | const AData: TGorillaMeshInstance; | ||
+ | const AAbsoluteMatrix: | ||
+ | out ABody: TQ3Body); | ||
+ | end; | ||
+ | |||
+ | { TGorillaPhysicsHelper } | ||
+ | |||
+ | procedure TGorillaPhysicsHelper.AddInstanceCollider(const ATemplate : TMeshDef; | ||
+ | const AData: TGorillaMeshInstance; | ||
+ | const AAbsoluteMatrix: | ||
+ | out ABody: TQ3Body); | ||
+ | var LTransform : TMatrix3D; | ||
+ | begin | ||
+ | // Get the translation from absolute instance matrix | ||
+ | LTransform := TMatrix3D.CreateTranslation( | ||
+ | TTransformationMatrixUtils.GetTranslationFromTransformationMatrix(AAbsoluteMatrix) | ||
+ | ); | ||
+ | |||
+ | // Add a sphere collider for each instance with the maximum size of a side as radius | ||
+ | // or use another internal registration method, like DoAddBoxCollider, | ||
+ | DoAddSphereCollider(AData, | ||
+ | LTransform, Max(ASize.X, | ||
+ | end; | ||
+ | </ | ||
+ | |||
+ | When you have declared this kind of helper class in your unit, the TGorillaPhysicsSystem component will then show you a new method to be callable " | ||
Next step: [[fmodaudio|FMOD Audio]] | Next step: [[fmodaudio|FMOD Audio]] |