-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorld.h
More file actions
174 lines (148 loc) · 5.22 KB
/
World.h
File metadata and controls
174 lines (148 loc) · 5.22 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
168
169
170
171
172
173
174
#ifndef WORLD_H
#define WORLD_H
#include <random>
#include <cmath>
#include "commonTypes.h"
namespace earshooter {
/** Essentially a set of application-wide global variables defining the
* dimensions of the "world" and the conversion factors from pixel to world
* units and back, as well as a few rendering constants.
*
*/
struct World {
/** Starting point for Frogger.
* @see setWorldBounds
*/
static float froggerStartHeight;
/** Static Background Variables
*
*/
static int numLowerHedges;
static float bottomTopHedgeHeight, topScoreAreaHeight, waterHeight, waterY, topHedgeHeight, topHedgeY, lowerHedgeHeight, lowerHedgeWidth, offsetLowerHedge, lowerHedgeX, lowerHedgeY, middleHedgeHeight, middleHedgeY, roadHeight, bottomScoreArea;
/** Minimum x value to get mapped to the display area.
* Set in the main program by a call to setWorldBounds.
* @see setWorldBounds
*/
static const float X_MIN;
/** Maximum x value to get mapped to the display area.
* Set in the main program by a call to setWorldBounds.
* @see setWorldBounds
*/
static const float X_MAX;
/** Minimum y value to get mapped to the display area.
* Set in the main program by a call to setWorldBounds.
* @see setWorldBounds
*/
static const float Y_MIN;
/** Maximum x value to get mapped to the display area.
* Set in the main program by a call to setWorldBounds.
* @see setWorldBounds
*/
static const float Y_MAX;
/** Calculated as X_MAX-X_MIN in the main program by a call to setWorldBounds.
* @see setWorldBounds
*/
static const float WIDTH;
/** Calculated as Y_MAX-Y_MIN in the main program by a call to setWorldBounds.
* @see setWorldBounds
*/
static const float HEIGHT;
/** Scaling factor converting pixel units to world units.
* Calculated in the main program by a call to setWorldBounds.
* @see setWorldBounds
*/
static float pixelToWorldRatio;
/** Scaling factor converting world units to pixel units.
* Calculated in the main program by a call to setWorldBounds.
* @see setWorldBounds
*/
static float worldToPixelRatio;
/** This one is really equal to pixelToWorldRatio, but it looks confusing
* to write glSCalef(pixelToWorldRatio, pixelToWorldRatio, 1.f);
* right before trying to drawe in pixel units.
* @see setWorldBounds
*/
static float drawInPixelScale;
static WorldType worldType;
// Flag to show status of showing Reference frames.
static bool showReferenceFrames;
/** Function called through the initialization of a global variable in the
* main program. Although the user specifies dimensions for the rendering pane,
* the function may set different values that agree better with the world
* aspect ratio.
* @param paneWidth user-set width of the redering pane
* @param paneHeight user-set height of the redering pane
*/
static void setScalingRatios(int& paneWidth, int& paneHeight);
static std::random_device randDev;
static std::default_random_engine randEngine;
//
static std::uniform_real_distribution<double> wallDist;
static std::uniform_real_distribution<float> speedDist;
static std::uniform_real_distribution<float> wxDist;
static std::uniform_real_distribution<float> wyDist;
static std::uniform_real_distribution<float> objectScaleDist;
static std::uniform_real_distribution<float> colorDist;
static std::uniform_real_distribution<float> normalDist;
static std::uniform_real_distribution<float> angleDegDist;
static std::uniform_real_distribution<float> angleRadDist;
static std::uniform_real_distribution<float> velocityDist;
static std::uniform_real_distribution<float> spinDegDist;
static std::bernoulli_distribution animatedChoiceDist;
static std::bernoulli_distribution headsOrTailsDist;
static std::uniform_real_distribution<float> radiusDist;
};
WorldPoint pixelToWorld(float ix, float iy);
PixelPoint worldToPixel(float wx, float wy);
WorldPoint pixelToWorld(const PixelPoint& pt);
PixelPoint worldToPixel(const WorldPoint& pt);
inline int randomWall()
{
return static_cast<int>(World::wallDist(World::randEngine));
}
inline float randomSpeed()
{
return static_cast<float>(World::speedDist(World::randEngine));
}
inline WorldPoint randomWorldPoint()
{
return WorldPoint{ World::wxDist(World::randEngine),
World::wyDist(World::randEngine)};
}
inline float randomAngleDeg()
{
return World::angleDegDist(World::randEngine);
}
inline float randomAngleRad()
{
return World::angleRadDist(World::randEngine);
}
inline float randomObjectScale()
{
return World::objectScaleDist(World::randEngine);
}
inline float randomSpinDeg()
{
return World::spinDegDist(World::randEngine) *
(World::headsOrTailsDist(World::randEngine) ? (+1.f) : (-1.f));
}
inline Velocity randomVelocity(float vmin, float vmax)
{
float speed = World::normalDist(World::randEngine)*(vmax-vmin) + vmin;
float angle = randomAngleRad();
return Velocity{speed*cosf(angle), speed*sinf(angle)};
}
inline float randomColor()
{
return World::colorDist(World::randEngine);
}
inline bool headsOrTails()
{
return World::headsOrTailsDist(World::randEngine);
}
inline bool isAnimated()
{
return World::animatedChoiceDist(World::randEngine);
}
}
#endif // WORLD_H