Support Forum       G3D Web Page     
Public Member Functions | Friends | List of all members
G3D::Triangle Class Reference

A generic triangle representation. More...

Public Member Functions

 Triangle (class BinaryInput &b)
 
 Triangle ()
 
 Triangle (const Point3 &v0, const Point3 &v1, const Point3 &v2)
 
 ~Triangle ()
 
float area () const
 
Vector3 barycentric (const Point3 &P) const
 result[i] is the weight applied to vertex(i) when blending More...
 
Point3 center () const
 Barycenter. More...
 
void deserialize (class BinaryInput &b)
 
const Vector3edge01 () const
 vertex[1] - vertex[0] More...
 
const Vector3edge02 () const
 vertex[2] - vertex[0] More...
 
void getBounds (class AABox &) const
 
void getRandomSurfacePoint (Point3 &P, Vector3 &N=Vector3::ignore, Random &rnd=Random::common()) const
 
size_t hashCode () const
 
bool intersect (const class Ray &ray, float &distance, float baryCoord[3]) const
 Intersect the ray at distance less than distance. More...
 
const Vector3normal () const
 
bool operator== (const Triangle &other) const
 
For two triangles to be equal they must have the same vertices in the same order. More...
 
Triangle otherSide () const
 Invert winding. More...
 
const Planeplane () const
 
Vector3::Axis primaryAxis () const
 
Point3 randomPoint (Random &rnd=Random::common()) const
 Returns a random point in the triangle. More...
 
void serialize (class BinaryOutput &b)
 
const Point3vertex (int n) const
 0, 1, or 2 More...
 

Friends

class CollisionDetection
 
class Ray
 

Detailed Description

A generic triangle representation.

This should not be used as the underlying triangle for creating models; it is intended for providing fast property queries but requires a lot of storage and is mostly immutable.

Constructor & Destructor Documentation

◆ Triangle() [1/3]

G3D::Triangle::Triangle ( class BinaryInput b)
explicit

◆ Triangle() [2/3]

G3D::Triangle::Triangle ( )

Referenced by otherSide().

◆ Triangle() [3/3]

G3D::Triangle::Triangle ( const Point3 v0,
const Point3 v1,
const Point3 v2 
)

◆ ~Triangle()

G3D::Triangle::~Triangle ( )

Member Function Documentation

◆ area()

float G3D::Triangle::area ( ) const

◆ barycentric()

Vector3 G3D::Triangle::barycentric ( const Point3 P) const

result[i] is the weight applied to vertex(i) when blending

◆ center()

Point3 G3D::Triangle::center ( ) const

Barycenter.

Referenced by G3D::TriangleShape::center().

◆ deserialize()

void G3D::Triangle::deserialize ( class BinaryInput b)

◆ edge01()

const Vector3& G3D::Triangle::edge01 ( ) const
inline

vertex[1] - vertex[0]

Referenced by G3D::Ray::intersectionTime(), and G3D::PrecomputedRay::intersectionTime().

◆ edge02()

const Vector3& G3D::Triangle::edge02 ( ) const
inline

vertex[2] - vertex[0]

Referenced by G3D::Ray::intersectionTime(), and G3D::PrecomputedRay::intersectionTime().

◆ getBounds()

void G3D::Triangle::getBounds ( class AABox ) const

◆ getRandomSurfacePoint()

void G3D::Triangle::getRandomSurfacePoint ( Point3 P,
Vector3 N = Vector3::ignore,
Random rnd = Random::common() 
) const
inline

◆ hashCode()

size_t G3D::Triangle::hashCode ( ) const
inline

◆ intersect()

bool G3D::Triangle::intersect ( const class Ray ray,
float &  distance,
float  baryCoord[3] 
) const

Intersect the ray at distance less than distance.

Parameters
distanceSet to the maximum distance (can be G3D::inf()) to search for an intersection. On return, this is the smaller of the distance to the intersection, if one exists, and the original value.
baryCoordIf a triangle is hit before distance, a the barycentric coordinates of the hit location on the triangle. Otherwise, unmodified.
Returns
True if there was an intersection before the original distance.

◆ normal()

const Vector3& G3D::Triangle::normal ( ) const

◆ operator==()

bool G3D::Triangle::operator== ( const Triangle other) const
inline


For two triangles to be equal they must have the same vertices in the same order.

That is, vertex[0] == vertex[0], etc.

◆ otherSide()

Triangle G3D::Triangle::otherSide ( ) const
inline

Invert winding.

◆ plane()

const Plane& G3D::Triangle::plane ( ) const

◆ primaryAxis()

Vector3::Axis G3D::Triangle::primaryAxis ( ) const
inline

◆ randomPoint()

Point3 G3D::Triangle::randomPoint ( Random rnd = Random::common()) const

Returns a random point in the triangle.

Referenced by getRandomSurfacePoint(), and G3D::TriangleShape::randomInteriorPoint().

◆ serialize()

void G3D::Triangle::serialize ( class BinaryOutput b)

◆ vertex()

const Point3& G3D::Triangle::vertex ( int  n) const
inline

Friends And Related Function Documentation

◆ CollisionDetection

friend class CollisionDetection
friend

◆ Ray

friend class Ray
friend

documentation generated on Wed Nov 24 2021 08:02:01 using doxygen 1.8.15