-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimationCycleWidget.cpp
More file actions
168 lines (146 loc) · 3.69 KB
/
AnimationCycleWidget.cpp
File metadata and controls
168 lines (146 loc) · 3.69 KB
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
///////////////////////////////////////////////////
//
// Hamish Carr
// October, 2023
//
// ------------------------
// AnimationCycleWidget.h
// ------------------------
//
// The main widget
//
///////////////////////////////////////////////////
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
// #include <GL/gl.h>
// #include <GL/glu.h>
#endif
#include "AnimationCycleWidget.h"
// constructor
AnimationCycleWidget::AnimationCycleWidget(QWidget *parent, SceneModel *TheScene)
: QOpenGLWidget(parent),
theScene(TheScene)
{ // constructor
// we want to create a timer for forcing animation
animationTimer = new QTimer(this);
// connect it to the desired slot
connect(animationTimer, SIGNAL(timeout()), this, SLOT(nextFrame()));
// set the timer to fire 60 times a second
animationTimer->start((double)41.6667);
} // constructor
// destructor
AnimationCycleWidget::~AnimationCycleWidget()
{ // destructor
// nothing yet
} // destructor
// called when OpenGL context is set up
void AnimationCycleWidget::initializeGL()
{ // AnimationCycleWidget::initializeGL()
} // AnimationCycleWidget::initializeGL()
// called every time the widget is resized
void AnimationCycleWidget::resizeGL(int w, int h)
{ // AnimationCycleWidget::resizeGL()
// reset the viewport
glViewport(0, 0, w, h);
// set projection matrix based on zoom & window size
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// compute the aspect ratio of the widget
float aspectRatio = (float) w / (float) h;
// we want a 90 degree vertical field of view, as wide as the window allows
// and we want to see from just in front of us to 100km away
gluPerspective(90.0, aspectRatio, 0.1, 100000);
// set model view matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
} // AnimationCycleWidget::resizeGL()
// called every time the widget needs painting
void AnimationCycleWidget::paintGL()
{ // AnimationCycleWidget::paintGL()
// call the scene to render itself
theScene->Render();
} // AnimationCycleWidget::paintGL()
// called when a key is pressed
void AnimationCycleWidget::keyPressEvent(QKeyEvent *event)
{ // keyPressEvent()
// just do a big switch statement
switch (event->key())
{ // end of key switch
// exit the program
case Qt::Key_X:
exit(0);
break;
// camera controls
case Qt::Key_W:
if (event->isAutoRepeat()) {
theScene->EventCharacterForward();
}
break;
case Qt::Key_S:
if (event->isAutoRepeat()) {
theScene->EventCharacterBackward();
}
break;
case Qt::Key_Space:
if (!event->isAutoRepeat()) {
if (!keyActive)
{
if (theScene->activeBVHMotion->forward)
{
theScene->EventCharacterForward();
}
else
{
theScene->EventCharacterBackward();
}
keyActive = !keyActive;
}
else
{
theScene->EventCharacterStand();
keyActive = !keyActive;
}
}
//theScene->ResetGame();
break;
case Qt::Key_L:
theScene->SwitchLand();
break;
case Qt::Key_M:
theScene->SwitchModel();
break;
// just in case
default:
break;
} // end of key switch
} // keyPressEvent()
// called when a key is released
void AnimationCycleWidget::keyReleaseEvent(QKeyEvent* event)
{
switch (event->key())
{
case Qt::Key_W:
//theScene->EventCharacterForward();
if (!event->isAutoRepeat()) {
theScene->EventCharacterStand();
}
break;
case Qt::Key_S:
if (!event->isAutoRepeat()) {
theScene->EventCharacterStand();
}
break;
// just in case
default:
break;
}
}
void AnimationCycleWidget::nextFrame()
{ // nextFrame()
// each time this gets called, we will update the scene
theScene->Update();
// now force an update
update();
} // nextFrame()