![]() |
ProtoTracer
1.0
Real-time 3D rendering and animation engine
|
Represents a 2D triangle with support for UV mapping, depth, and intersection testing. More...
#include <Triangle2D.h>
Public Member Functions | |
Triangle2D () | |
Default constructor. | |
Triangle2D (const Vector2D &p1, const Vector2D &p2, const Vector2D &p3) | |
Constructs a triangle from 2D vertices. | |
Triangle2D (const Quaternion &lookDirection, Transform *camT, Triangle3D *t, Material *material) | |
Constructs a triangle from 3D data with a camera transformation and material. | |
Triangle2D (Triangle3D *t) | |
Constructs a triangle from a 3D triangle. | |
Vector2D | GetP1 () |
Gets the first vertex as a 2D point. | |
Vector2D | GetP2 () |
Gets the second vertex as a 2D point. | |
Vector2D | GetP3 () |
Gets the third vertex as a 2D point. | |
Material * | GetMaterial () |
Gets the material assigned to the triangle. | |
bool | DidIntersect (const float &x, const float &y, float &u, float &v, float &w) |
Checks if a point intersects the triangle using barycentric coordinates. | |
bool | DidIntersect (BoundingBox2D *bbox) |
Checks if the triangle intersects a bounding box. | |
bool | DidIntersectSAT (BoundingBox2D *bbox) |
Checks if the triangle intersects a bounding box using the Separating Axis Theorem (SAT). | |
String | ToString () |
Converts the triangle's data to a string representation. | |
Public Attributes | |
float | denominator = 0.0f |
Precomputed denominator for barycentric coordinate calculations. | |
float | p1X |
float | p1Y |
float | p2X |
float | p2Y |
float | p3X |
float | p3Y |
Coordinates of the triangle's vertices. | |
float | v0X |
float | v0Y |
float | v1X |
float | v1Y |
float | v2X |
float | v2Y |
Edge vectors for barycentric coordinate calculations. | |
Vector2D | min |
Vector2D | max |
Minimum and maximum bounds of the triangle. | |
Vector3D * | normal |
Normal vector of the triangle (if available). | |
Material * | material |
Material assigned to the triangle. | |
Vector3D * | t3p1 |
Pointer to the first vertex in 3D space. | |
Vector3D * | t3p2 |
Pointer to the second vertex in 3D space. | |
Vector3D * | t3p3 |
Pointer to the third vertex in 3D space. | |
const Vector2D * | p1UV |
UV coordinates of the first vertex. | |
const Vector2D * | p2UV |
UV coordinates of the second vertex. | |
const Vector2D * | p3UV |
UV coordinates of the third vertex. | |
bool | hasUV = false |
Indicates whether the triangle has UV mapping. | |
float | averageDepth = 0.0f |
Average depth of the triangle for rendering. | |
Represents a 2D triangle with support for UV mapping, depth, and intersection testing.
Definition at line 25 of file Triangle2D.h.
Triangle2D | ( | ) |
Default constructor.
Definition at line 3 of file Triangle2D.cpp.
Constructs a triangle from 2D vertices.
p1 | First vertex. |
p2 | Second vertex. |
p3 | Third vertex. |
Definition at line 5 of file Triangle2D.cpp.
References denominator, p1X, p1Y, p2X, p2Y, p3X, p3Y, v0X, v0Y, v1X, v1Y, Vector2D::X, and Vector2D::Y.
Triangle2D | ( | const Quaternion & | lookDirection, |
Transform * | camT, | ||
Triangle3D * | t, | ||
Material * | material | ||
) |
Constructs a triangle from 3D data with a camera transformation and material.
lookDirection | Camera look direction as a quaternion. |
camT | Camera transform. |
t | Source 3D triangle. |
material | Material to assign to the triangle. |
Definition at line 21 of file Triangle2D.cpp.
References averageDepth, denominator, Transform::GetPosition(), Transform::GetRotation(), Transform::GetScale(), hasUV, Triangle3D::hasUV, material, max, min, Quaternion::Multiply(), normal, Triangle3D::Normal(), Triangle3D::p1, p1UV, Triangle3D::p1UV, p1X, p1Y, Triangle3D::p2, p2UV, Triangle3D::p2UV, p2X, p2Y, Triangle3D::p3, p3UV, Triangle3D::p3UV, p3X, p3Y, t3p1, t3p2, t3p3, Quaternion::UnrotateVector(), v0X, v0Y, v1X, v1Y, Vector2D::X, Vector3D::X, Vector2D::Y, Vector3D::Y, and Vector3D::Z.
Triangle2D | ( | Triangle3D * | t | ) |
Constructs a triangle from a 3D triangle.
t | Source 3D triangle. |
Definition at line 79 of file Triangle2D.cpp.
References averageDepth, denominator, max, min, Triangle3D::p1, p1X, p1Y, Triangle3D::p2, p2X, p2Y, Triangle3D::p3, p3X, p3Y, t3p1, t3p2, t3p3, v0X, v0Y, v1X, v1Y, Vector2D::X, Vector3D::X, Vector2D::Y, Vector3D::Y, and Vector3D::Z.
bool DidIntersect | ( | BoundingBox2D * | bbox | ) |
Checks if the triangle intersects a bounding box.
bbox | Bounding box to test against. |
Definition at line 150 of file Triangle2D.cpp.
References max, min, and BoundingBox2D::Overlaps().
Checks if a point intersects the triangle using barycentric coordinates.
x | X-coordinate of the point. |
y | Y-coordinate of the point. |
u | Output barycentric coordinate u. |
v | Output barycentric coordinate v. |
w | Output barycentric coordinate w. |
Definition at line 136 of file Triangle2D.cpp.
References denominator, p1X, p1Y, v0X, v0Y, v1X, and v1Y.
Referenced by Node::Insert().
bool DidIntersectSAT | ( | BoundingBox2D * | bbox | ) |
Checks if the triangle intersects a bounding box using the Separating Axis Theorem (SAT).
bbox | Bounding box to test against. |
Definition at line 155 of file Triangle2D.cpp.
References BoundingBox2D::GetMaximum(), BoundingBox2D::GetMinimum(), Mathematics::Max(), Mathematics::Min(), p1X, p1Y, p2X, p2Y, p3X, p3Y, Vector2D::X, and Vector2D::Y.
Material * GetMaterial | ( | ) |
Gets the material assigned to the triangle.
Definition at line 132 of file Triangle2D.cpp.
References material.
Referenced by Rasterizer::CheckRasterPixel(), and Rasterizer::CheckRasterPixelAccel().
Vector2D GetP1 | ( | ) |
Gets the first vertex as a 2D point.
Definition at line 120 of file Triangle2D.cpp.
Vector2D GetP2 | ( | ) |
Gets the second vertex as a 2D point.
Definition at line 124 of file Triangle2D.cpp.
Vector2D GetP3 | ( | ) |
Gets the third vertex as a 2D point.
Definition at line 128 of file Triangle2D.cpp.
String ToString | ( | ) |
Converts the triangle's data to a string representation.
Definition at line 195 of file Triangle2D.cpp.
References p1X, p1Y, p2X, p2Y, p3X, p3Y, and Vector2D::ToString().
float averageDepth = 0.0f |
Average depth of the triangle for rendering.
Definition at line 44 of file Triangle2D.h.
Referenced by Rasterizer::CheckRasterPixel(), Rasterizer::CheckRasterPixelAccel(), Triangle2D(), and Triangle2D().
float denominator = 0.0f |
Precomputed denominator for barycentric coordinate calculations.
Definition at line 27 of file Triangle2D.h.
Referenced by Rasterizer::CheckRasterPixelAccel(), DidIntersect(), Triangle2D(), Triangle2D(), and Triangle2D().
Indicates whether the triangle has UV mapping.
Definition at line 43 of file Triangle2D.h.
Referenced by Triangle2D().
Material* material |
Material assigned to the triangle.
Definition at line 33 of file Triangle2D.h.
Referenced by GetMaterial(), and Triangle2D().
Vector2D max |
Minimum and maximum bounds of the triangle.
Definition at line 30 of file Triangle2D.h.
Referenced by DidIntersect(), Triangle2D(), and Triangle2D().
Vector2D min |
Definition at line 30 of file Triangle2D.h.
Referenced by DidIntersect(), Triangle2D(), and Triangle2D().
Vector3D* normal |
Normal vector of the triangle (if available).
Definition at line 32 of file Triangle2D.h.
Referenced by Triangle2D().
UV coordinates of the first vertex.
Definition at line 39 of file Triangle2D.h.
Referenced by Rasterizer::CheckRasterPixel(), Rasterizer::CheckRasterPixelAccel(), and Triangle2D().
float p1X |
Definition at line 28 of file Triangle2D.h.
Referenced by Rasterizer::CheckRasterPixelAccel(), DidIntersect(), DidIntersectSAT(), GetP1(), ToString(), Triangle2D(), Triangle2D(), and Triangle2D().
float p1Y |
Definition at line 28 of file Triangle2D.h.
Referenced by Rasterizer::CheckRasterPixelAccel(), DidIntersect(), DidIntersectSAT(), GetP1(), ToString(), Triangle2D(), Triangle2D(), and Triangle2D().
UV coordinates of the second vertex.
Definition at line 40 of file Triangle2D.h.
Referenced by Rasterizer::CheckRasterPixel(), Rasterizer::CheckRasterPixelAccel(), and Triangle2D().
float p2X |
Definition at line 28 of file Triangle2D.h.
Referenced by DidIntersectSAT(), GetP2(), ToString(), Triangle2D(), Triangle2D(), and Triangle2D().
float p2Y |
Definition at line 28 of file Triangle2D.h.
Referenced by DidIntersectSAT(), GetP2(), ToString(), Triangle2D(), Triangle2D(), and Triangle2D().
UV coordinates of the third vertex.
Definition at line 41 of file Triangle2D.h.
Referenced by Rasterizer::CheckRasterPixel(), Rasterizer::CheckRasterPixelAccel(), and Triangle2D().
float p3X |
Definition at line 28 of file Triangle2D.h.
Referenced by DidIntersectSAT(), GetP3(), ToString(), Triangle2D(), Triangle2D(), and Triangle2D().
float p3Y |
Coordinates of the triangle's vertices.
Definition at line 28 of file Triangle2D.h.
Referenced by DidIntersectSAT(), GetP3(), ToString(), Triangle2D(), Triangle2D(), and Triangle2D().
Vector3D* t3p1 |
Pointer to the first vertex in 3D space.
Definition at line 35 of file Triangle2D.h.
Referenced by Rasterizer::CheckRasterPixel(), Rasterizer::CheckRasterPixelAccel(), Triangle2D(), and Triangle2D().
Vector3D* t3p2 |
Pointer to the second vertex in 3D space.
Definition at line 36 of file Triangle2D.h.
Referenced by Triangle2D(), and Triangle2D().
Vector3D* t3p3 |
Pointer to the third vertex in 3D space.
Definition at line 37 of file Triangle2D.h.
Referenced by Rasterizer::CheckRasterPixel(), Rasterizer::CheckRasterPixelAccel(), Triangle2D(), and Triangle2D().
float v0X |
Definition at line 29 of file Triangle2D.h.
Referenced by Rasterizer::CheckRasterPixelAccel(), DidIntersect(), Triangle2D(), Triangle2D(), and Triangle2D().
float v0Y |
Definition at line 29 of file Triangle2D.h.
Referenced by Rasterizer::CheckRasterPixelAccel(), DidIntersect(), Triangle2D(), Triangle2D(), and Triangle2D().
float v1X |
Definition at line 29 of file Triangle2D.h.
Referenced by Rasterizer::CheckRasterPixelAccel(), DidIntersect(), Triangle2D(), Triangle2D(), and Triangle2D().
float v1Y |
Definition at line 29 of file Triangle2D.h.
Referenced by Rasterizer::CheckRasterPixelAccel(), DidIntersect(), Triangle2D(), Triangle2D(), and Triangle2D().
float v2X |
Definition at line 29 of file Triangle2D.h.
float v2Y |
Edge vectors for barycentric coordinate calculations.
Definition at line 29 of file Triangle2D.h.