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
00056 mPosX3d = -0.5;
00057
00058 mPosY3d = -0.5;
00059 mPosZ3d = -2;
00060 mPosY3dInc = 0;
00061 }
00062
00063 int
00064 GetDistance()
00065 {
00066 return mDist;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 void
00088 GetPos2d(float tileW, float tileH, int& pX2d, int& pY2d)
00089 {
00090
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;
00099 }
00100 else
00101 {
00102 mPosX2d += mPrevWidth2d;
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);
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
00128
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;
00142 bool mFirstLine;
00143 int mPosX2d;
00144 int mPosY2d;
00145 int mLineY2d;
00146 int mLineY2dInc;
00147 int mPrevWidth2d;
00148 int mPrevHeight2d;
00149 float mPosX3d;
00150 float mPosY3d;
00151 float mPosZ3d;
00152 float mPosY3dInc;
00153
00154 };
00155
00156 }
00157 }
00158 }
00159
00160 #endif