rebuild the repulsion force grid every n frames
This commit is contained in:
@ -27,12 +27,13 @@ constexpr float ROT_SPEED = 1.0;
|
||||
|
||||
// Physics Engine
|
||||
constexpr float MASS = 1.0;
|
||||
constexpr float SPRING_CONSTANT = 1.0;
|
||||
constexpr float SPRING_CONSTANT = 1.5;
|
||||
constexpr float DAMPENING_CONSTANT = 0.8;
|
||||
constexpr float REST_LENGTH = 1.0;
|
||||
constexpr float REPULSION_FORCE = 0.1;
|
||||
constexpr float REPULSION_RANGE = 3.0 * REST_LENGTH;
|
||||
constexpr float VERLET_DAMPENING = 0.02; // [0, 1]
|
||||
constexpr int REPULSION_GRID_REFRESH = 5; // Frames between grid rebuilds
|
||||
constexpr float VERLET_DAMPENING = 0.01; // [0, 1]
|
||||
|
||||
// Graph Drawing
|
||||
constexpr float VERTEX_SIZE = 0.1;
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include <raymath.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class Mass {
|
||||
public:
|
||||
@ -83,12 +84,20 @@ public:
|
||||
};
|
||||
|
||||
class MassSpringSystem {
|
||||
private:
|
||||
std::vector<Mass *> mass_vec;
|
||||
std::vector<int> indices;
|
||||
std::vector<int64_t> cell_ids;
|
||||
int last_build;
|
||||
int last_masses_count;
|
||||
int last_springs_count;
|
||||
|
||||
public:
|
||||
std::unordered_map<std::string, Mass> masses;
|
||||
std::unordered_map<std::string, Spring> springs;
|
||||
|
||||
public:
|
||||
MassSpringSystem() {};
|
||||
MassSpringSystem() : last_build(1000) {};
|
||||
|
||||
MassSpringSystem(const MassSpringSystem ©) = delete;
|
||||
MassSpringSystem &operator=(const MassSpringSystem ©) = delete;
|
||||
@ -97,6 +106,9 @@ public:
|
||||
|
||||
~MassSpringSystem() {};
|
||||
|
||||
private:
|
||||
auto BuildGrid() -> void;
|
||||
|
||||
public:
|
||||
auto AddMass(float mass, Vector3 position, bool fixed,
|
||||
const std::string &state) -> void;
|
||||
|
||||
Reference in New Issue
Block a user