-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
executable file
·147 lines (119 loc) · 2.95 KB
/
utils.h
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
/***********************************************************************
* Realtime Rendering - Assignment 3
*
* Alyssa Biasi s3328976
* and
* Christopher Stojanovic s3334231
*
***********************************************************************/
#ifndef UTILS_H
#define UTILS_H
#ifdef __APPLE__
# include <OpenGL/gl.h>
# include <OpenGL/glu.h>
# include <GLUT/glut.h>
#else
# include <GL/gl.h>
# include <GL/glu.h>
# include <GL/glut.h>
#endif
#include <math.h>
#include <sys/time.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#define DEBUG
#undef DEBUG
/* Some handy macros */
#ifndef WIN32
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif
#define clamp(x, a, b) min(max(x, a), b)
#define PLAYER 0
#define AI 1
#define INIT_PARTICLE_SIZE 15
#define MIN_ZOOM 0.5
#define WIN 1
#define LOSE_SMALLEST -1
#define LOSE_ABSORBED 2
#define PAUSE 3
#define PLAY 0
#define BOUND 2.5
#define COOLTIME 1000
/* Debugging controls .*/
enum debugFlags {
debug_time,
debug_wall,
debug_initialise_particle,
debug_particle,
debug_particle_collision,
debug_collideParticlesBruteForce,
debug_collideParticlesUniformGrid,
debug_collisionReactionParticles2DbasisChange,
debug_collisionReactionParticles2DprojNormal,
debug_framerate,
debug_range_check,
debug_sum_kinetic_energy,
debug_sum_momentum,
numDebugFlags
};
/* Use our type so we can change precision easily. */
typedef double Real;
/* Particles (particles). */
struct Particle {
Real position[2];
Real velocity[2];
Real radius;
Real mass;
Real elasticity;
GLUquadric *quadric; /* For rendering. */
int slices, loops; /* For rendering. */
bool collided;
int collidedWith;
bool absorbed;
};
/* Control random or explicit initial positions */
enum {
randomly,
explicitly
} const initialiseParticles = randomly;
/* Collision detection method. */
enum CollisionDetectionMethod {
bruteForce,
uniformGrid
};
/* Control collision reaction calculation */
enum ReactionCalculation {
basisChange,
projNormal
} reacCalc = basisChange;
/* Arena. */
typedef struct {
Real min[2], max[2];
Real momentum[2];
Real outline[360][2];
int outcome;
int level;
Real dt;
Real maxVelocity;
} Arena;
typedef struct {
int width, height;
float axisMax;
}Window;
/* The Camera struct is used for viewing the contents of the scene */
typedef struct {
float fov; /* Field of view of the camera, in degrees, in the y direction */
float clipNear; /* Depth value of the near clipping plane (not position on z axis!) */
float clipFar; /* Depth value of the far clipping plane (not position on z axis!) */
bool zooming; /* Flag to determine if camera is zooming */
float zoom; /* Distance camera is zoomed in/out */
float scale;
float maxZoom;
float direction;
float sensitivity; /* Speed of camera rotation/zoom */
Real pos[3];
} Camera;
#endif