ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
QuadTree.cpp
Go to the documentation of this file.
1#include "QuadTree.h"
2
3QuadTree::QuadTree(const Vector2D& min, const Vector2D& max) : root(min, max) {}
4
6
7bool QuadTree::Insert(Triangle2D* triangle) {
8 bool inserted = root.Insert(triangle);
9
10 if (inserted) ++count;
11
12 return inserted;
13}
14
16 if (node->IsLeaf()) return node;
17
18 for (uint8_t i = 0; i < 4; ++i) {
19 if (node->GetChildNodes()[i].GetBBox()->Contains(p)) return Intersect(&node->GetChildNodes()[i], p);
20 }
21
22 return nullptr;
23}
24
26 return Intersect(&root, p);
27}
28
31}
Defines the QuadTree class for spatial partitioning in 2D space.
bool Contains(const Vector2D &v)
Checks if this bounding box contains a specified point.
Represents a node in a quadtree structure for spatial partitioning.
Definition Node.h:23
BoundingBox2D * GetBBox()
Retrieves the bounding box of the node.
Definition Node.cpp:14
bool IsLeaf()
Checks if the node is a leaf node (i.e., has no child nodes).
Definition Node.cpp:69
bool Insert(Triangle2D *triangle)
Inserts a triangle entity into the node.
Definition Node.cpp:43
void Subdivide(uint8_t depth=0)
Subdivides the node into child nodes if needed.
Definition Node.cpp:54
Node * GetChildNodes()
Retrieves the child nodes of this node.
Definition Node.cpp:18
QuadTree(const Vector2D &min, const Vector2D &max)
Constructs a QuadTree with specified bounds.
Definition QuadTree.cpp:3
~QuadTree()
Destructor for the QuadTree class.
Definition QuadTree.cpp:5
Node root
Root node of the quadtree.
Definition QuadTree.h:25
Node * Intersect(Node *node, const Vector2D &p)
Recursively finds the node intersecting with a given point.
Definition QuadTree.cpp:15
bool Insert(Triangle2D *triangle)
Inserts a triangle entity into the quadtree.
Definition QuadTree.cpp:7
uint16_t count
Current count of entities in the quadtree.
Definition QuadTree.h:26
void Rebuild()
Rebuilds the quadtree, recalculating all spatial partitions.
Definition QuadTree.cpp:29
Represents a 2D triangle with support for UV mapping, depth, and intersection testing.
Definition Triangle2D.h:25
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27