Files
cpp-masssprings/include/octree.hpp
2026-02-28 18:12:51 +01:00

51 lines
1.2 KiB
C++

#ifndef OCTREE_HPP_
#define OCTREE_HPP_
#include <array>
#include <raylib.h>
#include <raymath.h>
#include <vector>
class octree
{
class node
{
public:
Vector3 mass_center = Vector3Zero();
float mass_total = 0.0;
Vector3 box_min = Vector3Zero(); // area start
Vector3 box_max = Vector3Zero(); // area end
std::array<int, 8> children = {-1, -1, -1, -1, -1, -1, -1, -1};
int mass_id = -1;
bool leaf = true;
public:
[[nodiscard]] auto child_count() const -> int;
};
public:
static constexpr int MAX_DEPTH = 20;
std::vector<node> nodes;
public:
octree() = default;
octree(const octree& copy) = delete;
auto operator=(const octree& copy) -> octree& = delete;
octree(octree&& move) = delete;
auto operator=(octree&& move) -> octree& = delete;
public:
auto create_empty_leaf(const Vector3& box_min, const Vector3& box_max) -> int;
[[nodiscard]] auto get_octant(int node_idx, const Vector3& pos) const -> int;
[[nodiscard]] auto get_child_bounds(int node_idx, int octant) const -> std::pair<Vector3, Vector3>;
auto insert(int node_idx, int mass_id, const Vector3& pos, float mass, int depth) -> void;
[[nodiscard]] auto calculate_force(int node_idx, const Vector3& pos) const -> Vector3;
};
#endif