Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

RectangleTiler.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Geometry_RectangleTiler_h
00002 #define Impala_Core_Geometry_RectangleTiler_h
00003 
00004 #include "Basis/Std.h"
00005 
00006 namespace Impala
00007 {
00008 namespace Core
00009 {
00010 namespace Geometry
00011 {
00012 
00013 
00017 class RectangleTiler {
00018 public:
00019 
00020     RectangleTiler()
00021     {
00022         mWndWidth = 100;
00023         mWndHeight = 100;
00024         mDist = 2;
00025         ResetPos();
00026     }
00027 
00028     RectangleTiler(int wndWidth, int wndHeight, int distance = 2)
00029     {
00030         mWndWidth = wndWidth;
00031         mWndHeight = wndHeight;
00032         mDist = distance;
00033         ResetPos();
00034     }
00035 
00036     void
00037     ResetWnd(int wndWidth, int wndHeight, int distance = 2)
00038     {
00039         mWndWidth = wndWidth;
00040         mWndHeight = wndHeight;
00041         mDist = distance;
00042         ResetPos();
00043     }
00044 
00045     void
00046     ResetPos()
00047     {
00048         mFirstLine = true;
00049         mPosX2d = 0;
00050         mPosY2d = 0;
00051         mLineY2d = 0;
00052         mLineY2dInc = 0;
00053         mPrevHeight2d = 0;
00054         mPrevWidth2d = 0;
00055         //mPosX3d = -1;
00056         mPosX3d = -0.5;
00057         //mPosY3d = 0;
00058         mPosY3d = -0.5;
00059         mPosZ3d = -2;
00060         mPosY3dInc = 0;
00061     }
00062 
00063     int
00064     GetDistance()
00065     {
00066         return mDist;
00067     }
00068 
00069     /*
00070     void
00071     GetPos2d(float tileW, float tileH, int& pX2d, int& pY2d)
00072     {
00073         int s = 5; // room for window border and to separate tiles
00074         if (mPosX2d + tileW + s > mWndWidth)
00075         {
00076             mPosX2d = 0;
00077             mPosY2d += mPosY2dInc;
00078             mPosY2dInc = 0;
00079         }
00080         pX2d = mPosX2d;
00081         pY2d = mWndHeight - mPosY2d - tileH - 1; // 1 is for window border
00082         mPosX2d += tileW + s;
00083         mPosY2dInc = Max(mPosY2dInc, (int) tileH + s);
00084     }
00085     */
00086 
00087     void
00088     GetPos2d(float tileW, float tileH, int& pX2d, int& pY2d)
00089     {
00090         //int s = 5; // room for window border and to separate tiles
00091         if (mFirstLine)
00092         {
00093             mFirstLine = false;
00094         }
00095         else if ((tileW+mDist <= mPrevWidth2d) && (mPosX2d != 0) &&
00096                  (mPosY2d - mLineY2d + mPrevHeight2d + tileH+mDist <= mLineY2dInc))
00097         {
00098             mPosY2d += mPrevHeight2d; // put it in a "column" on this line
00099         }
00100         else
00101         {
00102             mPosX2d += mPrevWidth2d; // advance on this line
00103             mPosY2d = mLineY2d;
00104             if (mPosX2d + tileW+mDist > mWndWidth)
00105             {
00106                 mLineY2d += mLineY2dInc;
00107                 mLineY2dInc = 0;
00108                 mPosX2d = 0;
00109                 mPosY2d = mLineY2d;
00110             }
00111         }
00112         pX2d = mPosX2d;
00113         pY2d = (int)(mWndHeight - mPosY2d - tileH - 1); // 1 is for border
00114         mLineY2dInc = Max(mLineY2dInc, (int) tileH+mDist);
00115         mPrevWidth2d = (int)(tileW+mDist);
00116         mPrevHeight2d = (int)(tileH+mDist);
00117     }
00118 
00119     void
00120     GetPos3d(float imW, float imH, float& pX3d, float& pY3d, float& pZ3d)
00121     {
00122         if (mPosX3d > 2)
00123         {
00124             mPosX3d = 0;
00125             mPosY3d += mPosY3dInc;
00126             mPosY3dInc = 0;
00127             //if (mPosY3d > mWndHeight)
00128             //  mPosY3d = 0;
00129         }
00130         pX3d = mPosX3d + imW/2;
00131         pY3d = mPosY3d + imH/2;
00132         pZ3d = mPosZ3d;
00133         mPosX3d += imW;
00134         mPosY3dInc = Max(mPosY3dInc, imH);
00135     }
00136 
00137 private:
00138 
00139     int   mWndWidth;
00140     int   mWndHeight;
00141     int   mDist; // room for window border and to separate tiles
00142     bool  mFirstLine;
00143     int   mPosX2d; // position of upper left corner of last tile in coordinate
00144     int   mPosY2d; // system where upper left is (0,0) positive Y is down
00145     int   mLineY2d; // the grid line for placing tiles
00146     int   mLineY2dInc; // height of the current "row" of tiles
00147     int   mPrevWidth2d; // width of the previous tile
00148     int   mPrevHeight2d;
00149     float mPosX3d;
00150     float mPosY3d;
00151     float mPosZ3d;
00152     float mPosY3dInc;
00153 
00154 };
00155 
00156 } // namespace Geometry
00157 } // namespace Core
00158 } // namespace Impala
00159 
00160 #endif

Generated on Fri Mar 19 09:31:09 2010 for ImpalaSrc by  doxygen 1.5.1