class Eagle::Physics3D::World

Overview

A 3D physics simulation. See Physics3D for an example.

Defined in:

eagle/physics/physics3d.cr

Instance Method Summary

Instance Method Detail

def add(type : BodyType, position : Vec3, shape : Shape) : Body #

Creates a body with one shape, adds it and returns it.


def add_body(b : Body) : Body #

Adds an existing body and returns it.


Pairs of bodies that started touching in the last step.


def bias_factor : Float32 #

How aggressively overlap is corrected, from 0 to 1.


def bias_factor=(bias_factor : Float32) #

How aggressively overlap is corrected, from 0 to 1.


def bodies : Array(Eagle::Physics3D::Body) #

Every body in the world.


def cell_size : Float32 #

Broad-phase grid cell size in meters.


def cell_size=(cell_size : Float32) #

Broad-phase grid cell size in meters.


def clear : Nil #

Removes every body.


def contact_begin : Eagle::Emitter(Body, Body) #

Emitted during a step when two bodies start touching.


def contact_end : Eagle::Emitter(Body, Body) #

Emitted during a step when two bodies stop touching.


def emit_contact_begin(*args) : Nil #

Emitted during a step when two bodies start touching.


def emit_contact_end(*args) : Nil #

Emitted during a step when two bodies stop touching.


Pairs of bodies that stopped touching in the last step.


def gravity : Vec3 #

Acceleration applied to dynamic bodies, in m/s².


def gravity=(gravity : Vec3) #

Acceleration applied to dynamic bodies, in m/s².


def iterations : Int32 #

Solver iterations per step.


def iterations=(iterations : Int32) #

Solver iterations per step.


def move_and_slide(body : Body, motion : Vec3, max_slides : Int32 = 4) : Array(Vec3) #

Moves a body by motion, sliding along obstacles. Returns the normals hit.


def on_contact_begin(&block : Body, Body -> Nil) : Proc(Body, Body, Nil) #

Emitted during a step when two bodies start touching.


def on_contact_end(&block : Body, Body -> Nil) : Proc(Body, Body, Nil) #

Emitted during a step when two bodies stop touching.


def probe_floor(body : Body, up : Vec3, distance : Float32, max_angle : Float32) : Vec3 | Nil #

Looks for ground below the body without moving it. Returns the floor normal if found.


def query_aabb(box : AABB, mask : UInt32 = 4294967295_u32) : Array(Body) #

Every body whose bounds overlap box.


def query_point(p : Vec3, mask : UInt32 = 4294967295_u32) : Array(Body) #

Every body containing p.


def query_sphere(center : Vec3, radius : Number, mask : UInt32 = 4294967295_u32) : Array(Body) #

Every body overlapping a sphere, for explosions and proximity checks.


def raycast(origin : Vec3, direction : Vec3, max_distance : Number = 1e6, mask : UInt32 = 4294967295_u32, exclude : Body | Nil = nil) : RayHit | Nil #

Casts a ray and returns the closest hit, or nil.


def remove_body(b : Body) : Nil #

Removes a body.


def sleep_threshold : Float32 #

Speed below which resting bodies stop being simulated. 0 disables sleeping.


def sleep_threshold=(sleep_threshold : Float32) #

Speed below which resting bodies stop being simulated. 0 disables sleeping.


def slop : Float32 #

Overlap allowed before correction, in meters.


def slop=(slop : Float32) #

Overlap allowed before correction, in meters.


def step(dt : Float32) : Nil #

Advances the simulation by dt seconds.