forked from carboned4/CeGue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBox.h
70 lines (53 loc) · 1.33 KB
/
Box.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
#ifndef BOX_H
#define BOX_H
#include "Vector3.h"
/* Class Box - Class represents "Hit Boxes" */
class Box{
private: double _xMin;
private: double _xMax;
private: double _yMin;
private: double _yMax;
public: Box(){ //Default Values.
_xMin = -2.0;
_xMax = 2.0;
_yMin = -2.0;
_yMax = 2.0;
}
public: Box(double xMin,double xMax,double yMin,double yMax){
_xMin = xMin;
_xMax = xMax;
_yMin = yMin;
_yMax = yMax;
}
public: ~Box(){}
public: double getXMIN(){
return _xMin;
}
public: double getXMAX(){
return _xMax;
}
public: double getYMIN(){
return _yMin;
}
public: double getYMAX(){
return _yMax;
}
/* Collided() - Verifies if the boxes intercepts. */
public: static bool Collided(Box box1,Vector3 pos1,Box box2,Vector3 pos2){
double otherleft = pos1.getX() + box1.getXMIN();
double otherright = pos1.getX() + box1.getXMAX();
double otherbottom = pos1.getY() + box1.getYMIN();
double othertop = pos1.getY() + box1.getYMAX();
double selfleft = pos2.getX() + box2.getXMIN();
double selfright = pos2.getX() + box2.getXMAX();
double selfbottom = pos2.getY() + box2.getYMIN();
double selftop = pos2.getY() + box2.getYMAX();
if (!(selfleft > otherright || selfright < otherleft || selfbottom > othertop || selftop < otherbottom)){
return true;
}
else {
return false;
}
}
};
#endif