-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.cpp
78 lines (53 loc) · 1.49 KB
/
main.cpp
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
#include <iostream>
#include <thread>
#include <assignment_setup.h>
#include <visualization.h>
//Simulation State
Eigen::VectorXd q;
Eigen::VectorXd qdot;
//simulation time and time step
double t = 0; //simulation time
double dt = 0.01; //time step
//simulation loop
bool simulating = true;
bool simulation_callback() {
while(simulating) {
simulate(q, qdot, dt, t);
t += dt;
}
return false;
}
bool draw_callback(igl::opengl::glfw::Viewer &viewer) {
draw(q, qdot, t);
return false;
}
void f(int &a, int b, int c) {
a = b + c;
}
void g(Eigen::Vector3d &a, Eigen::Vector3d b, Eigen::Vector3d c) {
a = b + c;
}
template<typename Ret, typename B, typename C>
void h(Ret &&a, B b, C c, void (*func)(Ret, B, C)) {
func(a,b,c);
}
int main(int argc, char **argv) {
std::cout<<"Start A3\n";
//assignment specific setup
assignment_setup(argc, argv, q, qdot);
//run simulation in seperate thread to avoid slowing down the UI
std::thread simulation_thread(simulation_callback);
simulation_thread.detach();
//setup libigl viewer and activate
Visualize::setup(q, qdot, true);
Visualize::viewer().callback_post_draw = &draw_callback;
Visualize::viewer().launch();
/* Function pointer example code so I don't forget
int a1;
Eigen::Vector3d a2;
h(a1, 1,2, &f);
h(a2, Eigen::Vector3d(1,0,0), Eigen::Vector3d(0,1,0), &g);
std::cout<<a1<<"\n";
std::cout<<a2.transpose()<<"\n";*/
return 1;
}