X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fmesh-visual%2Fmesh-visual-example.cpp;h=4a039df6f788dbfb08064c30d9cf7da6fd78920f;hb=5fbb9e39fabb292daf6600dfdd4c637fe52faae2;hp=b157f635c0241faae8dfc076d5beb49cbcc930fe;hpb=c5d1b737570e3f11fa961391419ffd8e88870ce4;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 b157f63..4a039df 100644 --- a/examples/mesh-visual/mesh-visual-example.cpp +++ b/examples/mesh-visual/mesh-visual-example.cpp @@ -1,58 +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[] = - { - 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[] = - { - 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 - }; +// 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"; - //Files for background and toolbar - const char * const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-1.jpg"); +// 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 int NUM_MESHES = 3; +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; +// Used to identify actors. +const int MODEL_TAG = 0; +const int LIGHT_TAG = 1; +const int LAYER_TAG = 2; -} //End namespace +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 { @@ -61,10 +74,12 @@ public: MeshVisualController( Application& application ) : mApplication( application ), //Store handle to the application. mModelIndex( 1 ), //Start with metal robot. - mShadingModeIndex( 0 ), //Start with textured with detailed specular lighting. + mShadingModeIndex( 0 ), //Start with texture and detailed specular lighting. mTag( -1 ), //Non-valid default, which will get set to a correct value when used. mSelectedModelIndex( -1 ), //Non-valid default, which will get set to a correct value when used. - mPaused( false ) //Animations play by default. + mPaused( false ), //Animations play by default. + mLightFixed( true ), //The light is fixed by default. + mLightFront( true ) //The light is in front by default. { // Connect to the Application's Init signal mApplication.InitSignal().Connect( this, &MeshVisualController::Create ); @@ -79,69 +94,51 @@ public: { // Get a handle to the stage Stage stage = Stage::GetCurrent(); + 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( rootLayer ); - //Add background - ImageView backView = ImageView::New( BACKGROUND_IMAGE ); - backView.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - stage.Add( backView ); + //Place buttons on the scene. + SetupButtons( rootLayer ); - //Setup and load the 3D models and buttons - LoadScene(); + //Add a light to the scene. + SetupLight( rootLayer ); //Allow for exiting of the application via key presses. stage.KeyEventSignal().Connect( this, &MeshVisualController::OnKeyEvent ); } - //Sets up the on-screen elements. - void LoadScene() + //Loads and adds the models to the scene, inside containers for hit detection. + void SetupModels( Layer layer ) { - Stage stage = Stage::GetCurrent(); - - //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 ); - - //Add containers to house each visual-holding-actor. + //Add containers to house each renderer-holding-actor. for( int i = 0; i < NUM_MESHES; i++ ) { mContainers[i] = Actor::New(); 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].TouchSignal().Connect( this, &MeshVisualController::OnTouch ); + layer.Add( mContainers[i] ); + } - //Position each container on screen - if( i == 0 ) - { - //Main, central model - mContainers[i].SetSizeModeFactor( Vector3( MODEL_SCALE, MODEL_SCALE, 0.0f ) ); - mContainers[i].SetParentOrigin( ParentOrigin::CENTER ); - mContainers[i].SetAnchorPoint( AnchorPoint::CENTER ); - } - else if( i == 1 ) - { - //Top left model - mContainers[i].SetSizeModeFactor( Vector3( MODEL_SCALE / 3.0f, MODEL_SCALE / 3.0f, 0.0f ) ); - mContainers[i].SetParentOrigin( Vector3( 0.05, 0.03, 0.5 ) ); //Offset from top left - mContainers[i].SetAnchorPoint( AnchorPoint::TOP_LEFT ); - } - else if( i == 2 ) - { - //Top right model - mContainers[i].SetSizeModeFactor( Vector3( MODEL_SCALE / 3.0f, MODEL_SCALE / 3.0f, 0.0f ) ); - mContainers[i].SetParentOrigin( Vector3( 0.95, 0.03, 0.5 ) ); //Offset from top right - mContainers[i].SetAnchorPoint( AnchorPoint::TOP_RIGHT ); - } + //Position each container individually on screen - mContainers[i].TouchedSignal().Connect( this, &MeshVisualController::OnTouch ); - baseLayer.Add( mContainers[i] ); - } + //Main, central model + mContainers[0].SetSizeModeFactor( Vector3( MODEL_SCALE, MODEL_SCALE, 0.0f ) ); + mContainers[0].SetParentOrigin( ParentOrigin::CENTER ); + mContainers[0].SetAnchorPoint( AnchorPoint::CENTER ); + + //Top left model + mContainers[1].SetSizeModeFactor( Vector3( MODEL_SCALE / 3.0f, MODEL_SCALE / 3.0f, 0.0f ) ); + mContainers[1].SetParentOrigin( Vector3( 0.05, 0.03, 0.5 ) ); //Offset from top left + mContainers[1].SetAnchorPoint( AnchorPoint::TOP_LEFT ); //Set up models for( int i = 0; i < NUM_MESHES; i++ ) @@ -170,70 +167,151 @@ public: //Calling this sets the model in the controls. ReloadModel(); + } - //Create button for model changing - Toolkit::PushButton modelButton = Toolkit::PushButton::New(); + //Place the various buttons on the bottom of the screen, with title labels where necessary. + void SetupButtons( Layer layer ) + { + //Actor for positioning model and shading mode buttons. + Actor positionActorModel = Actor::New(); + positionActorModel.SetParentOrigin( Vector3( BUTTONS_OFFSET_SIDE, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) ); + positionActorModel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + layer.Add( positionActorModel ); + + //Create button for model changing. + PushButton modelButton = Toolkit::PushButton::New(); modelButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); modelButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeModelClicked ); - modelButton.SetParentOrigin( Vector3( 0.05, 0.95, 0.5 ) ); //Offset from bottom left - modelButton.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT ); - modelButton.SetLabelText( "Change Model" ); - baseLayer.Add( modelButton ); - - //Create button for shader changing - Toolkit::PushButton shaderButton = Toolkit::PushButton::New(); - shaderButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - shaderButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeShaderClicked ); - shaderButton.SetParentOrigin( Vector3( 0.95, 0.95, 0.5 ) ); //Offset from bottom right - shaderButton.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT ); - shaderButton.SetLabelText( "Change Shader" ); - baseLayer.Add( shaderButton ); - - //Create button for pausing animations - Toolkit::PushButton pauseButton = Toolkit::PushButton::New(); + modelButton.SetParentOrigin( ParentOrigin::TOP_CENTER ); + modelButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + modelButton.SetProperty( Toolkit::Button::Property::LABEL, "Model" ); + positionActorModel.Add( modelButton ); + + //Create button for shading mode changing. + PushButton shadingModeButton = Toolkit::PushButton::New(); + shadingModeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + shadingModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeShadingModeClicked ); + shadingModeButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); + shadingModeButton.SetAnchorPoint( AnchorPoint::TOP_CENTER ); + shadingModeButton.SetProperty( Toolkit::Button::Property::LABEL, "Shading Mode" ); + positionActorModel.Add( shadingModeButton ); + + //Text label title for changing model or shading mode. + TextLabel changeTitleLabel = TextLabel::New( "Change" ); + changeTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + changeTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" ); + changeTitleLabel.SetParentOrigin( ParentOrigin::TOP_CENTER ); + changeTitleLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + modelButton.Add( changeTitleLabel ); + + //Create button for pausing animations. + PushButton pauseButton = Toolkit::PushButton::New(); pauseButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); pauseButton.ClickedSignal().Connect( this, &MeshVisualController::OnPauseClicked ); - pauseButton.SetParentOrigin( Vector3( 0.5, 0.95, 0.5 ) ); //Offset from bottom center - pauseButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - pauseButton.SetLabelText( " || " ); - baseLayer.Add( pauseButton ); + pauseButton.SetParentOrigin( Vector3( 0.5, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) ); + pauseButton.SetAnchorPoint( AnchorPoint::CENTER ); + pauseButton.SetProperty( Toolkit::Button::Property::LABEL, PAUSE ); + layer.Add( pauseButton ); + + //Actor for positioning light position buttons. + Actor positionActorLight = Actor::New(); + positionActorLight.SetParentOrigin( Vector3( 1.0 - BUTTONS_OFFSET_SIDE, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) ); + positionActorLight.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + layer.Add( positionActorLight ); + + //Create button for switching between manual and fixed light position. + PushButton lightModeButton = Toolkit::PushButton::New(); + lightModeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + lightModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightModeClicked ); + lightModeButton.SetParentOrigin( ParentOrigin::TOP_CENTER ); + lightModeButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + lightModeButton.SetProperty( Toolkit::Button::Property::LABEL, FIXED ); + positionActorLight.Add( lightModeButton ); + + //Create button for switching between front and back light position. + PushButton lightSideButton = Toolkit::PushButton::New(); + lightSideButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + lightSideButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightSideClicked ); + lightSideButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); + lightSideButton.SetAnchorPoint( AnchorPoint::TOP_CENTER ); + lightSideButton.SetProperty( Toolkit::Button::Property::LABEL, FRONT ); + positionActorLight.Add( lightSideButton ); + + //Text label title for light position mode. + TextLabel lightTitleLabel = TextLabel::New( "Light Position" ); + lightTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + lightTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" ); + lightTitleLabel.SetParentOrigin( ParentOrigin::TOP_CENTER ); + lightTitleLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + lightModeButton.Add( lightTitleLabel ); + } + //Add a point light source the the scene, on a layer above the first. + void SetupLight( Layer baseLayer ) + { //Create control to act as light source of scene. mLightSource = Control::New(); - mLightSource.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH ); - mLightSource.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); mLightSource.RegisterProperty( "Tag", LIGHT_TAG ); + //Set size of control based on screen dimensions. + Stage stage = Stage::GetCurrent(); + if( stage.GetSize().width < stage.GetSize().height ) + { + //Scale to width. + mLightSource.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH ); + mLightSource.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); + mLightSource.SetSizeModeFactor( Vector3( LIGHT_SCALE, 0.0f, 0.0f ) ); + } + else + { + //Scale to height. + mLightSource.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT ); + mLightSource.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::WIDTH ); + mLightSource.SetSizeModeFactor( Vector3( 0.0f, LIGHT_SCALE, 0.0f ) ); + } + //Set position relative to top left, as the light source property is also relative to the top left. mLightSource.SetParentOrigin( ParentOrigin::TOP_LEFT ); mLightSource.SetAnchorPoint( AnchorPoint::CENTER ); - mLightSource.SetPosition( Stage::GetCurrent().GetSize().x * 0.5f, Stage::GetCurrent().GetSize().y * 0.1f ); + mLightSource.SetPosition( Stage::GetCurrent().GetSize().x * 0.85f, Stage::GetCurrent().GetSize().y * 0.125 ); - //Make white background. - Property::Map lightMap; - lightMap.Insert( Visual::Property::TYPE, Visual::COLOR ); - lightMap.Insert( ColorVisual::Property::MIX_COLOR, Color::WHITE ); - mLightSource.SetProperty( Control::Property::BACKGROUND, Property::Value( lightMap ) ); - - //Label to show what this actor is for the user. - TextLabel lightLabel = TextLabel::New( "Light" ); - lightLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - lightLabel.SetParentOrigin( ParentOrigin::CENTER ); - lightLabel.SetAnchorPoint( AnchorPoint::CENTER ); - float padding = 5.0f; - lightLabel.SetPadding( Padding( padding, padding, padding, padding ) ); - mLightSource.Add( lightLabel ); + //Supply an image to represent the light. + 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(); + upperLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + upperLayer.SetParentOrigin( ParentOrigin::CENTER ); + upperLayer.SetAnchorPoint( AnchorPoint::CENTER ); + baseLayer.Add( upperLayer ); upperLayer.Add( mLightSource ); - //Calling this sets the light position of each model to that of the light source control. - UpdateLight(); + //Decide which light to use to begin with. + SetLightMode(); + } + + //Sets the image to use for the light source depending on whether the light is in front or behind. + void SetLightImage() + { + std::string imageUrl; + + if( mLightFront ) + { + imageUrl = LIGHT_URL_FRONT; + } + else + { + imageUrl = LIGHT_URL_BACK; + } + + Property::Map lightMap; + lightMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE ); + lightMap.Insert( ImageVisual::Property::URL, imageUrl ); + mLightSource.SetProperty( Control::Property::BACKGROUND, Property::Value( lightMap ) ); } //Updates the displayed models to account for parameter changes. @@ -241,12 +319,14 @@ public: { //Create mesh property map Property::Map map; - map.Insert( Visual::Property::TYPE, Visual::MESH ); - map.Insert( MeshVisual::Property::OBJECT_URL, MODEL_FILE[mModelIndex] ); - map.Insert( MeshVisual::Property::MATERIAL_URL, MATERIAL_FILE[mModelIndex] ); + 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 ); map.Insert( MeshVisual::Property::SHADING_MODE, SHADING_MODE_TABLE[mShadingModeIndex] ); - map.Insert( MeshVisual::Property::USE_SOFT_NORMALS, false ); //Set the two controls to use the mesh for( int i = 0; i < NUM_MESHES; i++ ) @@ -255,12 +335,56 @@ public: } } + //Set the mode used to light the models. + void SetLightMode() + { + if( mLightFixed ) + { + UseFixedLight(); + } + else + { + UseManualLight(); + } + } + + //Make the models use a fixed, invisible light above the center of the stage. + void UseFixedLight() + { + //Hide draggable source + mLightSource.SetVisible( false ); + + //Use stage dimensions to place light at center, offset in z axis. + Stage stage = Stage::GetCurrent(); + float width = stage.GetSize().width; + float height = stage.GetSize().height; + Vector3 lightPosition = Vector3( width / 2.0f, height / 2.0f, + ( mLightFront ? 1 : -1 ) * std::max( width, height ) * 5.0f ); + + //Set global light position + for( int i = 0; i < NUM_MESHES; ++i ) + { + mModels[i].control.RegisterProperty( "lightPosition", lightPosition, Property::ANIMATABLE ); + } + } + + //Make the models use a light source that the user can drag around. + void UseManualLight() + { + //Show draggable source + mLightSource.SetVisible( true ); + + //Update to switch light position of models to that of the source. + UpdateLight(); + } + //Updates the light position for each model to account for changes in the source on screen. void UpdateLight() { - //Set light position to the x and y of the light control, offset out of the screen. + //Set light position to the x and y of the light control, offset into/out of the screen. Vector3 controlPosition = mLightSource.GetCurrentPosition(); - Vector3 lightPosition = Vector3( controlPosition.x, controlPosition.y, Stage::GetCurrent().GetSize().x * 2.0f ); + Vector3 lightPosition = Vector3( controlPosition.x, controlPosition.y, + ( mLightFront ? 1 : -1 ) * Stage::GetCurrent().GetSize().x / 2.0f ); for( int i = 0; i < NUM_MESHES; ++i ) { @@ -270,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 ); @@ -291,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 ) @@ -305,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) * @@ -319,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; @@ -328,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 ) { @@ -362,8 +483,8 @@ public: return true; } - //Cycle through the list of shaders. - bool OnChangeShaderClicked( Toolkit::Button button ) + //Cycle through the list of shading modes. + bool OnChangeShadingModeClicked( Toolkit::Button button ) { ++mShadingModeIndex %= 3; @@ -387,7 +508,7 @@ public: mModels[i].rotationAnimation.Pause(); } - button.SetLabelText( " > " ); + button.SetProperty( Toolkit::Button::Property::LABEL, PLAY ); } else //Unpause all animations again. { @@ -396,12 +517,57 @@ public: mModels[i].rotationAnimation.Play(); } - button.SetLabelText( " || " ); + button.SetProperty( Toolkit::Button::Property::LABEL, PAUSE ); } return true; } + + //Switch between a fixed light source above/behind the screen, and a light source the user can drag around. + bool OnChangeLightModeClicked( Toolkit::Button button ) + { + //Toggle state. + mLightFixed = !mLightFixed; + + if( mLightFixed ) + { + button.SetProperty( Toolkit::Button::Property::LABEL, FIXED ); + } + else + { + button.SetProperty( Toolkit::Button::Property::LABEL, MANUAL ); + } + + SetLightMode(); + + return true; + } + + //Switch between the light being in front of and behind the models. + bool OnChangeLightSideClicked( Toolkit::Button button ) + { + //Toggle state. + mLightFront = !mLightFront; + + if( mLightFront ) + { + button.SetProperty( Toolkit::Button::Property::LABEL, FRONT ); + } + else + { + button.SetProperty( Toolkit::Button::Property::LABEL, BACK ); + } + + //Change light image. + SetLightImage(); + + //Update light to account for the change. + SetLightMode(); + + return true; + } + //If escape or the back button is pressed, quit the application (and return to the launcher) void OnKeyEvent( const KeyEvent& event ) { @@ -429,15 +595,15 @@ private: Vector2 mRotationStart; int mModelIndex; //Index of model to load. - int mShadingModeIndex; //Index of shader type to use. + int mShadingModeIndex; //Index of shading mode to use. int mTag; //Identifies what kind of actor has been selected in OnTouch. int mSelectedModelIndex; //Index of model selected on screen. bool mPaused; //If true, all animations are paused and should stay so. + bool mLightFixed; //If false, the light is in manual. + bool mLightFront; //Bool for light being in front or behind the models. }; -// Entry point for Linux & Tizen applications -// -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); MeshVisualController test( application );