simvx.core.math.raycast¶
Rays: the Ray value type and ray-sphere intersection.
Module Contents¶
Classes¶
A half-line in world space: an origin and a unit direction. |
Functions¶
Ray-sphere intersection. Returns distance t or None if no hit. |
API¶
- class simvx.core.math.raycast.Ray(origin, direction)[source]¶
A half-line in world space: an origin and a unit direction.
Camera3D.ray_at(screen_pos)is the usual way to get one; build one by hand withRay(origin, direction), which normalises the direction. Distances along a ray are in world units, the samedistancea physicsRayHitreports, soray.at(hit.distance)is the hit point.Example::
ray = camera.ray_at(Input.mouse_position) ground = ray.intersect_plane((0, 0, 0), (0, 1, 0)) if ground is not None: marker.position = groundInitialization
- origin: simvx.core.math.types.Vec3¶
None
- direction: simvx.core.math.types.Vec3¶
None
- classmethod from_screen(screen_pos, screen_size, view, proj) simvx.core.math.raycast.Ray[source]¶
The ray through screen_pos for a camera given as matrices.
For a view drawn by a camera node,
Camera3D.ray_atis the spelling to use; this form is for a view whose size or matrices do not come from a node, such as a viewport panel inside a larger window.Args: screen_pos: Pixel position,
(0, 0)at the top left of the view. screen_size: The view’s(width, height)in the same units. view: Row-major 4x4 view matrix. proj: Row-major 4x4 reverse-Z projection matrix, Vulkan Y-flip included or not (the flip is read from the matrix).
- at(distance: float) simvx.core.math.types.Vec3[source]¶
The point distance world units along the ray.
- intersect_plane(point, normal) simvx.core.math.types.Vec3 | None[source]¶
Where the ray crosses the plane through point with normal, or
None.Nonewhen the ray runs parallel to the plane or the plane is behind the origin. Either side of the plane counts, so a ray from below a floor still meets it.