main.cpp 2.41 KB
Newer Older
Yuwei Xiao's avatar
ex3    
Yuwei Xiao committed
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
#include <igl/writeOFF.h>
#include <thread>
#include "Gui.h"
#include "Simulator.h"
#include "ClothSim.h"

/*
 */
class ClothGui : public Gui {
   public:
    // simulation parameters
    float m_dt = 1e-2;
    int n = 10, m = 10;
    double mass = 1;
    double domainX = 5;
    int m_log_frequency = 30;

    Spring m_spring;  // stores properties of the spring
    ClothSim *p_clothSim = NULL;
    const vector<char const *> m_integrators = {"Explicit Euler", "Implicit Euler", "Combination"};
    int m_selected_integrator = 0;


    ClothGui() {
        m_spring.damping = 10;
        m_spring.k_struct = 3000;
        m_spring.k_shear = 1000;
        m_spring.k_bend = 500;

        // initialize the pendulum to be used
        p_clothSim = new ClothSim();
        p_clothSim->setSpring(m_spring);
        setSimulation(p_clothSim);

        start();
    }

    virtual void updateSimulationParameters() override {
        // change all parameters of the simulation to the values that are set in the GUI
        double dx = domainX / (n-1);
        m_spring.L_struct = dx;
        m_spring.L_shear = dx * sqrt(2);
        m_spring.L_bend = 2 * dx;
        
        p_clothSim->setSpring(m_spring);
        p_clothSim->setTimestep(m_dt);
        p_clothSim->setLogFrequency(m_log_frequency);
        p_clothSim->setMethod(m_selected_integrator);
        p_clothSim->m_mass = mass;
        p_clothSim->n = n;
        p_clothSim->m = m;
        p_clothSim->domainX = domainX;
        p_clothSim->dx = dx;
    }

    virtual void clearSimulation() override {
        // 
    }


    virtual void drawSimulationParameterMenu() override {
        ImGui::InputInt("n", &n, 0, 0);
        ImGui::InputInt("m", &m, 0, 0);
        ImGui::InputDouble("mass", &mass, 0, 0);
        ImGui::InputDouble("Domain X", &domainX, 0, 0);
        ImGui::InputDouble("struct stiffness", &m_spring.k_struct, 0, 0);
        ImGui::InputDouble("shear stiffness", &m_spring.k_shear, 0, 0);
        ImGui::InputDouble("bend stiffness", &m_spring.k_bend, 0, 0);
        ImGui::InputDouble("damping", &m_spring.damping, 0, 0);
        ImGui::InputFloat("dt", &m_dt, 0, 0);
        ImGui::Combo("Integrator", &m_selected_integrator, m_integrators.data(), m_integrators.size());
        ImGui::InputInt("Log Frequency", &m_log_frequency, 0, 0);
    }
};

int main(int argc, char *argv[]) {
    // create a new instance of the GUI for the pendulum simulation
    new ClothGui();

    return 0;
}