Class TCastleCollider
Unit
CastleTransform
Declaration
type TCastleCollider = class(TCastleBehavior)
Description
Abstract collider that determines the shape used to determine collisions with physics bodies.
Hierarchy
Overview
Fields
Methods
Properties
Description
Fields
 |
nested const DefaultDensity = 1.0; |
Default for Density.
|
 |
nested const DefaultMass = 0.0; |
Default for Mass, zero means "use Density instead".
|
 |
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 = False ). Changing this only affects new size calculations.
|
 |
AutoSizeMinThickness2D: Single; |
Minimum collider thickness used by AutoSize in 2D mode (when Mode2D = True ). This is used for axis other than Z (like X, Y, or collider radiuses that affect size in a few axis). Changing this only affects new size calculations.
|
 |
AutoSizeMinThickness2DDepth: Single; |
Minimum collider thickness used by AutoSize in 2D mode (when Mode2D = True ) for Z. This is used only by TCastleBoxCollider now, as only that collider has specific size in Z. Changing this only affects new size calculations.
|
Methods
 |
function StoredWithAutoSize: Boolean; |
Use this for "stored" for properties that are auto-calculated when AutoSize.
|
 |
function CreateKraftShape(const APhysics: TKraft; const ARigidBody: TKraftRigidBody): TKraftShape; virtual; abstract; |
|
 |
procedure DeinitializePhysicsEngineObjects; virtual; |
|
 |
procedure UpdateVisualization; virtual; |
Called when the collider size has changed and needs to be updated.
|
 |
procedure WorldAfterAttach; override; |
|
 |
procedure WorldBeforeDetach; override; |
|
 |
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; |
|
 |
destructor Destroy; override; |
|
 |
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; |
|
 |
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
You have AutoSize = False and want to adjust size to bounding box at specific moment.
You have AutoSize = True but still want to force recalculation right now, because AutoSize doesn't do it too eagerly (see AutoSize description).
See also
- AutoSize
- Automatically calculate collider properties that determine collider size based on the parent transformation bounding box.
|
Properties
 |
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 True , the collider size recalculation is not done too "eagerly", i.e. the collider size is not recalculated on every possible change. For example, if you animate a TCastleScene, then bounding box may change every frame (note: it depends on the technique; e.g. glTF models with skinned animation have a complete bounding box of the animation precalculated and constant; but X3D models morphed using CoordinateInterpolator have bounding box changing every frame).
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; |
Density (per volume) in kg, this implicitly determines mass (volume is automatically calculated by the physics engine). If you instead prefer to explicitly set mass, set Mass property to something non-zero.
|
 |
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 Friction: Single read FFriction write SetFriction
default DefaultFriction; |
Larger friction means that it is harder for body to slide alongside another object.
|
 |
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 True :
AutoSize estimates collider 3D sizes (because internally Kraft colliders are always in 3D) based on geometry sizes only in XY dimensions. So it ignores how thin or thick is you geometry along the Z axis.
AutoSize assumes a bit larger "minimum thickness" for 2D, because typical 2D worlds use larger units. Moreover, it assumes even larger thickness in Z, to avoid too thin boxes (that would not be detected as collidable). See AutoSizeMinThickness, AutoSizeMinThickness2D, AutoSizeMinThickness2DDepth.
Non-uniform scale (coming from accumulated TCastleTransform.Scale on all our parents) is handled differently. When Mode2D = True , the non-uniform scale is converted into a scalar using Approximate2DScale, so it only looks at XY coordinates. When Mode2D = False , the non-uniform scale is converted using Approximate3DScale, so it looks at all coordinates.
In the future, esp. if we integrate with other physics engines like Box2D, it is possible that some colliders in 2D mode will have a shape much more suitable in 2D. "Suitable in 2D" ideally means "Z coordinate is ignored". This means that a 2D collider should (ideally) behave as if it is infinite in Z.
For example a 2D sphere collider may effectively be an infinite cylinder. That is: it should be a circle in XY, but extruded into infinity in -Z and +Z. This is not right now how the TCastleSphereCollider behaves with Mode2D = True , but it may be in the future.
|
Generated by PasDoc 0.16.0.