Currently, there is support for the following primitives:
An Axis-Aligned Bounding Box, or 'AABB', is as the name implies a box that is aligned with the coordinate system's axes. It is a rectangular box that completely encloses an object or set of objects by defining the minimum and maximum points in each of the three dimensions. The edges of the box are parallel to the x, y, and z axes, which simplifies collision detection and spatial calculations.
The AABB (Axis-Aligned Bounding Box) struct represents a rectangular cuboid in 3D space that is aligned with the X, Y, and Z axes.
It has three fields:
It also has three constructors:
AABB()
: sets the origin to (0,0,0) and size to (1,1,1)AABB(const Point& o, const Vector3& s)
: sets the origin to the given point and size to the given vectorAABB(const Vector3& min, const Vector3& max, bool isHalved = true)
: creates an AABB from two opposing corner points, min and max. If isHalved is true (default), the origin is set to the center of the cuboid and the size is half the distance between the min and max points. If isHalved is false, the origin is set to the average of the min and max points and the size is the full distance between them.The struct also provides two methods for getting the minimum and maximum points of the AABB:
GetMin()
: returns a Vector3 representing the minimum x, y, and z values of the AABBGetMax()
: returns a Vector3 representing the maximum x, y, and z values of the AABBExample usage:
AABB box1; // creates an AABB centered at (0,0,0) with size (1,1,1) AABB box2(Point(1,2,3), Vector3(2,3,4)); // creates an AABB centered at (1,2,3) with size (2,3,4) AABB box3(Vector3(-1,-1,-1), Vector3(1,1,1)); // creates an AABB centered at (0,0,0) with size (2,2,2)
The Line struct represents a line in 3D space with a start and end point.
It has two fields:
It also has two constructors:
The struct provides two static methods for getting the length of a line:
Example usage:
Line line1; // creates a line with start and end points at (0,0,0) Line line2(Point(1,2,3), Point(4,5,6)); // creates a line with start at (1,2,3) and end at (4,5,6) float length = Line::Length(line2); // computes the length of line2 using the precise Magnitude() method float lengthFast = Line::LengthFast(line2); // computes an approximation of the length of line2 using the faster MagnitudeFast() method
The OrientedBox struct represents a box-shaped object in 3D space, oriented in any direction.
It has three fields:
It has three constructors:
Example usage:
OrientedBox box1; // creates a unit box centered at (0,0,0) with no rotation OrientedBox box2(Point(1,2,3), Vector3(2,3,4)); // creates a box with center at (1,2,3), size (2,3,4), and no rotation Matrix3x3 rotation = // some arbitrary 3x3 rotation matrix OrientedBox box3(Point(0,0,0), Vector3(1,1,1), rotation); // creates a unit box at the origin, with rotation specified by the given matrix
The Plane struct represents a mathematical plane in 3D space. It is defined by a normal vector and a distance from the origin.
It has two fields:
It has two constructors:
It has one function:
Example usage:
Plane p1; // creates a plane with normal vector (1,0,0) and distance calculated from the origin Plane p2(Vector3(0,1,0), 5); // creates a plane with normal vector (0,1,0) and distance 5 Point pt(1,2,3); float planeEq = p1.PlaneEquation(pt); // calculates the result of the plane equation for point pt on plane p1
The Ray struct represents a ray in 3D space. It is defined by an origin point and a direction vector.
It has two fields:
It has three constructors:
It has one function:
Example usage:
Ray r1; // creates a default ray with origin (0,0,0) and direction (0,0,1) Line l1(Point(1,2,3), Point(4,5,6)); Ray r2(l1); // creates a ray with origin (1,2,3) and direction (3,3,3) Ray r3(Point(1,2,3), Vector3(4,5,6)); // creates a ray with origin (1,2,3) and direction (0.45584, 0.5698, 0.68276) r3.NormalizeDirection(); // normalizes the direction vector of r3
The Sphere struct represents a sphere in 3D space. It is defined by an origin point and a radius.
It has two fields:
It has two constructors:
Example usage:
Sphere s1; // creates a default sphere with center (0,0,0) and radius 1.0 Sphere s2(Point(1,2,3), 4.0f); // creates a sphere with center (1,2,3) and radius 4.0
The Triangle struct represents a triangle in 3D space. It is defined by three vertices.
It has one union field containing:
It has two constructors:
Example usage:
Triangle t1; // creates a default triangle with all vertices at (0, 0, 0) Triangle t2(Vector3(1, 2, 3), Vector3(4, 5, 6), Vector3(7, 8, 9)); // creates a triangle with vertices (1, 2, 3), (4, 5, 6), and (7, 8, 9)