Physics Simulation & Visualization Tool 0.1
A C++ physics simulation engine with real-time 3D visualization
Loading...
Searching...
No Matches
Octree.h
Go to the documentation of this file.
1#pragma once
2
3#include "../PhysicsBody.h"
4#include "NodeIndex.h"
5#include <glm/glm.hpp>
6#include <vector>
7#include <cstdint>
8
9struct Octant {
10 std::uint8_t val; // 0-7 representing the octant
11
12 static constexpr std::uint8_t X_MASK = 1 << 0;
13 static constexpr std::uint8_t Y_MASK = 1 << 1;
14 static constexpr std::uint8_t Z_MASK = 1 << 2;
15};
16
17struct OctreeNode {
18 glm::vec3 center;
19 float halfSize;
21 uint8_t childMask = 0; // Bitmask to track which children exist
22
23 // Leaf nodes only
24 std::vector<Physics::PhysicsBody*> bodies;
25
26 // Aggregated properties (center, mass)
27 glm::vec3 massCenter;
28 double totalMass = 0.0;
29
30 // Aggregated thermal properties
31 double totalEffectiveArea = 0.0; // sum of (epsilon * Area)
32 double totalEmission = 0.0; // sum of (epsilon * Area * T^4)
33
34 bool isLeaf() const {
35 return childMask == 0;
36 }
37};
38
39class Octree {
40private:
41 std::vector<OctreeNode> nodes;
42 void clear();
43 NodeIndex allocateNode(const glm::vec3& center, float halfSize);
44 void insert(NodeIndex nodeIndex, Physics::PhysicsBody* body);
45 Octant getOctant(NodeIndex nodeIdx, const glm::vec3& pos) const;
46public:
47 Octree() = default;
48 glm::vec3 computeForce(Physics::PhysicsBody* body, double G);
50 void build(const std::vector<Physics::PhysicsBody*>& bodies);
51};
double computeHeat(Physics::PhysicsBody *body)
Definition Octree.cpp:195
void build(const std::vector< Physics::PhysicsBody * > &bodies)
Definition Octree.cpp:111
glm::vec3 computeForce(Physics::PhysicsBody *body, double G)
Definition Octree.cpp:136
Octree()=default
Definition Octree.h:9
static constexpr std::uint8_t X_MASK
Definition Octree.h:12
static constexpr std::uint8_t Y_MASK
Definition Octree.h:13
static constexpr std::uint8_t Z_MASK
Definition Octree.h:14
std::uint8_t val
Definition Octree.h:10
bool isLeaf() const
Definition Octree.h:34
double totalEmission
Definition Octree.h:32
double totalEffectiveArea
Definition Octree.h:31
glm::vec3 center
Definition Octree.h:18
float halfSize
Definition Octree.h:19
double totalMass
Definition Octree.h:28
NodeIndex children[8]
Definition Octree.h:20
glm::vec3 massCenter
Definition Octree.h:27
std::vector< Physics::PhysicsBody * > bodies
Definition Octree.h:24
uint8_t childMask
Definition Octree.h:21