-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helper.h
384 lines (287 loc) · 8.5 KB
/
Helper.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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#pragma once
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>
#include <vector>
#include "vecmath.h"
/*================================================================================
Macros
==================================================================================*/
//#define TABLE_X (0.3f) //width of table from both sides
//#define TABLE_Z (1.2f) // length of table from both sides
#define SIM_UPDATE_MS (10)
#define BALL_RADIUS (0.05f)
#define NUM_BALLS (5)
#define SMALL_FORCE (0.01)
// Complex datatype for point x and y.
//struct pointf2D {
// GLfloat x;
// GLfloat y;
//
//};
/*===========================================================================
For Circles (source and target) and collisions on the sheet
=============================================================================*/
// Complex datatype for starting and ending point (circles) on the sheet
struct circle {
vec2 center;
float radius;
bool filled = false;
// compute the distance between the circles, i.e. to check collision
float distance(vec2 point)
{
return pow((this->center.elem[0] - point.elem[0]), 2) + pow((this->center.elem[1] - point.elem[1]), 2);
}
// function to check if the curling stone is in the circle
bool in_circle(vec2 point, float radius)
{
float d_square = this->distance(point);
float r_square = pow(this->radius + radius, 2);
return d_square <= r_square;
}
};
/*=========================================================================
For arrow on the sheet
=============================================================================*/
// Complex datatype defined for the beam (cue) for 3D game
struct beam {
vec2 start_point; // center of outer circle
float direction;
float length;
int width = 3;
// Get - set functions for start point
vec2 get_start_point()
{
return this->start_point;
}
void set_start_point(vec2 point)
{
this->start_point = point;
}
// Get - set function for direction
float get_direction()
{
return this->direction;
}
void set_direction(float dir)
{
if (dir > 3 * M_PI / 4)
{
this->direction = 3 * M_PI / 4;
}
else if (dir < M_PI / 4)
{
this->direction = M_PI / 4;
}
else
{
this->direction = dir;
}
}
// Get - set function for length
float get_length()
{
return this->length;
}
void set_length(float len)
{
if (len > 0.05 && len < 0.60)
{
this->length = len;
}
}
//Get - set function for width
/*void get_width()
{
return this -> width;
}*/
// Get - set function for end point
vec2 get_end_point()
{
vec2 end_point;
end_point.elem[0] = this->length * cos(this->get_direction()) + this->get_start_point().elem[0];
end_point.elem[1] = this->length * sin(this->get_direction()) + this->get_start_point().elem[1];
return end_point;
}
void reset()
{
this->length = 0.25;
this->width = 2;
this->direction = M_PI / 2;
}
};
/*=========================================================================
For Base Curling Sheet Dimenstions
===========================================================================*/
struct sheet_dim {
double offset_x;
vec3 dim;
vec3 TL;
vec3 TR;
vec3 BL;
vec3 BR;
std::vector< circle > house_circles;
std::vector< circle > hack_circles;
vec3 hog_line_house_start;
vec3 hog_line_house_end;
vec3 hog_line_hack_start;
vec3 hog_line_hack_end;
sheet_dim() {}
sheet_dim(vec3 dim, double offset_x)
{
this->offset_x = offset_x;
this->dim = dim;
this->find_coordinates();
this->set_circles();
this->set_hog_lines();
}
void find_coordinates()
{
// find TL, TR, BL, BR;
this->TR = vec3(1 * this->dim.elem[1] * 33 / 150 + this->offset_x, 1 * this->dim.elem[1], this->dim.elem[2]);
this->TL = vec3(-1 * this->dim.elem[1] * 33/150 + this->offset_x, 1* this->dim.elem[1], this->dim.elem[2]);
this->BL = vec3(-1 * this->dim.elem[1] * 33 / 150 + this->offset_x, -1* this->dim.elem[1], this->dim.elem[2]);
this->BR = vec3( 1 * this->dim.elem[1] * 33 / 150 + this->offset_x, -1* this->dim.elem[1], this->dim.elem[2]);
}
void set_hog_lines()
{
hog_line_house_start = vec3(
this->TR.elem[0],
this->TR.elem[1] * 36.0f/75.0f,
this->TR.elem[2]
);
hog_line_house_end = vec3(
this->TL.elem[0],
this->TL.elem[1] * 36.0f / 75.0f,
this->TL.elem[2]
);
hog_line_hack_start = vec3(
this->BR.elem[0],
this->BR.elem[1] * 36.0f / 75.0f,
this->BR.elem[2]
);
hog_line_hack_end = vec3(
this->BL.elem[0],
this->BL.elem[1] * 36.0f / 75.0f,
this->BR.elem[2]
);
}
void set_circles()
{
double x1 = (this->TR.elem[0] + this->TL.elem[0]) / 2;
double y1 = (this->TR.elem[1]) * 57.0f / 75.0f;
vec2 house_center = vec2(x1, y1);
double x2 = (this->BR.elem[0] + this->BL.elem[0]) / 2;
double y2 = (this->BR.elem[1]) * 57.0f / 75.0f;
vec2 hack_center = vec2(x2, y2);
int count = 4;
this->house_circles.resize(count);
this->hack_circles.resize(count);
double radii[] = { this->TR.elem[1] * 1.0/150 , this->TR.elem[1] * 4 / 150, this->TR.elem[1] * 8 / 150, this->TR.elem[1] * 12 / 150 };
for (int i = 0; i < count; i++)
{
this->house_circles.at(i).filled = i < 2;
this->house_circles.at(i).radius = radii[i];
this->house_circles.at(i).center = house_center;
this->hack_circles.at(i).filled = i < 2;
this->hack_circles.at(i).radius = radii[i];
this->hack_circles.at(i).center = hack_center;
}
}
};
/*=========================================================================
For Base Curling Sheet
===========================================================================*/
class BaseCurlingSheet
{
public:
BaseCurlingSheet();
virtual void Update(int ms);
virtual void Draw();
private:
protected:
};
/*==========================================================================
For curling stones
============================================================================*/
// Task 2. Curling Stone class: Here are all the variables and functions declarations for the Curling Stone class
class CurlingStone
{
public:
CurlingStone(void);
CurlingStone(vec2 pos, vec3 minimumboundary, vec3 maximumboundary);
//int IsColliding(std::vector<CurlingStone> stones);
vec3 minimumboundary;
vec3 maximumboundary;
vec2 position = vec2(0, 0);
vec2 velocity = vec2(0, 0);
vec2 acceleration = vec2(0, 0);
vec2 force = vec2(0, 0);
vec2 init_position = vec2(0, 0);
vec2 friction = vec2(0, 0.1);
float radius = 0.025;
float mass = 1;
bool is_moving = false;
bool is_draw = false;
bool is_filled = false;
bool is_rendered = false;
vec2 original_force_applied = vec2(0.0f, 0.0f);
//static int stoneIndexCnt;
bool IsCollidingWihOther(CurlingStone stone);
bool IsHittingBoundary();
void Draw();
void Update(int ms);
void Reset();
void DrawStone(circle c);
void SetPosition(vec2 pos);
void SetVelocity(vec2 vel);
void SetAcceleration(vec2 acc);
void SetForce(vec2 f);
float GetRadius();
vec2 GetPosition();
vec2 GetVelocity();
vec2 GetAcceleration();
vec2 GetForce();
};
/*==========================================================================
For teams/Players and scores
===========================================================================*/
// Task 3. Class for teams, players and scores
class Team {
public:
Team();
Team(std::string teamname, sheet_dim dim, bool is_solid);
void Update(int ms);
vec3 hog_line_house_start;
vec3 hog_line_house_end;
std::string name;
int score = 0;
sheet_dim dim;
int last_ball_checked = -1;
std::vector<CurlingStone> stones;
private:
std::vector<std::string> players;
};
/*=========================================================================
For one curling sheet
=================================================================== ==========*/
// Task 1. Curling Sheet class: Here are all the variables and functions declarations for the Curling Sheet class.
class LongCurlingSheet :
public BaseCurlingSheet
{
public:
LongCurlingSheet(void);
LongCurlingSheet(vec3 d, double offset_x, bool is_solid );
sheet_dim dim;
beam arrow;
Team my_team;
Team other_team;
void Update();
void Update(int duration);
void Draw();
void Reset();
void DrawCircle(circle c);
private:
};