Commit d09d79b0f1b318d9b4f68d6afcc55441f4475c3b

Authored by Adeel Kazmi
Committed by Gerrit Code Review
2 parents a3d1018b 5cfe8d98

Merge "Removed model from Shadow View demo" into tizen

examples/shadows/shadow-bone-lighting-example.cpp
... ... @@ -29,9 +29,6 @@ using namespace DemoHelper;
29 29  
30 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 32 const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-default.png" );
36 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 39 const char* CHANGE_EFFECT_IMAGE( DALI_IMAGE_DIR "icon-change.png" );
43 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 46 const Quaternion JAUNTY_ROTATION(Math::PI/5.0f, Math::PI/5.0f, 0.0f); // Euler angles
46 47 const float MIN_PINCH_SCALE( 0.3f );
47 48 const float MAX_PINCH_SCALE( 2.05f );
... ... @@ -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 62 * casting a shadow onto a wall. The whole scene can be rotated.
62 63 */
63 64  
... ... @@ -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 140 * This method gets called once the main loop of application is up and running
... ... @@ -129,11 +145,9 @@ public:
129 145  
130 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 148 CreateToolbarAndView(app);
136 149 CreateShadowViewAndLights();
  150 + CreateScene();
137 151 }
138 152  
139 153 void CreateToolbarAndView(Application& app)
... ... @@ -191,42 +205,7 @@ public:
191 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 210 void CreateShadowViewAndLights()
232 211 {
... ... @@ -256,7 +235,7 @@ public:
256 235 mLightAnchor.SetRotation(CalculateWorldRotation(Radian(mLightLongitudinal), Radian(mLightAxisTilt)));
257 236  
258 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 239 Vector2 stageSize( Stage::GetCurrent().GetSize() );
261 240 float scaleFactor = stageSize.x / DEFAULT_STAGE_SIZE.x;
262 241  
... ... @@ -282,44 +261,51 @@ public:
282 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 309 Quaternion CalculateWorldRotation(Radian longitude, Radian axisTilt )
324 310 {
325 311 Quaternion q(longitude, Vector3::YAXIS);
... ... @@ -329,17 +315,18 @@ public:
329 315  
330 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 368 mObjectLongitudinal += gesture.displacement.x/4.0f;
382 369 mObjectAxisTilt -= gesture.displacement.y/6.0f;
383 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 372 break;
386 373 }
387 374 }
... ... @@ -410,13 +397,9 @@ public:
410 397  
411 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 404 if( mView )
422 405 {
... ... @@ -473,6 +456,7 @@ public:
473 456 // Reset translation
474 457 mTranslation = Vector3::ZERO;
475 458 mContents.SetPosition(mTranslation);
  459 +
476 460 // Align scene so that light anchor orientation is Z Axis
477 461 mAxisTilt = -mLightAxisTilt;
478 462 mLongitudinal = -mLightLongitudinal;
... ... @@ -485,18 +469,18 @@ private:
485 469 Application& mApp;
486 470 Toolkit::View mView;
487 471 Layer mContents;
488   - Model mModel;
489   - Actor mModelActor;
490   - LightActor mKeyLightActor;
  472 + Actor mSceneActor;
491 473 Animation mAnimation;
492   - Animation mModelAnimation;
  474 + Animation mSceneAnimation;
493 475 bool mPaused;
494 476 Toolkit::ShadowView mShadowView;
495 477 ImageActor mShadowPlaneBg;
496 478 ImageActor mShadowPlane;
497 479 Actor mCastingLight;
498 480 Actor mLightAnchor;
499   -
  481 + ImageActor mImageActor1;
  482 + ImageActor mImageActor2;
  483 + ImageActor mImageActor3;
500 484 PanGestureDetector mPanGestureDetector;
501 485 PinchGestureDetector mPinchGestureDetector;
502 486 TapGestureDetector mTapGestureDetector;
... ... @@ -510,6 +494,9 @@ private:
510 494 float mPinchScale;
511 495 float mScaleAtPinchStart;
512 496  
  497 + Property::Index mAngle1Index;
  498 + Property::Index mAngle3Index;
  499 +
513 500 Toolkit::TextView mTitleActor;
514 501  
515 502 enum PanState
... ...