-
Notifications
You must be signed in to change notification settings - Fork 0
/
animate.cpp
84 lines (62 loc) · 1.74 KB
/
animate.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
79
80
81
82
83
84
#include "include/animate.hpp"
#include <GL/glut.h>
#include "include/vector2.hpp"
#include <iostream>
AnimatedWindow* curr_instance;
void drawCallback()
{
curr_instance->draw();
}
void timerCallback(int value)
{
curr_instance->timer(value);
}
AnimatedWindow::AnimatedWindow(int argc, char** argv, IKSolver* ik_solver)
{
this->ik_solver = ik_solver;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(400, 300);
glutInitWindowPosition(100, 100);
glutCreateWindow("Hello world!");
glutTimerFunc(500,timerCallback,0);
::curr_instance = this;
glutDisplayFunc(drawCallback);
glutMainLoop();
}
void AnimatedWindow::timer(int value)
{
if (!cont)
return;
glutTimerFunc(500,timerCallback,0);
ik_solver->solveIteration();
bool solved = ik_solver->reached();
std::cout << solved << ", " << iter_count << std::endl;
if (solved)
std::cout << "DONE" << std::endl;
if (solved || iter_count > 10)
cont = false;
iter_count ++;
glutPostRedisplay();
}
void AnimatedWindow::draw()
{
//navigate to last line, draw all lines until that
glClear(GL_COLOR_BUFFER_BIT);
Link* link_next = ik_solver->end_link;
while (link_next != NULL)
{
vector2 origin = vector2();
if (link_next->parent != NULL)
origin = link_next->parent->end_pos / 3;
vector2 dest = link_next->end_pos / 3;
std::cout << origin*3 << " to " << dest*3 << std::endl;
glBegin(GL_LINES);
glVertex2f(origin[0], origin[1]);
glVertex2f(dest[0], dest[1]);
glEnd();
link_next = link_next->parent;
}
// std::cout << origin << " to " << dest << std::endl;
glFlush();
}