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
Next revisionBoth sides next revision
1.0.0:physics [2023/03/16 08:52] – [Remote-Control] admin1.0.0:physics [2023/03/16 09:00] – [Override Collider-Registration] admin
Line 221: Line 221:
 </file> </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.+By the methods above you're able to set a position and/or rotation explicitly, modify linear/angular velocity 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 or may lead to unexpected behaviour.** **__CAUTION:__ By this methods you can influence physical mechanics so heavily, that overstep bounds / limits or may lead to unexpected behaviour.**
  
 +**__WARNING:__ Modifying objects from the visual scene can have unexpected effects on collision detection. You may place or push an object inside another, which disables collision detection or causes unexpected behaviour!**
  
 ===== 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 299:
 end; end;
 </file> </file>
 +
 +==== 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; const AAbsoluteMatrix : TMatrix3D; const ASize : TPoint3D; out ABody : TQ3Body); virtual;|
 +|procedure DoAddSphereCollider(const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; const AAbsoluteMatrix : TMatrix3D; const ARadius : Single; out ABody : TQ3Body); virtual;|
 +|procedure DoAddCapsuleCollider(const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; const AAbsoluteMatrix : TMatrix3D; const ARadius : Single; const AHeight : Single; out ABody : TQ3Body); virtual;|
 +|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;|
 +|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;|
 +
 +<file pascal>
 +type
 +  /// <summary>
 +  /// 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).
 +  /// </summary>
 +  TGorillaPhysicsHelper = class helper for TGorillaPhysicsSystem
 +    public
 +      procedure AddInstanceCollider(const ATemplate : TMeshDef;
 +        const AData: TGorillaMeshInstance; const APrefab: TGorillaColliderSettings;
 +        const AAbsoluteMatrix: TMatrix3D; const ASize: TPoint3D; const AFlipData : Boolean;
 +        out ABody: TQ3Body);
 +  end;
 +
 +{ TGorillaPhysicsHelper }
 +
 +procedure TGorillaPhysicsHelper.AddInstanceCollider(const ATemplate : TMeshDef;
 +  const AData: TGorillaMeshInstance; const APrefab: TGorillaColliderSettings;
 +  const AAbsoluteMatrix: TMatrix3D; const ASize: TPoint3D; const AFlipData : Boolean;
 +  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, DoAddCapsuleCollider, ...
 +  DoAddSphereCollider(AData, TypeInfo(TGorillaMeshInstance), APrefab,
 +    LTransform, Max(ASize.X, Max(ASize.Y, ASize.Z)), ABody);
 +end;
 +</file>
 +
 +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 "AddInstanceCollider".
  
  
 Next step: [[fmodaudio|FMOD Audio]] Next step: [[fmodaudio|FMOD Audio]]