6 float zBuffer = 3.402823466e+38f;
8 bool didIntersect =
false;
9 float u = 0.0f, v = 0.0f, w = 0.0f;
14 for (
int t = 0; t < numTriangles; t++) {
15 if (triangles[t]->averageDepth < zBuffer) {
16 if (triangles[t]->DidIntersect(pixelRay.
X, pixelRay.
Y, u, v, w)) {
30 float32_t subA[numTriangles * 2];
31 float32_t subB[numTriangles * 2];
32 float32_t subDst[numTriangles * 2];
34 for (
int i = 0; i < numTriangles; i++){
35 subA[i * 2 + 0] = pixelRay.
X;
36 subA[i * 2 + 1] = pixelRay.
Y;
38 subB[i * 2 + 0] = triangles[i]->
p1X;
39 subB[i * 2 + 1] = triangles[i]->
p1Y;
42 arm_sub_f32(subA, subB, subDst, numTriangles * 2);
47 float32_t multA[numTriangles * 4];
48 float32_t multB[numTriangles * 4];
49 float32_t multDst[numTriangles * 4];
51 for (
int i = 0; i < numTriangles; i++){
52 multA[i * 4 + 0] = subDst[i * 2 + 0];
53 multA[i * 4 + 1] = triangles[i]->
v1X;
54 multA[i * 4 + 2] = triangles[i]->
v0X;
55 multA[i * 4 + 3] = subDst[i * 2 + 0];
57 multB[i * 4 + 0] = triangles[i]->
v1Y;
58 multB[i * 4 + 1] = subDst[i * 2 + 1];
59 multB[i * 4 + 2] = subDst[i * 2 + 1];
60 multB[i * 4 + 3] = triangles[i]->
v0Y;
63 arm_mult_f32(multA, multB, multDst, numTriangles * 4);
66 float32_t sub1A[numTriangles * 2];
67 float32_t sub1B[numTriangles * 2];
68 float32_t sub1Dst[numTriangles * 2];
70 for (
int i = 0; i < numTriangles; i++){
71 sub1A[i * 2 + 0] = multDst[i * 4];
72 sub1A[i * 2 + 1] = multDst[i * 4 + 2];
74 sub1B[i * 2 + 0] = multDst[i * 4 + 1];
75 sub1B[i * 2 + 1] = multDst[i * 4 + 3];
78 arm_sub_f32(sub1A, sub1B, sub1Dst, numTriangles * 2);
81 float32_t mult1A[numTriangles * 2];
82 float32_t mult1B[numTriangles * 2];
83 float32_t mult1Dst[numTriangles * 2];
85 for (
int i = 0; i < numTriangles; i++){
86 mult1A[i * 2 + 0] = sub1Dst[i * 2 + 0];
87 mult1A[i * 2 + 1] = sub1Dst[i * 2 + 1];
93 arm_mult_f32(mult1A, mult1B, mult1Dst, numTriangles * 2);
95 for (
int i = 0; i < numTriangles; i++){
96 v = mult1Dst[i * 2 + 0];
97 w = mult1Dst[i * 2 + 1];
100 if (triangles[i]->averageDepth < zBuffer) {
101 bool intersect = !(v < 0.0f || w < 0.0f || v > 1.0f || w > 1.0f) && u > 0.0f;
115 Vector3D intersect = (*triangles[triangle]->
t3p1 * uvw.
X) + (*triangles[triangle]->t3p2 * uvw.
Y) + (*triangles[triangle]->
t3p3 * uvw.
Z);
118 if (triangles[triangle]->hasUV) uv = *triangles[triangle]->
p1UV * uvw.
X + *triangles[triangle]->
p2UV * uvw.
Y + *triangles[triangle]->
p3UV * uvw.
Z;
127 float zBuffer = 3.402823466e+38f;
129 bool didIntersect =
false;
130 float u = 0.0f, v = 0.0f, w = 0.0f;
134 for (
int t = 0; t < numTriangles; ++t) {
135 if (triangles[t]->averageDepth < zBuffer) {
136 if (triangles[t]->DidIntersect(pixelRay.
X, pixelRay.
Y, u, v, w)) {
148 Vector3D intersect = (*triangles[triangle]->
t3p1 * uvw.
X) + (*triangles[triangle]->t3p2 * uvw.
Y) + (*triangles[triangle]->
t3p3 * uvw.
Z);
151 if (triangles[triangle]->hasUV) uv = *triangles[triangle]->
p1UV * uvw.
X + *triangles[triangle]->
p2UV * uvw.
Y + *triangles[triangle]->
p3UV * uvw.
Z;
160 if (camera->
Is2D()) {
161 for (
unsigned int i = 0; i < camera->
GetPixelGroup()->GetPixelCount(); i++) {
191 uint16_t iterCount = 0;
195 for (uint16_t j = 0; j < scene->
GetObjects()[i]->GetTriangleGroup()->GetTriangleCount(); ++j) {
199 tree.
Insert(&triangles[iterCount]);
207 Vector2D scale, pixelRay, materialRay;
208 for (uint16_t i = 0; i < camera->
GetPixelGroup()->GetPixelCount(); ++i) {
214 if (!leafNode || leafNode->
GetCount() == 0) {
Provides functionality for rasterizing 3D scenes into 2D camera views.
Base class for managing camera properties and transformations.
virtual IPixelGroup * GetPixelGroup()=0
Retrieves the associated pixel group.
Quaternion GetLookOffset()
Retrieves the camera's look offset.
virtual Vector2D GetCameraMinCoordinate()=0
Retrieves the minimum coordinate of the camera in 2D space.
virtual Vector2D GetCameraMaxCoordinate()=0
Retrieves the maximum coordinate of the camera in 2D space.
bool Is2D()
Checks if the camera operates in 2D mode.
CameraLayout * GetCameraLayout()
Retrieves the camera's layout.
Transform * GetTransform()
Retrieves the camera's transformation data.
Quaternion GetRotation()
Retrieves the camera's rotation.
virtual Vector2D GetCoordinate(uint16_t count)=0
Retrieves the coordinate of a specific pixel.
virtual RGBColor * GetColor(uint16_t count)=0
Retrieves the color of a specific pixel.
virtual Triangle3D * GetTriangles()=0
Retrieves the array of Triangle3D objects representing the triangles.
virtual int GetTriangleCount()=0
Retrieves the total number of triangles in the group.
virtual RGBColor GetRGB(const Vector3D &position, const Vector3D &normal, const Vector3D &uvw)=0
Pure virtual function to calculate color based on surface parameters.
Represents a node in a quadtree structure for spatial partitioning.
Triangle2D ** GetEntities()
Retrieves the entities contained in this node.
uint16_t GetCount()
Retrieves the current count of entities in the node.
bool IsEnabled()
Checks if the object is enabled.
Material * GetMaterial()
Retrieves the material assigned to the object.
ITriangleGroup * GetTriangleGroup()
Retrieves the modifiable geometry of the object.
Represents a quadtree for spatial partitioning of 2D entities.
Node * Intersect(Node *node, const Vector2D &p)
Recursively finds the node intersecting with a given point.
bool Insert(Triangle2D *triangle)
Inserts a triangle entity into the quadtree.
void Rebuild()
Rebuilds the quadtree, recalculating all spatial partitions.
A mathematical construct representing a rotation in 3D space.
Quaternion Multiply(const Quaternion &quaternion) const
Multiplies (composes) this quaternion with another (order matters).
Represents an RGB color and provides methods for manipulation.
uint8_t B
Blue component of the color (0-255).
uint8_t G
Green component of the color (0-255).
uint8_t R
Red component of the color (0-255).
static void Rasterize(Scene *scene, CameraBase *camera)
Rasterizes a 3D scene onto a 2D camera view.
static RGBColor CheckRasterPixel(Triangle2D **triangles, int numTriangles, Vector2D pixelRay)
Determines the color of a pixel by checking which triangle it intersects.
static RGBColor CheckRasterPixelAccel(Triangle2D **triangles, int numTriangles, Vector2D pixelRay)
Optimized version of CheckRasterPixel using acceleration structures.
static Quaternion rayDirection
Direction of the ray cast for rasterization.
Manages a collection of 3D objects and applies optional screen-space effects.
uint8_t GetObjectCount()
Retrieves the current number of objects in the scene.
Object3D ** GetObjects()
Retrieves all objects in the scene.
Represents a 2D triangle with support for UV mapping, depth, and intersection testing.
Material * GetMaterial()
Gets the material assigned to the triangle.
const Vector2D * p2UV
UV coordinates of the second vertex.
Vector3D * t3p1
Pointer to the first vertex in 3D space.
float averageDepth
Average depth of the triangle for rendering.
float denominator
Precomputed denominator for barycentric coordinate calculations.
Vector3D * t3p3
Pointer to the third vertex in 3D space.
const Vector2D * p3UV
UV coordinates of the third vertex.
const Vector2D * p1UV
UV coordinates of the first vertex.
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
float X
The X-component of the 2D vector.
float Y
The Y-component of the 2D vector.
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
float Z
The Z-component of the 3D vector.
float X
The X-component of the 3D vector.
float Y
The Y-component of the 3D vector.