Using migrated Public Visual API
[platform/core/uifw/dali-demo.git] / examples / mesh-visual / mesh-visual-example.cpp
1 #include <dali-toolkit/dali-toolkit.h>
2
3 using namespace Dali;
4 using namespace Dali::Toolkit;
5
6 namespace
7 {
8 // Keeps information about each model for access.
9 struct Model
10 {
11   Control control; // Control housing the mesh visual of the model.
12   Vector2 rotation; // Keeps track of rotation about x and y axis for manual rotation.
13   Animation rotationAnimation; // Automatically rotates when left alone.
14 };
15
16 // Files for meshes
17 const char * const MODEL_FILE_TABLE[] =
18 {
19     DEMO_MODEL_DIR "Dino.obj",
20     DEMO_MODEL_DIR "ToyRobot-Metal.obj",
21     DEMO_MODEL_DIR "Toyrobot-Plastic.obj"
22 };
23
24 const char * const MATERIAL_FILE_TABLE[] =
25 {
26     DEMO_MODEL_DIR "Dino.mtl",
27     DEMO_MODEL_DIR "ToyRobot-Metal.mtl",
28     DEMO_MODEL_DIR "Toyrobot-Plastic.mtl"
29 };
30
31 const char * const TEXTURES_PATH( DEMO_IMAGE_DIR "" );
32
33 // Possible shading modes.
34 MeshVisual::ShadingMode::Value SHADING_MODE_TABLE[] =
35 {
36   MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING,
37   MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING,
38   MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING
39 };
40
41 // Button labels.
42 const char * const PAUSE =  "  ||  ";
43 const char * const PLAY =   "  >  ";
44 const char * const FIXED =  "FIXED";
45 const char * const MANUAL = "MANUAL";
46 const char * const FRONT =  "FRONT";
47 const char * const BACK =   "BACK";
48
49 // Image urls for the light.
50 const char * const LIGHT_URL_FRONT = DEMO_IMAGE_DIR "light-icon-front.png";
51 const char * const LIGHT_URL_BACK =  DEMO_IMAGE_DIR "light-icon-back.png";
52
53 const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
54 const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
55 const float MODEL_SCALE =                    0.75f;
56 const float LIGHT_SCALE =                    0.15f;
57 const float BUTTONS_OFFSET_BOTTOM =          0.08f;
58 const float BUTTONS_OFFSET_SIDE =            0.2f;
59 const int   NUM_MESHES =                     2;
60
61 // Used to identify actors.
62 const int MODEL_TAG = 0;
63 const int LIGHT_TAG = 1;
64 const int LAYER_TAG = 2;
65
66 const Vector4 STAGE_COLOR( 211.0f / 255.0f, 211.0f / 255.0f, 211.0f / 255.0f, 1.0f ); ///< The color of the stage
67
68 } // unnamed namespace
69
70 class MeshVisualController : public ConnectionTracker
71 {
72 public:
73
74   MeshVisualController( Application& application )
75   : mApplication( application ),   //Store handle to the application.
76     mModelIndex( 1 ),              //Start with metal robot.
77     mShadingModeIndex( 0 ),        //Start with texture and detailed specular lighting.
78     mTag( -1 ),                    //Non-valid default, which will get set to a correct value when used.
79     mSelectedModelIndex( -1 ),     //Non-valid default, which will get set to a correct value when used.
80     mPaused( false ),              //Animations play by default.
81     mLightFixed( true ),           //The light is fixed by default.
82     mLightFront( true )            //The light is in front by default.
83   {
84     // Connect to the Application's Init signal
85     mApplication.InitSignal().Connect( this, &MeshVisualController::Create );
86   }
87
88   ~MeshVisualController()
89   {
90   }
91
92   // The Init signal is received once (only) during the Application lifetime
93   void Create( Application& application )
94   {
95     // Get a handle to the stage
96     Stage stage = Stage::GetCurrent();
97     stage.SetBackgroundColor( STAGE_COLOR );
98
99     //Set up root layer to receive touch gestures.
100     Layer rootLayer = stage.GetRootLayer();
101     rootLayer.RegisterProperty( "Tag", LAYER_TAG ); //Used to differentiate between different kinds of actor.
102     rootLayer.TouchSignal().Connect( this, &MeshVisualController::OnTouch );
103
104     //Place models on the scene.
105     SetupModels( rootLayer );
106
107     //Place buttons on the scene.
108     SetupButtons( rootLayer );
109
110     //Add a light to the scene.
111     SetupLight( rootLayer );
112
113     //Allow for exiting of the application via key presses.
114     stage.KeyEventSignal().Connect( this, &MeshVisualController::OnKeyEvent );
115   }
116
117   //Loads and adds the models to the scene, inside containers for hit detection.
118   void SetupModels( Layer layer )
119   {
120     //Add containers to house each renderer-holding-actor.
121     for( int i = 0; i < NUM_MESHES; i++ )
122     {
123       mContainers[i] = Actor::New();
124       mContainers[i].SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
125       mContainers[i].RegisterProperty( "Tag", MODEL_TAG ); //Used to differentiate between different kinds of actor.
126       mContainers[i].RegisterProperty( "Model", Property::Value( i ) ); //Used to index into the model.
127       mContainers[i].TouchSignal().Connect( this, &MeshVisualController::OnTouch );
128       layer.Add( mContainers[i] );
129     }
130
131     //Position each container individually on screen
132
133     //Main, central model
134     mContainers[0].SetSizeModeFactor( Vector3( MODEL_SCALE, MODEL_SCALE, 0.0f ) );
135     mContainers[0].SetParentOrigin( ParentOrigin::CENTER );
136     mContainers[0].SetAnchorPoint( AnchorPoint::CENTER );
137
138     //Top left model
139     mContainers[1].SetSizeModeFactor( Vector3( MODEL_SCALE / 3.0f, MODEL_SCALE / 3.0f, 0.0f ) );
140     mContainers[1].SetParentOrigin( Vector3( 0.05, 0.03, 0.5 ) ); //Offset from top left
141     mContainers[1].SetAnchorPoint( AnchorPoint::TOP_LEFT );
142
143     //Set up models
144     for( int i = 0; i < NUM_MESHES; i++ )
145     {
146       //Create control to display model
147       Control control = Control::New();
148       control.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
149       control.SetParentOrigin( ParentOrigin::CENTER );
150       control.SetAnchorPoint( AnchorPoint::CENTER );
151       mContainers[i].Add( control );
152
153       //Make model spin to demonstrate 3D
154       Animation rotationAnimation = Animation::New( 15.0f );
155       float spin = i % 2 == 0 ? 1.0f : -1.0f; //Make actors spin in different directions to better show independence.
156       rotationAnimation.AnimateBy( Property( control, Actor::Property::ORIENTATION ),
157                                    Quaternion( Degree( 0.0f ), Degree( spin * 360.0f ), Degree( 0.0f ) ) );
158       rotationAnimation.SetLooping( true );
159       rotationAnimation.Play();
160
161       //Store model information in corresponding structs.
162       mModels[i].control = control;
163       mModels[i].rotation.x = 0.0f;
164       mModels[i].rotation.y = 0.0f;
165       mModels[i].rotationAnimation = rotationAnimation;
166     }
167
168     //Calling this sets the model in the controls.
169     ReloadModel();
170   }
171
172   //Place the various buttons on the bottom of the screen, with title labels where necessary.
173   void SetupButtons( Layer layer )
174   {
175     //Actor for positioning model and shading mode buttons.
176     Actor positionActorModel = Actor::New();
177     positionActorModel.SetParentOrigin( Vector3( BUTTONS_OFFSET_SIDE, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) );
178     positionActorModel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
179     layer.Add( positionActorModel );
180
181     //Create button for model changing.
182     PushButton modelButton = Toolkit::PushButton::New();
183     modelButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
184     modelButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeModelClicked );
185     modelButton.SetParentOrigin( ParentOrigin::TOP_CENTER );
186     modelButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
187     modelButton.SetProperty( Toolkit::Button::Property::LABEL, "Model" );
188     positionActorModel.Add( modelButton );
189
190     //Create button for shading mode changing.
191     PushButton shadingModeButton = Toolkit::PushButton::New();
192     shadingModeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
193     shadingModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeShadingModeClicked );
194     shadingModeButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
195     shadingModeButton.SetAnchorPoint( AnchorPoint::TOP_CENTER );
196     shadingModeButton.SetProperty( Toolkit::Button::Property::LABEL, "Shading Mode" );
197     positionActorModel.Add( shadingModeButton );
198
199     //Text label title for changing model or shading mode.
200     TextLabel changeTitleLabel = TextLabel::New( "Change" );
201     changeTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
202     changeTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" );
203     changeTitleLabel.SetParentOrigin( ParentOrigin::TOP_CENTER );
204     changeTitleLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
205     modelButton.Add( changeTitleLabel );
206
207     //Create button for pausing animations.
208     PushButton pauseButton = Toolkit::PushButton::New();
209     pauseButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
210     pauseButton.ClickedSignal().Connect( this, &MeshVisualController::OnPauseClicked );
211     pauseButton.SetParentOrigin( Vector3( 0.5, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) );
212     pauseButton.SetAnchorPoint( AnchorPoint::CENTER );
213     pauseButton.SetProperty( Toolkit::Button::Property::LABEL, PAUSE );
214     layer.Add( pauseButton );
215
216     //Actor for positioning light position buttons.
217     Actor positionActorLight = Actor::New();
218     positionActorLight.SetParentOrigin( Vector3( 1.0 - BUTTONS_OFFSET_SIDE, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) );
219     positionActorLight.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
220     layer.Add( positionActorLight );
221
222     //Create button for switching between manual and fixed light position.
223     PushButton lightModeButton = Toolkit::PushButton::New();
224     lightModeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
225     lightModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightModeClicked );
226     lightModeButton.SetParentOrigin( ParentOrigin::TOP_CENTER );
227     lightModeButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
228     lightModeButton.SetProperty( Toolkit::Button::Property::LABEL, FIXED );
229     positionActorLight.Add( lightModeButton );
230
231     //Create button for switching between front and back light position.
232     PushButton lightSideButton = Toolkit::PushButton::New();
233     lightSideButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
234     lightSideButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightSideClicked );
235     lightSideButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
236     lightSideButton.SetAnchorPoint( AnchorPoint::TOP_CENTER );
237     lightSideButton.SetProperty( Toolkit::Button::Property::LABEL, FRONT );
238     positionActorLight.Add( lightSideButton );
239
240     //Text label title for light position mode.
241     TextLabel lightTitleLabel = TextLabel::New( "Light Position" );
242     lightTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
243     lightTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" );
244     lightTitleLabel.SetParentOrigin( ParentOrigin::TOP_CENTER );
245     lightTitleLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
246     lightModeButton.Add( lightTitleLabel );
247   }
248
249   //Add a point light source the the scene, on a layer above the first.
250   void SetupLight( Layer baseLayer )
251   {
252     //Create control to act as light source of scene.
253     mLightSource = Control::New();
254     mLightSource.RegisterProperty( "Tag", LIGHT_TAG );
255
256     //Set size of control based on screen dimensions.
257     Stage stage = Stage::GetCurrent();
258     if( stage.GetSize().width < stage.GetSize().height )
259     {
260       //Scale to width.
261       mLightSource.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
262       mLightSource.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
263       mLightSource.SetSizeModeFactor( Vector3( LIGHT_SCALE, 0.0f, 0.0f ) );
264     }
265     else
266     {
267       //Scale to height.
268       mLightSource.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT );
269       mLightSource.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::WIDTH );
270       mLightSource.SetSizeModeFactor( Vector3( 0.0f, LIGHT_SCALE, 0.0f ) );
271     }
272
273     //Set position relative to top left, as the light source property is also relative to the top left.
274     mLightSource.SetParentOrigin( ParentOrigin::TOP_LEFT );
275     mLightSource.SetAnchorPoint( AnchorPoint::CENTER );
276     mLightSource.SetPosition( Stage::GetCurrent().GetSize().x * 0.85f, Stage::GetCurrent().GetSize().y * 0.125 );
277
278     //Supply an image to represent the light.
279     SetLightImage();
280
281     //Connect to touch signal for dragging.
282     mLightSource.TouchSignal().Connect( this, &MeshVisualController::OnTouch );
283
284     //Place the light source on a layer above the base, so that it is rendered above everything else.
285     Layer upperLayer = Layer::New();
286     upperLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
287     upperLayer.SetParentOrigin( ParentOrigin::CENTER );
288     upperLayer.SetAnchorPoint( AnchorPoint::CENTER );
289
290     baseLayer.Add( upperLayer );
291     upperLayer.Add( mLightSource );
292
293     //Decide which light to use to begin with.
294     SetLightMode();
295   }
296
297   //Sets the image to use for the light source depending on whether the light is in front or behind.
298   void SetLightImage()
299   {
300     std::string imageUrl;
301
302     if( mLightFront )
303     {
304       imageUrl = LIGHT_URL_FRONT;
305     }
306     else
307     {
308       imageUrl = LIGHT_URL_BACK;
309     }
310
311     Property::Map lightMap;
312     lightMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
313     lightMap.Insert( ImageVisual::Property::URL, imageUrl );
314     mLightSource.SetProperty( Control::Property::BACKGROUND, Property::Value( lightMap ) );
315   }
316
317   //Updates the displayed models to account for parameter changes.
318   void ReloadModel()
319   {
320     //Create mesh property map
321     Property::Map map;
322     map.Insert( Toolkit::Visual::Property::TYPE,  Visual::MESH );
323     map.Insert( Visual::Property::TRANSFORM,
324                 Property::Map().Add( Visual::Transform::Property::ORIGIN, Align::CENTER )
325                                .Add( Visual::Transform::Property::ANCHOR_POINT, Align::CENTER ) );
326     map.Insert( MeshVisual::Property::OBJECT_URL, MODEL_FILE_TABLE[mModelIndex] );
327     map.Insert( MeshVisual::Property::MATERIAL_URL, MATERIAL_FILE_TABLE[mModelIndex] );
328     map.Insert( MeshVisual::Property::TEXTURES_PATH, TEXTURES_PATH );
329     map.Insert( MeshVisual::Property::SHADING_MODE, SHADING_MODE_TABLE[mShadingModeIndex] );
330
331     //Set the two controls to use the mesh
332     for( int i = 0; i < NUM_MESHES; i++ )
333     {
334       mModels[i].control.SetProperty( Control::Property::BACKGROUND, Property::Value( map ) );
335     }
336   }
337
338   //Set the mode used to light the models.
339   void SetLightMode()
340   {
341     if( mLightFixed )
342     {
343       UseFixedLight();
344     }
345     else
346     {
347       UseManualLight();
348     }
349   }
350
351   //Make the models use a fixed, invisible light above the center of the stage.
352   void UseFixedLight()
353   {
354     //Hide draggable source
355     mLightSource.SetVisible( false );
356
357     //Use stage dimensions to place light at center, offset in z axis.
358     Stage stage = Stage::GetCurrent();
359     float width = stage.GetSize().width;
360     float height = stage.GetSize().height;
361     Vector3 lightPosition = Vector3( width / 2.0f, height / 2.0f,
362                                      ( mLightFront ? 1 : -1 ) * std::max( width, height ) * 5.0f );
363
364     //Set global light position
365     for( int i = 0; i < NUM_MESHES; ++i )
366     {
367       mModels[i].control.RegisterProperty( "lightPosition", lightPosition, Property::ANIMATABLE );
368     }
369   }
370
371   //Make the models use a light source that the user can drag around.
372   void UseManualLight()
373   {
374     //Show draggable source
375     mLightSource.SetVisible( true );
376
377     //Update to switch light position of models to that of the source.
378     UpdateLight();
379   }
380
381   //Updates the light position for each model to account for changes in the source on screen.
382   void UpdateLight()
383   {
384     //Set light position to the x and y of the light control, offset into/out of the screen.
385     Vector3 controlPosition = mLightSource.GetCurrentPosition();
386     Vector3 lightPosition = Vector3( controlPosition.x, controlPosition.y,
387                                      ( mLightFront ? 1 : -1 ) * Stage::GetCurrent().GetSize().x / 2.0f );
388
389     for( int i = 0; i < NUM_MESHES; ++i )
390     {
391       mModels[i].control.RegisterProperty( "lightPosition", lightPosition, Property::ANIMATABLE );
392     }
393   }
394
395   //If the light source is touched, move it by dragging it.
396   //If a model is touched, rotate it by panning around.
397   bool OnTouch( Actor actor, const TouchData& touch )
398   {
399     switch( touch.GetState( 0 ) )
400     {
401       case PointState::DOWN:
402       {
403         //Determine what was touched.
404         actor.GetProperty( actor.GetPropertyIndex( "Tag" ) ).Get( mTag );
405
406         if( mTag == MODEL_TAG )
407         {
408           //Find out which model has been selected
409           actor.GetProperty( actor.GetPropertyIndex( "Model" ) ).Get( mSelectedModelIndex );
410
411           //Pause current animation, as the touch gesture will be used to manually rotate the model
412           mModels[mSelectedModelIndex].rotationAnimation.Pause();
413
414           //Store start points.
415           mPanStart = touch.GetScreenPosition( 0 );
416           mRotationStart = mModels[mSelectedModelIndex].rotation;
417         }
418
419         break;
420       }
421       case PointState::MOTION:
422       {
423         //Switch on the kind of actor we're interacting with.
424         switch( mTag )
425         {
426           case MODEL_TAG: //Rotate model
427           {
428             //Calculate displacement and corresponding rotation.
429             Vector2 displacement = touch.GetScreenPosition( 0 ) - mPanStart;
430             mModels[mSelectedModelIndex].rotation = Vector2( mRotationStart.x - displacement.y / Y_ROTATION_DISPLACEMENT_FACTOR,   // Y displacement rotates around X axis
431                                                              mRotationStart.y + displacement.x / X_ROTATION_DISPLACEMENT_FACTOR ); // X displacement rotates around Y axis
432             Quaternion rotation = Quaternion( Radian( mModels[mSelectedModelIndex].rotation.x ), Vector3::XAXIS) *
433                                   Quaternion( Radian( mModels[mSelectedModelIndex].rotation.y ), Vector3::YAXIS);
434
435             //Apply rotation.
436             mModels[mSelectedModelIndex].control.SetOrientation( rotation );
437
438             break;
439           }
440           case LIGHT_TAG: //Drag light
441           {
442             //Set light source to new position and update the models accordingly.
443             mLightSource.SetPosition( Vector3( touch.GetScreenPosition( 0 ) ) );
444             UpdateLight();
445
446             break;
447           }
448         }
449
450         break;
451       }
452       case PointState::INTERRUPTED: //Same as finished.
453       case PointState::FINISHED:
454       {
455         if( mTag == MODEL_TAG )
456         {
457           //Return to automatic animation
458           if( !mPaused )
459           {
460             mModels[mSelectedModelIndex].rotationAnimation.Play();
461           }
462         }
463
464         break;
465       }
466       default:
467       {
468         //Other touch states do nothing.
469         break;
470       }
471     }
472
473     return true;
474   }
475
476   //Cycle through the list of models.
477   bool OnChangeModelClicked( Toolkit::Button button )
478   {
479     ++mModelIndex %= 3;
480
481     ReloadModel();
482
483     return true;
484   }
485
486   //Cycle through the list of shading modes.
487   bool OnChangeShadingModeClicked( Toolkit::Button button )
488   {
489     ++mShadingModeIndex %= 3;
490
491     ReloadModel();
492
493     return true;
494   }
495
496   //Pause all animations, and keep them paused even after user panning.
497   //This button is a toggle, so pressing again will start the animations again.
498   bool OnPauseClicked( Toolkit::Button button )
499   {
500     //Toggle pause state.
501     mPaused = !mPaused;
502
503     //If we wish to pause animations, do so and keep them paused.
504     if( mPaused )
505     {
506       for( int i = 0; i < NUM_MESHES ; ++i )
507       {
508         mModels[i].rotationAnimation.Pause();
509       }
510
511       button.SetProperty( Toolkit::Button::Property::LABEL, PLAY );
512     }
513     else //Unpause all animations again.
514     {
515       for( int i = 0; i < NUM_MESHES ; ++i )
516       {
517         mModels[i].rotationAnimation.Play();
518       }
519
520       button.SetProperty( Toolkit::Button::Property::LABEL, PAUSE );
521     }
522
523     return true;
524   }
525
526
527   //Switch between a fixed light source above/behind the screen, and a light source the user can drag around.
528   bool OnChangeLightModeClicked( Toolkit::Button button )
529   {
530     //Toggle state.
531     mLightFixed = !mLightFixed;
532
533     if( mLightFixed )
534     {
535       button.SetProperty( Toolkit::Button::Property::LABEL, FIXED );
536     }
537     else
538     {
539       button.SetProperty( Toolkit::Button::Property::LABEL, MANUAL );
540     }
541
542     SetLightMode();
543
544     return true;
545   }
546
547   //Switch between the light being in front of and behind the models.
548   bool OnChangeLightSideClicked( Toolkit::Button button )
549   {
550     //Toggle state.
551     mLightFront = !mLightFront;
552
553     if( mLightFront )
554     {
555       button.SetProperty( Toolkit::Button::Property::LABEL, FRONT );
556     }
557     else
558     {
559       button.SetProperty( Toolkit::Button::Property::LABEL, BACK );
560     }
561
562     //Change light image.
563     SetLightImage();
564
565     //Update light to account for the change.
566     SetLightMode();
567
568     return true;
569   }
570
571   //If escape or the back button is pressed, quit the application (and return to the launcher)
572   void OnKeyEvent( const KeyEvent& event )
573   {
574     if( event.state == KeyEvent::Down )
575     {
576       if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
577       {
578         mApplication.Quit();
579       }
580     }
581   }
582
583 private:
584   Application&  mApplication;
585
586   //The models displayed on screen, including information about rotation.
587   Model mModels[NUM_MESHES];
588   Actor mContainers[NUM_MESHES];
589
590   //Acts as a global light source, which can be dragged around.
591   Control mLightSource;
592
593   //Used to detect panning to rotate the selected model.
594   Vector2 mPanStart;
595   Vector2 mRotationStart;
596
597   int mModelIndex; //Index of model to load.
598   int mShadingModeIndex; //Index of shading mode to use.
599   int mTag; //Identifies what kind of actor has been selected in OnTouch.
600   int mSelectedModelIndex; //Index of model selected on screen.
601   bool mPaused; //If true, all animations are paused and should stay so.
602   bool mLightFixed; //If false, the light is in manual.
603   bool mLightFront; //Bool for light being in front or behind the models.
604 };
605
606 // Entry point for Linux & Tizen applications
607 //
608 int main( int argc, char **argv )
609 {
610   Application application = Application::New( &argc, &argv );
611   MeshVisualController test( application );
612   application.MainLoop();
613   return 0;
614 }