User Tools

Site Tools


raycasting_line_intersections

Raycasting Namespace

The Raycasting namespace provides functions for testing ray intersections with various shapes.

What is "Raycasting"?

Raycasting is a technique used in real-time physics simulations and games to detect collisions between objects. It involves projecting a ray from an origin point in a certain direction, and checking if it intersects with any objects in its path.

Raycasting can be used for a variety of purposes, such as detecting line-of-sight, finding the distance between two objects, and determining the surface normal of a collision. In games, it's often used to simulate realistic lighting and shadows, as well as to detect collisions between a player and the environment or other game objects.

For example, in a first-person shooter game, raycasting can be used to determine whether a bullet fired by the player hits an enemy or not. Similarly, in a racing game, it can be used to detect collisions between a player's car and other objects on the track.

Overall, raycasting is a powerful technique for simulating physics in real-time applications and games, and it has a wide range of practical uses.

What's the difference between Raycasting and Linetesting?

Raycasting and linetesting are two common techniques, while both techniques are used to determine if a line segment intersects with any objects in a scene, they have distinct differences in their approach.

The main difference between raycasting and linetesting is that raycasting uses a single point to check for intersection, whereas linetesting uses a line segment. Raycasting is also faster than linetesting because it only needs to check a single point, whereas linetesting needs to check multiple points along the line segment. However, linetesting is more accurate because it checks the entire line segment for intersections, whereas raycasting only checks for intersections along a single ray.

Raycasting functions

Spheres

Raycasting::Raycast(const Sphere& a, const Ray& ray)

Tests if a ray intersects a sphere.

Parameters:

  1. a : Sphere - The sphere to test.
  2. ray : Ray - The ray to test.

Returns:

  1. float - The distance along the ray where the intersection occurs. If there is no intersection, returns a negative value.

AABBs

Raycasting::Raycast(const AABB& aabb, const Ray& ray)

Tests if a ray intersects an axis-aligned bounding box (AABB).

Parameters:

  1. aabb : AABB - The AABB to test.
  2. ray : Ray - The ray to test.

Returns:

  1. float - The distance along the ray where the intersection occurs. If there is no intersection, returns a negative value.

Oriented Boxes

Raycasting::Raycast(const OrientedBox& obb, const Ray& ray)

Tests if a ray intersects an oriented bounding box (OBB).

Parameters:

  1. obb : OrientedBox - The OBB to test.
  2. ray : Ray - The ray to test.

Returns:

  1. float - The distance along the ray where the intersection occurs. If there is no intersection, returns a negative value.

Planes

Raycasting::Raycast(const Plane& plane, const Ray& ray)

Tests if a ray intersects a plane.

Parameters:

  1. plane : Plane - The plane to test.
  2. ray : Ray - The ray to test.

Returns:

  1. float - The distance along the ray where the intersection occurs. If there is no intersection, returns a negative value.

Triangles

Raycasting::Raycast(const Triangle& triangle, const Ray& ray)

Tests if a ray intersects a triangle.

Parameters:

  1. triangle : Triangle - The triangle to test.
  2. ray : Ray - The ray to test.

Returns:

  1. float - The distance along the ray where the intersection occurs. If there is no intersection, returns a negative value.

Meshes

Raycasting::Raycast(const Mesh& mesh, const Ray& ray)

Tests if a ray intersects a mesh.

Parameters:

  1. mesh : Mesh - The mesh to test.
  2. ray : Ray - The ray to test.

Returns:

  1. float - The distance along the ray where the intersection occurs. If there is no intersection, returns a negative value.

Entities

Raycasting::Raycast(const Entity& entity, const Ray& ray)

Tests if a ray intersects an entity.

Parameters:

  1. entity : Entity - The entity to test.
  2. ray : Ray - The ray to test.

Returns:

  1. float - The distance along the ray where the intersection occurs. If there is no intersection, returns a negative value.

Line testing

Spheres

Raycasting::Linetest(const Sphere& sphere, const Line& line)

Tests if a line intersects a sphere.

Parameters:

  1. sphere : Sphere - The sphere to test.
  2. line : Line - The line to test.

Returns:

  1. bool - true if the line intersects the sphere, false otherwise.

AABBs

Raycasting::Linetest(const AABB& aabb, const Line& line)

Tests if a line intersects an axis-aligned bounding box (AABB).

Parameters:

  1. aabb : AABB - The AABB to test.
  2. line : Line - The line to test.

Returns:

  1. bool - true if the line intersects the AABB, false otherwise.

Oriented Boxes

Raycasting::Linetest(const OrientedBox& obb, const Line& line)

Tests if a line intersects an oriented bounding box (OBB).

Parameters:

  1. obb : OrientedBox - The OBB to test.
  2. line : Line - The line to test.

Returns:

  1. bool - true if the line intersects the OBB, false otherwise.

Planes

Raycasting::Linetest(const Plane& plane, const Line& line)

Tests if a line intersects a plane.

Parameters:

  1. plane : Plane - The plane to test.
  2. line : Line - The line to test.

Returns:

  1. bool - true if the line intersects the plane, false otherwise.

Triangles

Raycasting::Linetest(const Triangle& triangle, const Line& line)

Tests if a line intersects a triangle.

Parameters:

  1. triangle : Triangle - The triangle to test.
  2. line : Line - The line to test.

Returns:

  1. bool - true if the line intersects the triangle, false otherwise.

Meshes

Raycasting::Linetest(const Mesh& mesh, const Line& line)

Tests if a line intersects a mesh.

Parameters:

  1. mesh : Mesh - The mesh to test.
  2. line : Line - The line to test.

Returns:

  1. bool - true if the line intersects the mesh, false otherwise.

Entities

Raycasting::Linetest(const Entity& entity, const Line& line)

Tests if a line intersects an entity.

Parameters:

  1. entity : Entity - The entity to test.
  2. line : Line - The line to test.

Returns:

  1. bool - true if the line intersects the entity, false otherwise.

Support Functions

Raycasting::Barycentric(const Point& p, const Triangle& t)

Calculates the barycentric coordinates of a point in relation to a triangle.

Parameters:

  1. p : Point - The point for which to calculate barycentric coordinates.
  2. t : Triangle - The triangle to use for the calculation.

Returns:

  1. Vector3 - The barycentric coordinates of the point in relation to the triangle.
raycasting_line_intersections.txt · Last modified: 2023/04/17 16:13 by max