Commit 963e6b2a authored by bbguimaraes's avatar bbguimaraes
Browse files

sms: simple wind simulation

parent 8e7a235c
......@@ -14,6 +14,7 @@ class Simulation {
bool m_texturable;
unsigned int m_texture_width;
unsigned int m_texture_height;
bool m_wind;
public:
Simulation() :
......@@ -22,7 +23,8 @@ class Simulation {
m_textured(false),
m_texturable(false),
m_texture_width(0),
m_texture_height(0) {}
m_texture_height(0),
m_wind(false) {}
const std::vector<SpringMassSystem *> * systems() const
{return &this->m_systems;}
......@@ -33,6 +35,7 @@ class Simulation {
bool texturable() const {return this->m_texturable;}
unsigned int texture_width() const {return this->m_texture_width;}
unsigned int texture_height() const {return this->m_texture_height;}
bool wind() const {return this->m_wind;}
void set_systems(const std::vector<SpringMassSystem *> & v)
{this->m_systems = v;}
......@@ -43,6 +46,7 @@ class Simulation {
void set_texturable(bool t) {this->m_texturable = t;}
void set_texture_width(unsigned int w) {this->m_texture_width = w;}
void set_texture_height(unsigned int h) {this->m_texture_height = h;}
void set_wind(bool w) {this->m_wind = w;}
void update();
};
......
......@@ -165,6 +165,10 @@ void Display::keyPressEvent(QKeyEvent * event) {
if(x->texturable())
x->set_textured(!x->textured());
break;
case 'W':
for(auto x : this->m_simulations)
x->set_wind(!x->wind());
break;
case Qt::Key_Control:
this->m_ctrl_key_down = true;
break;
......
......@@ -51,8 +51,10 @@ int main(int argc, char ** argv) {
void update_simulations(
std::vector<Simulation> * simulations, Display * display) {
const auto F = Vector();
const auto W = Vector(0.0f, 0.0f, -0.2f)
* (static_cast<float>(std::rand()) / RAND_MAX);
for(auto & simulation : *simulations) {
const auto F = simulation.wind() ? W : Vector();
for(auto system : *simulation.systems())
for(auto & mass : *system->masses()) {
auto f = F;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment