fix octree corruption bug because of node vector reallocation
This commit is contained in:
@ -4,8 +4,8 @@
|
||||
#include <raylib.h>
|
||||
|
||||
#define PRINT_TIMINGS
|
||||
// #define WEB // Disables multithreading
|
||||
#define BARNES_HUT // Use octree BH instead of uniform grid
|
||||
// #define WEB // Disables multithreading
|
||||
|
||||
// Window
|
||||
constexpr int INITIAL_WIDTH = 800;
|
||||
@ -31,7 +31,7 @@ constexpr float ROT_SPEED = 1.0;
|
||||
|
||||
// Physics Engine
|
||||
constexpr float SIM_SPEED = 4.0; // How large each update should be
|
||||
constexpr float TIMESTEP = 1.0 / 60; // Do 60 physics updates per second
|
||||
constexpr float TIMESTEP = 1.0 / 90; // Do 90 physics updates per second
|
||||
constexpr float MASS = 1.0; // Mass spring system
|
||||
constexpr float SPRING_CONSTANT = 5.0; // Mass spring system
|
||||
constexpr float DAMPENING_CONSTANT = 1.0; // Mass spring system
|
||||
|
||||
@ -20,7 +20,8 @@ public:
|
||||
: mass_center(Vector3Zero()), mass_total(0.0),
|
||||
children(-1, -1, -1, -1, -1, -1, -1, -1), mass_id(-1), leaf(true) {}
|
||||
|
||||
~OctreeNode() {}
|
||||
public:
|
||||
auto ChildCount() const -> int;
|
||||
};
|
||||
|
||||
class Octree {
|
||||
@ -35,8 +36,6 @@ public:
|
||||
Octree(Octree &&move) = delete;
|
||||
Octree &operator=(Octree &&move) = delete;
|
||||
|
||||
~Octree() {}
|
||||
|
||||
public:
|
||||
auto CreateNode(const Vector3 &box_min, const Vector3 &box_max) -> int;
|
||||
|
||||
@ -47,7 +46,9 @@ public:
|
||||
auto Insert(int node_idx, int mass_id, const Vector3 &pos, float mass)
|
||||
-> void;
|
||||
|
||||
auto CalculateForce(int node_idx, const Vector3 &pos) -> Vector3;
|
||||
auto CalculateForce(int node_idx, const Vector3 &pos) const -> Vector3;
|
||||
|
||||
auto Print() const -> void;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -106,8 +106,6 @@ public:
|
||||
MassSpringSystem(MassSpringSystem &move) = delete;
|
||||
MassSpringSystem &operator=(MassSpringSystem &&move) = delete;
|
||||
|
||||
~MassSpringSystem() {};
|
||||
|
||||
private:
|
||||
#ifdef BARNES_HUT
|
||||
auto BuildOctree() -> void;
|
||||
|
||||
Reference in New Issue
Block a user