00001 #ifndef CxRectZTiler_h
00002 #define CxRectZTiler_h
00003
00004
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
00063 mPosX3d = -0.5;
00064
00065 mPosY3d = -0.5;
00066 mPosZ3d = -2;
00067 mPosY3dInc = 0;
00068 }
00069
00070 int
00071 GetDistance()
00072 {
00073 return mDist;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 void
00095 GetPos2d(float tileW, float tileH, int& pX2d, int& pY2d)
00096 {
00097
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;
00106 }
00107 else
00108 {
00109 mPosX2d += mPrevWidth2d;
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);
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
00135
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;
00149 bool mFirstLine;
00150 int mPosX2d;
00151 int mPosY2d;
00152 int mLineY2d;
00153 int mLineY2dInc;
00154 int mPrevWidth2d;
00155 int mPrevHeight2d;
00156 float mPosX3d;
00157 float mPosY3d;
00158 float mPosZ3d;
00159 float mPosY3dInc;
00160
00161 };
00162
00163 #endif