Reference TSpace
Declared in Codebot.Physics.pas on line 952
TSpace contains your physics simulation
TSpace = record
public
Ref: cpSpace;
class operator Implicit(const Value: TSpace): cpSpace; inline;
class operator Implicit(const Value: cpSpace): TSpace; inline;
{ Free the space and everything in it. Note: This must not be called while
the space is locked, such as in a collision callback. }
procedure Free;
{ True if this refers to nothing }
function IsNil: Boolean; inline;
{ Release all bodies along with their shapes and joints }
procedure ReleaseBodies;
{ Release all joints }
procedure ReleaseJoints;
{ Release all bodies, shapes, and joints in this space. If the space is
locked, such as in a collision callback, this happens after the current
step. }
procedure ReleaseObjects;
{ Calculate changes to all bodies }
procedure Step(DeltaTime: Float);
{ Add a custom collision handler for shapes of type A and B }
function AddCollisionHandler(A, B: TCollisionType): TCollisionHandler;
{ Add a collision handler for shapes of type A colliding with anything }
function AddWildcardHandler(A: TCollisionType): TCollisionHandler;
{ Add the handler for collisions not handled by any other handler }
function AddDefaultCollisionHandler: TCollisionHandler;
{ Schedule a callback after the current step, which is where shapes, bodies,
and joints may be safely removed or freed. Only one callback is kept per
key, and the result is true if the key was not already scheduled. }
function AddPostStepCallback(Func: cpPostStepFunc; Key: Pointer; Data: Pointer = nil): Boolean;
{ Create a dynamic body in this space. A dynamic body reacts to and is
updated by physics }
function NewBody: TBody;
{ Create a kinematic body in this space. A kinematic body is one you can
move but is not updated by physics }
function NewKinematicBody: TBody;
{ Create a static body in this space. A static body is one you cannot move
and is not updated by physics }
function NewStaticBody: TBody;
{ Create a joint of each kind between two bodies }
function NewPin(A, B: TBody; const PinA, PinB: TVec2): TJoint;
function NewSlide(A, B: TBody; const PinA, PinB: TVec2; Min, Max: Float): TJoint;
function NewPivot(A, B: TBody; const Pivot: TVec2): TJoint; overload;
function NewPivot(A, B: TBody; const PinA, PinB: TVec2): TJoint; overload;
function NewGroove(A, B: TBody; const GrooveA, GrooveB, PinB: TVec2): TJoint;
function NewDampedSpring(A, B: TBody; const PinA, PinB: TVec2; RestLength, Stiffness, Damping: Float): TJoint;
function NewDampedRotarySpring(A, B: TBody; RestAngle, Stiffness, Damping: Float): TJoint;
function NewRotaryLimit(A, B: TBody; Min, Max: Float): TJoint;
function NewRatchet(A, B: TBody; Phase, Ratchet: Float): TJoint;
function NewGear(A, B: TBody; Phase, Ratio: Float): TJoint;
{ To simulate an axle tie one body to a static body such as ground }
function NewMotor(A, B: TBody; Rate: Float): TJoint;
function Add(Body: TBody): TBody; overload;
function Add(Joint: TJoint): TJoint; overload;
function Add(Shape: TShape): TShape; overload;
{ Remove a body and its shapes from the space. Note: Shapes are no longer
attached to a body once they are removed from the space. }
procedure Remove(Body: TBody); overload;
procedure Remove(Joint: TJoint); overload;
procedure Remove(Shape: TShape); overload;
{ True if the space contains a body, a joint, or a shape }
function Contains(Body: TBody): Boolean; overload;
function Contains(Joint: TJoint): Boolean; overload;
function Contains(Shape: TShape): Boolean; overload;
{ All shapes within a distance of a point }
function PointQuery(const P: TVec2; MaxDistance: Float; const Filter: cpShapeFilter): TArrayList<cpPointQueryInfoStruct>;
{ The nearest shape within a distance of a point or a nil shape }
function PointQueryNearest(const P: TVec2; MaxDistance: Float; const Filter: cpShapeFilter; out Info: cpPointQueryInfoStruct): TShape;
{ All shapes hit by a segment with a radius from A to B }
function SegmentQuery(const A, B: TVec2; Radius: Float; const Filter: cpShapeFilter): TArrayList<cpSegmentQueryInfoStruct>;
{ The first shape hit by a segment with a radius from A to B or a nil shape }
function SegmentQueryFirst(const A, B: TVec2; Radius: Float; const Filter: cpShapeFilter; out Info: cpSegmentQueryInfoStruct): TShape;
{ All shapes whose bounding boxes overlap a box }
function BoxQuery(const Box: cpBB; const Filter: cpShapeFilter): TArrayList<TShape>;
{ All shapes overlapping a shape, which does not need to be in the space }
function ShapeQuery(Shape: TShape): TArrayList<TShape>;
procedure ReindexStatic;
procedure ReindexShape(Shape: TShape);
procedure ReindexBody(Body: TBody);
{ Switch the space to a spatial hash, which can be faster for many shapes of
the same size }
procedure UseSpatialHash(Dim: Float; Count: Integer);
{ Draw the space using the callbacks in options }
procedure DebugDraw(const Options: cpSpaceDebugDrawOptions);
{ Ground is a built in static body. Note: Do not remove or free this body }
property Ground: TBody read GetGround;
{ The number of iterations in each step. The default value is 10 }
property Iterations: LongWord read GetIterations write SetIterations;
{ Damping on space is a global reduction of movement applied to dynamic
bodies with each step }
property Damping: Float read GetDamping write SetDamping;
{ Force applied to all dynamic bodies }
property Gravity: TVec2 read GetGravity write SetGravity;
{ Speed limit under which dynamic bodies are put to sleep. Increasing this
value causes bodies to sleep faster }
property IdleSpeedThreshold: Float read GetIdleSpeedThreshold write SetIdleSpeedThreshold;
{ Amount of time when a dynamic body is put to sleep while idle. The default
value is infinity, indicating that bodies will never sleep }
property SleepTimeThreshold: Float read GetSleepTimeThreshold write SetSleepTimeThreshold;
{ The amount of overlap allowed between shapes }
property CollisionSlop: Float read GetCollisionSlop write SetCollisionSlop;
{ The percentage of overlap which remains unfixed after a second }
property CollisionBias: Float read GetCollisionBias write SetCollisionBias;
{ The number of steps to keep collision solutions }
property CollisionPersistence: LongWord read GetCollisionPersistence write SetCollisionPersistence;
{ The time step of the current or most recent step }
property CurrentTimeStep: Float read GetCurrentTimeStep;
{ True while the space is stepping, when objects cannot be added or removed }
property Locked: Boolean read GetLocked;
{ A value of your own kept with the space }
property UserData: Pointer read GetUserData write SetUserData;
{ A for...in enumerator for all bodies (except ground) inside this space }
property Bodies: TSpaceBodyEnumerator read GetBodies;
{ A for...in enumerator for all shapes inside this space }
property Shapes: TSpaceShapeEnumerator read GetShapes;
{ A for...in enumerator for all joints inside this space, including the
joints of sleeping bodies }
property Joints: TSpaceJointEnumerator read GetJoints;
end;See also
Float in Codebot.System.pas
TArrayList<T> in Codebot.System.pas
TVec2 in Codebot.Geometry.pas