class
Eagle::Physics2D::Body
- Eagle::Physics2D::Body
- Reference
- Object
Overview
A physics body: position, velocity, mass and one or more shapes.
The physics nodes create bodies for you. Use Body directly with a World when you
don't need nodes.
Defined in:
eagle/physics/body2d.crConstructors
-
.new(type : BodyType = BodyType::Dynamic, position : Vec2 = Vec2::ZERO, shape : Shape | Nil = nil)
Creates a body, optionally with a first shape.
Instance Method Summary
-
#aabb : Rect
World-space bounds of all shapes.
-
#add_shape(s : Shape) : Shape
Adds a shape and recomputes mass.
-
#angular_damping : Float32
Drag on spin.
-
#angular_damping=(angular_damping : Float32)
Drag on spin.
-
#angular_velocity : Float32
Spin in radians per second.
-
#angular_velocity=(angular_velocity : Float32)
Spin in radians per second.
-
#apply_force(f : Vec2, point : Vec2 | Nil = nil) : Nil
Adds a force for the next step, at a world-space point if given.
-
#apply_impulse(i : Vec2, point : Vec2 | Nil = nil) : Nil
Changes velocity instantly, at a world-space point if given.
-
#apply_torque(t : Number) : Nil
Adds torque for the next step.
-
#collides_with?(o : Body) : Bool
True when the layer and mask bits allow these two bodies to collide.
-
#contacts : Set(Eagle::Physics2D::Body)
Bodies touching this one after the last step.
-
#contains_point?(p : Vec2) : Bool
True when a world-space point is inside any of the shapes.
-
#density : Float32
Mass per unit area, used to compute mass from shapes.
-
#density=(density : Float32)
Mass per unit area, used to compute mass from shapes.
-
#density=(d : Number)
Sets the density and recomputes mass from the shapes.
-
#dynamic? : Bool
True for dynamic bodies.
-
#each_world_shape(& : Shape -> ) : Nil
Yields each world-space shape.
-
#enabled=(enabled : Bool)
Disabled bodies are skipped by the simulation and by queries.
-
#enabled? : Bool
Disabled bodies are skipped by the simulation and by queries.
-
#fixed_rotation=(v : Bool)
Enables or disables rotation.
-
#fixed_rotation=(fixed_rotation : Bool)
Prevents rotation.
-
#fixed_rotation? : Bool
Prevents rotation.
-
#force : Vec2
Force accumulated for the next step.
-
#force=(force : Vec2)
Force accumulated for the next step.
-
#friction : Float32
Surface grip.
-
#friction=(friction : Float32)
Surface grip.
-
#gravity_scale : Float32
Multiplies the world's gravity for this body.
-
#gravity_scale=(gravity_scale : Float32)
Multiplies the world's gravity for this body.
-
#id : Int32
A unique id.
-
#inertia : Float32
Rotational inertia.
-
#inv_inertia : Float32
1 / inertia, or 0 when rotation is fixed.
-
#inv_mass : Float32
1 / mass, or 0 for static and kinematic bodies.
-
#kinematic? : Bool
True for kinematic bodies.
-
#layer : UInt32
Bits for the layers this body is on.
-
#layer=(layer : UInt32)
Bits for the layers this body is on.
-
#linear_damping : Float32
Drag on linear velocity.
-
#linear_damping=(linear_damping : Float32)
Drag on linear velocity.
-
#mask : UInt32
Bits for the layers this body collides with.
-
#mask=(mask : UInt32)
Bits for the layers this body collides with.
-
#mass : Float32
Mass, computed from shapes and density unless set directly.
-
#mass=(m : Number)
Sets the mass directly, scaling inertia to match.
-
#owner : Node | Nil
The node that owns this body, if any.
-
#owner=(owner : Node | Nil)
The node that owns this body, if any.
-
#position : Vec2
World-space position of the body's origin.
-
#position=(position : Vec2)
World-space position of the body's origin.
-
#remove_shape(s : Shape) : Nil
Removes a shape and recomputes mass.
-
#restitution : Float32
Bounciness from 0 to 1.
-
#restitution=(restitution : Float32)
Bounciness from 0 to 1.
-
#rotation : Float32
Rotation in radians.
-
#rotation=(rotation : Float32)
Rotation in radians.
-
#sensor=(sensor : Bool)
Sensors report overlaps but don't collide.
-
#sensor? : Bool
Sensors report overlaps but don't collide.
-
#shapes : Array(Eagle::Physics2D::Shape)
Shapes in local space.
-
#static? : Bool
True for static bodies.
-
#tag : String
A free-form label for your own bookkeeping.
-
#tag=(tag : String)
A free-form label for your own bookkeeping.
-
#to_s(io : IO) : Nil
Appends a short String representation of this object which includes its class name and its object address.
-
#torque : Float32
Torque accumulated for the next step.
-
#torque=(torque : Float32)
Torque accumulated for the next step.
-
#transform : Transform2D
The body's transform.
-
#type : BodyType
Static, kinematic or dynamic.
-
#type=(t : BodyType)
Changes the body type and recomputes mass.
-
#velocity : Vec2
Linear velocity in pixels per second.
-
#velocity=(velocity : Vec2)
Linear velocity in pixels per second.
-
#velocity_at(point : Vec2) : Vec2
Velocity of a world-space point on the body, including spin.
-
#world_shapes : Array(Eagle::Physics2D::Shape)
Shapes transformed into world space for the current step.
Constructor Detail
Creates a body, optionally with a first shape.
Instance Method Detail
Adds a force for the next step, at a world-space point if given.
Changes velocity instantly, at a world-space point if given.
True when the layer and mask bits allow these two bodies to collide.
Bits for the layers this body is on. A pair collides when
(a.layer & b.mask) != 0 && (b.layer & a.mask) != 0.
Bits for the layers this body is on. A pair collides when
(a.layer & b.mask) != 0 && (b.layer & a.mask) != 0.
Appends a short String representation of this object which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Torque accumulated for the next step. It is cleared after every step.
Shapes transformed into world space for the current step.