LightsprintSDK 2021.08.08
rr::RRRay Class Reference

#include <RRCollider.h>

Inheritance diagram for rr::RRRay:
rr::RRAligned rr::RRUniformlyAllocated

Public Types

enum  Flags {
  FILL_DISTANCE =(1<<0) ,
  FILL_POINT3D =(1<<1) ,
  FILL_POINT2D =(1<<2) ,
  FILL_PLANE =(1<<3) ,
  FILL_TRIANGLE =(1<<4) ,
  FILL_SIDE =(1<<5)
}
 

Public Member Functions

 RRRay ()
 
bool convertHitFromMultiToSingleObject (const class RRSolver *solver)
 
- Public Member Functions inherited from rr::RRAligned
void * operator new (std::size_t n)
 
void * operator new[] (std::size_t n)
 
void operator delete (void *p, std::size_t n)
 
void operator delete[] (void *p, std::size_t n)
 
- Public Member Functions inherited from rr::RRUniformlyAllocated
void * operator new (std::size_t n)
 
void * operator new[] (std::size_t n)
 
void operator delete (void *p, std::size_t n)
 
void operator delete[] (void *p, std::size_t n)
 

Static Public Member Functions

static RRRaycreate ()
 
static RRRaycreate (unsigned n)
 

Public Attributes

RRVec3p rayOrigin
 
RRVec3p rayDir
 
RRReal rayLengthMin
 
RRReal rayLengthMax
 
unsigned rayFlags
 
RRReal hitDistance
 
unsigned hitTriangle
 
RRVec2 hitPoint2d
 
RRVec4 hitPlane
 
RRVec3 hitPoint3d
 
bool hitFrontSide
 
RRVec3 hitPadding1
 
RRVec2 hitPadding2
 
RRVec2 hitPadding3
 
const class RRObjecthitObject
 
RRCollisionHandlercollisionHandler
 

Detailed Description

Ray to intersect with object.

Contains all inputs and outputs for RRCollider::intersect(), with all RRVec3/4 aligned for SIMD instructions. Alignment is automatic for all static and local instances on stack (thanks to RR_ALIGNED) and for instances on heap (thanks to RRAligned). If you add ray into your class as a member variable, either dynamically allocate ray (with create()) or statically allocate instances of your class or derive your class from RRAligned, otherwise program might crash due to unaligned data access.

Thread safe: no, holds state, may be accessed by one thread at moment.

Member Enumeration Documentation

◆ Flags

Flags define which outputs to fill. (Some outputs may be filled even when not requested by flag.)

Enumerator
FILL_DISTANCE 

Fill hitDistance.

FILL_POINT3D 

Fill hitPoint3d.

FILL_POINT2D 

Fill hitPoint2d.

FILL_PLANE 

Fill hitPlane.

FILL_TRIANGLE 

Fill hitTriangle.

FILL_SIDE 

Fill hitFrontSide.

Constructor & Destructor Documentation

◆ RRRay()

rr::RRRay::RRRay ( )

Initializes 1 RRRay. All is zeroed, all FILL flags on.

Member Function Documentation

◆ create() [1/2]

static RRRay * rr::RRRay::create ( )
static

Creates 1 RRRay. All is zeroed, all FILL flags on. Use delete when no longer needed.

◆ create() [2/2]

static RRRay * rr::RRRay::create ( unsigned  n)
static

Creates array of RRRays. Use delete[] when no longer needed.

◆ convertHitFromMultiToSingleObject()

bool rr::RRRay::convertHitFromMultiToSingleObject ( const class RRSolver solver)

If hitObject points to solver's multiobject, this function changes it to individual object. hitTriangle is modified accordingly.

After successful solver->getCollider()->intersect(this), hitObject might point to solver's multiobject. This function checks if it is the case, and modifies hitObject and hitTriangle to point to singleobject, using code similar to hitObject = solver->getStaticObjects()[hitObject->getCollider()->getMesh()->getPreImportTriangle(hitTriangle).object] It is not done automatically, because it is often unnecessary, not doing it makes collider faster.

Member Data Documentation

◆ rayOrigin

RRVec3p rr::RRRay::rayOrigin

In. (-Inf,Inf), ray origin. Never modify last component, it must stay 1.

◆ rayDir

RRVec3p rr::RRRay::rayDir

In. <-Inf,Inf>, ray direction. Must be normalized.

◆ rayLengthMin

RRReal rr::RRRay::rayLengthMin

In. <0,Inf), test intersection in distances from range <rayLengthMin,rayLengthMax>.

◆ rayLengthMax

RRReal rr::RRRay::rayLengthMax

In. <0,Inf), test intersection in distances from range <rayLengthMin,rayLengthMax>.

◆ rayFlags

unsigned rr::RRRay::rayFlags

InOut. Flags that specify what to find. Additional flags may be set by collision handler.

◆ hitDistance

RRReal rr::RRRay::hitDistance

Out. Hit distance in object space.

◆ hitTriangle

unsigned rr::RRRay::hitTriangle

Out. Index of triangle (postImport) within object that was hit.

◆ hitPoint2d

RRVec2 rr::RRRay::hitPoint2d

Out. Hit coordinate in triangle space defined so that vertex[0]=0,0 vertex[1]=1,0 vertex[2]=0,1. Barycentric/areal coordinates of hit point are 1-hitPoint2d[0]-hitPoint2d[1],hitPoint2d[0],hitPoint2d[1].

◆ hitPlane

RRVec4 rr::RRRay::hitPlane

Out. Plane of hitTriangle in object space. RRVec3 part is normal, normalized. Result is based on vertex positions rather than normals provided by mesh, so plane is constant for whole triangle.

◆ hitPoint3d

RRVec3 rr::RRRay::hitPoint3d

Out. Hit coordinate in object space.

◆ hitFrontSide

bool rr::RRRay::hitFrontSide

Out. True = face was hit from the front side.

◆ hitPadding1

RRVec3 rr::RRRay::hitPadding1

Out. Undefined, never modify.

◆ hitPadding2

RRVec2 rr::RRRay::hitPadding2

Out. Undefined, never modify.

◆ hitPadding3

RRVec2 rr::RRRay::hitPadding3

Out. Undefined, never modify.

◆ hitObject

const class RRObject* rr::RRRay::hitObject

(In/)Out. If collider was created from RRObjects, intersected object is stored here. If collider was created from RRMesh, hitObject is not modified (but it's good practise to set it before calling intersect(), so that your collision handlers and other code can rely on hitObject being always set). If pointer to multiObject is returned, hitTriangle also points to triangle within multiObject; you can translate both to singleObject using convertHitFromMultiToSingleObject().

◆ collisionHandler

RRCollisionHandler* rr::RRRay::collisionHandler

In. Optional collision handler for user-defined surface behaviour.