Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
Raycaster Class Reference

Allows to cast rays against a polygonal mesh, on the CPU. Relies on an internal acceleration structure to speed up intersection queries. More...

#include <Raycaster.hpp>

Classes

struct  Hit
 
struct  Node
 
struct  TriangleInfos
 

Public Member Functions

 Raycaster ()=default
 
void addMesh (const Mesh &mesh, const glm::mat4 &model)
 
void updateHierarchy ()
 
Hit intersects (const glm::vec3 &origin, const glm::vec3 &direction, float mini=0.0001f, float maxi=1e8f) const
 
bool intersectsAny (const glm::vec3 &origin, const glm::vec3 &direction, float mini=0.0001f, float maxi=1e8f) const
 
bool visible (const glm::vec3 &p0, const glm::vec3 &p1) const
 
 Raycaster (const Raycaster &)=delete
 
Raycasteroperator= (const Raycaster &)=delete
 
 Raycaster (Raycaster &&)=delete
 
Raycasteroperator= (Raycaster &&)=delete
 

Static Public Member Functions

template<typename T >
static T interpolateAttribute (const Hit &hit, const Mesh &geometry, const std::vector< T > &attribute)
 

Private Member Functions

Hit intersects (const Ray &ray, const TriangleInfos &tri, float mini, float maxi) const
 

Static Private Member Functions

static bool intersects (const Ray &ray, const BoundingBox &box, float mini, float maxi)
 

Private Attributes

std::vector< TriangleInfos_triangles
 Merged triangles informations.
 
std::vector< glm::vec3 > _vertices
 Merged vertices.
 
std::vector< Node_hierarchy
 Acceleration structure.
 
unsigned int _meshCount = 0
 Number of meshes stored in the raycaster.
 

Friends

class RaycasterVisualisation
 For debug visualisation.
 

Detailed Description

Allows to cast rays against a polygonal mesh, on the CPU. Relies on an internal acceleration structure to speed up intersection queries.

Constructor & Destructor Documentation

◆ Raycaster() [1/3]

Raycaster::Raycaster ( )
default

Default constructor.

◆ Raycaster() [2/3]

Raycaster::Raycaster ( const Raycaster )
delete

Copy constructor.

◆ Raycaster() [3/3]

Raycaster::Raycaster ( Raycaster &&  )
delete

Move constructor.

Member Function Documentation

◆ addMesh()

void Raycaster::addMesh ( const Mesh mesh,
const glm::mat4 &  model 
)

Adds a mesh to the internal geometry.

Parameters
meshthe mesh to add
modelthe transformation matrix to apply to the vertices

◆ interpolateAttribute()

template<typename T >
static T Raycaster::interpolateAttribute ( const Hit hit,
const Mesh geometry,
const std::vector< T > &  attribute 
)
inlinestatic

Return the interpolated attribute for a hit at the surface of the mesh.

Parameters
hitthe intersection record
geometrythe mesh geometry information
attributethe vector containing per-vertex values for the attribute
Returns
the interpolated attribute

◆ intersects() [1/3]

Raycaster::Hit Raycaster::intersects ( const glm::vec3 &  origin,
const glm::vec3 &  direction,
float  mini = 0.0001f,
float  maxi = 1e8f 
) const

Find the closest intersection of a ray with the geometry.

Parameters
originray origin
directionray direction (not necessarily normalized)
minithe minimum distance allowed for the intersection
maxithe maximum distance allowed for the intersection
Returns
a hit object containg the potential hit informations

◆ intersects() [2/3]

static bool Raycaster::intersects ( const Ray ray,
const BoundingBox box,
float  mini,
float  maxi 
)
staticprivate

Test a ray and bounding box intersection.

Parameters
raythe ray
boxthe bounding box
minithe minimum allowed distance along the ray
maxithe maximum allowed distance along the ray
Returns
a boolean denoting intersection

◆ intersects() [3/3]

Raycaster::Hit Raycaster::intersects ( const Ray ray,
const TriangleInfos tri,
float  mini,
float  maxi 
) const
private

Test a ray and triangle intersection using the Muller-Trumbore test.

Parameters
raythe ray
trithe triangle infos
minithe minimum allowed distance along the ray
maxithe maximum allowed distance along the ray
Returns
a hit object containg the potential hit informations

◆ intersectsAny()

bool Raycaster::intersectsAny ( const glm::vec3 &  origin,
const glm::vec3 &  direction,
float  mini = 0.0001f,
float  maxi = 1e8f 
) const

Intersect a ray with the geometry.

Parameters
originray origin
directionray direction (not necessarily normalized)
minithe minimum distance allowed for the intersection
maxithe maximum distance allowed for the intersection
Returns
true if the ray intersected geometry

◆ operator=() [1/2]

Raycaster & Raycaster::operator= ( const Raycaster )
delete

Copy assignment.

Returns
a reference to the object assigned to

◆ operator=() [2/2]

Raycaster & Raycaster::operator= ( Raycaster &&  )
delete

Move assignment.

Returns
a reference to the object assigned to

◆ updateHierarchy()

void Raycaster::updateHierarchy ( )

Update the internal bounding volume hierarchy.

Note
This operation can be costful in time.

◆ visible()

bool Raycaster::visible ( const glm::vec3 &  p0,
const glm::vec3 &  p1 
) const

Test visibility between two points.

Parameters
p0first point
p1second point
Returns
true if the two points are joined by a free-space segment
Note
A ray is shot from the first to the second point to test for visibility.

The documentation for this class was generated from the following files: