24 float invDet = 1.0f / det;
26 if (fabs(det) < 0.000001f)
return false;
30 if (u < 0.0f || u > 1.0f)
return false;
34 if (v < 0.0f || u + v > 1.0f)
return false;
41 tempInt = ray + direction.
Multiply(t);
43 intersect->
X = tempInt.
X;
44 intersect->
Y = tempInt.
Y;
45 intersect->
Z = tempInt.
Z;
49 color->
Z = (1.0f - u - v);
Defines the Triangle3D class for representing and manipulating 3D triangles.
String ToString()
Converts the triangle's data to a string representation.
Triangle3D()
Default constructor.
Vector3D * p1
Pointer to the first vertex of the triangle.
Vector3D * Normal()
Calculates and returns the normal of the triangle.
Vector3D * p3
Pointer to the third vertex of the triangle.
Vector3D normal
Normal vector of the triangle.
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.
Vector3D edge2
Edge vector from the first to the third vertex.
Vector3D edge1
Edge vector from the first to the second vertex.
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Vector3D CrossProduct(const Vector3D &vector) const
Computes the cross product of this vector with another Vector3D.
String ToString() const
Converts the vector to a string representation.
float Z
The Z-component of the 3D vector.
Vector3D UnitSphere() const
Normalizes this vector such that its magnitude is 1 (if non-zero).
Vector3D Multiply(const Vector3D &vector) const
Multiplies this vector by another Vector3D component-wise.
float X
The X-component of the 3D vector.
float Y
The Y-component of the 3D vector.
float DotProduct(const Vector3D &vector) const
Computes the dot product of this vector with another Vector3D.