From 5cfe8d9893649da47ddea1632a5625fec491d5b0 Mon Sep 17 00:00:00 2001 From: David Steele Date: Tue, 24 Feb 2015 14:47:46 +0000 Subject: [PATCH] Removed model from Shadow View demo Replaced with an animating set of images that cast a moving shadow. Change-Id: I76c61416241b542e2b5b3327a70c8e18dde3a9a2 Signed-off-by: David Steele --- examples/shadows/shadow-bone-lighting-example.cpp | 171 ++++++++++------------ 1 file changed, 79 insertions(+), 92 deletions(-) diff --git a/examples/shadows/shadow-bone-lighting-example.cpp b/examples/shadows/shadow-bone-lighting-example.cpp index 053eb65..fbacd82 100644 --- a/examples/shadows/shadow-bone-lighting-example.cpp +++ b/examples/shadows/shadow-bone-lighting-example.cpp @@ -29,9 +29,6 @@ using namespace DemoHelper; namespace { -const char* gModelFile = DALI_MODEL_DIR "AlbumCute.dae"; -const char* gBinaryModelFile = DALI_MODEL_DIR "AlbumCute.dali-bin"; - const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-default.png" ); const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); @@ -42,6 +39,10 @@ const char* APPLICATION_TITLE_ROTATE_SCENE( "Lighting: Rotate Scene" ); const char* CHANGE_EFFECT_IMAGE( DALI_IMAGE_DIR "icon-change.png" ); const char* RESET_ICON( DALI_IMAGE_DIR "icon-reset.png" ); +const char* SCENE_IMAGE_1( DALI_IMAGE_DIR "gallery-small-10.jpg"); +const char* SCENE_IMAGE_2( DALI_IMAGE_DIR "gallery-small-42.jpg"); +const char* SCENE_IMAGE_3( DALI_IMAGE_DIR "gallery-small-48.jpg"); + const Quaternion JAUNTY_ROTATION(Math::PI/5.0f, Math::PI/5.0f, 0.0f); // Euler angles const float MIN_PINCH_SCALE( 0.3f ); const float MAX_PINCH_SCALE( 2.05f ); @@ -57,7 +58,7 @@ const Vector2 DEFAULT_STAGE_SIZE( 480.0f, 800.0f ); } /** - * This example shows a fixed point light onto an animating model + * This example shows a fixed point light onto an animating set of images * casting a shadow onto a wall. The whole scene can be rotated. */ @@ -119,6 +120,21 @@ public: } }; + struct RotationConstraint + { + RotationConstraint(float sign) + : mSign(sign) + { + } + + Quaternion operator()( const Quaternion& current, const PropertyInput& property ) + { + Degree angle(property.GetFloat()); + return Quaternion( Radian(angle) * mSign, Vector3::YAXIS ); + } + + float mSign; + }; /** * This method gets called once the main loop of application is up and running @@ -129,11 +145,9 @@ public: Stage::GetCurrent().KeyEventSignal().Connect(this, &TestApp::OnKeyEvent); - mModel = Model::New(gBinaryModelFile); // trigger model load - mModel.LoadingFinishedSignal().Connect(this, &TestApp::BinaryModelLoaded); - CreateToolbarAndView(app); CreateShadowViewAndLights(); + CreateScene(); } void CreateToolbarAndView(Application& app) @@ -191,42 +205,7 @@ public: mTapGestureDetector.DetectedSignal().Connect(this, &TestApp::OnTap); } - /** - * This method gets called once the model is loaded by the resource manager - */ - void BinaryModelLoaded(Model model) - { - if( model.GetLoadingState() == ResourceLoadingSucceeded ) - { - std::cout << "Succeeded loading binary model" << std::endl; - - ModelReady(); - } - else - { - std::cout << "Failed loading binary model" << std::endl; - - mModel = Model::New(gModelFile); - mModel.LoadingFinishedSignal().Connect(this, &TestApp::ModelLoaded); - } - } - - void ModelLoaded(Model model) - { - if( model.GetLoadingState() == ResourceLoadingSucceeded ) - { - std::cout << "Succeeded loading collada model" << std::endl; - - model.Save(gBinaryModelFile); - ModelReady(); - } - else - { - std::cout << "Failed loading collada model" << std::endl; - mApp.Quit(); - } - } void CreateShadowViewAndLights() { @@ -256,7 +235,7 @@ public: mLightAnchor.SetRotation(CalculateWorldRotation(Radian(mLightLongitudinal), Radian(mLightAxisTilt))); // Work out a scaling factor as the initial light position was calculated for desktop - // Need to scale light position as model size is based on stage size (i.e. much bigger on device) + // Need to scale light position as scene actor size is based on stage size (i.e. much bigger on device) Vector2 stageSize( Stage::GetCurrent().GetSize() ); float scaleFactor = stageSize.x / DEFAULT_STAGE_SIZE.x; @@ -282,44 +261,51 @@ public: mShadowView.SetPointLight(mCastingLight); } - void ModelReady() + void CreateScene() { - mModelActor = ModelActorFactory::BuildActorTree(mModel, ""); // Gets root actor + mSceneActor = Actor::New(); + mSceneActor.SetParentOrigin(ParentOrigin::CENTER); - if (mModelActor) - { - Vector2 stageSize(Stage::GetCurrent().GetSize()); + // Create and add images to the scene actor: + mImageActor1 = ImageActor::New( ResourceImage::New(SCENE_IMAGE_1) ); + mImageActor2 = ImageActor::New( ResourceImage::New(SCENE_IMAGE_2) ); + mImageActor3 = ImageActor::New( ResourceImage::New(SCENE_IMAGE_3) ); - mModelActor.SetSize(250.0f, 250.0f); - mModelActor.SetPosition(0.0f, 0.0f, 130.0f); - //Create a Key light - Light keylight = Light::New("KeyLight"); - keylight.SetFallOff(Vector2(10000.0f, 10000.0f)); - //keylight.SetSpecularColor(Vector3::ZERO); - mKeyLightActor = LightActor::New(); - mKeyLightActor.SetParentOrigin(ParentOrigin::CENTER); - mKeyLightActor.SetName(keylight.GetName()); + mImageActor2.SetParentOrigin(ParentOrigin::CENTER); - //Add all the actors to the stage - mCastingLight.Add(mKeyLightActor); - mKeyLightActor.SetLight(keylight); + mImageActor1.SetParentOrigin(ParentOrigin::CENTER_LEFT); + mImageActor1.SetAnchorPoint(AnchorPoint::CENTER_RIGHT); - mShadowView.Add(mModelActor); + mImageActor3.SetParentOrigin(ParentOrigin::CENTER_RIGHT); + mImageActor3.SetAnchorPoint(AnchorPoint::CENTER_LEFT); + mSceneActor.Add(mImageActor2); + mImageActor2.Add(mImageActor1); + mImageActor2.Add(mImageActor3); - if (mModel.NumberOfAnimations()) - { - mModelAnimation = ModelActorFactory::BuildAnimation(mModel, mModelActor, 0); - mModelAnimation.SetDuration(4.0f); - mModelAnimation.SetLooping(true); - mModelAnimation.Play(); - } + Property::Index angleIndex = mImageActor2.RegisterProperty("angle", Property::Value(30.0f)); + Source angleSrc( mImageActor2, angleIndex ); + mImageActor1.ApplyConstraint(Constraint::New( Actor::ROTATION, angleSrc, + RotationConstraint(-1.0f))); + mImageActor3.ApplyConstraint(Constraint::New( Actor::ROTATION, angleSrc, + RotationConstraint(+1.0f))); - //StartAnimation(); - } + mSceneAnimation = Animation::New(2.5f); + + // Want to animate angle from 30 => -30 and back again smoothly. + + mSceneAnimation.AnimateTo( Property( mImageActor2, angleIndex ), Property::Value(-30.0f), AlphaFunctions::Sin ); + + mSceneAnimation.SetLooping(true); + mSceneAnimation.Play(); + + mSceneActor.SetSize(250.0f, 250.0f); + mSceneActor.SetPosition(0.0f, 0.0f, 130.0f); + mShadowView.Add(mSceneActor); } + Quaternion CalculateWorldRotation(Radian longitude, Radian axisTilt ) { Quaternion q(longitude, Vector3::YAXIS); @@ -329,17 +315,18 @@ public: void OnTap(Dali::Actor actor, const TapGesture& gesture) { - if( ! mPaused ) - { - //mAnimation.Pause(); - mModelAnimation.Pause(); - mPaused = true; - } - else + if( mSceneAnimation ) { - //mAnimation.Play(); - mModelAnimation.Play(); - mPaused = false; + if( ! mPaused ) + { + mSceneAnimation.Pause(); + mPaused = true; + } + else + { + mSceneAnimation.Play(); + mPaused = false; + } } } @@ -381,7 +368,7 @@ public: mObjectLongitudinal += gesture.displacement.x/4.0f; mObjectAxisTilt -= gesture.displacement.y/6.0f; mObjectAxisTilt = Clamp(mObjectAxisTilt, -90.0f, 90.0f); - mModelActor.SetRotation(CalculateWorldRotation(Radian(mObjectLongitudinal), Radian(mObjectAxisTilt))); + mSceneActor.SetRotation(CalculateWorldRotation(Radian(mObjectLongitudinal), Radian(mObjectAxisTilt))); break; } } @@ -410,13 +397,9 @@ public: void Terminate(Application& app) { - if( mModelActor ) - { - Stage::GetCurrent().Remove(mModelActor); - } - if( mKeyLightActor ) + if( mSceneActor ) { - Stage::GetCurrent().Remove(mKeyLightActor); + Stage::GetCurrent().Remove(mSceneActor); } if( mView ) { @@ -473,6 +456,7 @@ public: // Reset translation mTranslation = Vector3::ZERO; mContents.SetPosition(mTranslation); + // Align scene so that light anchor orientation is Z Axis mAxisTilt = -mLightAxisTilt; mLongitudinal = -mLightLongitudinal; @@ -485,18 +469,18 @@ private: Application& mApp; Toolkit::View mView; Layer mContents; - Model mModel; - Actor mModelActor; - LightActor mKeyLightActor; + Actor mSceneActor; Animation mAnimation; - Animation mModelAnimation; + Animation mSceneAnimation; bool mPaused; Toolkit::ShadowView mShadowView; ImageActor mShadowPlaneBg; ImageActor mShadowPlane; Actor mCastingLight; Actor mLightAnchor; - + ImageActor mImageActor1; + ImageActor mImageActor2; + ImageActor mImageActor3; PanGestureDetector mPanGestureDetector; PinchGestureDetector mPinchGestureDetector; TapGestureDetector mTapGestureDetector; @@ -510,6 +494,9 @@ private: float mPinchScale; float mScaleAtPinchStart; + Property::Index mAngle1Index; + Property::Index mAngle3Index; + Toolkit::TextView mTitleActor; enum PanState -- 2.7.4