ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
Triangle3D Class Reference

Represents a 3D triangle with support for UV mapping and ray intersection testing. More...

#include <Triangle3D.h>

Collaboration diagram for Triangle3D:

Public Member Functions

 Triangle3D ()
 Default constructor.
 
 Triangle3D (Vector3D *p1, Vector3D *p2, Vector3D *p3)
 Constructs a triangle with specified vertices.
 
Vector3DNormal ()
 Calculates and returns the normal of the triangle.
 
bool DidIntersect (Vector3D ray, Vector3D direction, Vector3D *intersect, Vector3D *color)
 Tests whether a ray intersects with the triangle.
 
String ToString ()
 Converts the triangle's data to a string representation.
 

Public Attributes

Vector3Dp1
 Pointer to the first vertex of the triangle.
 
Vector3Dp2
 Pointer to the second vertex of the triangle.
 
Vector3Dp3
 Pointer to the third vertex of the triangle.
 
const Vector2Dp1UV
 Pointer to the UV coordinates of the first vertex.
 
const Vector2Dp2UV
 Pointer to the UV coordinates of the second vertex.
 
const Vector2Dp3UV
 Pointer to the UV coordinates of the third vertex.
 
Vector3D edge1
 Edge vector from the first to the second vertex.
 
Vector3D edge2
 Edge vector from the first to the third vertex.
 
Vector3D normal
 Normal vector of the triangle.
 
bool hasUV = false
 Indicates whether the triangle has UV mapping.
 

Detailed Description

Represents a 3D triangle with support for UV mapping and ray intersection testing.

Definition at line 22 of file Triangle3D.h.

Constructor & Destructor Documentation

◆ Triangle3D() [1/2]

Default constructor.

Definition at line 3 of file Triangle3D.cpp.

◆ Triangle3D() [2/2]

Triangle3D ( Vector3D p1,
Vector3D p2,
Vector3D p3 
)

Constructs a triangle with specified vertices.

Parameters
p1Pointer to the first vertex.
p2Pointer to the second vertex.
p3Pointer to the third vertex.

Definition at line 5 of file Triangle3D.cpp.

References Normal(), p1, p2, and p3.

Member Function Documentation

◆ DidIntersect()

bool DidIntersect ( Vector3D  ray,
Vector3D  direction,
Vector3D intersect,
Vector3D color 
)

Tests whether a ray intersects with the triangle.

Parameters
rayThe origin of the ray.
directionThe direction of the ray.
intersectOutput parameter for the intersection point.
colorOutput parameter for color (optional).
Returns
True if the ray intersects the triangle, otherwise false.

Definition at line 21 of file Triangle3D.cpp.

References Vector3D::CrossProduct(), Vector3D::DotProduct(), edge1, edge2, Vector3D::Multiply(), p1, Vector3D::X, Vector3D::Y, and Vector3D::Z.

◆ Normal()

Vector3D * Normal ( )

Calculates and returns the normal of the triangle.

Returns
Pointer to the calculated normal vector.

Definition at line 13 of file Triangle3D.cpp.

References Vector3D::CrossProduct(), edge1, edge2, normal, p1, p2, p3, and Vector3D::UnitSphere().

Referenced by ObjectAlign::GetPlaneNormal(), Triangle2D::Triangle2D(), and Triangle3D().

◆ ToString()

String ToString ( )

Converts the triangle's data to a string representation.

Returns
String representation of the triangle.

Definition at line 58 of file Triangle3D.cpp.

References p1, p2, p3, and Vector3D::ToString().

Member Data Documentation

◆ edge1

Vector3D edge1

Edge vector from the first to the second vertex.

Definition at line 32 of file Triangle3D.h.

Referenced by DidIntersect(), and Normal().

◆ edge2

Vector3D edge2

Edge vector from the first to the third vertex.

Definition at line 33 of file Triangle3D.h.

Referenced by DidIntersect(), and Normal().

◆ hasUV

bool hasUV = false

Indicates whether the triangle has UV mapping.

Definition at line 36 of file Triangle3D.h.

Referenced by Triangle2D::Triangle2D().

◆ normal

Vector3D normal

Normal vector of the triangle.

Definition at line 34 of file Triangle3D.h.

Referenced by Normal().

◆ p1

Vector3D* p1

Pointer to the first vertex of the triangle.

Definition at line 24 of file Triangle3D.h.

Referenced by DidIntersect(), Normal(), ToString(), Triangle2D::Triangle2D(), Triangle2D::Triangle2D(), and Triangle3D().

◆ p1UV

const Vector2D* p1UV

Pointer to the UV coordinates of the first vertex.

Definition at line 28 of file Triangle3D.h.

Referenced by Triangle2D::Triangle2D().

◆ p2

Vector3D* p2

Pointer to the second vertex of the triangle.

Definition at line 25 of file Triangle3D.h.

Referenced by Normal(), ToString(), Triangle2D::Triangle2D(), Triangle2D::Triangle2D(), and Triangle3D().

◆ p2UV

const Vector2D* p2UV

Pointer to the UV coordinates of the second vertex.

Definition at line 29 of file Triangle3D.h.

Referenced by Triangle2D::Triangle2D().

◆ p3

Vector3D* p3

Pointer to the third vertex of the triangle.

Definition at line 26 of file Triangle3D.h.

Referenced by Normal(), ToString(), Triangle2D::Triangle2D(), Triangle2D::Triangle2D(), and Triangle3D().

◆ p3UV

const Vector2D* p3UV

Pointer to the UV coordinates of the third vertex.

Definition at line 30 of file Triangle3D.h.

Referenced by Triangle2D::Triangle2D().


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