CMU462 Library
1.0
15-462/15-662: Computer Graphics (Fall 2015)
Main Page
Classes
Files
File List
include
CMU462
misc.h
1
#ifndef CMU462_MISC_H
2
#define CMU462_MISC_H
3
4
#include <cmath>
5
#include <limits>
6
#include <algorithm>
7
8
namespace
CMU462
{
9
10
#define PI (3.14159265358979323)
11
#define EPS_D (0.00000000001)
12
#define EPS_F (0.00001f)
13
#define INF_D (std::numeric_limits<double>::infinity())
14
#define INF_F (std::numeric_limits<float>::infinity())
15
16
// MOUSE INPUTS //
17
#define MOUSE_LEFT 0
18
#define MOUSE_RIGHT 1
19
#define MOUSE_MIDDLE 2
20
21
// KEYBOARD INPUTS //
22
#define KEYBOARD_ENTER 257
23
#define KEYBOARD_TAB 258
24
#define KEYBOARD_BACKSPACE 259
25
#define KEYBOARD_INSERT 260
26
#define KEYBOARD_DELETE 261
27
#define KEYBOARD_RIGHT 262
28
#define KEYBOARD_LEFT 263
29
#define KEYBOARD_DOWN 264
30
#define KEYBOARD_UP 265
31
#define KEYBOARD_PAGE_UP 266
32
#define KEYBOARD_PAGE_DOWN 267
33
#define KEYBOARD_PRINT_SCREEN 283
34
35
// EVENT TYPES //
36
#define EVENT_RELEASE 0
37
#define EVENT_PRESS 1
38
#define EVENT_REPEAT 2
39
40
// MODIFIERS //
41
#define MOD_SHIFT 0x0001
42
#define MOD_CTRL 0x0002
43
#define MOD_ALT 0x0004
44
#define MOD_SUPER 0x0008
45
46
/*
47
Takes any kind of number and converts from degrees to radians.
48
*/
49
template
<
typename
T>
50
inline
T radians(T deg) {
51
return
deg * (PI / 180);
52
}
53
54
/*
55
Takes any kind of number and converts from radians to degrees.
56
*/
57
template
<
typename
T>
58
inline
T degrees(T rad) {
59
return
rad * (180 / PI);
60
}
61
62
/*
63
Takes any kind of number, as well as a lower and upper bound, and clamps the
64
number to be within the bound.
65
NOTE: x, lo, and hi must all be the same type or compilation will fail. A
66
common mistake is to pass an int for x and size_ts for lo and hi.
67
*/
68
template
<
typename
T>
69
inline
T clamp(T x, T lo, T hi) {
70
return
std::min(std::max(x, lo), hi);
71
}
72
73
}
// namespace CMU462
74
75
#endif // CMU462_MISCMATH_H
CMU462
Definition:
CMU462.h:8
Generated on Sat Oct 10 2015 03:34:42 for CMU462 Library by
1.8.9.1