source: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/IMG/IMGBox2d.h @ 700

Revision 700, 2.4 KB checked in by igarcia, 18 years ago (diff)
Line 
1#ifndef _IMGBOX2D_H
2#define _IMGBOX2D_H
3
4#include "IMGBBox.h"
5
6namespace IMG {
7
8//* this class represents a 2d bound box for a texture
9class Box2d {
10  public:
11    inline Box2d() {
12                mMinimum.x =  BOUNDINGBOX_MAXVALUE;
13                mMinimum.y =  BOUNDINGBOX_MAXVALUE;
14               
15                mMaximum.x = -BOUNDINGBOX_MAXVALUE;
16                mMaximum.y = -BOUNDINGBOX_MAXVALUE;             
17        };
18
19    // GametoolsError -- Isma 17/08/2005
20    inline Box2d & operator =(const Box2d & p) {
21                mMinimum = p.mMinimum;
22                mMaximum = p.mMaximum;
23        };
24
25        inline Ogre::Vector2 GetMinimum() {
26                return mMinimum;
27        };
28
29        inline Ogre::Vector2 GetMaximum() {
30                return mMaximum;
31        };
32
33    inline void SetBoundBox(float x, float y, float X, float Y) {
34                mMinimum.x = x;
35                mMinimum.y = y;
36                mMaximum.x = X;
37                mMaximum.y = Y;
38        };
39
40    inline void AddBoundingVector3(float x, float y) {
41                        if (x < mMinimum.x) mMinimum.x = x; if (x > mMaximum.x) mMaximum.x = x;
42                        if (y < mMinimum.y) mMinimum.y = y; if (y > mMaximum.y) mMaximum.y = y;
43        };
44
45    inline void Print() {
46                printf("\nValor de la Caixa: (%.4f, %.4f) - (%.4f, %.4f)", mMinimum.x, mMinimum.y, mMaximum.x, mMaximum.y);
47        };
48
49        inline Ogre::Vector2 * GetCorner(int corner) const {
50       
51                //if (corner < 0 || corner > 7) return Ogre::Vector3 (-1111111111, -1111111111, -1111111111);
52                //return Ogre::AxisAlignedBox::getAllCorners ()[corner];
53                //printf("\nGetCorner: %d", corner);
54               
55                if (corner < 0 || corner > 4) return NULL;
56                               
57                        Ogre::Vector2 *vector;
58                switch (corner)
59                {               
60                        case BOX_CORNER_xy: vector = new Ogre::Vector2(mMinimum.x, mMinimum.y ); break;
61                        case BOX_CORNER_xY: vector = new Ogre::Vector2(mMinimum.x, mMaximum.y ); break;
62                        case BOX_CORNER_Xy: vector = new Ogre::Vector2(mMaximum.x, mMinimum.y ); break;
63                        case BOX_CORNER_XY: vector = new Ogre::Vector2(mMaximum.x, mMaximum.y ); break;
64                       
65                }
66               
67                return vector;
68         };
69
70    inline bool In(int w, int h) {
71                if (w <= (mMaximum.x - mMinimum.x) &&
72                    h <= (mMaximum.y - mMinimum.y)) return true;
73                   
74                return false;
75        };
76
77    inline bool FitPerfect(int w, int h) {     
78                if (w == (mMaximum.x - mMinimum.x) &&
79                    h == (mMaximum.y - mMinimum.y)) return true;
80                 
81                return false;
82        };
83
84    ~Box2d();
85
86        private:
87                Ogre::Vector2 mMinimum, mMaximum;
88};
89
90}
91#endif
Note: See TracBrowser for help on using the repository browser.