Class TCastleSphereCollider
Unit
Declaration
type TCastleSphereCollider = class(TCastleCollider)
Description
Collide as a sphere. Add this collider to TCastleTransform behaviors, along with a TCastleRigidBody, to make the given TCastleTransform be affected by physics and collide with other physics bodies.
Source: transform/castletransform_physics.inc (line 554).
Hierarchy
- TObject
- TPersistent
- TComponent
- TCastleComponent
- TCastleBehavior
- TCastleCollider
- TCastleSphereCollider
Overview
Constants
| Public | DefaultDensity = 1.0; |
| Public | DefaultMass = 0.0; |
| Public | DefaultRestitution = 0.0; |
| Public | DefaultFriction = 0.5; |
Fields
| Public | class var AutoSizeMinThickness: Single; |
| Public | AutoSizeMinThickness2D: Single; |
| Public | AutoSizeMinThickness2DDepth: Single; |
Methods
| Protected | function GetInternalText: String; virtual; |
| Protected | procedure SetInternalText(const Value: String); virtual; |
| Protected | procedure SetName(const Value: TComponentName); override; |
| Protected | procedure TranslateProperties(const TranslatePropertyEvent: TTranslatePropertyEvent); virtual; |
| Public | destructor Destroy; override; |
| Public | procedure CustomSerialization(const SerializationProcess: TSerializationProcess); virtual; |
| Public | function PropertySections(const PropertyName: String): TPropertySections; virtual; |
| Public | procedure SetTransient; |
| Public | procedure AddNonVisualComponent(const NonVisualComponent: TComponent); |
| Public | procedure InsertNonVisualComponent(const Index: Integer; const NonVisualComponent: TComponent); |
| Public | procedure RemoveNonVisualComponent(const NonVisualComponent: TComponent); |
| Public | function NonVisualComponentsIndexOf(const NonVisualComponent: TComponent): Integer; |
| Public | function NonVisualComponentsCount: Integer; |
| Public | function NonVisualComponentsEnumerate: TNonVisualComponentsEnumerator; |
| Public | function ValueIsStreamed: Boolean; virtual; |
| Public | procedure DesignerInfo(const SList: TStrings); virtual; |
| Public | procedure DesignerWarnings(const SList: TStrings); virtual; |
| Protected | procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); virtual; |
| Protected | procedure BeforeRender( const CameraView: TViewVectors; const ParentParentWorldTransformation: TTransformation); virtual; |
| Protected | procedure ParentChanged; virtual; deprecated 'Use ParentAfterAttach / ParentBeforeDetach or WorldAfterAttach / WorldBeforeDetach'; |
| Protected | procedure ParentAfterAttach; virtual; |
| Protected | procedure ParentBeforeDetach; virtual; |
| Protected | procedure WorldAfterAttach; virtual; |
| Protected | procedure WorldBeforeDetach; virtual; |
| Protected | function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; virtual; |
| Public | procedure BeforeDestruction; override; |
| Public | function World: TCastleAbstractRootTransform; |
| Protected | function StoredWithAutoSize: Boolean; |
| Protected | function TotalScale: Single; |
| Protected | function CreateKraftShape(const APhysics: TKraft; const ARigidBody: TKraftRigidBody): TKraftShape; virtual; abstract; |
| Protected | procedure DeinitializePhysicsEngineObjects; virtual; |
| Protected | procedure ShapeChangedNotifyRigidBody; |
| Protected | procedure UpdateVisualization; virtual; |
| Protected | procedure WorldAfterAttach; override; |
| Protected | procedure WorldBeforeDetach; override; |
| Protected | function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; override; |
| Protected | procedure DisableAutoSize; |
| Protected | procedure CalculateSizeCore; virtual; |
| Public | constructor Create(AOwner: TComponent); override; |
| Public | destructor Destroy; override; |
| Public | function PropertySections(const PropertyName: String): TPropertySections; override; |
| Public | procedure CustomSerialization(const SerializationProcess: TSerializationProcess); override; |
| Public | procedure InternalTransformChanged(const TransformChanged: TCastleTransform); virtual; |
| Public | procedure InternalDesigningBegin; virtual; |
| Public | procedure InternalDesigningEnd; virtual; |
| Public | procedure ParentBeforeDetach; override; |
| Public | procedure InternalAutoSize; |
| Public | procedure CalculateSize; |
| Protected | function CreateKraftShape(const APhysics: TKraft; const ARigidBody: TKraftRigidBody): TKraftShape; override; |
| Protected | procedure CalculateSizeCore; override; |
| Protected | procedure UpdateVisualization; override; |
| Public | constructor Create(AOwner: TComponent); override; |
| Public | function PropertySections(const PropertyName: String): TPropertySections; override; |
| Public | procedure InternalDesigningBegin; override; |
| Public | procedure InternalDesigningEnd; override; |
Properties
| Public | property NonVisualComponents [const Index: Integer]: TComponent read GetNonVisualComponents; |
| Public | property IsLoading: Boolean read FIsLoading; |
| Public | property Parent: TCastleTransform read FParent; |
| Public | property ListenWorldChange: Boolean
read FListenWorldChange write SetListenWorldChange; |
| Public | property Translation: TVector3 read FTranslation write SetTranslation; |
| Public | property Rotation: TVector4 read FRotation write SetRotation; |
| Published | property AutoSize: Boolean read FAutoSize write SetAutoSize default true; |
| Published | property Density: Single read FDensity write SetDensity
default DefaultDensity; |
| Published | property Mass: Single read FMass write SetMass
default DefaultMass; |
| Published | property Restitution: Single read FRestitution write SetRestitution
default DefaultRestitution; |
| Published | property Friction: Single read FFriction write SetFriction
default DefaultFriction; |
| Published | property SizeScale: Single read FSizeScale write SetSizeScale default 1.0; |
| Published | property Mode2D: Boolean read FMode2D write SetMode2D default false; |
| Published | property TranslationPersistent: TCastleVector3Persistent read FTranslationPersistent stored StoredWithAutoSize; |
| Published | property RotationPersistent: TCastleVector4RotationPersistent read FRotationPersistent stored StoredWithAutoSize; |
| Published | property Radius: Single read FRadius write SetRadius stored StoredWithAutoSize; |
Description
Constants
| Public | DefaultDensity = 1.0; |
|
Default for Density. | |
| Public | DefaultMass = 0.0; |
| Public | DefaultRestitution = 0.0; |
|
Default for Restitution. | |
| Public | DefaultFriction = 0.5; |
|
Default for Friction. | |
Fields
| Public | class var AutoSizeMinThickness: Single; |
|
Minimum collider thickness used by AutoSize in 3D mode (when Mode2D = | |
| Public | AutoSizeMinThickness2D: Single; |
|
Minimum collider thickness used by AutoSize in 2D mode (when Mode2D = | |
| Public | AutoSizeMinThickness2DDepth: Single; |
|
Minimum collider thickness used by AutoSize in 2D mode (when Mode2D = | |
Methods
| Protected | function GetInternalText: String; virtual; |
|
This item has no description. | |
| Protected | procedure SetInternalText(const Value: String); virtual; |
|
This item has no description. | |
| Protected | procedure SetName(const Value: TComponentName); override; |
|
This item has no description. | |
| Protected | procedure TranslateProperties(const TranslatePropertyEvent: TTranslatePropertyEvent); virtual; |
|
Enumerate all properties that are possible to translate in this component. E.g. in TCastleLabel it will return TCastleLabel.Caption, in TCastleEdit it will return TCastleEdit.Text and TCastleEdit.Placeholder. Returns only non-empty properties, thus assuming that if current (by convention, English) text is empty, then there is no point in translating it. Moreover descendants may define boolean properties to exclude particular text from translating, e.g. TCastleLabel.CaptionTranslate, TCastleEdit.TextTranslate, TCastleEdit.PlaceholderTranslate. It is not recursive (it doesn't enumerate children properties). Use global TranslateProperties procedure to call this on a hierarchy of TComponent. You usually don't want to call this method (it is called by other engine routines). But you may find it useful to override this, if you define new component. | |
| Public | destructor Destroy; override; |
|
This item has no description. | |
| Public | procedure CustomSerialization(const SerializationProcess: TSerializationProcess); virtual; |
|
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. | |
| Public | function PropertySections(const PropertyName: String): TPropertySections; virtual; |
|
Section where to show property in the editor. | |
| Public | procedure SetTransient; |
|
Ignore this component when serializing parent's TCastleUserInterface.Controls list or TCastleTransform.List, and do not show this component in CGE editor. This simply sets csTransient flag in ComponentStyle. This is useful for children that are automatically managed by the parent, and should not be modified by user code. For example, TCastleCheckbox is internally composed from TCastleImageControl and TCastleLabel children, but we don't want to serialize or even show these children to user. Note that if you want to prevent this component from serializing as part of TCastleUserInterface.Controls list or TCastleTransform.List, but you still want it to be visible in CGE editor, then make it a "subcomponent" instead, by Note that both csSubComponent and csTransient only disable the component serialization as part of parent's lists enumerated by CustomSerialization (see internal TCastleUserInterface.SerializeChildrenEnumerate , TCastleTransform.SerializeChildrenEnumerate, TCastleTransform.SerializeBehaviorsEnumerate). If you will make the component published in its own property (which is normal for "subcomponents") then it will be serialized anyway, just as part of it's own property (like TCastleScrollView.ScrollArea). So to really avoid serializing a children component make it csSubComponent and/or csTransient, and do not publish it. | |
| Public | procedure AddNonVisualComponent(const NonVisualComponent: TComponent); |
|
Add non-visual component to this component. This is used to organize non-visual components in a tree hierarchy, in CGE designs and editor.
See also
| |
| Public | procedure InsertNonVisualComponent(const Index: Integer; const NonVisualComponent: TComponent); |
|
Insert non-visual component to this component. This is used to organize non-visual components in a tree hierarchy, in CGE designs and editor.
See also
| |
| Public | procedure RemoveNonVisualComponent(const NonVisualComponent: TComponent); |
|
Removes the component previously added by AddNonVisualComponent. | |
| Public | function NonVisualComponentsIndexOf(const NonVisualComponent: TComponent): Integer; |
|
Index of the previously added non-visual component. Returns -1 if the component was not found. | |
| Public | function NonVisualComponentsCount: Integer; |
|
Count of components added by AddNonVisualComponent.
See also
| |
| Public | function NonVisualComponentsEnumerate: TNonVisualComponentsEnumerator; |
|
You can enumerate current non-visual components using loop like See also
| |
| Public | function ValueIsStreamed: Boolean; virtual; |
|
Whether the current value of this object should be written to the stream. This should be This is used by CastleComponentSerialize, which is used in Castle Game Engine for all serialization. In simple cases, this just says whether the current value of this object equals to some default value. The default implementation of this class returns Descendants that override this to sometimes return The name of this method is consistent with TPropertyEditor.ValueIsStreamed in LCL. | |
| Public | procedure DesignerInfo(const SList: TStrings); virtual; |
|
Override to add information that should be visible at design-time. Call | |
| Public | procedure DesignerWarnings(const SList: TStrings); virtual; |
|
Override to add warnings that should be visible at design-time. Call | |
| Protected | procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); virtual; |
|
Continuously occuring event, for various tasks. Parameters
| |
| Protected | procedure BeforeRender( const CameraView: TViewVectors; const ParentParentWorldTransformation: TTransformation); virtual; |
|
Event called right before rendering the parent TCastleTransform. Override this if you have to adjust the parent transformation strictly before the rendering. Compared to adjusting the parent transformation in e.g. Update, adjusting the parent transformation here has advantages:
For example, adjusting the TCastleTransform done by the TCastleBillboard is done using this method. The transformation in this case is determined by the camera and parent's parent transformation. The transformation has to be applied without any delay (even a 1-frame delay would be visible, as artifacts caused by billboard not perfectly aligned with the camera would be visible – blending sort along camera direction in sort3D is not perfect if billboard doesn't exactly match camera direction). And the transformation with billboard may be present in multiple viewports and/or multiple times in the same viewport tree.
Parameters
| |
| Protected | procedure ParentChanged; virtual; deprecated 'Use ParentAfterAttach / ParentBeforeDetach or WorldAfterAttach / WorldBeforeDetach'; |
|
Warning: this symbol is deprecated: Use ParentAfterAttach / ParentBeforeDetach or WorldAfterAttach / WorldBeforeDetach Called after Parent changed, at the end of TCastleTransform.AddBehavior, TCastleTransform.RemoveBehavior. | |
| Protected | procedure ParentAfterAttach; virtual; |
|
Called after Parent changed, e.g. at the end of TCastleTransform.AddBehavior. | |
| Protected | procedure ParentBeforeDetach; virtual; |
|
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 | |
| Protected | procedure WorldAfterAttach; virtual; |
|
Called after Parent became part of World. Called only if ListenWorldChange is | |
| Protected | procedure WorldBeforeDetach; virtual; |
|
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 | |
| Protected | function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; virtual; |
|
Check can this behavior be added to NewParent. When this returns function TCastleBillboard.CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; begin Result := inherited; if not Result then Exit; if NewParent.FindBehavior(TCastleBillboard) <> nil then begin ReasonWhyCannot := 'Only one TCastleBillboard behavior can be added to a given TCastleTransform'; Result := false; end; end; | |
| Public | procedure BeforeDestruction; override; |
|
This item has no description. | |
| Public | function World: TCastleAbstractRootTransform; |
|
Reference to the root transformation (typically matching the TCastleViewport.Items value) corresponding to the parent of this behavior. May be | |
| Protected | function StoredWithAutoSize: Boolean; |
|
Use this for "stored" for properties that are auto-calculated when AutoSize. | |
| Protected | function TotalScale: Single; |
|
Total scale, accumulated from all parents TCastleTransform.Scale (converted to scalar following Mode2D) and collider SizeScale. | |
| Protected | function CreateKraftShape(const APhysics: TKraft; const ARigidBody: TKraftRigidBody): TKraftShape; virtual; abstract; |
|
This item has no description. | |
| Protected | procedure DeinitializePhysicsEngineObjects; virtual; |
|
This item has no description. | |
| Protected | procedure ShapeChangedNotifyRigidBody; |
|
Notify associated TCastleRigidBody that Kraft shape needs to be recreated. This may in turn call TCastleCollider.InitializeKraft and TCastleCollider.CreateKraftShape. | |
| Protected | procedure UpdateVisualization; virtual; |
|
Called when the collider size has changed and needs to be updated. | |
| Protected | 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 | |
| Protected | 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 | |
| Protected | 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. | |
| Protected | procedure DisableAutoSize; |
|
Sets AutoSize = | |
| Protected | procedure CalculateSizeCore; virtual; |
|
Recalculate collider size. Do not be concerned about AutoSize here, just update collider properties. The default implementation resets Translation and Rotation. | |
| Public | constructor Create(AOwner: TComponent); override; |
|
This item has no description. | |
| Public | destructor Destroy; override; |
|
This item has no description. | |
| Public | 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. | |
| Public | 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. | |
| Public | 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). | |
| Public | procedure InternalDesigningBegin; virtual; |
|
Create collider visualization. | |
| Public | procedure InternalDesigningEnd; virtual; |
|
Destroy collider visualization. | |
| Public | 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 | |
| Public | procedure InternalAutoSize; |
|
Recalculate collider size using parent bounding box, only if AutoSize says we should recalculate. Ignored if not AutoSize. | |
| Public | 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
| |
| Protected | function CreateKraftShape(const APhysics: TKraft; const ARigidBody: TKraftRigidBody): TKraftShape; override; |
|
This item has no description. | |
| Protected | procedure CalculateSizeCore; override; |
|
This item has no description. Showing description inherited from TCastleCollider.CalculateSizeCore. Recalculate collider size. Do not be concerned about AutoSize here, just update collider properties. The default implementation resets Translation and Rotation. | |
| Protected | procedure UpdateVisualization; override; |
|
This item has no description. Showing description inherited from TCastleCollider.UpdateVisualization. Called when the collider size has changed and needs to be updated. | |
| Public | constructor Create(AOwner: TComponent); override; |
|
This item has no description. | |
| Public | 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. | |
| Public | procedure InternalDesigningBegin; override; |
|
This item has no description. Showing description inherited from TCastleCollider.InternalDesigningBegin. Create collider visualization. | |
| Public | procedure InternalDesigningEnd; override; |
|
This item has no description. Showing description inherited from TCastleCollider.InternalDesigningEnd. Destroy collider visualization. | |
Properties
| Public | property NonVisualComponents [const Index: Integer]: TComponent read GetNonVisualComponents; |
|
Components added by AddNonVisualComponent. | |
| Public | property IsLoading: Boolean read FIsLoading; |
|
Is the component during deserialization now. Note: We can't use | |
| Public | property Parent: TCastleTransform read FParent; |
|
Parent TCastleTransform of this behavior. Change it by doing TCastleTransform.AddBehavior, TCastleTransform.RemoveBehavior.
| |
| Public | property ListenWorldChange: Boolean
read FListenWorldChange write SetListenWorldChange; |
|
Set this to | |
| Public | property Translation: TVector3 read FTranslation write SetTranslation; |
|
Local collider translation, relative to parent TCastleTransform. Note that CalculateSize and AutoSize mechanisms set it automatically. | |
| Public | property Rotation: TVector4 read FRotation write SetRotation; |
|
Local collider rotation, relative to parent TCastleTransform. Note that CalculateSize and AutoSize mechanisms set it automatically. | |
| Published | 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. | |
| Published | property Density: Single read FDensity write SetDensity
default DefaultDensity; |
|
| |
| Published | 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. | |
| Published | property Restitution: Single read FRestitution write SetRestitution
default DefaultRestitution; |
|
Larger restitution means that on collision, this object behaves more elastic. Reasonable values are between 0 (inelastic) and 1 (elastic). See https://en.wikipedia.org/wiki/Coefficient_of_restitution . | |
| Published | property Friction: Single read FFriction write SetFriction
default DefaultFriction; |
|
Larger friction means that it is harder for body to slide alongside another object. | |
| Published | 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. | |
| Published | 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
| |
| Published | 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
| |
| Published | 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
| |
| Published | property Radius: Single read FRadius write SetRadius stored StoredWithAutoSize; |
|
Sphere radius. Default is 1 (if not AutoSize), consistent with TCastleSphere. | |
Generated by PasDoc 0.17.0.snapshot.