00001 #ifndef Impala_Application_Videolympics_VidolviView_h
00002 #define Impala_Application_Videolympics_VidolviView_h
00003
00004 #include "Basis/CmdOptions.h"
00005 #include "Core/ImageSet/ImageSet.h"
00006 #include "Core/Array/Arrays.h"
00007 #include "Core/Geometry/Rectangle.h"
00008 #include "OglGui/View.h"
00009 #include "OglGui/Window.h"
00010 #include "Core/Array/Arrays.h"
00011
00012 #include "PhysicsEngine.h"
00013
00014 namespace Impala {
00015 namespace Application {
00016 namespace Videolympics {
00017
00018 using namespace OglGui;
00019
00020 class VidolviView : public OglGui::View
00021 {
00022 public:
00023 VidolviView(OGLWND* oglWnd, Core::Array::Array2dVec3UInt8 *image, float x, float y, float z,
00024 float w, float h, float d, ViewListener* li=0):
00025 OglGui::View(oglWnd, InitOGLIMAGE(image), x, y, z, w, h, d, li)
00026 {
00027 static int viewnr = 0;
00028 mViewNr = viewnr;
00029 viewnr++;
00030 view3DSys.SetTags(GetOGLVIEW3D(), FlexViewTags);
00031 view3DSys.SetZoom(GetOGLVIEW3D(), 2.2f, 1.4f);
00032
00033
00034 oglSys.ReleaseOglImage(mOglIm);
00035 mPPart = new PhysicsPart(GetOGLVIEW3D(), mViewNr);
00036
00037 mRelevance = mSelectedByOthers = mStepsShown = 0;
00038 }
00039
00040 ~VidolviView()
00041 {
00042 ILOG_DEBUG("~Destroying " << mViewNr);
00043 mPPart->DoDestroyPart();
00044
00045
00046 }
00047
00048 OGLIMAGE *
00049 UpdateImage(Core::Array::Array2dVec3UInt8 *image)
00050 {
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 }
00087
00088 PhysicsPart*
00089 GetPPart()
00090 {
00091 return mPPart;
00092 }
00093
00094 int
00095 GetViewNr()
00096 {
00097 return mViewNr;
00098 }
00099
00100 void
00101 SetRelevance(int relevance, int selectedByOthers)
00102 {
00103
00104
00105
00106
00107 mRelevance = relevance;
00108 mSelectedByOthers = selectedByOthers;
00109 }
00110
00111 void
00112 SetRelColor()
00113 {
00114 float r, g, b, a;
00115 switch (mRelevance)
00116 {
00117 case 0:
00118 r = g = b = 0.0f; a = 0.5f;
00119 break;
00120 case 1:
00121 r = 0.0f; g = 1.0f; b = 0.0f; a = 0.5f;
00122 break;
00123 case 2:
00124 r = 1.0f; g = 0.0f; b = 0.0f; a = 0.5f;
00125 break;
00126 }
00127
00128 if (mStepsShown < 500)
00129 {
00130 float factor = (float)mStepsShown / 500.0f;
00131 mStepsShown++;
00132
00133
00134
00135 a = a * factor;
00136 }
00137
00138 glColor4f(r,g,b,a);
00139 }
00140
00141
00142 virtual void OnMouse(int msg, int btn, int state, float x, float y)
00143 {
00144 OglGui::View::OnMouse(msg, btn, state, x, y);
00145 }
00146
00147 virtual void OnDrawView()
00148 {
00149 OglGui::View::OnDrawView();
00150
00151 float w,h,d;
00152 view3DSys.GetDimensions(GetOGLVIEW3D(), 0, 0, 0, &w, &h, &d);
00153
00154 glPushMatrix();
00155 glTranslatef(0.0, 0.0, +0.02f);
00156 glScalef(w + 0.01,h,d);
00157 INT oldBlendInfo[3];
00158 OGC oldOGC;
00159 OGCSave( &oldOGC );
00160 oglSys.StartBlend( &oldBlendInfo[0] );
00161
00162
00163 SetRelColor();
00164 glBegin(GL_QUADS);
00165 glVertex3f( -0.5f, -0.5f, -0.02f );
00166 glVertex3f( +0.5f, -0.5f, -0.02f );
00167 glVertex3f( +0.5f, +0.5f, +0.02f );
00168 glVertex3f( -0.5f, +0.5f, +0.02f );
00169
00170 glEnd();
00171 oglSys.EndBlend( &oldBlendInfo[0] );
00172 OGCRestore( &oldOGC );
00173 glPopMatrix();
00174 }
00175
00176
00177 virtual void OnSelection(bool selected) {
00178 OglGui::View::OnSelection(selected);
00179
00180 }
00181
00182 protected:
00183
00184 OGLIMAGE*
00185 InitOGLIMAGE(Core::Array::Array2dVec3UInt8* im)
00186 {
00187
00188 mOglIm = oglSys.OglImage(GL_RGB, im->CW(), im->CH());
00189 mOglIm->imDataFunc = MyOglImdataFunc;
00190 mOglIm->onDestroy = MyOglImdataDestroyFunc;
00191
00192 mOglIm->noTexScaling = 1;
00193
00194
00195 mOglIm->imageHandle = im;
00196 return mOglIm;
00197
00198 }
00199
00200 static void*
00201 MyOglImdataFunc(OGLIMAGE* oglIm)
00202 {
00203
00204 Core::Array::Array2dVec3UInt8* ar = (Core::Array::Array2dVec3UInt8 *) oglIm->imageHandle;
00205
00206
00207 oglIm->w = ar->CW();
00208 oglIm->h = ar->CH();
00209 oglIm->changed = 0;
00210
00211 return (void *) ar->CPB(0, 0);
00212 }
00213
00214 static void
00215 MyOglImdataDestroyFunc(OGLIMAGE* oglIm)
00216 {
00217 ILOG_DEBUG("OGL image destroyed.");
00218 if (!oglIm)
00219 return;
00220 Core::Array::Array2dVec3UInt8* ar = (Core::Array::Array2dVec3UInt8 *) oglIm->imageHandle;
00221 if (ar)
00222 {
00223 delete ar;
00224 ar = 0;
00225 }
00226 }
00227
00228 OGLIMAGE *mOglIm;
00229 PhysicsPart *mPPart;
00230 int mViewNr;
00231
00232 int mRelevance, mSelectedByOthers, mStepsShown;
00233
00234 ILOG_VAR_DEC;
00235
00236 };
00237
00238 ILOG_VAR_INIT(VidolviView, Visualization.Application.Videolympics);
00239
00240 }
00241 }
00242 }
00243
00244 #endif
00245