Repository navigation
Expand file tree
/
Copy pathLab08.cpp
More file actions
130 lines (92 loc) · 2.99 KB
/
Copy pathLab08.cpp
File metadata and controls
130 lines (92 loc) · 2.99 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
/*************************************************************
* 1. Name:
* The Key
* 2. Assignment Name:
* Lab 08: M777 Howitzer
* 3. Assignment Description:
* Simulate firing the M777 howitzer 15mm artillery piece
* 4. What was the hardest part? Be as specific as possible.
* ??
* 5. How long did it take for you to complete the assignment?
* ??
*****************************************************************/
#include <cassert> // for ASSERT
#include "uiInteract.h" // for INTERFACE
#include "uiDraw.h" // for RANDOM and DRAW*
#include "ground.h" // for GROUND
#include "position.h" // for POINT
#include <iostream>
#include <cmath>
#include "projectile.h"
#include "gameState.h"
using namespace std;
/*************************************
* All the interesting work happens here, when
* I get called back from OpenGL to draw a frame.
* When I am finished drawing, then the graphics
* engine will wait until the proper amount of
* time has passed and put the drawing on the screen.
**************************************/
void callBack(const Interface* pUI, void* p)
{
// the first step is to cast the void pointer into a game object. This
// is the first step of every single callback function in OpenGL.
GameState* pGameStateInstance = (GameState*)p;
//
// accept input
//
// move a large amount
if (pUI->isRight())
pGameStateInstance->getHowitzer()->advanceLaunchAngleFullStep();
if (pUI->isLeft())
pGameStateInstance->getHowitzer()->decrementLaunchAngleFullStep();
// move by a little
if (pUI->isUp())
pGameStateInstance->getHowitzer()->advanceLaunchAngleHalfStep();
if (pUI->isDown())
pGameStateInstance->getHowitzer()->decrementLaunchAngleHalfStep();
// fire that gun
if (pUI->isSpace())
{
pGameStateInstance->activatePreFlightCheck();
}
if (pGameStateInstance->isPreFlightCheckComplete())
{
pGameStateInstance->deactivatePreFlightCheck();
pGameStateInstance->activateSimulation();
}
if (pGameStateInstance->isSimActive())
{
pGameStateInstance->activeSimulationTickProgression();
}
pGameStateInstance->displayScreen();
}
double Position::metersFromPixels = 40.0;
/*********************************
* Initialize the simulation and set it in motion
*********************************/
#ifdef _WIN32_X
#include <windows.h>
int WINAPI wWinMain(
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ PWSTR pCmdLine,
_In_ int nCmdShow)
#else // !_WIN32
int main(int argc, char** argv)
#endif // !_WIN32
{
// Initialize OpenGL
Position ptUpperRight;
ptUpperRight.setPixelsX(700.0);
ptUpperRight.setPixelsY(500.0);
Position().setZoom(40.0 /* 42 meters equals 1 pixel */);
Interface ui(0, NULL,
"Demo", /* name on the window */
ptUpperRight);
// Initialize the demo
GameState demo(ptUpperRight);
// set everything into action
ui.run(callBack, &demo);
return 0;
}