-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreakout.h
118 lines (100 loc) · 2 KB
/
breakout.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
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <SDL.h>
#include <SDL_timer.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
unsigned long long rdtsc(){
unsigned int lo,hi;
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
return ((unsigned long long)hi << 32) | lo;
}
struct vector2 {
float x, y;
};
std::ostream &operator<<(std::ostream &os, vector2 const &A) {
return os << A.x << "," << A.y;
}
std::ostream &operator<<(std::ostream &os, SDL_Rect const &R) {
return os << "x:"<< R.x << " y:" << R.y << " w:" << R.w << " h:" << R.h;
}
// convert pair of floats to vector2
vector2 v2(float A, float B) {
vector2 r;
r.x = A;
r.y = B;
return r;
};
// negation
vector2 operator-(vector2 A) {
vector2 r;
r.x = -A.x;
r.y = -A.y;
return r;
};
// scalar multiplication
vector2 operator*(float A, vector2 B) {
vector2 r;
r.x = A*B.x;
r.y = A*B.y;
return r;
};
// scalar multiplication
vector2 operator*(vector2 A, float B) {
vector2 r;
r.x = B*A.x;
r.y = B*A.y;
return r;
};
// hadamari product
vector2 operator*(vector2 A, vector2 B) {
vector2 r;
r.x = A.x*B.x;
r.y = A.y*B.y;
return r;
};
// vector add
vector2 operator+(vector2 A, vector2 B) {
vector2 r;
r.x = A.x+B.x;
r.y = A.y+B.y;
return r;
};
// vector subtract
vector2 operator-(vector2 A, vector2 B) {
vector2 r;
r.x = A.x-B.x;
r.y = A.y-B.y;
return r;
};
// dot or inner product
float dot(vector2 A, vector2 B) {
float r = A.x*B.x + A.y*B.y;
return r;
};
//square
float square(float A) {
float r = A*A;
return r;
};
vector2 reflect(vector2 v, vector2 normal) {
vector2 r;
r = v - 2*(dot(normal,v))*normal;
return r;
};
float length_sq(vector2 v) {
float r = dot(v,v);
return r;
};
float length(vector2 v) {
float r = sqrt(length_sq(v));
return r;
};
vector2 normalize(vector2 v) {
vector2 r;
r = v*(1.0/length(v));
return r;
};