-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdisplayplay.cpp
executable file
·150 lines (132 loc) · 4.33 KB
/
displayplay.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
Copyright ©2013 The Regents of the University of California
(Regents). All Rights Reserved. Permission to use, copy, modify, and
distribute this software and its documentation for educational,
research, and not-for-profit purposes, without fee and without a
signed licensing agreement, is hereby granted, provided that the
above copyright notice, this paragraph and the following two
paragraphs appear in all copies, modifications, and
distributions. Contact The Office of Technology Licensing, UC
Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620,
(510) 643-7201, for commercial licensing opportunities.
IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING
DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/
#include "displayplay.hpp"
#include "hylc/hylc_conf.hpp"
#include "hylc/hylc.hpp"
#include "conf.hpp"
#include "display.hpp"
#include "io.hpp"
#include "misc.hpp"
#include "opengl.hpp"
#include <cstdio>
#include <fstream>
#include <boost/filesystem.hpp>
using namespace std;
#ifndef NO_OPENGL
static string inprefix, outprefix;
static int frameskip;
static bool running = false;
static void reload () {
int fullframe = ::frame*::frameskip;
sim.time = fullframe * sim.frame_time;
if(sim.time > sim.end_time){
std::cout << "reach the end time, exit" << std::endl;
exit(EXIT_SUCCESS);
}
// load_objs(sim.cloth_meshes, stringf("%s/%04d",inprefix.c_str(), fullframe));
/*
if (sim.cloth_meshes[0]->verts.empty() and !sim.is_smpl) {
if (::frame == 0)
exit(EXIT_FAILURE);
if (!outprefix.empty())
exit(EXIT_SUCCESS);
::frame = 0;
reload();
}
*/
for (int o = 0; o < sim.obstacles.size(); o++) {
if(!sim.is_smpl) sim.obstacles[o].get_mesh(sim.time);
else sim.obstacles[o].get_smpl_mesh(sim.time);
}
}
static void idle () {
if (!running)
return;
fps.tick();
if (!outprefix.empty()) {
char filename[256];
snprintf(filename, 256, "%s/%04d.png", outprefix.c_str(), ::frame);
save_screenshot(filename);
}
::frame++;
reload();
fps.tock();
redisplay();
}
static void keyboard (unsigned char key, int x, int y) {
unsigned char esc = 27, space = ' ';
if (key == esc) {
exit(0);
} else if (key == space) {
running = !running;
} else if (key == 'p') {
std::string filename = "TMP_c";
int c = 0;
for (auto & cloth : sim.cloths) {
hylc::hylc_write_strains(filename + std::to_string(c) + ".txt", cloth);
c++;
}
}
}
static void special (int key, int x, int y) {
bool shift = glutGetModifiers() & GLUT_ACTIVE_SHIFT,
alt = glutGetModifiers() & GLUT_ACTIVE_ALT;
int delta = alt ? 100 : shift ? 10 : 1;
if (key == GLUT_KEY_LEFT) {
::frame -= delta;
reload();
} else if (key == GLUT_KEY_RIGHT) {
::frame += delta;
reload();
} else if (key == GLUT_KEY_HOME) {
::frame = 0;
reload();
}
redisplay();
}
void display_play (const vector<string> &args) {
if (args.size() < 1 || args.size() > 2) {
cout << "play the results of a simulation." << endl;
cout << "Arguments:" << endl;
cout << " <json-path> path to the json config file"
<< endl;
cout << " <sshot-dir> (optional): Directory to save images" << endl;
exit(EXIT_FAILURE);
}
::inprefix = args[0];
::outprefix = args.size()>1 ? args[1] : "";
::frameskip = 1;
if (!::outprefix.empty())
ensure_existing_directory(::outprefix);
load_json(inprefix, sim);
prepare(sim);
reload();
GlutCallbacks cb;
cb.idle = idle;
cb.keyboard = keyboard;
cb.special = special;
run_glut(cb);
}
#else
#endif // NO_OPENGL