SpringSim.cpp 1 KB
Newer Older
Yuwei Xiao's avatar
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
#include "SpringSim.h"

bool SpringSim::advance() {
    // perform time integration with different integrators

	// use p_cube, m_spring, m_dt, m_gravity

	Eigen::Vector3d v = p_cube->getLinearVelocity();
	Eigen::Vector3d p = p_cube->getPosition();

    // TODO

	// note that it is required to update both m_sptring.end and p_cube's position
    switch (m_method) {
        case 0: // analytical solution
        {
            break;
        }
        case 1: // explicit euler
			
            break;

        case 2: // symplectic euler
        
            break;

        case 3: // midpoint

            break;

        default:
            std::cerr << m_method << " is not a valid integrator method."
                        << std::endl;
    }

	// update spring end position
	m_spring.end = p_cube->getPosition();


    // advance m_time
    m_time += m_dt;
    m_step++;

    // log
    if ((m_step % m_log_frequency) == 0) {
        m_trajectories.back().push_back(p_cube->getPosition());
    }

    return false;
}