1 | |
---|
2 | #include <IMGBox2d.h> |
---|
3 | |
---|
4 | namespace IMG |
---|
5 | { |
---|
6 | |
---|
7 | Box2d::Box2d() |
---|
8 | { |
---|
9 | mMinimum.x = BOUNDINGBOX_MAXVALUE; |
---|
10 | mMinimum.y = BOUNDINGBOX_MAXVALUE; |
---|
11 | |
---|
12 | mMaximum.x = -BOUNDINGBOX_MAXVALUE; |
---|
13 | mMaximum.y = -BOUNDINGBOX_MAXVALUE; |
---|
14 | } |
---|
15 | |
---|
16 | Box2d::~Box2d() |
---|
17 | { |
---|
18 | } |
---|
19 | |
---|
20 | Ogre::Vector2 Box2d::getMinimum() |
---|
21 | { |
---|
22 | return mMinimum; |
---|
23 | } |
---|
24 | |
---|
25 | Ogre::Vector2 Box2d::getMaximum() |
---|
26 | { |
---|
27 | return mMaximum; |
---|
28 | } |
---|
29 | |
---|
30 | void Box2d::setBoundBox(float x, float y, float X, float Y) |
---|
31 | { |
---|
32 | mMinimum.x = x; |
---|
33 | mMinimum.y = y; |
---|
34 | mMaximum.x = X; |
---|
35 | mMaximum.y = Y; |
---|
36 | } |
---|
37 | |
---|
38 | void Box2d::addBoundingVector3(float x, float y) |
---|
39 | { |
---|
40 | if (x < mMinimum.x) |
---|
41 | { |
---|
42 | mMinimum.x = x; |
---|
43 | } |
---|
44 | |
---|
45 | if (x > mMaximum.x) |
---|
46 | { |
---|
47 | mMaximum.x = x; |
---|
48 | } |
---|
49 | |
---|
50 | if (y < mMinimum.y) |
---|
51 | { |
---|
52 | mMinimum.y = y; |
---|
53 | } |
---|
54 | |
---|
55 | if (y > mMaximum.y) |
---|
56 | { |
---|
57 | mMaximum.y = y; |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | void Box2d::print() |
---|
62 | { |
---|
63 | Ogre::LogManager::getSingleton().logMessage("Valor de la Caixa: (" + Ogre::StringConverter::toString(Ogre::Vector3(mMinimum.x, mMinimum.y, 0)) + ") - (" + Ogre::StringConverter::toString(Ogre::Vector3(mMaximum.x, mMaximum.y, 0)) + ")"); |
---|
64 | } |
---|
65 | |
---|
66 | Ogre::Vector2 Box2d::getCorner(int corner) const |
---|
67 | { |
---|
68 | Ogre::Vector2 vector; |
---|
69 | |
---|
70 | switch (corner) |
---|
71 | { |
---|
72 | case BOX_CORNER_xy: vector = Ogre::Vector2(mMinimum.x, mMinimum.y ); break; |
---|
73 | case BOX_CORNER_xY: vector = Ogre::Vector2(mMinimum.x, mMaximum.y ); break; |
---|
74 | case BOX_CORNER_Xy: vector = Ogre::Vector2(mMaximum.x, mMinimum.y ); break; |
---|
75 | case BOX_CORNER_XY: vector = Ogre::Vector2(mMaximum.x, mMaximum.y ); break; |
---|
76 | } |
---|
77 | |
---|
78 | return vector; |
---|
79 | } |
---|
80 | |
---|
81 | bool Box2d::in(int w, int h) |
---|
82 | { |
---|
83 | if (w <= (mMaximum.x - mMinimum.x) && h <= (mMaximum.y - mMinimum.y)) |
---|
84 | { |
---|
85 | return true; |
---|
86 | } |
---|
87 | |
---|
88 | return false; |
---|
89 | } |
---|
90 | |
---|
91 | bool Box2d::fitPerfect(int w, int h) |
---|
92 | { |
---|
93 | if (w == (mMaximum.x - mMinimum.x) && h == (mMaximum.y - mMinimum.y)) |
---|
94 | { |
---|
95 | return true; |
---|
96 | } |
---|
97 | |
---|
98 | return false; |
---|
99 | } |
---|
100 | |
---|
101 | } |
---|