class Eagle::Physics2D::Body

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(type : BodyType = BodyType::Dynamic, position : Vec2 = Vec2::ZERO, shape : Shape | Nil = nil) #

Creates a body, optionally with a first shape.


Instance Method Detail

def aabb : Rect #

World-space bounds of all shapes.


def add_shape(s : Shape) : Shape #

Adds a shape and recomputes mass. Returns the shape.


def angular_damping : Float32 #

Drag on spin.


def angular_damping=(angular_damping : Float32) #

Drag on spin.


def angular_velocity : Float32 #

Spin in radians per second.


def angular_velocity=(angular_velocity : Float32) #

Spin in radians per second.


def apply_force(f : Vec2, point : Vec2 | Nil = nil) : Nil #

Adds a force for the next step, at a world-space point if given.


def apply_impulse(i : Vec2, point : Vec2 | Nil = nil) : Nil #

Changes velocity instantly, at a world-space point if given.


def apply_torque(t : Number) : Nil #

Adds torque for the next step.


def collides_with?(o : Body) : Bool #

True when the layer and mask bits allow these two bodies to collide.


def contacts : Set(Eagle::Physics2D::Body) #

Bodies touching this one after the last step.


def contains_point?(p : Vec2) : Bool #

True when a world-space point is inside any of the shapes.


def density : Float32 #

Mass per unit area, used to compute mass from shapes.


def density=(density : Float32) #

Mass per unit area, used to compute mass from shapes.


def density=(d : Number) #

Sets the density and recomputes mass from the shapes.


def dynamic? : Bool #

True for dynamic bodies.


def each_world_shape(& : Shape -> ) : Nil #

Yields each world-space shape.


def enabled=(enabled : Bool) #

Disabled bodies are skipped by the simulation and by queries.


def enabled? : Bool #

Disabled bodies are skipped by the simulation and by queries.


def fixed_rotation=(v : Bool) #

Enables or disables rotation.


def fixed_rotation=(fixed_rotation : Bool) #

Prevents rotation.


def fixed_rotation? : Bool #

Prevents rotation.


def force : Vec2 #

Force accumulated for the next step. It is cleared after every step.


def force=(force : Vec2) #

Force accumulated for the next step. It is cleared after every step.


def friction : Float32 #

Surface grip. Contact friction combines both bodies' values.


def friction=(friction : Float32) #

Surface grip. Contact friction combines both bodies' values.


def gravity_scale : Float32 #

Multiplies the world's gravity for this body.


def gravity_scale=(gravity_scale : Float32) #

Multiplies the world's gravity for this body.


def id : Int32 #

A unique id.


def inertia : Float32 #

Rotational inertia.


def inv_inertia : Float32 #

1 / inertia, or 0 when rotation is fixed.


def inv_mass : Float32 #

1 / mass, or 0 for static and kinematic bodies.


def kinematic? : Bool #

True for kinematic bodies.


def layer : UInt32 #

Bits for the layers this body is on. A pair collides when (a.layer & b.mask) != 0 && (b.layer & a.mask) != 0.


def layer=(layer : UInt32) #

Bits for the layers this body is on. A pair collides when (a.layer & b.mask) != 0 && (b.layer & a.mask) != 0.


def linear_damping : Float32 #

Drag on linear velocity.


def linear_damping=(linear_damping : Float32) #

Drag on linear velocity.


def mask : UInt32 #

Bits for the layers this body collides with.


def mask=(mask : UInt32) #

Bits for the layers this body collides with.


def mass : Float32 #

Mass, computed from shapes and density unless set directly.


def mass=(m : Number) #

Sets the mass directly, scaling inertia to match.


def owner : Node | Nil #

The node that owns this body, if any. Physics nodes set it.


def owner=(owner : Node | Nil) #

The node that owns this body, if any. Physics nodes set it.


def position : Vec2 #

World-space position of the body's origin.


def position=(position : Vec2) #

World-space position of the body's origin.


def remove_shape(s : Shape) : Nil #

Removes a shape and recomputes mass.


def restitution : Float32 #

Bounciness from 0 to 1.


def restitution=(restitution : Float32) #

Bounciness from 0 to 1.


def rotation : Float32 #

Rotation in radians.


def rotation=(rotation : Float32) #

Rotation in radians.


def sensor=(sensor : Bool) #

Sensors report overlaps but don't collide.


def sensor? : Bool #

Sensors report overlaps but don't collide.


def shapes : Array(Eagle::Physics2D::Shape) #

Shapes in local space.


def static? : Bool #

True for static bodies.


def tag : String #

A free-form label for your own bookkeeping.


def tag=(tag : String) #

A free-form label for your own bookkeeping.


def to_s(io : IO) : Nil #
Description copied from class Reference

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>

def torque : Float32 #

Torque accumulated for the next step. It is cleared after every step.


def torque=(torque : Float32) #

Torque accumulated for the next step. It is cleared after every step.


def transform : Transform2D #

The body's transform.


def type : BodyType #

Static, kinematic or dynamic.


def type=(t : BodyType) #

Changes the body type and recomputes mass.


def velocity : Vec2 #

Linear velocity in pixels per second.


def velocity=(velocity : Vec2) #

Linear velocity in pixels per second.


def velocity_at(point : Vec2) : Vec2 #

Velocity of a world-space point on the body, including spin.


def world_shapes : Array(Eagle::Physics2D::Shape) #

Shapes transformed into world space for the current step.