-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdisplayphysics.cpp
executable file
·136 lines (117 loc) · 4.08 KB
/
displayphysics.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
/*
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 "displayphysics.hpp"
#include "hylc/hylc_conf.hpp"
#include "hylc/hylc.hpp"
#include "display.hpp"
#include "io.hpp"
#include "opengl.hpp"
#include "misc.hpp"
#include "runphysics.hpp"
#include "simulation.hpp"
#include "timer.hpp"
#include "util.hpp"
#include <assert.h>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <sstream>
using namespace std;
#ifndef NO_OPENGL
extern string outprefix;
extern fstream timingfile;
static bool running = false;
static void idle () {
if (!::running)
return;
sim_step();
redisplay();
}
extern void zoom (bool in);
static void keyboard (unsigned char key, int x, int y) {
unsigned char esc = 27, space = ' ';
if (key == esc) {
exit(EXIT_SUCCESS);
} else if (key == space) {
::running = !::running;
} else if (key == 's') {
::running = !::running;
idle();
::running = !::running;
} else if (key == 'z') {
zoom(true);
} else if (key == 'x') {
zoom(false);
} else if (key == 'c') {
hylc::debug.debug_color = (hylc::debug.debug_color + 1) % 6;
printf("Displaying strain: %d\n", hylc::debug.debug_color - 1);
} 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++;
}
}
}
void display_physics (const vector<string> &args) {
if (args.size() != 1 && args.size() != 2) {
cout << "Runs the simulation with an OpenGL display." << endl;
cout << "Arguments:" << endl;
cout << " <scene-file>: JSON file describing the simulation setup"
<< endl;
cout << " <out-dir> (optional): Directory to save output in" << endl;
exit(EXIT_FAILURE);
}
string json_file = args[0];
string outprefix = args.size()>1 ? args[1] : "";
if (!outprefix.empty())
ensure_existing_directory(outprefix);
init_physics(json_file, outprefix, false);
if (!outprefix.empty())
save(sim, 0);
GlutCallbacks cb;
cb.idle = idle;
cb.keyboard = keyboard;
run_glut(cb);
}
void display_resume (const vector<string> &args) {
if (args.size() != 2) {
cout << "Resumes an incomplete simulation." << endl;
cout << "Arguments:" << endl;
cout << " <out-dir>: Directory containing simulation output files"
<< endl;
cout << " <resume-frame>: Frame number to resume from" << endl;
exit(EXIT_FAILURE);
}
init_resume(args);
GlutCallbacks cb;
cb.idle = idle;
cb.keyboard = keyboard;
run_glut(cb);
}
#else
void display_physics (const vector<string> &args) {opengl_fail();}
void display_resume (const vector<string> &args) {opengl_fail();}
#endif // NO_OPENGL