00001
00002 #include "main.h"
00003 #include "controler.h"
00004 #include "photo.h"
00005 #include "table.h"
00006 #include "mouse.h"
00007 #include "photoCollection.h"
00008 #include "irrlichtEventReceiver.h"
00009 #include "irrlichtDebugHelper.h"
00010 #include "physxDebugHelper.h"
00011
00012
00013
00014
00015
00016
00017
00018 ERR_TYPE onKeyEvent( EKEY_CODE keyCode );
00019
00020 ERR_TYPE onMouseButtonLeftEvent( s32 x, s32 y, f32 wheel );
00021
00022 ERR_TYPE onMouseButtonLeftReleaseEvent();
00023
00024 ERR_TYPE onMouseButtonLeftDoubleClickEvent( s32 x, s32 y, f32 wheel );
00025
00026 ERR_TYPE onMouseButtonRightEvent( s32 x, s32 y, f32 wheel );
00027
00028 ERR_TYPE onMouseButtonRightReleaseEvent();
00029
00030 ERR_TYPE onMouseMoveEvent( s32 x, s32 y );
00031
00032 ERR_TYPE onCheckForPhotoDelete( Photo* photo );
00033
00034
00035
00036
00037 static PhotoCollection* myPhotoCollection = NULL;
00038 static Table* myTable = NULL;
00039 static Mouse* myMouse = NULL;
00040 static ICameraSceneNode* myCamera = NULL;
00041 static ILightSceneNode* myLight = NULL;
00042 static IrrlichtEventReceiver* myEvents = NULL;
00043 static bool isRunning = true;
00044 static Photo* myZoomedPhoto = NULL;
00045
00046
00047
00048
00049
00050
00051 ERR_TYPE controlerInit()
00052 {
00053
00054 myEvents = new IrrlichtEventReceiver();
00055 myEvents->registerKeyEventCallback( onKeyEvent );
00056 myEvents->registerMouseButtonLeftEventCallback( onMouseButtonLeftEvent );
00057 myEvents->registerMouseButtonLeftReleaseEventCallback( onMouseButtonLeftReleaseEvent );
00058 myEvents->registerMouseButtonLeftDoubleClickEventCallback( onMouseButtonLeftDoubleClickEvent );
00059 myEvents->registerMouseButtonRightEventCallback( onMouseButtonRightEvent );
00060 myEvents->registerMouseButtonRightReleaseEventCallback( onMouseButtonRightReleaseEvent );
00061 myEvents->registerMouseMoveEventCallback( onMouseMoveEvent );
00062
00063
00064
00065 myPhotoCollection = new PhotoCollection();
00066
00067 myPhotoCollection->registerCheckForDeleteCallback( onCheckForPhotoDelete );
00068
00069
00070 myTable = new Table();
00071 myTable->load( "../../media/table_v4_irr.3DS",
00072 "../../media/tabtex_metall.jpg",
00073 vector3df(1.0f, 1.0f, 1.0f) );
00074
00075
00076 vector3df camPosition(0.0f, 72.0f, -0.2f);
00077 vector3df camLookAt(0.0f, 0.0f, 0.0f);
00078 myCamera = smgr->addCameraSceneNode( NULL, camPosition, camLookAt );
00079
00080
00081
00082
00083
00084 myMouse = new Mouse( 1.0f, 12.0f, 0.0f );
00085
00086
00087
00088 irrlichtDebugHelperAddArrows( vector3df(510.0f, 200.0f, 200.0f) );
00089
00090
00091 vector3df lightPos( -40.0f, 100.0f, 40.0f );
00092 SColorf lightColor( 1.0f, 1.0f, 1.0f, 1.0f );
00093 f32 lightRadius = 200.0f;
00094 myLight = smgr->addLightSceneNode( NULL, lightPos, lightColor, lightRadius );
00095 smgr->setShadowColor( SColor(100, 0, 0, 0) );
00096
00097
00098
00099
00100
00101
00102
00103 IBillboardSceneNode* bill = smgr->addBillboardSceneNode( myLight, dimension2df(30.0f, 30.0f) );
00104 bill->setMaterialFlag( EMF_LIGHTING, false );
00105 bill->setMaterialType( EMT_TRANSPARENT_ADD_COLOR );
00106 bill->setMaterialTexture( 0, driver->getTexture("../../media/particlewhite.bmp") );
00107
00108
00109 logger->log( "" );
00110 logger->log( "Press C, P, R, L, D, ESC" );
00111 logger->log( "Use Mouse To Move Photos, Doubleclick To Zoom." );
00112
00113 return ERR_OK;
00114 }
00115
00116
00117
00118 ERR_TYPE controlerUpdate()
00119 {
00120 u32 now = timer->getRealTime();
00121
00122
00123 if ( ! isRunning )
00124 {
00125 return ERR_UNKWON;
00126 }
00127
00128
00129 myPhotoCollection->update( now );
00130
00131 if ( NULL != myTable )
00132 {
00133
00134 myTable->update( now );
00135 }
00136
00137 return ERR_OK;
00138 }
00139
00140
00141
00142 ERR_TYPE controlerDeinit()
00143 {
00144 if ( NULL != myMouse )
00145 {
00146 delete myMouse;
00147 myMouse = NULL;
00148 }
00149 if ( NULL != myPhotoCollection )
00150 {
00151 delete myPhotoCollection;
00152 myPhotoCollection = NULL;
00153 }
00154 if ( NULL != myTable )
00155 {
00156 delete myTable;
00157 myTable = NULL;
00158 }
00159 if ( NULL != myEvents )
00160 {
00161 delete myEvents;
00162 myEvents = NULL;
00163 }
00164
00165 return ERR_OK;
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175 ERR_TYPE onKeyEvent( EKEY_CODE keyCode )
00176 {
00177 switch ( keyCode )
00178 {
00179 case KEY_KEY_P:
00180 {
00181
00182 myPhotoCollection->addPhoto( stringc("../../media/stones.jpg"), NxVec3(0.0f, 60.0f, 0.0f) );
00183 return ERR_EVENT_CONSUMED;
00184 }
00185
00186 case KEY_KEY_R:
00187 {
00188
00189 myPhotoCollection->resetPhotos();
00190 return ERR_EVENT_CONSUMED;
00191 }
00192
00193 case KEY_KEY_L:
00194 {
00195
00196 myPhotoCollection->addPhotosFromDirectory( stringc("../../media/photo") );
00197 return ERR_EVENT_CONSUMED;
00198 }
00199
00200 case KEY_KEY_D:
00201 {
00202
00203 switchPhysxDebugRenderingEnabled();
00204 return ERR_EVENT_CONSUMED;
00205 }
00206
00207 case KEY_KEY_C:
00208 {
00209 static bool useFPSCamera = true;
00210 static vector3df oldCamPos(0, 0, 0);
00211 static vector3df oldCamTarget(0, 0, 0);
00212
00213
00214 oldCamPos = myCamera->getPosition();
00215 oldCamTarget = myCamera->getTarget();
00216
00217 if ( useFPSCamera )
00218 {
00219 myCamera->remove();
00220
00221 myCamera = smgr->addCameraSceneNodeFPS();
00222 myCamera->setPosition( oldCamPos );
00223 myCamera->setTarget( oldCamTarget );
00224 logger->log( "Using FPS Camera" );
00225 }
00226 else
00227 {
00228 myCamera->remove();
00229
00230 myCamera = smgr->addCameraSceneNode();
00231 myCamera->setPosition( oldCamPos );
00232 myCamera->setTarget( oldCamTarget );
00233 logger->log( "Using Fixed Camera" );
00234 }
00235
00236 useFPSCamera = !useFPSCamera;
00237
00238 return ERR_EVENT_CONSUMED;
00239 }
00240
00241 case KEY_KEY_S:
00242 {
00243
00244 IParticleSystemSceneNode* p = smgr->addParticleSystemSceneNode();
00245 p->setParticleSize( dimension2d<f32>(5.0f, 5.0f) );
00246 IParticleEmitter* em = p->createBoxEmitter( aabbox3d<f32>(-5.0f, 9.0f, -5.0f, 5.0f, 10.0f, 5.0f),
00247 vector3df(0.0f, 0.02f, 0.0f),
00248 10,
00249 20,
00250 SColor(255,255,255,255),
00251 SColor(255,255,255,255),
00252 1100,
00253 2000 );
00254 p->setEmitter( em );
00255 p->setMaterialTexture( 0, driver->getTexture("../../media/particlewhite.bmp") );
00256 p->setMaterialFlag( EMF_LIGHTING, false );
00257 p->setMaterialType( EMT_TRANSPARENT_ADD_COLOR );
00258 em->drop();
00259 IParticleAffector* paf = p->createFadeOutParticleAffector();
00260 p->addAffector( paf );
00261 paf->drop();
00262
00263 return ERR_EVENT_CONSUMED;
00264 }
00265
00266 case KEY_ESCAPE:
00267 {
00268
00269 isRunning = false;
00270 return ERR_EVENT_CONSUMED;
00271 }
00272 }
00273
00274 return ERR_OK;
00275 }
00276
00277
00278
00279 ERR_TYPE onMouseButtonLeftEvent( s32 x, s32 y, f32 wheel )
00280 {
00281 NxActor* tempActor = NULL;
00282
00283
00284 if ( NULL != myZoomedPhoto )
00285 {
00286 myZoomedPhoto->zoomEnd();
00287 myZoomedPhoto = NULL;
00288 return ERR_EVENT_CONSUMED;
00289 }
00290
00291
00292 tempActor = myMouse->actorHit( x, y );
00293 if ( NULL != tempActor )
00294 {
00295 stringc name = tempActor->getName();
00296
00297
00298
00299
00300
00301
00302 if ( name.equals_ignore_case( "photo" ) )
00303 {
00304 myMouse->pickActorElasticStrap( tempActor );
00305 return ERR_EVENT_CONSUMED;
00306 }
00307 }
00308
00309 return ERR_OK;
00310 }
00311
00312
00313
00314 ERR_TYPE onMouseButtonLeftReleaseEvent()
00315 {
00316
00317 myMouse->dropActor();
00318 return ERR_EVENT_CONSUMED;
00319 }
00320
00321
00322
00323 ERR_TYPE onMouseButtonLeftDoubleClickEvent( s32 x, s32 y, f32 wheel )
00324 {
00325 NxActor* tempActor = NULL;
00326
00327
00328 myMouse->dropActor();
00329
00330
00331 if ( NULL != myZoomedPhoto )
00332 {
00333 myZoomedPhoto->zoomEnd();
00334 myZoomedPhoto = NULL;
00335 return ERR_EVENT_CONSUMED;
00336 }
00337
00338
00339 tempActor = myMouse->actorHit( x, y );
00340 if ( NULL != tempActor )
00341 {
00342 stringc name = tempActor->getName();
00343
00344
00345 if ( name.equals_ignore_case( "photo" ) )
00346 {
00347
00348 myZoomedPhoto = (Photo*) tempActor->userData;
00349
00350 vector3df camPos = myCamera->getPosition();
00351 NxVec3 destinationPos( camPos.X, camPos.Y-10.0f, camPos.Z );
00352 myZoomedPhoto->zoomStart( destinationPos, 1000 );
00353 }
00354 }
00355
00356 return ERR_EVENT_CONSUMED;
00357 }
00358
00359
00360
00361 ERR_TYPE onMouseButtonRightEvent( s32 x, s32 y, f32 wheel )
00362 {
00363 NxActor* tempActor = NULL;
00364
00365
00366 if ( NULL != myZoomedPhoto )
00367 {
00368 myZoomedPhoto->zoomEnd();
00369 myZoomedPhoto = NULL;
00370 return ERR_EVENT_CONSUMED;
00371 }
00372
00373
00374 tempActor = myMouse->actorHit( x, y );
00375 if ( NULL != tempActor )
00376 {
00377 stringc name = tempActor->getName();
00378
00379
00380 if ( name.equals_ignore_case( "photo" ) )
00381 {
00382 myMouse->pickActorFixed( tempActor );
00383 return ERR_EVENT_CONSUMED;
00384 }
00385 }
00386
00387 return ERR_OK;
00388 }
00389
00390
00391
00392 ERR_TYPE onMouseButtonRightReleaseEvent()
00393 {
00394
00395 myMouse->dropActor();
00396 return ERR_EVENT_CONSUMED;
00397 }
00398
00399
00400
00401 ERR_TYPE onMouseMoveEvent( s32 x, s32 y )
00402 {
00403 myMouse->moveTo( x, y );
00404 return ERR_EVENT_CONSUMED;
00405 }
00406
00407
00408
00409 ERR_TYPE onCheckForPhotoDelete( Photo* photo )
00410 {
00411 NxVec3 pos;
00412 photo->getPosition( &pos );
00413
00414 if ( (pos.y < -30.0f) && (pos.y > -100.0f) )
00415 {
00416
00417
00418 photo->particelStart( stringc("../../media/particlewhite.bmp") );
00419 }
00420
00421 if ( pos.y < -100.0f )
00422 {
00423
00424 photo->particelEnd();
00425 }
00426
00427 if ( pos.y > 0.0f )
00428 {
00429
00430
00431 photo->particelEnd();
00432 }
00433
00434
00435 if ( pos.y < -900.0f )
00436 {
00437 return ERR_YES;
00438 }
00439
00440 return ERR_NO;
00441 }