Commit d09d79b0f1b318d9b4f68d6afcc55441f4475c3b
Committed by
Gerrit Code Review
Merge "Removed model from Shadow View demo" into tizen
Showing
1 changed file
with
79 additions
and
92 deletions
examples/shadows/shadow-bone-lighting-example.cpp
| @@ -29,9 +29,6 @@ using namespace DemoHelper; | @@ -29,9 +29,6 @@ using namespace DemoHelper; | ||
| 29 | 29 | ||
| 30 | namespace | 30 | namespace |
| 31 | { | 31 | { |
| 32 | -const char* gModelFile = DALI_MODEL_DIR "AlbumCute.dae"; | ||
| 33 | -const char* gBinaryModelFile = DALI_MODEL_DIR "AlbumCute.dali-bin"; | ||
| 34 | - | ||
| 35 | const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-default.png" ); | 32 | const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-default.png" ); |
| 36 | const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); | 33 | const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); |
| 37 | 34 | ||
| @@ -42,6 +39,10 @@ const char* APPLICATION_TITLE_ROTATE_SCENE( "Lighting: Rotate Scene" ); | @@ -42,6 +39,10 @@ const char* APPLICATION_TITLE_ROTATE_SCENE( "Lighting: Rotate Scene" ); | ||
| 42 | const char* CHANGE_EFFECT_IMAGE( DALI_IMAGE_DIR "icon-change.png" ); | 39 | const char* CHANGE_EFFECT_IMAGE( DALI_IMAGE_DIR "icon-change.png" ); |
| 43 | const char* RESET_ICON( DALI_IMAGE_DIR "icon-reset.png" ); | 40 | const char* RESET_ICON( DALI_IMAGE_DIR "icon-reset.png" ); |
| 44 | 41 | ||
| 42 | +const char* SCENE_IMAGE_1( DALI_IMAGE_DIR "gallery-small-10.jpg"); | ||
| 43 | +const char* SCENE_IMAGE_2( DALI_IMAGE_DIR "gallery-small-42.jpg"); | ||
| 44 | +const char* SCENE_IMAGE_3( DALI_IMAGE_DIR "gallery-small-48.jpg"); | ||
| 45 | + | ||
| 45 | const Quaternion JAUNTY_ROTATION(Math::PI/5.0f, Math::PI/5.0f, 0.0f); // Euler angles | 46 | const Quaternion JAUNTY_ROTATION(Math::PI/5.0f, Math::PI/5.0f, 0.0f); // Euler angles |
| 46 | const float MIN_PINCH_SCALE( 0.3f ); | 47 | const float MIN_PINCH_SCALE( 0.3f ); |
| 47 | const float MAX_PINCH_SCALE( 2.05f ); | 48 | const float MAX_PINCH_SCALE( 2.05f ); |
| @@ -57,7 +58,7 @@ const Vector2 DEFAULT_STAGE_SIZE( 480.0f, 800.0f ); | @@ -57,7 +58,7 @@ const Vector2 DEFAULT_STAGE_SIZE( 480.0f, 800.0f ); | ||
| 57 | } | 58 | } |
| 58 | 59 | ||
| 59 | /** | 60 | /** |
| 60 | - * This example shows a fixed point light onto an animating model | 61 | + * This example shows a fixed point light onto an animating set of images |
| 61 | * casting a shadow onto a wall. The whole scene can be rotated. | 62 | * casting a shadow onto a wall. The whole scene can be rotated. |
| 62 | */ | 63 | */ |
| 63 | 64 | ||
| @@ -119,6 +120,21 @@ public: | @@ -119,6 +120,21 @@ public: | ||
| 119 | } | 120 | } |
| 120 | }; | 121 | }; |
| 121 | 122 | ||
| 123 | + struct RotationConstraint | ||
| 124 | + { | ||
| 125 | + RotationConstraint(float sign) | ||
| 126 | + : mSign(sign) | ||
| 127 | + { | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + Quaternion operator()( const Quaternion& current, const PropertyInput& property ) | ||
| 131 | + { | ||
| 132 | + Degree angle(property.GetFloat()); | ||
| 133 | + return Quaternion( Radian(angle) * mSign, Vector3::YAXIS ); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + float mSign; | ||
| 137 | + }; | ||
| 122 | 138 | ||
| 123 | /** | 139 | /** |
| 124 | * This method gets called once the main loop of application is up and running | 140 | * This method gets called once the main loop of application is up and running |
| @@ -129,11 +145,9 @@ public: | @@ -129,11 +145,9 @@ public: | ||
| 129 | 145 | ||
| 130 | Stage::GetCurrent().KeyEventSignal().Connect(this, &TestApp::OnKeyEvent); | 146 | Stage::GetCurrent().KeyEventSignal().Connect(this, &TestApp::OnKeyEvent); |
| 131 | 147 | ||
| 132 | - mModel = Model::New(gBinaryModelFile); // trigger model load | ||
| 133 | - mModel.LoadingFinishedSignal().Connect(this, &TestApp::BinaryModelLoaded); | ||
| 134 | - | ||
| 135 | CreateToolbarAndView(app); | 148 | CreateToolbarAndView(app); |
| 136 | CreateShadowViewAndLights(); | 149 | CreateShadowViewAndLights(); |
| 150 | + CreateScene(); | ||
| 137 | } | 151 | } |
| 138 | 152 | ||
| 139 | void CreateToolbarAndView(Application& app) | 153 | void CreateToolbarAndView(Application& app) |
| @@ -191,42 +205,7 @@ public: | @@ -191,42 +205,7 @@ public: | ||
| 191 | mTapGestureDetector.DetectedSignal().Connect(this, &TestApp::OnTap); | 205 | mTapGestureDetector.DetectedSignal().Connect(this, &TestApp::OnTap); |
| 192 | } | 206 | } |
| 193 | 207 | ||
| 194 | - /** | ||
| 195 | - * This method gets called once the model is loaded by the resource manager | ||
| 196 | - */ | ||
| 197 | - void BinaryModelLoaded(Model model) | ||
| 198 | - { | ||
| 199 | - if( model.GetLoadingState() == ResourceLoadingSucceeded ) | ||
| 200 | - { | ||
| 201 | - std::cout << "Succeeded loading binary model" << std::endl; | ||
| 202 | - | ||
| 203 | - ModelReady(); | ||
| 204 | - } | ||
| 205 | - else | ||
| 206 | - { | ||
| 207 | - std::cout << "Failed loading binary model" << std::endl; | ||
| 208 | - | ||
| 209 | - mModel = Model::New(gModelFile); | ||
| 210 | - mModel.LoadingFinishedSignal().Connect(this, &TestApp::ModelLoaded); | ||
| 211 | - } | ||
| 212 | - } | ||
| 213 | - | ||
| 214 | - void ModelLoaded(Model model) | ||
| 215 | - { | ||
| 216 | - if( model.GetLoadingState() == ResourceLoadingSucceeded ) | ||
| 217 | - { | ||
| 218 | - std::cout << "Succeeded loading collada model" << std::endl; | ||
| 219 | - | ||
| 220 | - model.Save(gBinaryModelFile); | ||
| 221 | - ModelReady(); | ||
| 222 | - } | ||
| 223 | - else | ||
| 224 | - { | ||
| 225 | - std::cout << "Failed loading collada model" << std::endl; | ||
| 226 | 208 | ||
| 227 | - mApp.Quit(); | ||
| 228 | - } | ||
| 229 | - } | ||
| 230 | 209 | ||
| 231 | void CreateShadowViewAndLights() | 210 | void CreateShadowViewAndLights() |
| 232 | { | 211 | { |
| @@ -256,7 +235,7 @@ public: | @@ -256,7 +235,7 @@ public: | ||
| 256 | mLightAnchor.SetRotation(CalculateWorldRotation(Radian(mLightLongitudinal), Radian(mLightAxisTilt))); | 235 | mLightAnchor.SetRotation(CalculateWorldRotation(Radian(mLightLongitudinal), Radian(mLightAxisTilt))); |
| 257 | 236 | ||
| 258 | // Work out a scaling factor as the initial light position was calculated for desktop | 237 | // Work out a scaling factor as the initial light position was calculated for desktop |
| 259 | - // Need to scale light position as model size is based on stage size (i.e. much bigger on device) | 238 | + // Need to scale light position as scene actor size is based on stage size (i.e. much bigger on device) |
| 260 | Vector2 stageSize( Stage::GetCurrent().GetSize() ); | 239 | Vector2 stageSize( Stage::GetCurrent().GetSize() ); |
| 261 | float scaleFactor = stageSize.x / DEFAULT_STAGE_SIZE.x; | 240 | float scaleFactor = stageSize.x / DEFAULT_STAGE_SIZE.x; |
| 262 | 241 | ||
| @@ -282,44 +261,51 @@ public: | @@ -282,44 +261,51 @@ public: | ||
| 282 | mShadowView.SetPointLight(mCastingLight); | 261 | mShadowView.SetPointLight(mCastingLight); |
| 283 | } | 262 | } |
| 284 | 263 | ||
| 285 | - void ModelReady() | 264 | + void CreateScene() |
| 286 | { | 265 | { |
| 287 | - mModelActor = ModelActorFactory::BuildActorTree(mModel, ""); // Gets root actor | 266 | + mSceneActor = Actor::New(); |
| 267 | + mSceneActor.SetParentOrigin(ParentOrigin::CENTER); | ||
| 288 | 268 | ||
| 289 | - if (mModelActor) | ||
| 290 | - { | ||
| 291 | - Vector2 stageSize(Stage::GetCurrent().GetSize()); | 269 | + // Create and add images to the scene actor: |
| 270 | + mImageActor1 = ImageActor::New( ResourceImage::New(SCENE_IMAGE_1) ); | ||
| 271 | + mImageActor2 = ImageActor::New( ResourceImage::New(SCENE_IMAGE_2) ); | ||
| 272 | + mImageActor3 = ImageActor::New( ResourceImage::New(SCENE_IMAGE_3) ); | ||
| 292 | 273 | ||
| 293 | - mModelActor.SetSize(250.0f, 250.0f); | ||
| 294 | - mModelActor.SetPosition(0.0f, 0.0f, 130.0f); | ||
| 295 | 274 | ||
| 296 | - //Create a Key light | ||
| 297 | - Light keylight = Light::New("KeyLight"); | ||
| 298 | - keylight.SetFallOff(Vector2(10000.0f, 10000.0f)); | ||
| 299 | - //keylight.SetSpecularColor(Vector3::ZERO); | ||
| 300 | - mKeyLightActor = LightActor::New(); | ||
| 301 | - mKeyLightActor.SetParentOrigin(ParentOrigin::CENTER); | ||
| 302 | - mKeyLightActor.SetName(keylight.GetName()); | 275 | + mImageActor2.SetParentOrigin(ParentOrigin::CENTER); |
| 303 | 276 | ||
| 304 | - //Add all the actors to the stage | ||
| 305 | - mCastingLight.Add(mKeyLightActor); | ||
| 306 | - mKeyLightActor.SetLight(keylight); | 277 | + mImageActor1.SetParentOrigin(ParentOrigin::CENTER_LEFT); |
| 278 | + mImageActor1.SetAnchorPoint(AnchorPoint::CENTER_RIGHT); | ||
| 307 | 279 | ||
| 308 | - mShadowView.Add(mModelActor); | 280 | + mImageActor3.SetParentOrigin(ParentOrigin::CENTER_RIGHT); |
| 281 | + mImageActor3.SetAnchorPoint(AnchorPoint::CENTER_LEFT); | ||
| 309 | 282 | ||
| 283 | + mSceneActor.Add(mImageActor2); | ||
| 284 | + mImageActor2.Add(mImageActor1); | ||
| 285 | + mImageActor2.Add(mImageActor3); | ||
| 310 | 286 | ||
| 311 | - if (mModel.NumberOfAnimations()) | ||
| 312 | - { | ||
| 313 | - mModelAnimation = ModelActorFactory::BuildAnimation(mModel, mModelActor, 0); | ||
| 314 | - mModelAnimation.SetDuration(4.0f); | ||
| 315 | - mModelAnimation.SetLooping(true); | ||
| 316 | - mModelAnimation.Play(); | ||
| 317 | - } | 287 | + Property::Index angleIndex = mImageActor2.RegisterProperty("angle", Property::Value(30.0f)); |
| 288 | + Source angleSrc( mImageActor2, angleIndex ); | ||
| 289 | + mImageActor1.ApplyConstraint(Constraint::New<Quaternion>( Actor::ROTATION, angleSrc, | ||
| 290 | + RotationConstraint(-1.0f))); | ||
| 291 | + mImageActor3.ApplyConstraint(Constraint::New<Quaternion>( Actor::ROTATION, angleSrc, | ||
| 292 | + RotationConstraint(+1.0f))); | ||
| 318 | 293 | ||
| 319 | - //StartAnimation(); | ||
| 320 | - } | 294 | + mSceneAnimation = Animation::New(2.5f); |
| 295 | + | ||
| 296 | + // Want to animate angle from 30 => -30 and back again smoothly. | ||
| 297 | + | ||
| 298 | + mSceneAnimation.AnimateTo( Property( mImageActor2, angleIndex ), Property::Value(-30.0f), AlphaFunctions::Sin ); | ||
| 299 | + | ||
| 300 | + mSceneAnimation.SetLooping(true); | ||
| 301 | + mSceneAnimation.Play(); | ||
| 302 | + | ||
| 303 | + mSceneActor.SetSize(250.0f, 250.0f); | ||
| 304 | + mSceneActor.SetPosition(0.0f, 0.0f, 130.0f); | ||
| 305 | + mShadowView.Add(mSceneActor); | ||
| 321 | } | 306 | } |
| 322 | 307 | ||
| 308 | + | ||
| 323 | Quaternion CalculateWorldRotation(Radian longitude, Radian axisTilt ) | 309 | Quaternion CalculateWorldRotation(Radian longitude, Radian axisTilt ) |
| 324 | { | 310 | { |
| 325 | Quaternion q(longitude, Vector3::YAXIS); | 311 | Quaternion q(longitude, Vector3::YAXIS); |
| @@ -329,17 +315,18 @@ public: | @@ -329,17 +315,18 @@ public: | ||
| 329 | 315 | ||
| 330 | void OnTap(Dali::Actor actor, const TapGesture& gesture) | 316 | void OnTap(Dali::Actor actor, const TapGesture& gesture) |
| 331 | { | 317 | { |
| 332 | - if( ! mPaused ) | ||
| 333 | - { | ||
| 334 | - //mAnimation.Pause(); | ||
| 335 | - mModelAnimation.Pause(); | ||
| 336 | - mPaused = true; | ||
| 337 | - } | ||
| 338 | - else | 318 | + if( mSceneAnimation ) |
| 339 | { | 319 | { |
| 340 | - //mAnimation.Play(); | ||
| 341 | - mModelAnimation.Play(); | ||
| 342 | - mPaused = false; | 320 | + if( ! mPaused ) |
| 321 | + { | ||
| 322 | + mSceneAnimation.Pause(); | ||
| 323 | + mPaused = true; | ||
| 324 | + } | ||
| 325 | + else | ||
| 326 | + { | ||
| 327 | + mSceneAnimation.Play(); | ||
| 328 | + mPaused = false; | ||
| 329 | + } | ||
| 343 | } | 330 | } |
| 344 | } | 331 | } |
| 345 | 332 | ||
| @@ -381,7 +368,7 @@ public: | @@ -381,7 +368,7 @@ public: | ||
| 381 | mObjectLongitudinal += gesture.displacement.x/4.0f; | 368 | mObjectLongitudinal += gesture.displacement.x/4.0f; |
| 382 | mObjectAxisTilt -= gesture.displacement.y/6.0f; | 369 | mObjectAxisTilt -= gesture.displacement.y/6.0f; |
| 383 | mObjectAxisTilt = Clamp<float>(mObjectAxisTilt, -90.0f, 90.0f); | 370 | mObjectAxisTilt = Clamp<float>(mObjectAxisTilt, -90.0f, 90.0f); |
| 384 | - mModelActor.SetRotation(CalculateWorldRotation(Radian(mObjectLongitudinal), Radian(mObjectAxisTilt))); | 371 | + mSceneActor.SetRotation(CalculateWorldRotation(Radian(mObjectLongitudinal), Radian(mObjectAxisTilt))); |
| 385 | break; | 372 | break; |
| 386 | } | 373 | } |
| 387 | } | 374 | } |
| @@ -410,13 +397,9 @@ public: | @@ -410,13 +397,9 @@ public: | ||
| 410 | 397 | ||
| 411 | void Terminate(Application& app) | 398 | void Terminate(Application& app) |
| 412 | { | 399 | { |
| 413 | - if( mModelActor ) | ||
| 414 | - { | ||
| 415 | - Stage::GetCurrent().Remove(mModelActor); | ||
| 416 | - } | ||
| 417 | - if( mKeyLightActor ) | 400 | + if( mSceneActor ) |
| 418 | { | 401 | { |
| 419 | - Stage::GetCurrent().Remove(mKeyLightActor); | 402 | + Stage::GetCurrent().Remove(mSceneActor); |
| 420 | } | 403 | } |
| 421 | if( mView ) | 404 | if( mView ) |
| 422 | { | 405 | { |
| @@ -473,6 +456,7 @@ public: | @@ -473,6 +456,7 @@ public: | ||
| 473 | // Reset translation | 456 | // Reset translation |
| 474 | mTranslation = Vector3::ZERO; | 457 | mTranslation = Vector3::ZERO; |
| 475 | mContents.SetPosition(mTranslation); | 458 | mContents.SetPosition(mTranslation); |
| 459 | + | ||
| 476 | // Align scene so that light anchor orientation is Z Axis | 460 | // Align scene so that light anchor orientation is Z Axis |
| 477 | mAxisTilt = -mLightAxisTilt; | 461 | mAxisTilt = -mLightAxisTilt; |
| 478 | mLongitudinal = -mLightLongitudinal; | 462 | mLongitudinal = -mLightLongitudinal; |
| @@ -485,18 +469,18 @@ private: | @@ -485,18 +469,18 @@ private: | ||
| 485 | Application& mApp; | 469 | Application& mApp; |
| 486 | Toolkit::View mView; | 470 | Toolkit::View mView; |
| 487 | Layer mContents; | 471 | Layer mContents; |
| 488 | - Model mModel; | ||
| 489 | - Actor mModelActor; | ||
| 490 | - LightActor mKeyLightActor; | 472 | + Actor mSceneActor; |
| 491 | Animation mAnimation; | 473 | Animation mAnimation; |
| 492 | - Animation mModelAnimation; | 474 | + Animation mSceneAnimation; |
| 493 | bool mPaused; | 475 | bool mPaused; |
| 494 | Toolkit::ShadowView mShadowView; | 476 | Toolkit::ShadowView mShadowView; |
| 495 | ImageActor mShadowPlaneBg; | 477 | ImageActor mShadowPlaneBg; |
| 496 | ImageActor mShadowPlane; | 478 | ImageActor mShadowPlane; |
| 497 | Actor mCastingLight; | 479 | Actor mCastingLight; |
| 498 | Actor mLightAnchor; | 480 | Actor mLightAnchor; |
| 499 | - | 481 | + ImageActor mImageActor1; |
| 482 | + ImageActor mImageActor2; | ||
| 483 | + ImageActor mImageActor3; | ||
| 500 | PanGestureDetector mPanGestureDetector; | 484 | PanGestureDetector mPanGestureDetector; |
| 501 | PinchGestureDetector mPinchGestureDetector; | 485 | PinchGestureDetector mPinchGestureDetector; |
| 502 | TapGestureDetector mTapGestureDetector; | 486 | TapGestureDetector mTapGestureDetector; |
| @@ -510,6 +494,9 @@ private: | @@ -510,6 +494,9 @@ private: | ||
| 510 | float mPinchScale; | 494 | float mPinchScale; |
| 511 | float mScaleAtPinchStart; | 495 | float mScaleAtPinchStart; |
| 512 | 496 | ||
| 497 | + Property::Index mAngle1Index; | ||
| 498 | + Property::Index mAngle3Index; | ||
| 499 | + | ||
| 513 | Toolkit::TextView mTitleActor; | 500 | Toolkit::TextView mTitleActor; |
| 514 | 501 | ||
| 515 | enum PanState | 502 | enum PanState |