-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.h
336 lines (321 loc) · 11.4 KB
/
util.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
/*
* util.h
*
* Created on: May 2, 2014
* Author: Sibt ul Hussain
*/
#ifndef UTIL_H_
#define UTIL_H_
#include <GL/gl.h>
#include <GL/glut.h>
#include <iostream>
#include<string>
#include<cmath> // for basic math functions such as cos, sin, sqrt
using namespace std;
#define FPS 5 // frame per seconds
// define another constant to hold ASCII for Escape key.
#define KEY_ESC 27 // A
//
// ColorName you can refer any color by its name..
// In other words you can use colorname as an index in color array (see below)
enum ColorNames {
MAROON,
DARK_RED,
BROWN,
FIREBRICK,
CRIMSON,
RED,
TOMATO,
CORAL,
INDIAN_RED,
LIGHT_CORAL,
DARK_SALMON,
SALMON,
LIGHT_SALMON,
ORANGE_RED,
DARK_ORANGE,
ORANGE,
GOLD,
DARK_GOLDEN_ROD,
GOLDEN_ROD,
PALE_GOLDEN_ROD,
DARK_KHAKI,
KHAKI,
OLIVE,
YELLOW,
YELLOW_GREEN,
DARK_OLIVE_GREEN,
OLIVE_DRAB,
LAWN_GREEN,
CHART_REUSE,
GREEN_YELLOW,
DARK_GREEN,
GREEN,
FOREST_GREEN,
LIME,
LIME_GREEN,
LIGHT_GREEN,
PALE_GREEN,
DARK_SEA_GREEN,
MEDIUM_SPRING_GREEN,
SPRING_GREEN,
SEA_GREEN,
MEDIUM_AQUA_MARINE,
MEDIUM_SEA_GREEN,
LIGHT_SEA_GREEN,
DARK_SLATE_GRAY,
TEAL,
DARK_CYAN,
AQUA,
CYAN,
LIGHT_CYAN,
DARK_TURQUOISE,
TURQUOISE,
MEDIUM_TURQUOISE,
PALE_TURQUOISE,
AQUA_MARINE,
POWDER_BLUE,
CADET_BLUE,
STEEL_BLUE,
CORN_FLOWER_BLUE,
DEEP_SKY_BLUE,
DODGER_BLUE,
LIGHT_BLUE,
SKY_BLUE,
LIGHT_SKY_BLUE,
MIDNIGHT_BLUE,
NAVY,
DARK_BLUE,
MEDIUM_BLUE,
BLUE,
ROYAL_BLUE,
BLUE_VIOLET,
INDIGO,
DARK_SLATE_BLUE,
SLATE_BLUE,
MEDIUM_SLATE_BLUE,
MEDIUM_PURPLE,
DARK_MAGENTA,
DARK_VIOLET,
DARK_ORCHID,
MEDIUM_ORCHID,
PURPLE,
THISTLE,
PLUM,
VIOLET,
MAGENTA,
ORCHID,
MEDIUM_VIOLET_RED,
PALE_VIOLET_RED,
DEEP_PINK,
HOT_PINK,
LIGHT_PINK,
PINK,
ANTIQUE_WHITE,
BEIGE,
BISQUE,
BLANCHED_ALMOND,
WHEAT,
CORN_SILK,
LEMON_CHIFFON,
LIGHT_GOLDEN_ROD_YELLOW,
LIGHT_YELLOW,
SADDLE_BROWN,
SIENNA,
CHOCOLATE,
PERU,
SANDY_BROWN,
BURLY_WOOD,
TAN,
ROSY_BROWN,
MOCCASIN,
NAVAJO_WHITE,
PEACH_PUFF,
MISTY_ROSE,
LAVENDER_BLUSH,
LINEN,
OLD_LACE,
PAPAYA_WHIP,
SEA_SHELL,
MINT_CREAM,
SLATE_GRAY,
LIGHT_SLATE_GRAY,
LIGHT_STEEL_BLUE,
LAVENDER,
FLORAL_WHITE,
ALICE_BLUE,
GHOST_WHITE,
HONEYDEW,
IVORY,
AZURE,
SNOW,
BLACK,
DIM_GRAY,
GRAY,
DARK_GRAY,
SILVER,
LIGHT_GRAY,
GAINSBORO,
WHITE_SMOKE,
WHITE,
};
// set of colors ...
static float colors[][3] = { { 0.501960784313726, 0, 0 }, { 0.545098039215686,
0, 0 }, { 0.647058823529412, 0.164705882352941, 0.164705882352941 }, {
0.698039215686275, 0.133333333333333, 0.133333333333333 }, {
0.862745098039216, 0.0784313725490196, 0.235294117647059 }, { 1, 0, 0 },
{ 1, 0.388235294117647, 0.278431372549020 }, { 1, 0.498039215686275,
0.313725490196078 }, { 0.803921568627451, 0.360784313725490,
0.360784313725490 }, { 0.941176470588235, 0.501960784313726,
0.501960784313726 }, { 0.913725490196078, 0.588235294117647,
0.478431372549020 }, { 0.980392156862745, 0.501960784313726,
0.447058823529412 },
{ 1, 0.627450980392157, 0.478431372549020 },
{ 1, 0.270588235294118, 0 }, { 1, 0.549019607843137, 0 }, { 1,
0.647058823529412, 0 }, { 1, 0.843137254901961, 0 }, {
0.721568627450980, 0.525490196078431, 0.0431372549019608 }, {
0.854901960784314, 0.647058823529412, 0.125490196078431 }, {
0.933333333333333, 0.909803921568627, 0.666666666666667 }, {
0.741176470588235, 0.717647058823529, 0.419607843137255 }, {
0.941176470588235, 0.901960784313726, 0.549019607843137 }, {
0.501960784313726, 0.501960784313726, 0 }, { 1, 1, 0 }, {
0.603921568627451, 0.803921568627451, 0.196078431372549 }, {
0.333333333333333, 0.419607843137255, 0.184313725490196 }, {
0.419607843137255, 0.556862745098039, 0.137254901960784 }, {
0.486274509803922, 0.988235294117647, 0 }, { 0.498039215686275,
1, 0 }, { 0.678431372549020, 1, 0.184313725490196 }, { 0,
0.392156862745098, 0 }, { 0, 0.501960784313726, 0 }, {
0.133333333333333, 0.545098039215686, 0.133333333333333 }, { 0,
1, 0 }, { 0.196078431372549, 0.803921568627451,
0.196078431372549 }, { 0.564705882352941, 0.933333333333333,
0.564705882352941 }, { 0.596078431372549, 0.984313725490196,
0.596078431372549 }, { 0.560784313725490, 0.737254901960784,
0.560784313725490 },
{ 0, 0.980392156862745, 0.603921568627451 },
{ 0, 1, 0.498039215686275 }, { 0.180392156862745, 0.545098039215686,
0.341176470588235 }, { 0.400000000000000, 0.803921568627451,
0.666666666666667 }, { 0.235294117647059, 0.701960784313725,
0.443137254901961 }, { 0.125490196078431, 0.698039215686275,
0.666666666666667 }, { 0.184313725490196, 0.309803921568627,
0.309803921568627 },
{ 0, 0.501960784313726, 0.501960784313726 }, { 0, 0.545098039215686,
0.545098039215686 }, { 0, 1, 1 }, { 0, 1, 1 }, {
0.878431372549020, 1, 1 }, { 0, 0.807843137254902,
0.819607843137255 }, { 0.250980392156863, 0.878431372549020,
0.815686274509804 }, { 0.282352941176471, 0.819607843137255,
0.800000000000000 }, { 0.686274509803922, 0.933333333333333,
0.933333333333333 },
{ 0.498039215686275, 1, 0.831372549019608 }, { 0.690196078431373,
0.878431372549020, 0.901960784313726 }, { 0.372549019607843,
0.619607843137255, 0.627450980392157 }, { 0.274509803921569,
0.509803921568627, 0.705882352941177 }, { 0.392156862745098,
0.584313725490196, 0.929411764705882 }, { 0, 0.749019607843137,
1 }, { 0.117647058823529, 0.564705882352941, 1 }, {
0.678431372549020, 0.847058823529412, 0.901960784313726 }, {
0.529411764705882, 0.807843137254902, 0.921568627450980 }, {
0.529411764705882, 0.807843137254902, 0.980392156862745 }, {
0.0980392156862745, 0.0980392156862745, 0.439215686274510 }, {
0, 0, 0.501960784313726 }, { 0, 0, 0.545098039215686 }, { 0, 0,
0.803921568627451 }, { 0, 0, 1 }, { 0.254901960784314,
0.411764705882353, 0.882352941176471 }, { 0.541176470588235,
0.168627450980392, 0.886274509803922 }, { 0.294117647058824, 0,
0.509803921568627 }, { 0.282352941176471, 0.239215686274510,
0.545098039215686 }, { 0.415686274509804, 0.352941176470588,
0.803921568627451 }, { 0.482352941176471, 0.407843137254902,
0.933333333333333 }, { 0.576470588235294, 0.439215686274510,
0.858823529411765 },
{ 0.545098039215686, 0, 0.545098039215686 }, { 0.580392156862745, 0,
0.827450980392157 }, { 0.600000000000000, 0.196078431372549,
0.800000000000000 }, { 0.729411764705882, 0.333333333333333,
0.827450980392157 },
{ 0.501960784313726, 0, 0.501960784313726 }, { 0.847058823529412,
0.749019607843137, 0.847058823529412 }, { 0.866666666666667,
0.627450980392157, 0.866666666666667 }, { 0.933333333333333,
0.509803921568627, 0.933333333333333 }, { 1, 0, 1 }, {
0.854901960784314, 0.439215686274510, 0.839215686274510 }, {
0.780392156862745, 0.0823529411764706, 0.521568627450980 }, {
0.858823529411765, 0.439215686274510, 0.576470588235294 }, { 1,
0.0784313725490196, 0.576470588235294 }, { 1, 0.411764705882353,
0.705882352941177 },
{ 1, 0.713725490196078, 0.756862745098039 }, { 1, 0.752941176470588,
0.796078431372549 }, { 0.980392156862745, 0.921568627450980,
0.843137254901961 }, { 0.960784313725490, 0.960784313725490,
0.862745098039216 },
{ 1, 0.894117647058824, 0.768627450980392 }, { 1, 0.921568627450980,
0.803921568627451 }, { 0.960784313725490, 0.870588235294118,
0.701960784313725 },
{ 1, 0.972549019607843, 0.862745098039216 }, { 1, 0.980392156862745,
0.803921568627451 }, { 0.980392156862745, 0.980392156862745,
0.823529411764706 }, { 1, 1, 0.878431372549020 }, {
0.545098039215686, 0.270588235294118, 0.0745098039215686 }, {
0.627450980392157, 0.321568627450980, 0.176470588235294 }, {
0.823529411764706, 0.411764705882353, 0.117647058823529 }, {
0.803921568627451, 0.521568627450980, 0.247058823529412 }, {
0.956862745098039, 0.643137254901961, 0.376470588235294 }, {
0.870588235294118, 0.721568627450980, 0.529411764705882 }, {
0.823529411764706, 0.705882352941177, 0.549019607843137 }, {
0.737254901960784, 0.560784313725490, 0.560784313725490 }, { 1,
0.894117647058824, 0.709803921568628 }, { 1, 0.870588235294118,
0.678431372549020 },
{ 1, 0.854901960784314, 0.725490196078431 }, { 1, 0.894117647058824,
0.882352941176471 },
{ 1, 0.941176470588235, 0.960784313725490 }, { 0.980392156862745,
0.941176470588235, 0.901960784313726 }, { 0.992156862745098,
0.960784313725490, 0.901960784313726 }, { 1, 0.937254901960784,
0.835294117647059 },
{ 1, 0.960784313725490, 0.933333333333333 }, { 0.960784313725490, 1,
0.980392156862745 }, { 0.439215686274510, 0.501960784313726,
0.564705882352941 }, { 0.466666666666667, 0.533333333333333,
0.600000000000000 }, { 0.690196078431373, 0.768627450980392,
0.870588235294118 }, { 0.901960784313726, 0.901960784313726,
0.980392156862745 },
{ 1, 0.980392156862745, 0.941176470588235 }, { 0.941176470588235,
0.972549019607843, 1 }, { 0.972549019607843, 0.972549019607843,
1 }, { 0.941176470588235, 1, 0.941176470588235 }, { 1, 1,
0.941176470588235 }, { 0.941176470588235, 1, 1 }, { 1,
0.980392156862745, 0.980392156862745 }, { 0, 0, 0 }, {
0.411764705882353, 0.411764705882353, 0.411764705882353 }, {
0.501960784313726, 0.501960784313726, 0.501960784313726 }, {
0.662745098039216, 0.662745098039216, 0.662745098039216 }, {
0.752941176470588, 0.752941176470588, 0.752941176470588 }, {
0.827450980392157, 0.827450980392157, 0.827450980392157 }, {
0.862745098039216, 0.862745098039216, 0.862745098039216 }, {
0.960784313725490, 0.960784313725490, 0.960784313725490 }, { 1,
1, 1 } };
//defining some MACROS
#define MAX(A,B) ((A) > (B) ? (A):(B)) // finds max of two numbers
#define MIN(A,B) ((A) < (B) ? (A):(B)) // find min of two numbers
#define ABS(A) ((A) < (0) ? -(A):(A)) // find ABS of a given number
// define some constants
float Deg2rad(float degree);
// Function draws a circle of given radius and color at the
// given point sx and sy.
void DrawCircle(float sx, float sy, float radius, float*color);
// Function draws a circular curve of given
void Torus2d(int x /*Starting position x*/, int y /*Starting position Y*/,
float angle, // starting angle in degrees
float length, // length of arc in degrees, >0
float radius, // inner radius, >0
float width, // width of torus, >0
unsigned int samples, // number of circle samples, >=3
float *color = NULL);
// Function draws a line between point P1(x1,y1) and P2(x2,y2)
// of given width and colour
void DrawLine(int x1, int y1, int x2, int y2, int lwidth = 3, float *color =
NULL);
// Function draws a rectangle with rounded corners at given x,y coordinates
void DrawRoundRect(float x, float y, float width, float height,
float* color = 0, float radius = 0.0);
// Function draws a string at given x,y coordinates
void DrawString(int x, int y, const string& str, float * color = NULL);
// seed the random numbers generator by current time (see the documentation of srand for further help)...
void InitRandomizer();
//This function returns a random value within the specified range of [rmin, rmax] ...
long GetRandInRange(const long &rmin, const long &rmax);
/*To draw a triangle we need three vertices with each vertex having 2-coordinates [x, y] and a color for the triangle.
* This function takes 4 arguments first three arguments (3 vertices + 1 color) to
* draw the triangle with the given color.
* */
void DrawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, float *color);
void DrawSquare(int sx, int sy, int size,float color[]);
#endif /* UTIL_H_ */