-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparticleSystem.h
131 lines (92 loc) · 3.51 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
120
121
122
123
124
125
126
127
128
129
130
131
/***********************
* 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 <vector>
#include <FL/gl.h>
#include <map>
using namespace std;
class Particle {
public:
double timeStep;
//bool hinata;
//float dampFactor;
double mass;
Vec3d position;
Vec3d velocity;
Vec3d netForce;
Particle(Vec3d p, double m) : position(p), mass(m) {}
void setParticle(Vec3d p, Vec3d v, Vec3d n) { position = p; velocity = v; netForce = n; }
void setNetForce(Vec3d f) { netForce = f; }
void setTimeStep(float value) { timeStep = value; }
void setVelocity(Vec3d v) { velocity = v; }
Vec3d getPosition() const { return position; }
Vec3d getVelocity() const { return velocity; }
Vec3d getNetForce() const { return netForce; }
double getMass() const { return mass; }
void update(double timeStep);
void Particle::bounce(double timeStep, Particle& p);
void draw();
};
class ParticleSystem {
public:
/** Constructor **/
ParticleSystem();
/** 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.
virtual void bakeParticles(double 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; }
bool isSimulate() { return simulate; }
bool isDirty() { return dirty; }
void setDirty(bool d) { dirty = d; }
public:
float currentT;
vector<Particle> particles;
std::map<double, vector<Particle>> bakeContainer;
/** Some baking-related state **/
float bake_fps; // frame rate at which simulation was baked
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)
};
#endif // __PARTICLE_SYSTEM_H__