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

CxRectZTiler.h

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

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