struct
Eagle::Ray
- Eagle::Ray
- Struct
- Value
- Object
Overview
A 3D ray: an #origin and a unit #direction. Use it for picking, line of sight and
simple hit-scan weapons.
Camera3D#mouse_ray gives you the ray under the mouse cursor. Each intersect_*
method returns the distance along the ray to the hit, or nil on a miss. Pass that
distance to #at to get the hit point.
ray = Ray.new(v3(0, 2, 0), v3(0, -1, 0))
if t = ray.intersect_plane(Vec3::ZERO, Vec3::UP)
ground = ray.at(t) # => (0, 0, 0)
end
ray.intersect_sphere(v3(0, -5, 0), 1) # => 6.0
Defined in:
eagle/math/rect.crConstructors
-
.new(origin : Vec3, direction : Vec3)
Creates a ray.
Instance Method Summary
-
#at(t : Number) : Vec3
The point at distance t along the ray.
-
#direction : Vec3
Unit direction of the ray.
-
#direction=(direction : Vec3)
Unit direction of the ray.
-
#intersect_aabb(box : AABB) : Float32 | Nil
Distance to the first hit on box, or
nil. -
#intersect_plane(point : Vec3, normal : Vec3) : Float32 | Nil
Distance to where the ray crosses the plane through point with normal, or
nilwhen the ray is parallel to it or pointing away. -
#intersect_sphere(center : Vec3, radius : Number) : Float32 | Nil
Distance to the first hit on a sphere, or
nil. -
#origin : Vec3
Where the ray starts.
-
#origin=(origin : Vec3)
Where the ray starts.
Constructor Detail
Instance Method Detail
Distance to the first hit on box, or nil. If the ray starts inside the box,
this is the distance to where it exits.
Distance to where the ray crosses the plane through point with normal, or nil
when the ray is parallel to it or pointing away.
Distance to the first hit on a sphere, or nil.