X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fmesh-visual%2Fmesh-visual-example.cpp;h=682c243528f1b98592234a4b893dbdd939005fdf;hb=a832af2813558a32f0a18747f3e6134ff6f6f301;hp=8376f61c228c672927918c0ca70261a8b37573df;hpb=9c0583f85a9024bdf989764832d2adc2dcf0386e;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/mesh-visual/mesh-visual-example.cpp b/examples/mesh-visual/mesh-visual-example.cpp index 8376f61..682c243 100644 --- a/examples/mesh-visual/mesh-visual-example.cpp +++ b/examples/mesh-visual/mesh-visual-example.cpp @@ -1,70 +1,71 @@ #include -#include using namespace Dali; using namespace Dali::Toolkit; namespace { - //Keeps information about each model for access. - struct Model - { - Control control; // Control housing the mesh visual of the model. - Vector2 rotation; // Keeps track of rotation about x and y axis for manual rotation. - Animation rotationAnimation; // Automatically rotates when left alone. - }; +// Keeps information about each model for access. +struct Model +{ + Control control; // Control housing the mesh visual of the model. + Vector2 rotation; // Keeps track of rotation about x and y axis for manual rotation. + Animation rotationAnimation; // Automatically rotates when left alone. +}; - //Files for meshes - const char * const MODEL_FILE_TABLE[] = - { - DEMO_MODEL_DIR "Dino.obj", - DEMO_MODEL_DIR "ToyRobot-Metal.obj", - DEMO_MODEL_DIR "Toyrobot-Plastic.obj" - }; +// Files for meshes +const char * const MODEL_FILE_TABLE[] = +{ + DEMO_MODEL_DIR "Dino.obj", + DEMO_MODEL_DIR "ToyRobot-Metal.obj", + DEMO_MODEL_DIR "Toyrobot-Plastic.obj" +}; - const char * const MATERIAL_FILE_TABLE[] = - { - DEMO_MODEL_DIR "Dino.mtl", - DEMO_MODEL_DIR "ToyRobot-Metal.mtl", - DEMO_MODEL_DIR "Toyrobot-Plastic.mtl" - }; +const char * const MATERIAL_FILE_TABLE[] = +{ + DEMO_MODEL_DIR "Dino.mtl", + DEMO_MODEL_DIR "ToyRobot-Metal.mtl", + DEMO_MODEL_DIR "Toyrobot-Plastic.mtl" +}; - const char * const TEXTURES_PATH( DEMO_IMAGE_DIR "" ); +const char * const TEXTURES_PATH( DEMO_IMAGE_DIR "" ); - //Possible shading modes. - MeshVisual::ShadingMode::Value SHADING_MODE_TABLE[] = - { - MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING, - MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING, - MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING - }; - - //Button labels. - const char * const PAUSE = " || "; - const char * const PLAY = " > "; - const char * const FIXED = "FIXED"; - const char * const MANUAL = "MANUAL"; - const char * const FRONT = "FRONT"; - const char * const BACK = "BACK"; - - //Image urls for the light. - const char * const LIGHT_URL_FRONT = DEMO_IMAGE_DIR "light-icon-front.png"; - const char * const LIGHT_URL_BACK = DEMO_IMAGE_DIR "light-icon-back.png"; - - const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f; - const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f; - const float MODEL_SCALE = 0.75f; - const float LIGHT_SCALE = 0.15f; - const float BUTTONS_OFFSET_BOTTOM = 0.08f; - const float BUTTONS_OFFSET_SIDE = 0.2f; - const int NUM_MESHES = 2; - - //Used to identify actors. - const int MODEL_TAG = 0; - const int LIGHT_TAG = 1; - const int LAYER_TAG = 2; - -} //End namespace +// Possible shading modes. +MeshVisual::ShadingMode::Value SHADING_MODE_TABLE[] = +{ + MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING, + MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING, + MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING +}; + +// Button labels. +const char * const PAUSE = " || "; +const char * const PLAY = " > "; +const char * const FIXED = "FIXED"; +const char * const MANUAL = "MANUAL"; +const char * const FRONT = "FRONT"; +const char * const BACK = "BACK"; + +// Image urls for the light. +const char * const LIGHT_URL_FRONT = DEMO_IMAGE_DIR "light-icon-front.png"; +const char * const LIGHT_URL_BACK = DEMO_IMAGE_DIR "light-icon-back.png"; + +const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f; +const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f; +const float MODEL_SCALE = 0.75f; +const float LIGHT_SCALE = 0.15f; +const float BUTTONS_OFFSET_BOTTOM = 0.08f; +const float BUTTONS_OFFSET_SIDE = 0.2f; +const int NUM_MESHES = 2; + +// Used to identify actors. +const int MODEL_TAG = 0; +const int LIGHT_TAG = 1; +const int LAYER_TAG = 2; + +const Vector4 STAGE_COLOR( 211.0f / 255.0f, 211.0f / 255.0f, 211.0f / 255.0f, 1.0f ); ///< The color of the stage + +} // unnamed namespace class MeshVisualController : public ConnectionTracker { @@ -93,27 +94,21 @@ public: { // Get a handle to the stage Stage stage = Stage::GetCurrent(); - stage.SetBackgroundColor( Vector4( 0.0, 0.5, 1.0, 1.0 ) ); - - //Set up layer to place objects on. - Layer baseLayer = Layer::New(); - baseLayer.SetParentOrigin( ParentOrigin::CENTER ); - baseLayer.SetAnchorPoint( AnchorPoint::CENTER ); - baseLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - baseLayer.SetBehavior( Layer::LAYER_2D ); //We use a 2D layer as this is closer to UI work than full 3D scene creation. - baseLayer.SetDepthTestDisabled( false ); //Enable depth testing, as otherwise the 2D layer would not do so. - baseLayer.RegisterProperty( "Tag", LAYER_TAG ); //Used to differentiate between different kinds of actor. - baseLayer.TouchedSignal().Connect( this, &MeshVisualController::OnTouch ); - stage.Add( baseLayer ); + stage.SetBackgroundColor( STAGE_COLOR ); + + //Set up root layer to receive touch gestures. + Layer rootLayer = stage.GetRootLayer(); + rootLayer.RegisterProperty( "Tag", LAYER_TAG ); //Used to differentiate between different kinds of actor. + rootLayer.TouchSignal().Connect( this, &MeshVisualController::OnTouch ); //Place models on the scene. - SetupModels( baseLayer ); + SetupModels( rootLayer ); //Place buttons on the scene. - SetupButtons( baseLayer ); + SetupButtons( rootLayer ); //Add a light to the scene. - SetupLight( baseLayer ); + SetupLight( rootLayer ); //Allow for exiting of the application via key presses. stage.KeyEventSignal().Connect( this, &MeshVisualController::OnKeyEvent ); @@ -129,7 +124,7 @@ public: mContainers[i].SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); mContainers[i].RegisterProperty( "Tag", MODEL_TAG ); //Used to differentiate between different kinds of actor. mContainers[i].RegisterProperty( "Model", Property::Value( i ) ); //Used to index into the model. - mContainers[i].TouchedSignal().Connect( this, &MeshVisualController::OnTouch ); + mContainers[i].TouchSignal().Connect( this, &MeshVisualController::OnTouch ); layer.Add( mContainers[i] ); } @@ -189,7 +184,7 @@ public: modelButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeModelClicked ); modelButton.SetParentOrigin( ParentOrigin::TOP_CENTER ); modelButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - modelButton.SetLabelText( "Model" ); + modelButton.SetProperty( Toolkit::Button::Property::LABEL, "Model" ); positionActorModel.Add( modelButton ); //Create button for shading mode changing. @@ -198,7 +193,7 @@ public: shadingModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeShadingModeClicked ); shadingModeButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); shadingModeButton.SetAnchorPoint( AnchorPoint::TOP_CENTER ); - shadingModeButton.SetLabelText( "Shading Mode" ); + shadingModeButton.SetProperty( Toolkit::Button::Property::LABEL, "Shading Mode" ); positionActorModel.Add( shadingModeButton ); //Text label title for changing model or shading mode. @@ -215,7 +210,7 @@ public: pauseButton.ClickedSignal().Connect( this, &MeshVisualController::OnPauseClicked ); pauseButton.SetParentOrigin( Vector3( 0.5, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) ); pauseButton.SetAnchorPoint( AnchorPoint::CENTER ); - pauseButton.SetLabelText( PAUSE ); + pauseButton.SetProperty( Toolkit::Button::Property::LABEL, PAUSE ); layer.Add( pauseButton ); //Actor for positioning light position buttons. @@ -230,7 +225,7 @@ public: lightModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightModeClicked ); lightModeButton.SetParentOrigin( ParentOrigin::TOP_CENTER ); lightModeButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - lightModeButton.SetLabelText( FIXED ); + lightModeButton.SetProperty( Toolkit::Button::Property::LABEL, FIXED ); positionActorLight.Add( lightModeButton ); //Create button for switching between front and back light position. @@ -239,7 +234,7 @@ public: lightSideButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightSideClicked ); lightSideButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); lightSideButton.SetAnchorPoint( AnchorPoint::TOP_CENTER ); - lightSideButton.SetLabelText( FRONT ); + lightSideButton.SetProperty( Toolkit::Button::Property::LABEL, FRONT ); positionActorLight.Add( lightSideButton ); //Text label title for light position mode. @@ -284,7 +279,7 @@ public: SetLightImage(); //Connect to touch signal for dragging. - mLightSource.TouchedSignal().Connect( this, &MeshVisualController::OnTouch ); + mLightSource.TouchSignal().Connect( this, &MeshVisualController::OnTouch ); //Place the light source on a layer above the base, so that it is rendered above everything else. Layer upperLayer = Layer::New(); @@ -314,7 +309,7 @@ public: } Property::Map lightMap; - lightMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); + lightMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE ); lightMap.Insert( ImageVisual::Property::URL, imageUrl ); mLightSource.SetProperty( Control::Property::BACKGROUND, Property::Value( lightMap ) ); } @@ -324,7 +319,10 @@ public: { //Create mesh property map Property::Map map; - map.Insert( Visual::Property::TYPE, Visual::MESH ); + map.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH ); + map.Insert( Visual::Property::TRANSFORM, + Property::Map().Add( Visual::Transform::Property::ORIGIN, Align::CENTER ) + .Add( Visual::Transform::Property::ANCHOR_POINT, Align::CENTER ) ); map.Insert( MeshVisual::Property::OBJECT_URL, MODEL_FILE_TABLE[mModelIndex] ); map.Insert( MeshVisual::Property::MATERIAL_URL, MATERIAL_FILE_TABLE[mModelIndex] ); map.Insert( MeshVisual::Property::TEXTURES_PATH, TEXTURES_PATH ); @@ -396,14 +394,11 @@ public: //If the light source is touched, move it by dragging it. //If a model is touched, rotate it by panning around. - bool OnTouch( Actor actor, const TouchEvent& event ) + bool OnTouch( Actor actor, const TouchData& touch ) { - //Get primary touch point. - const Dali::TouchPoint& point = event.GetPoint( 0 ); - - switch( point.state ) + switch( touch.GetState( 0 ) ) { - case TouchPoint::Down: + case PointState::DOWN: { //Determine what was touched. actor.GetProperty( actor.GetPropertyIndex( "Tag" ) ).Get( mTag ); @@ -417,13 +412,13 @@ public: mModels[mSelectedModelIndex].rotationAnimation.Pause(); //Store start points. - mPanStart = point.screen; + mPanStart = touch.GetScreenPosition( 0 ); mRotationStart = mModels[mSelectedModelIndex].rotation; } break; } - case TouchPoint::Motion: + case PointState::MOTION: { //Switch on the kind of actor we're interacting with. switch( mTag ) @@ -431,7 +426,7 @@ public: case MODEL_TAG: //Rotate model { //Calculate displacement and corresponding rotation. - Vector2 displacement = point.screen - mPanStart; + Vector2 displacement = touch.GetScreenPosition( 0 ) - mPanStart; mModels[mSelectedModelIndex].rotation = Vector2( mRotationStart.x - displacement.y / Y_ROTATION_DISPLACEMENT_FACTOR, // Y displacement rotates around X axis mRotationStart.y + displacement.x / X_ROTATION_DISPLACEMENT_FACTOR ); // X displacement rotates around Y axis Quaternion rotation = Quaternion( Radian( mModels[mSelectedModelIndex].rotation.x ), Vector3::XAXIS) * @@ -445,7 +440,7 @@ public: case LIGHT_TAG: //Drag light { //Set light source to new position and update the models accordingly. - mLightSource.SetPosition( Vector3( point.screen ) ); + mLightSource.SetPosition( Vector3( touch.GetScreenPosition( 0 ) ) ); UpdateLight(); break; @@ -454,8 +449,8 @@ public: break; } - case TouchPoint::Interrupted: //Same as finished. - case TouchPoint::Finished: + case PointState::INTERRUPTED: //Same as finished. + case PointState::FINISHED: { if( mTag == MODEL_TAG ) { @@ -513,7 +508,7 @@ public: mModels[i].rotationAnimation.Pause(); } - button.SetLabelText( PLAY ); + button.SetProperty( Toolkit::Button::Property::LABEL, PLAY ); } else //Unpause all animations again. { @@ -522,7 +517,7 @@ public: mModels[i].rotationAnimation.Play(); } - button.SetLabelText( PAUSE ); + button.SetProperty( Toolkit::Button::Property::LABEL, PAUSE ); } return true; @@ -537,11 +532,11 @@ public: if( mLightFixed ) { - button.SetLabelText( FIXED ); + button.SetProperty( Toolkit::Button::Property::LABEL, FIXED ); } else { - button.SetLabelText( MANUAL ); + button.SetProperty( Toolkit::Button::Property::LABEL, MANUAL ); } SetLightMode(); @@ -557,11 +552,11 @@ public: if( mLightFront ) { - button.SetLabelText( FRONT ); + button.SetProperty( Toolkit::Button::Property::LABEL, FRONT ); } else { - button.SetLabelText( BACK ); + button.SetProperty( Toolkit::Button::Property::LABEL, BACK ); } //Change light image.