ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
Triangle3D.h
Go to the documentation of this file.
1/**
2 * @file Triangle3D.h
3 * @brief Defines the Triangle3D class for representing and manipulating 3D triangles.
4 *
5 * The Triangle3D class provides functionality for defining, calculating normals,
6 * testing ray intersections, and managing UV mappings of 3D triangles.
7 *
8 * @date 22/12/2024
9 * @version 1.0
10 * @author Coela Can't
11 */
12
13#pragma once
14
15#include "../../Utils/Math/Quaternion.h"
16#include "../../Utils/Math/Vector3D.h"
17
18/**
19 * @class Triangle3D
20 * @brief Represents a 3D triangle with support for UV mapping and ray intersection testing.
21 */
23public:
24 Vector3D* p1; ///< Pointer to the first vertex of the triangle.
25 Vector3D* p2; ///< Pointer to the second vertex of the triangle.
26 Vector3D* p3; ///< Pointer to the third vertex of the triangle.
27
28 const Vector2D* p1UV; ///< Pointer to the UV coordinates of the first vertex.
29 const Vector2D* p2UV; ///< Pointer to the UV coordinates of the second vertex.
30 const Vector2D* p3UV; ///< Pointer to the UV coordinates of the third vertex.
31
32 Vector3D edge1; ///< Edge vector from the first to the second vertex.
33 Vector3D edge2; ///< Edge vector from the first to the third vertex.
34 Vector3D normal; ///< Normal vector of the triangle.
35
36 bool hasUV = false; ///< Indicates whether the triangle has UV mapping.
37
38 /**
39 * @brief Default constructor.
40 */
41 Triangle3D();
42
43 /**
44 * @brief Constructs a triangle with specified vertices.
45 * @param p1 Pointer to the first vertex.
46 * @param p2 Pointer to the second vertex.
47 * @param p3 Pointer to the third vertex.
48 */
50
51 /**
52 * @brief Calculates and returns the normal of the triangle.
53 * @return Pointer to the calculated normal vector.
54 */
56
57 /**
58 * @brief Tests whether a ray intersects with the triangle.
59 * @param ray The origin of the ray.
60 * @param direction The direction of the ray.
61 * @param intersect Output parameter for the intersection point.
62 * @param color Output parameter for color (optional).
63 * @return True if the ray intersects the triangle, otherwise false.
64 */
65 bool DidIntersect(Vector3D ray, Vector3D direction, Vector3D* intersect, Vector3D* color);
66
67 /**
68 * @brief Converts the triangle's data to a string representation.
69 * @return String representation of the triangle.
70 */
71 String ToString();
72};
Represents a 3D triangle with support for UV mapping and ray intersection testing.
Definition Triangle3D.h:22
String ToString()
Converts the triangle's data to a string representation.
Triangle3D()
Default constructor.
Definition Triangle3D.cpp:3
const Vector2D * p2UV
Pointer to the UV coordinates of the second vertex.
Definition Triangle3D.h:29
Vector3D * p1
Pointer to the first vertex of the triangle.
Definition Triangle3D.h:24
Vector3D * Normal()
Calculates and returns the normal of the triangle.
Vector3D * p3
Pointer to the third vertex of the triangle.
Definition Triangle3D.h:26
bool hasUV
Indicates whether the triangle has UV mapping.
Definition Triangle3D.h:36
Vector3D normal
Normal vector of the triangle.
Definition Triangle3D.h:34
bool DidIntersect(Vector3D ray, Vector3D direction, Vector3D *intersect, Vector3D *color)
Tests whether a ray intersects with the triangle.
Vector3D * p2
Pointer to the second vertex of the triangle.
Definition Triangle3D.h:25
const Vector2D * p3UV
Pointer to the UV coordinates of the third vertex.
Definition Triangle3D.h:30
Vector3D edge2
Edge vector from the first to the third vertex.
Definition Triangle3D.h:33
Vector3D edge1
Edge vector from the first to the second vertex.
Definition Triangle3D.h:32
const Vector2D * p1UV
Pointer to the UV coordinates of the first vertex.
Definition Triangle3D.h:28
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26