-
Notifications
You must be signed in to change notification settings - Fork 2
/
tool_frame.cpp
287 lines (238 loc) · 7.75 KB
/
tool_frame.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/* --------------------------------------------------------------------
EXTREME TUXRACER
Copyright (C) 1999-2001 Jasmin F. Patry (Tuxracer)
Copyright (C) 2010 Extreme Tuxracer Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
---------------------------------------------------------------------*/
#include "tool_frame.h"
#include "tools.h"
#include "ogl.h"
#include "keyframe.h"
#include "font.h"
#include "textures.h"
static int curr_frame = 0;
static int curr_joint = 0;
static int last_joint = 0;
static TVector3 ref_position = MakeVector (0, 0, 0);
static bool must_render = true;
static int framebase = 24;
static int jointbase = 16;
static bool shift = false;
static bool control = false;
static bool alt = false;
static bool keyrun = false;
void InitFrameTools () {
framebase = (int)((param.y_resolution - 350) / 18);
if (TestFrame.numFrames < 1) TestFrame.AddFrame ();
curr_joint = 0;
last_joint = TestFrame.GetNumJoints () -1;
}
void SingleFrameKeys (unsigned int key, bool special, bool release, int x, int y) {
//PrintInt (key);
must_render = true;
int keyfact;
TKeyframe2 *frame = TestFrame.GetFrame (curr_frame);
// setting the camera change state
if (key == SDLK_F1) {GluCamera.turnright = !release; return;}
else if (key == SDLK_F2) {GluCamera.turnleft = !release; return;}
else if (key == SDLK_F3) {GluCamera.nearer = !release; return;}
else if (key == SDLK_F4) {GluCamera.farther = !release; return;}
// additional keys if needed
switch (key)
{
case SDLK_LSHIFT:
case SDLK_RSHIFT:
shift = !release; break;
case SDLK_LCTRL:
case SDLK_RCTRL:
control = !release; break;
case SDLK_LALT:
case SDLK_RALT:
alt = !release; break;
}
if (shift) keyfact = -1; else keyfact = 1;
if (release) return;
switch (key) {
case SDLK_y: case SDLK_j:
if (ToolsFinalStage ()) {
SaveToolCharacter ();
SaveToolFrame ();
Winsys.Quit();
} break;
case SDLK_n: if (ToolsFinalStage ()) Winsys.Quit (); break;
case SDLK_ESCAPE: case SDLK_q: QuitTool (); break;
case SDLK_s: SaveToolFrame (); break;
case SDLK_TAB: SetToolMode (0); break;
case SDLK_a:
TestFrame.AddFrame ();
SetFrameChanged (true);
break;
case SDLK_INSERT:
TestFrame.InsertFrame (curr_frame);
SetFrameChanged (true);
break;
case SDLK_DELETE:
curr_frame = TestFrame.DeleteFrame (curr_frame);
SetFrameChanged (true);
break;
case SDLK_PAGEDOWN: if (curr_frame < TestFrame.numFrames-1) curr_frame++; break;
case SDLK_PAGEUP: if (curr_frame > 0) curr_frame--; break;
case SDLK_UP: if (curr_joint > 0) curr_joint--; break;
case SDLK_DOWN: if (curr_joint < last_joint) curr_joint++; break;
case SDLK_RIGHT:
if (curr_joint < 4) frame->val[curr_joint] += 0.05;
else frame->val[curr_joint] += 1;
SetFrameChanged (true);
break;
case SDLK_LEFT:
if (curr_joint < 4) frame->val[curr_joint] -= 0.05;
else frame->val[curr_joint] -= 1;
SetFrameChanged (true);
break;
case SDLK_0:
frame->val[curr_joint] = 0.0;
SetFrameChanged (true);
break;
case SDLK_SPACE:
if (curr_joint < 4) frame->val[curr_joint] += 0.05 * keyfact;
else frame->val[curr_joint] += 1 * keyfact;
SetFrameChanged (true);
break;
case SDLK_RETURN:
TestFrame.InitTest (ref_position, &TestChar);
SetToolMode (2);
must_render = true;
break;
case SDLK_m: TestChar.useMaterials = !TestChar.useMaterials; break;
case SDLK_h: TestChar.useHighlighting = !TestChar.useHighlighting; break;
case SDLK_c:
if (control) TestFrame.CopyToClipboard (curr_frame);
else TestFrame.ClearFrame (curr_frame);
SetFrameChanged (true);
break;
case SDLK_v:
if (control) TestFrame.PasteFromClipboard (curr_frame);
SetFrameChanged (true);
break;
case SDLK_p: if (curr_frame>0)
TestFrame.CopyFrame (curr_frame-1, curr_frame); break;
case SDLK_F10: ScreenshotN (); break;
case SDLK_1: GluCamera.angle = 0; break;
case SDLK_2: GluCamera.angle = 45; break;
case SDLK_3: GluCamera.angle = 90; break;
case SDLK_4: GluCamera.angle = 135; break;
case SDLK_5: GluCamera.angle = 180; break;
case SDLK_6: GluCamera.angle = 225; break;
case SDLK_7: GluCamera.angle = 270; break;
case SDLK_8: GluCamera.angle = 315; break;
}
}
void SingleFrameMouse (int button, int state, int x, int y) {
must_render = true;
if (ToolsFinalStage ()) return;
if (button == 4) {
GluCamera.distance += 0.1;
} else if (button == 5) {
GluCamera.distance -= 0.1;
}
}
void SingleFrameMotion (int x, int y) {
}
void PrintFrameParams (int ytop, TKeyframe2 *frame) {
int y, x;
int offs = 18;
for (int i=0; i<=last_joint; i++) {
if (i == curr_joint) FT.SetColor (colYellow);
else FT.SetColor (colLGrey);
x = ITrunc (i, jointbase) * 140 + 20;
y = IFrac (i, jointbase) * offs + ytop;
FT.DrawString (x, y, TestFrame.GetJointName(i));
if (i < 4) FT.DrawString (x+80, y, Float_StrN (frame->val[i], 2));
else FT.DrawString (x+80, y, Float_StrN (frame->val[i], 0));
}
}
void RenderSingleFrame (double timestep) {
if (!must_render) return;
check_gl_error ();
// ------------------ 3d scenery ----------------------------------
set_gl_options (TUX);
ClearRenderContext (colDDBackgr);
string hlname = TestFrame.GetHighlightName (curr_joint);
TestChar.highlight_node = TestChar.GetNodeName (hlname);
glPushMatrix ();
SetToolLight ();
GluCamera.Update (timestep);
TestFrame.CalcKeyframe (curr_frame, &TestChar, ref_position);
TestChar.Draw ();
glPopMatrix ();
// ----------------- 2d screen ------------------------------------
SetupGuiDisplay ();
set_gl_options (TEXFONT);
if (FrameHasChanged ()) DrawChanged ();
FT.SetFont ("bold");
FT.SetSize (20);
FT.SetColor (colYellow);
FT.DrawString (-1, 10, "Keyframe mode");
FT.SetFont ("normal");
FT.SetSize (16);
int xl, yt;
for (int i=0; i<TestFrame.numFrames; i++) {
if (i != curr_frame) {
FT.SetColor (colLGrey);
FT.SetFont ("normal");
} else {
FT.SetColor (colYellow);
FT.SetFont ("bold");
}
xl = ITrunc (i, framebase) * 100 + 20;
yt = IFrac (i, framebase) * 18 + 20;
FT.DrawString (xl, yt, Int_StrN (i));
}
FT.SetFont ("normal");
FT.SetColor (colLGrey);
PrintFrameParams (param.y_resolution - 330, TestFrame.GetFrame (curr_frame));
if (ToolsFinalStage ()) {
FT.SetSize (20);
FT.SetColor (colYellow);
FT.DrawString (-1, param.y_resolution - 50, "Quit program. Save character list (y/n)");
}
Reshape (param.x_resolution, param.y_resolution);
Winsys.SwapBuffers();
must_render = false;
}
// --------------------------------------------------------------------
// frame sequence
// --------------------------------------------------------------------
void SequenceKeys (unsigned int key, bool special, bool release, int x, int y) {
if (release) return;
switch (key) {
case SDLK_RETURN: keyrun = true; break;
case SDLK_ESCAPE: case SDLK_TAB: SetToolMode (1); break;
case SDLK_q: QuitTool (); break;
}
}
void SequenceMouse (int button, int state, int x, int y) {}
void SequenceMotion (int x, int y) {}
void RenderSequence (double timestep) {
check_gl_error();
set_gl_options (TUX);
ClearRenderContext (colDDBackgr);
GluCamera.Update (timestep);
if (TestFrame.active) TestFrame.UpdateTest (timestep, &TestChar);
else if (keyrun) {
TestFrame.InitTest (NullVec, &TestChar);
keyrun = false;
}
glPushMatrix ();
TestChar.Draw ();
glPopMatrix ();
Reshape (param.x_resolution, param.y_resolution);
Winsys.SwapBuffers();
}