-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparticleSystem.h
119 lines (90 loc) · 3.44 KB
/
particleSystem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/***********************
* ParticleSystem class
***********************/
/**
* The particle system class simply "manages" a collection of particles.
* Its primary responsibility is to run the simulation, evolving particles
* over time according to the applied forces using Euler's method.
* This header file contains the functions that you are required to implement.
* (i.e. the rest of the code relies on this interface)
* In addition, there are a few suggested state variables included.
* You should add to this class (and probably create new classes to model
* particles and forces) to build your system.
*/
#ifndef __PARTICLE_SYSTEM_H__
#define __PARTICLE_SYSTEM_H__
#include "vec.h"
#include "model\ParticleSource.h"
#include <vector>
#include <map>
#include <cmath>
//implemented as a singleton
class ParticleSystem {
public:
static ParticleSystem& Instance() {
static ParticleSystem instance;
return instance;
}
/** Destructor **/
virtual ~ParticleSystem();
/** Simulation fxns **/
// This fxn should render all particles in the system,
// at current time t.
virtual void drawParticles(float t);
// This fxn should save the configuration of all particles
// at current time t.
// NOTE: NEVER CALLED
virtual void bakeParticles(float t);
// This function should compute forces acting on all particles
// and update their state (pos and vel) appropriately.
virtual void computeForcesAndUpdateParticles(float t);
// This function should reset the system to its initial state.
// When you need to reset your simulation, PLEASE USE THIS FXN.
// It sets some state variables that the UI requires to properly
// update the display. Ditto for the following two functions.
virtual void resetSimulation(float t);
// This function should start the simulation
virtual void startSimulation(float t);
// This function should stop the simulation
virtual void stopSimulation(float t);
// This function should clear out your data structure
// of baked particles (without leaking memory).
virtual void clearBaked();
// These accessor fxns are implemented for you
float getBakeStartTime() { return bake_start_time; }
float getBakeEndTime() { return bake_end_time; }
float getBakeFps() { return bake_fps; } //NO USE
bool isSimulate() { return simulate; }
bool isDirty() { return dirty; }
void setDirty(bool d) { dirty = d; }
void addParticleSource(ParticleSource* ps) {
m_particleSrcs.push_back(ps);
}
protected:
/** Some baking-related state **/
int bake_fps; // frame rate at which simulation was baked //NO USE
float bake_start_time; // time at which baking started
// These 2 variables are used by the UI for
// updating the grey indicator
float bake_end_time; // time at which baking ended
/** General state variables **/
bool simulate; // flag for simulation mode
bool dirty; // flag for updating ui (don't worry about this)
std::vector<ParticleSource*> m_particleSrcs;
std::map<int, Particles> m_cache; //maps frame to whole state of particle
Vec3d m_gravity; //TODO: initialize this in constructor
//time conversion functions that prevent precision lost
int get_frame(float t) {
return round(t * bake_fps);
}
/*float get_time(int frame) {
return (float)frame / bake_fps;
}*/
double m_groundY;
private:
/** Constructor **/
ParticleSystem();
ParticleSystem(ParticleSystem const&) = delete;
void operator=(ParticleSystem const&) = delete;
};
#endif // __PARTICLE_SYSTEM_H__