Download Now

    Reference TBody

    Declared in Codebot.Physics.pas on line 375

    TBody is a rigid body, which has a mass, a position, and a velocity, and holds shapes
      TBody = record
      public
        Ref: cpBody;
        class operator Implicit(const Value: TBody): cpBody; inline;
        class operator Implicit(const Value: cpBody): TBody; inline;
        class operator Equal(const A, B: TBody): Boolean; inline;
        class operator NotEqual(const A, B: TBody): Boolean; inline;
        { Remove the body, its shapes, and its joints from its space and free them.
          If the space is locked, such as in a collision callback, this happens
          after the current step. Note: The ground body of a space is not freed. }
        procedure Free;
        { True if this refers to nothing }
        function IsNil: Boolean; inline;
        { Add shape to the body. Note: A default density of 1 is set on all shapes.
          As shapes are added to bodies they become a rigid part of the body and do
          not move or collide in relation to other shapes in the same body. Shape
          coordinates are relative to the body. }
        function NewCircle(Radius: Float): TShape; overload;
        { Add a circle shape to the body }
        function NewCircle(Radius: Float; const Offset: TVec2): TShape; overload;
        { Add a segment shape to the body }
        function NewSegment(const A, B: TVec2; Border: Float = 0): TShape;
        { Add a box shape to the body }
        function NewBox(Width, Height: Float; Border: Float = 0; Transform: PMatrix2x3 = nil): TShape; overload;
        function NewBox(X, Y, Width, Height: Float; Border: Float = 0; Transform: PMatrix2x3 = nil): TShape; overload;
        function NewBox(const Box: cpBB; Border: Float = 0): TShape; overload;
        { Add a polygon shape to the body }
        function NewPolygon(Verts: PVec2; Count: Integer; Border: Float = 0; Transform: PMatrix2x3 = nil): TShape;
        { Add a polygon without computing a convex hull. The vertices must be convex
          with a counter-clockwise winding. }
        function NewPolygonRaw(Verts: PVec2; Count: Integer; Border: Float = 0): TShape;
        { Force a dynamic body and every other dynamic body it touches to fall
          asleep immediately. Sleeping bodies do not consume physics calculations
          unless they are awoken or are hit by a non-sleeping body }
        procedure Sleep;
        { Join two groups of dynamic sleeping bodies together }
        procedure SleepWithGroup(Body: TBody);
        { Test if a dynamic body is sleeping }
        function IsSleeping: Boolean;
        { Wake up this body and anything it touches. Note: Works on non-dynamic
          bodies as well }
        procedure WakeUp;
        { Translate a body point to a world point }
        function BodyToWorld(const Point: TVec2): TVec2;
        { Translate a world point to a body point }
        function WorldToBody(const Point: TVec2): TVec2;
        { Apply a force to a body at a point in world coordinates }
        procedure ApplyForceAtWorld(const Force, Point: TVec2);
        { Apply a force to a body at a point in body coordinates }
        procedure ApplyForceAtBody(const Force, Point: TVec2);
        { Apply an impulse to a body at a point in world coordinates }
        procedure ApplyImpulseAtWorld(const Impulse, Point: TVec2);
        { Apply an impulse to a body at a point in body coordinates }
        procedure ApplyImpulseAtBody(const Impulse, Point: TVec2);
        { The velocity of a point in world coordinates on a body }
        function VelocityAtWorld(const Point: TVec2): TVec2;
        { The velocity of a point in body coordinates on a body }
        function VelocityAtBody(const Point: TVec2): TVec2;
        { The default velocity integration, which can be called from a custom
          VelocityFunc }
        procedure UpdateVelocity(const Gravity: TVec2; Damping, DeltaTime: Float);
        { The default position integration, which can be called from a custom
          PositionFunc }
        procedure UpdatePosition(DeltaTime: Float);
        { Kind can be either dynamic, kinematic, or static. Note: Kind is set for
          you automatically during body creation }
        property Kind: TBodyKind read GetKind write SetKind;
        { Mass and moment are calculated from the density of the shapes in the body,
          but may be set directly }
        property Mass: Float read GetMass write SetMass;
        { The moment of inertia of the body }
        property Moment: Float read GetMoment write SetMoment;
        { The center of gravity in body coordinates }
        property CenterOfGravity: TVec2 read GetCenterOfGravity write SetCenterOfGravity;
        { The position of the body }
        property Position: TVec2 read GetPosition write SetPosition;
        { The velocity of the body }
        property Velocity: TVec2 read GetVelocity write SetVelocity;
        { The force applied to the body for the next step, which is reset to zero
          after each step }
        property Force: TVec2 read GetForce write SetForce;
        { Angle of the body in radians }
        property Angle: Float read GetAngle write SetAngle;
        { How fast the body is turning }
        property AngularVelocity: Float read GetAngularVelocity write SetAngularVelocity;
        { The torque applied to the body for the next step, which is reset to zero
          after each step }
        property Torque: Float read GetTorque write SetTorque;
        { The rotation of the body as a unit vector }
        property Rotation: TVec2 read GetRotation;
        { The kinetic energy of the body }
        property KineticEnergy: Float read GetKineticEnergy;
        { Callbacks which replace the velocity and position integration of the body }
        property VelocityFunc: cpBodyVelocityFunc read GetVelocityFunc write SetVelocityFunc;
        { A callback which replaces how the position of the body is updated }
        property PositionFunc: cpBodyPositionFunc read GetPositionFunc write SetPositionFunc;
        { The first shape if one exists or a nil reference }
        property Shape: TShape read GetShape;
        { User assignable data associated with the body }
        property UserData: Pointer read GetUserData write SetUserData;
        { A for...in enumerator for the shapes in this body }
        property Shapes: TBodyShapeEnumerator read GetShapes;
      end;

    See also

    Float in Codebot.System.pas
    TVec2 in Codebot.Geometry.pas