Commit a694ac423033ba8a50099d04b43941c5ca7d8285
1 parent
efa2b59b
Fixed the rotation interaction in the Mesh Visual example.
Change-Id: I4d4c8df78c78281e565ec9932df43a598e68a439 Signed-off-by: György Straub <g.straub@partner.samsung.com>
Showing
1 changed file
with
11 additions
and
14 deletions
examples/mesh-visual/mesh-visual-example.cpp
| @@ -9,7 +9,6 @@ namespace | @@ -9,7 +9,6 @@ namespace | ||
| 9 | struct Model | 9 | struct Model |
| 10 | { | 10 | { |
| 11 | Control control; // Control housing the mesh visual of the model. | 11 | Control control; // Control housing the mesh visual of the model. |
| 12 | - Vector2 rotation; // Keeps track of rotation about x and y axis for manual rotation. | ||
| 13 | Animation rotationAnimation; // Automatically rotates when left alone. | 12 | Animation rotationAnimation; // Automatically rotates when left alone. |
| 14 | }; | 13 | }; |
| 15 | 14 | ||
| @@ -156,8 +155,6 @@ public: | @@ -156,8 +155,6 @@ public: | ||
| 156 | 155 | ||
| 157 | //Store model information in corresponding structs. | 156 | //Store model information in corresponding structs. |
| 158 | mModels[i].control = control; | 157 | mModels[i].control = control; |
| 159 | - mModels[i].rotation.x = 0.0f; | ||
| 160 | - mModels[i].rotation.y = 0.0f; | ||
| 161 | mModels[i].rotationAnimation = rotationAnimation; | 158 | mModels[i].rotationAnimation = rotationAnimation; |
| 162 | } | 159 | } |
| 163 | 160 | ||
| @@ -403,11 +400,10 @@ public: | @@ -403,11 +400,10 @@ public: | ||
| 403 | actor.GetProperty(actor.GetPropertyIndex("Model")).Get(mSelectedModelIndex); | 400 | actor.GetProperty(actor.GetPropertyIndex("Model")).Get(mSelectedModelIndex); |
| 404 | 401 | ||
| 405 | //Pause current animation, as the touch gesture will be used to manually rotate the model | 402 | //Pause current animation, as the touch gesture will be used to manually rotate the model |
| 406 | - mModels[mSelectedModelIndex].rotationAnimation.Pause(); | 403 | + mModels[mSelectedModelIndex].rotationAnimation.Stop(); |
| 407 | 404 | ||
| 408 | //Store start points. | 405 | //Store start points. |
| 409 | - mPanStart = touch.GetScreenPosition(0); | ||
| 410 | - mRotationStart = mModels[mSelectedModelIndex].rotation; | 406 | + mLastTouchPosition = touch.GetScreenPosition(0); |
| 411 | } | 407 | } |
| 412 | 408 | ||
| 413 | break; | 409 | break; |
| @@ -420,14 +416,15 @@ public: | @@ -420,14 +416,15 @@ public: | ||
| 420 | case MODEL_TAG: //Rotate model | 416 | case MODEL_TAG: //Rotate model |
| 421 | { | 417 | { |
| 422 | //Calculate displacement and corresponding rotation. | 418 | //Calculate displacement and corresponding rotation. |
| 423 | - Vector2 displacement = touch.GetScreenPosition(0) - mPanStart; | ||
| 424 | - mModels[mSelectedModelIndex].rotation = Vector2(mRotationStart.x - displacement.y / Y_ROTATION_DISPLACEMENT_FACTOR, // Y displacement rotates around X axis | ||
| 425 | - mRotationStart.y + displacement.x / X_ROTATION_DISPLACEMENT_FACTOR); // X displacement rotates around Y axis | ||
| 426 | - Quaternion rotation = Quaternion(Radian(mModels[mSelectedModelIndex].rotation.x), Vector3::XAXIS) * | ||
| 427 | - Quaternion(Radian(mModels[mSelectedModelIndex].rotation.y), Vector3::YAXIS); | 419 | + const Vector2 touchPosition = touch.GetScreenPosition(0); |
| 420 | + const Vector2 displacement = touchPosition - mLastTouchPosition; | ||
| 421 | + mLastTouchPosition = touchPosition; | ||
| 422 | + | ||
| 423 | + const Quaternion q(Radian(displacement.y / -Y_ROTATION_DISPLACEMENT_FACTOR), Radian(displacement.x / X_ROTATION_DISPLACEMENT_FACTOR), Radian(0.f)); | ||
| 424 | + const Quaternion q0 = mModels[mSelectedModelIndex].control.GetProperty(Actor::Property::ORIENTATION).Get<Quaternion>(); | ||
| 428 | 425 | ||
| 429 | //Apply rotation. | 426 | //Apply rotation. |
| 430 | - mModels[mSelectedModelIndex].control.SetProperty(Actor::Property::ORIENTATION, rotation); | 427 | + mModels[mSelectedModelIndex].control.SetProperty(Actor::Property::ORIENTATION, q * q0); |
| 431 | 428 | ||
| 432 | break; | 429 | break; |
| 433 | } | 430 | } |
| @@ -584,7 +581,7 @@ private: | @@ -584,7 +581,7 @@ private: | ||
| 584 | Control mLightSource; | 581 | Control mLightSource; |
| 585 | 582 | ||
| 586 | //Used to detect panning to rotate the selected model. | 583 | //Used to detect panning to rotate the selected model. |
| 587 | - Vector2 mPanStart; | 584 | + Vector2 mLastTouchPosition; |
| 588 | Vector2 mRotationStart; | 585 | Vector2 mRotationStart; |
| 589 | 586 | ||
| 590 | int mModelIndex; //Index of model to load. | 587 | int mModelIndex; //Index of model to load. |
| @@ -598,7 +595,7 @@ private: | @@ -598,7 +595,7 @@ private: | ||
| 598 | 595 | ||
| 599 | int DALI_EXPORT_API main(int argc, char** argv) | 596 | int DALI_EXPORT_API main(int argc, char** argv) |
| 600 | { | 597 | { |
| 601 | - Application application = Application::New(&argc, &argv); | 598 | + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); |
| 602 | MeshVisualController test(application); | 599 | MeshVisualController test(application); |
| 603 | application.MainLoop(); | 600 | application.MainLoop(); |
| 604 | return 0; | 601 | return 0; |