Fixed the rotation interaction in the Primitive Shapes example. 54/246354/4
authorGyörgy Straub <g.straub@partner.samsung.com>
Wed, 28 Oct 2020 14:26:52 +0000 (14:26 +0000)
committerGyörgy Straub <g.straub@partner.samsung.com>
Mon, 2 Nov 2020 13:17:43 +0000 (13:17 +0000)
Change-Id: If50a69da01c02fdb6047d766d5d213648b02a360
Signed-off-by: György Straub <g.straub@partner.samsung.com>
examples/primitive-shapes/primitive-shapes-example.cpp

index 9120faf..38e08de 100644 (file)
@@ -67,8 +67,7 @@ class PrimitiveShapesController : public ConnectionTracker
 public:
   PrimitiveShapesController(Application& application)
   : mApplication(application),
-    mColor(Vector4(0.3f, 0.7f, 1.0f, 1.0f)),
-    mRotation(Vector2::ZERO)
+    mColor(Vector4(0.3f, 0.7f, 1.0f, 1.0f))
   {
     // Connect to the Application's Init signal
     mApplication.InitSignal().Connect(this, &PrimitiveShapesController::Create);
@@ -639,13 +638,13 @@ public:
       case GestureState::CONTINUING:
       {
         //Rotate based off the gesture.
-        const Vector2& displacement = gesture.GetDisplacement();
-        mRotation.x -= displacement.y / X_ROTATION_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis
-        mRotation.y += displacement.x / Y_ROTATION_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis
-        Quaternion rotation = Quaternion(Radian(mRotation.x), Vector3::XAXIS) *
-                              Quaternion(Radian(mRotation.y), Vector3::YAXIS);
+        Vector2 displacement = gesture.GetDisplacement();
+        Quaternion q0 = mModel.GetProperty(Actor::Property::ORIENTATION).Get<Quaternion>();
+        Vector2 rotation { displacement.y / X_ROTATION_DISPLACEMENT_FACTOR, // Y displacement rotates around X axis
+          displacement.x / Y_ROTATION_DISPLACEMENT_FACTOR }; // X displacement rotates around Y axis
+        Quaternion q = Quaternion(Radian(rotation.x), Radian(rotation.y), Radian(0.f));
 
-        mModel.SetProperty(Actor::Property::ORIENTATION, rotation);
+        mModel.SetProperty(Actor::Property::ORIENTATION, q * q0);
 
         break;
       }
@@ -697,12 +696,11 @@ private:
   Animation          mRotationAnimation;  ///< Automatically rotates the model, unless it is being panned.
 
   Vector4 mColor;    ///< Color to set all shapes.
-  Vector2 mRotation; ///< Keeps track of model rotation.
 };
 
 int DALI_EXPORT_API main(int argc, char** argv)
 {
-  Application               application = Application::New(&argc, &argv);
+  Application               application = Application::New(&argc, &argv, DEMO_THEME_PATH);
   PrimitiveShapesController test(application);
   application.MainLoop();
   return 0;