Skip to content

Libs/Mesh/PreviewMeshQC/Intersect.h

Classes

Name
struct Ray
struct Intersection
struct Triangle
struct Quad

Functions

Name
bool IntersectTriangle(const Ray & ray, const Triangle & tri, Intersection & q, bool evalNormal =true)
bool IntersectQuad(const Ray & ray, const Quad & quad, Intersection & q)
bool FastIntersectQuad(const Ray & ray, const Quad & quad, Intersection & q)

Functions Documentation

function IntersectTriangle

bool IntersectTriangle(
    const Ray & ray,
    const Triangle & tri,
    Intersection & q,
    bool evalNormal =true
)

function IntersectQuad

bool IntersectQuad(
    const Ray & ray,
    const Quad & quad,
    Intersection & q
)

function FastIntersectQuad

bool FastIntersectQuad(
    const Ray & ray,
    const Quad & quad,
    Intersection & q
)

Source code

#pragma once
#include "math3d.h"

// tools for finding intersections
struct Ray
{
    vec3d   origin;         // origin of ray
    vec3d   direction;      // direction of ray (must be unit vector!)
};

//-----------------------------------------------------------------------------
struct Intersection
{
    vec3d   point;          // point of intersection
    float   r[2];           // natural coordinates
    int     m_index;        // index of item that was intersected (context dependent)
    int     m_faceIndex;    // index of face that was intersected (context dependent)
};

//-----------------------------------------------------------------------------
struct Triangle
{
    vec3d   r0;
    vec3d   r1;
    vec3d   r2;
    vec3d   fn; // face normal
};

//-----------------------------------------------------------------------------
struct Quad
{
    vec3d   r0;
    vec3d   r1;
    vec3d   r2;
    vec3d   r3;
};

//-----------------------------------------------------------------------------
// Find intersection of a ray with a triangle
// To evaluate the normal automatically, set evalNormal to true. Otherwise, the normal in Triangle is used
bool IntersectTriangle(const Ray& ray, const Triangle& tri, Intersection& q, bool evalNormal = true);

//-----------------------------------------------------------------------------
// Find intersection of a ray with a quad
bool IntersectQuad(const Ray& ray, const Quad& quad, Intersection& q);
bool FastIntersectQuad(const Ray& ray, const Quad& quad, Intersection& q);

Updated on 2024-03-17 at 12:58:44 -0600