Class TCastleCollider
Unit
Declaration
type TCastleCollider = class(TCastleBehavior)
Description
Abstract collider that determines the shape used to determine collisions with physics bodies.
Hierarchy
- TObject
- TPersistent
- TComponent
- TCastleComponent
- TCastleBehavior
- TCastleCollider
Overview
Fields
nested const DefaultDensity = 1.0; |
|
nested const DefaultMass = 0.0; |
|
nested const DefaultRestitution = 0.0; |
|
nested const DefaultFriction = 0.5; |
|
class var AutoSizeMinThickness: Single; |
|
AutoSizeMinThickness2D: Single; |
|
AutoSizeMinThickness2DDepth: Single; |
Methods
function StoredWithAutoSize: Boolean; |
|
function TotalScale: Single; |
|
function CreateKraftShape(const APhysics: TKraft; const ARigidBody: TKraftRigidBody): TKraftShape; virtual; abstract; |
|
procedure DeinitializePhysicsEngineObjects; virtual; |
|
procedure ShapeChangedNotifyRigidBody; |
|
procedure UpdateVisualization; virtual; |
|
procedure WorldAfterAttach; override; |
|
procedure WorldBeforeDetach; override; |
|
function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; override; |
|
procedure DisableAutoSize; |
|
procedure CalculateSizeCore; virtual; |
|
constructor Create(AOwner: TComponent); override; |
|
destructor Destroy; override; |
|
function PropertySections(const PropertyName: String): TPropertySections; override; |
|
procedure CustomSerialization(const SerializationProcess: TSerializationProcess); override; |
|
procedure InternalTransformChanged(const TransformChanged: TCastleTransform); virtual; |
|
procedure InternalDesigningBegin; virtual; |
|
procedure InternalDesigningEnd; virtual; |
|
procedure ParentBeforeDetach; override; |
|
procedure InternalAutoSize; |
|
procedure CalculateSize; |
Properties
property Translation: TVector3 read FTranslation write SetTranslation; |
|
property Rotation: TVector4 read FRotation write SetRotation; |
|
property AutoSize: Boolean read FAutoSize write SetAutoSize default true; |
|
property Density: Single read FDensity write SetDensity
default DefaultDensity; |
|
property Mass: Single read FMass write SetMass
default DefaultMass; |
|
property Restitution: Single read FRestitution write SetRestitution
default DefaultRestitution; |
|
property Friction: Single read FFriction write SetFriction
default DefaultFriction; |
|
property SizeScale: Single read FSizeScale write SetSizeScale default 1.0; |
|
property Mode2D: Boolean read FMode2D write SetMode2D default false; |
|
property TranslationPersistent: TCastleVector3Persistent read FTranslationPersistent stored StoredWithAutoSize; |
|
property RotationPersistent: TCastleVector4RotationPersistent read FRotationPersistent stored StoredWithAutoSize; |
Description
Fields
nested const DefaultDensity = 1.0; |
|
Default for Density. |
nested const DefaultMass = 0.0; |
|
nested const DefaultRestitution = 0.0; |
|
Default for Restitution. |
nested const DefaultFriction = 0.5; |
|
Default for Friction. |
class var AutoSizeMinThickness: Single; |
|
Minimum collider thickness used by AutoSize in 3D mode (when Mode2D = |
AutoSizeMinThickness2D: Single; |
|
Minimum collider thickness used by AutoSize in 2D mode (when Mode2D = |
AutoSizeMinThickness2DDepth: Single; |
|
Minimum collider thickness used by AutoSize in 2D mode (when Mode2D = |
Methods
function StoredWithAutoSize: Boolean; |
|
Use this for "stored" for properties that are auto-calculated when AutoSize. |
function TotalScale: Single; |
|
Total scale, accumulated from all parents TCastleTransform.Scale (converted to scalar following Mode2D) and collider SizeScale. |
function CreateKraftShape(const APhysics: TKraft; const ARigidBody: TKraftRigidBody): TKraftShape; virtual; abstract; |
|
This item has no description. |
procedure DeinitializePhysicsEngineObjects; virtual; |
|
This item has no description. |
procedure ShapeChangedNotifyRigidBody; |
|
Notify associated TCastleRigidBody that Kraft shape needs to be recreated. This may in turn call TCastleCollider.InitializeKraft and TCastleCollider.CreateKraftShape. |
procedure UpdateVisualization; virtual; |
|
Called when the collider size has changed and needs to be updated. |
procedure WorldAfterAttach; override; |
|
This item has no description. Showing description inherited from TCastleBehavior.WorldAfterAttach.
Called after Parent became part of World. Called only if ListenWorldChange is |
procedure WorldBeforeDetach; override; |
|
This item has no description. Showing description inherited from TCastleBehavior.WorldBeforeDetach.
Called before Parent stops being part of World. Called only if ListenWorldChange is This is also called at the destruction of behavior (more precisely from BeforeDestruction now). Even in this case, we guarantee that Parent is still valid during this call, and not in half-destroyed state. Before the actual destructor of TCastleBehavior we do BeforeParentDetach and BeforeWorldDetach and set Parent to |
function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; override; |
|
Only one TCastleCollider behavior can be added to a given TCastleTransform so we check that here. |
procedure DisableAutoSize; |
|
Sets AutoSize = |
procedure CalculateSizeCore; virtual; |
|
Recalculate collider size. Do not be concerned about AutoSize here, just update collider properties. The default implementation resets Translation and Rotation. |
constructor Create(AOwner: TComponent); override; |
|
This item has no description. |
destructor Destroy; override; |
|
This item has no description. |
function PropertySections(const PropertyName: String): TPropertySections; override; |
|
This item has no description. Showing description inherited from TCastleComponent.PropertySections. Section where to show property in the editor. |
procedure CustomSerialization(const SerializationProcess: TSerializationProcess); override; |
|
This item has no description. Showing description inherited from TCastleComponent.CustomSerialization. Override this method to call various methods of SerializationProcess, which in turn allows to serialize/deserialize things that are not published. This allows to serialize/deserialize with more freedom, e.g. to serialize/deserialize some private field. |
procedure InternalTransformChanged(const TransformChanged: TCastleTransform); virtual; |
|
Notify this collider that given TCastleTransform changed. It can provoke AutoSize recalculation (if Parent changed) or other reactions (e.g. mesh update, if TransformChanged corresponds to Mesh). |
procedure InternalDesigningBegin; virtual; |
|
Create collider visualization. |
procedure InternalDesigningEnd; virtual; |
|
Destroy collider visualization. |
procedure ParentBeforeDetach; override; |
|
This item has no description. Showing description inherited from TCastleBehavior.ParentBeforeDetach. Called before Parent changed, e.g. at the beginning of TCastleTransform.RemoveBehavior. This is also called at the destruction of behavior (more precisely from BeforeDestruction now). Even in this case, we guarantee that Parent is still valid during this call, and not in half-destroyed state. Before the actual destructor of TCastleBehavior we do BeforeParentDetach and BeforeWorldDetach and set Parent to |
procedure InternalAutoSize; |
|
Recalculate collider size using parent bounding box, only if AutoSize says we should recalculate. Ignored if not AutoSize. |
procedure CalculateSize; |
|
Calculate collider size to reflect parent bounding box now. This works regardless of AutoSize value, and doesn't change AutoSize value. The idea is that you can call it when
See also
|
Properties
property Translation: TVector3 read FTranslation write SetTranslation; |
|
Local collider translation, relative to parent TCastleTransform. Note that CalculateSize and AutoSize mechanisms set it automatically. |
property Rotation: TVector4 read FRotation write SetRotation; |
|
Local collider rotation, relative to parent TCastleTransform. Note that CalculateSize and AutoSize mechanisms set it automatically. |
property AutoSize: Boolean read FAutoSize write SetAutoSize default true; |
|
Automatically calculate collider properties that determine collider size based on the parent transformation bounding box. When this is set, properties like TCastleSphereCollider.Radius or TCastleBoxCollider.Size are automatically updated to the best values to match collider size with the parent TCastleTransform.LocalBoundingBox. Note that even when this is But it would be bad to change the collider size (even at design-time) every frame. That's because changing the collider size may imply (for the underlying physics engine) recreation of internal srtuctures and reinitialization of the collision state. So in the ideal case, the collider size should just stay constant once the object has been added to some TCastleViewport and it may interact with other physics bodies. You can always manually force recalculation of the collider size using the CalculateSize method. |
property Density: Single read FDensity write SetDensity
default DefaultDensity; |
|
|
property Mass: Single read FMass write SetMass
default DefaultMass; |
|
Mass in kg. When non-zero, this overrides the automatically calculated mass from the volume and Density. |
property Restitution: Single read FRestitution write SetRestitution
default DefaultRestitution; |
|
Larger |
property Friction: Single read FFriction write SetFriction
default DefaultFriction; |
|
Larger |
property SizeScale: Single read FSizeScale write SetSizeScale default 1.0; |
|
Local collider size scale. This is particularly useful if AutoSize mechanism calculated too large box. For collision purposes, you sometimes want a collider that is a bit smaller than the bounding box/sphere around the object. Maybe it should even be too small at certain places, but then it will make a better fit overall. You can achieve this (and still keep using AutoSize) by adjusting this property e.g. to 0.9 to have collider be 90% of what AutoSize calculated. This is not reset by CalculateSize and AutoSize mechanisms (in contrast to Translation, Rotation) because the idea is that user adjusts the auto-calculated size this way. |
property Mode2D: Boolean read FMode2D write SetMode2D default false; |
|
Make various features (in particular automatic size calculation caused by AutoSize) better adjusted to 2D models, where the user-visible shape is in XY and the Z coordinate (position in Z, thickness in Z) should have little or no effect on the result. More precisely, when this is
|
property TranslationPersistent: TCastleVector3Persistent read FTranslationPersistent stored StoredWithAutoSize; |
|
Translation that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write Translation directly. See also
|
property RotationPersistent: TCastleVector4RotationPersistent read FRotationPersistent stored StoredWithAutoSize; |
|
Rotation that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write Rotation directly. See also
|
Generated by PasDoc 0.16.0-snapshot.