From 3c19df3108c8ea3d7e4d42d0203218a3bc5077f2 Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Tue, 14 Apr 2015 16:03:14 +0100 Subject: [PATCH] Cleaned up Degree, Radian, AngleAxis and Quaternion classes - Inline Degree, Radian and AngleAxis types to avoid unnecessary exports / export table lookups in using code - Change AngleAxis to store a Radian angle for better accuracy - Make Quaternion explicitly take a Radian as constructor Change-Id: I25bacfb011d4f24d60cabb53b7993dc51633b175 --- .../dali-test-suite-utils/dali-test-suite-utils.h | 4 +- automated-tests/src/dali/utc-Dali-Actor.cpp | 31 +-- automated-tests/src/dali/utc-Dali-AngleAxis.cpp | 8 +- automated-tests/src/dali/utc-Dali-Animation.cpp | 64 ++--- automated-tests/src/dali/utc-Dali-Degree.cpp | 76 +----- automated-tests/src/dali/utc-Dali-Matrix.cpp | 20 +- .../src/dali/utc-Dali-PropertyValue.cpp | 2 +- automated-tests/src/dali/utc-Dali-Quaternion.cpp | 107 ++++---- automated-tests/src/dali/utc-Dali-Radian.cpp | 35 ++- automated-tests/src/dali/utc-Dali-Vector3.cpp | 2 +- dali/integration-api/debug.cpp | 4 +- dali/internal/event/actors/actor-impl.cpp | 4 +- dali/internal/event/actors/camera-actor-impl.cpp | 2 +- dali/internal/event/animation/progress-value.h | 4 +- dali/internal/event/common/stage-impl.cpp | 14 +- .../event/events/pan-gesture-detector-impl.cpp | 13 +- .../event/events/pan-gesture-processor.cpp | 4 +- .../update/animation/scene-graph-animator.h | 8 +- .../update/manager/update-manager-debug.cpp | 9 +- dali/public-api/actors/actor.cpp | 11 - dali/public-api/actors/actor.h | 16 +- dali/public-api/animation/animation.cpp | 4 - dali/public-api/common/constants.h | 9 +- dali/public-api/file.list | 2 - dali/public-api/math/angle-axis.cpp | 46 ---- dali/public-api/math/angle-axis.h | 26 +- dali/public-api/math/degree.cpp | 54 +--- dali/public-api/math/degree.h | 125 +++++---- dali/public-api/math/quaternion.cpp | 143 ++++------ dali/public-api/math/quaternion.h | 113 ++++---- dali/public-api/math/radian.cpp | 80 ------ dali/public-api/math/radian.h | 291 +++++++++++++++++---- dali/public-api/object/property-value.cpp | 6 +- 33 files changed, 619 insertions(+), 718 deletions(-) delete mode 100644 dali/public-api/math/angle-axis.cpp delete mode 100644 dali/public-api/math/radian.cpp diff --git a/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h b/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h index 925d18a..eecabce 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h +++ b/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h @@ -140,13 +140,13 @@ inline bool CompareType(Quaternion q1, Quaternion q2, float epsilon) template <> inline bool CompareType(Radian q1, Radian q2, float epsilon) { - return CompareType(float(q1), float(q2), epsilon); + return CompareType(q1.radian, q2.radian, epsilon); } template <> inline bool CompareType(Degree q1, Degree q2, float epsilon) { - return CompareType(float(q1), float(q2), epsilon); + return CompareType(q1.degree, q2.degree, epsilon); } bool operator==(TimePeriod a, TimePeriod b); diff --git a/automated-tests/src/dali/utc-Dali-Actor.cpp b/automated-tests/src/dali/utc-Dali-Actor.cpp index d883b56..fcf2c03 100644 --- a/automated-tests/src/dali/utc-Dali-Actor.cpp +++ b/automated-tests/src/dali/utc-Dali-Actor.cpp @@ -1147,7 +1147,7 @@ int UtcDaliActorSetOrientation01(void) { TestApplication application; - Quaternion rotation(0.785f, Vector3(1.0f, 1.0f, 0.0f)); + Quaternion rotation( Radian(0.785f), Vector3(1.0f, 1.0f, 0.0f)); Actor actor = Actor::New(); actor.SetOrientation(rotation); @@ -1166,10 +1166,10 @@ int UtcDaliActorSetOrientation02(void) Actor actor = Actor::New(); - float angle = 0.785f; + Radian angle( 0.785f ); Vector3 axis(1.0f, 1.0f, 0.0f); - actor.SetOrientation(Radian( angle ), axis); + actor.SetOrientation( angle, axis); Quaternion rotation( angle, axis ); // flush the queue and render once application.SendNotification(); @@ -1181,13 +1181,13 @@ int UtcDaliActorSetOrientation02(void) DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION); actor.SetOrientation( Degree( 0 ), Vector3( 1.0f, 0.0f, 0.0f ) ); - Quaternion result( 0, Vector3( 1.0f, 0.0f, 0.0f ) ); + Quaternion result( Radian( 0 ), Vector3( 1.0f, 0.0f, 0.0f ) ); // flush the queue and render once application.SendNotification(); application.Render(); DALI_TEST_EQUALS( result, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION); - actor.SetOrientation(Radian( angle ), axis); + actor.SetOrientation( angle, axis); // flush the queue and render once application.SendNotification(); application.Render(); @@ -1204,20 +1204,20 @@ int UtcDaliActorRotateBy01(void) Actor actor = Actor::New(); - float angle = M_PI * 0.25f; - actor.RotateBy(Radian( angle ), Vector3::ZAXIS); + Radian angle( M_PI * 0.25f ); + actor.RotateBy(( angle ), Vector3::ZAXIS); // flush the queue and render once application.SendNotification(); application.Render(); - DALI_TEST_EQUALS(Quaternion(M_PI*0.25f, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION); + DALI_TEST_EQUALS(Quaternion( angle, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION); Stage::GetCurrent().Add( actor ); - actor.RotateBy(Radian( angle ), Vector3::ZAXIS); + actor.RotateBy( angle, Vector3::ZAXIS); // flush the queue and render once application.SendNotification(); application.Render(); - DALI_TEST_EQUALS(Quaternion(M_PI*0.5f, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION); + DALI_TEST_EQUALS(Quaternion(angle * 2.0f, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION); Stage::GetCurrent().Remove( actor ); END_TEST; @@ -1230,7 +1230,8 @@ int UtcDaliActorRotateBy02(void) Actor actor = Actor::New(); - Quaternion rotation(M_PI*0.25f, Vector3::ZAXIS); + Radian angle( M_PI * 0.25f ); + Quaternion rotation(angle, Vector3::ZAXIS); actor.RotateBy(rotation); // flush the queue and render once application.SendNotification(); @@ -1241,7 +1242,7 @@ int UtcDaliActorRotateBy02(void) // flush the queue and render once application.SendNotification(); application.Render(); - DALI_TEST_EQUALS(Quaternion(M_PI*0.5f, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION); + DALI_TEST_EQUALS(Quaternion(angle * 2.0f, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION); END_TEST; } @@ -1250,7 +1251,7 @@ int UtcDaliActorGetCurrentOrientation(void) TestApplication application; Actor actor = Actor::New(); - Quaternion rotation(0.785f, Vector3(1.0f, 1.0f, 0.0f)); + Quaternion rotation(Radian(0.785f), Vector3(1.0f, 1.0f, 0.0f)); actor.SetOrientation(rotation); // flush the queue and render once application.SendNotification(); @@ -1275,8 +1276,8 @@ int UtcDaliActorGetCurrentWorldOrientation(void) parent.Add( child ); // The actors should not have a world rotation yet - DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION ); + DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion(Radian(0.0f), Vector3::YAXIS), 0.001, TEST_LOCATION ); + DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), Quaternion(Radian(0.0f), Vector3::YAXIS), 0.001, TEST_LOCATION ); application.SendNotification(); application.Render(0); diff --git a/automated-tests/src/dali/utc-Dali-AngleAxis.cpp b/automated-tests/src/dali/utc-Dali-AngleAxis.cpp index 46a2c70..c4fd31a 100644 --- a/automated-tests/src/dali/utc-Dali-AngleAxis.cpp +++ b/automated-tests/src/dali/utc-Dali-AngleAxis.cpp @@ -51,7 +51,7 @@ int UtcDaliAngleAxisNew02(void) Degree d(75.0f); AngleAxis a(d, Vector3::XAXIS); - DALI_TEST_EQUALS(a.angle, d, 0.001f, TEST_LOCATION); + DALI_TEST_EQUALS(a.angle, Radian(d), 0.001f, TEST_LOCATION); DALI_TEST_EQUALS(a.axis, Vector3::XAXIS, 0.001f, TEST_LOCATION); END_TEST; } @@ -65,7 +65,7 @@ int UtcDaliAngleAxisNew03(void) AngleAxis a(r, Vector3::ZAXIS); // AngleAxis stores its angle as a degree, so should only do degree comparison. - DALI_TEST_EQUALS(a.angle, Degree(Radian(Math::PI_2)), 0.001f, TEST_LOCATION); + DALI_TEST_EQUALS(a.angle, Radian(Math::PI_2), 0.001f, TEST_LOCATION); DALI_TEST_EQUALS(a.axis, Vector3::ZAXIS, 0.001f, TEST_LOCATION); END_TEST; } @@ -80,7 +80,7 @@ int UtcDaliAngleAxisAssign(void) AngleAxis b = a; // AngleAxis stores its angle as a degree, so should only do degree comparison. - DALI_TEST_EQUALS(b.angle, Degree(Radian(Math::PI_2)), 0.001f, TEST_LOCATION); + DALI_TEST_EQUALS(b.angle, Radian(Math::PI_2), 0.001f, TEST_LOCATION); DALI_TEST_EQUALS(b.axis, Vector3::ZAXIS, 0.001f, TEST_LOCATION); END_TEST; } @@ -94,7 +94,7 @@ int UtcDaliAngleAxisCopy(void) AngleAxis b(a); // AngleAxis stores its angle as a degree, so should only do degree comparison. - DALI_TEST_EQUALS(b.angle, Degree(Radian(Math::PI_2)), 0.001f, TEST_LOCATION); + DALI_TEST_EQUALS(b.angle, Radian(Math::PI_2), 0.001f, TEST_LOCATION); DALI_TEST_EQUALS(b.axis, Vector3::ZAXIS, 0.001f, TEST_LOCATION); END_TEST; } diff --git a/automated-tests/src/dali/utc-Dali-Animation.cpp b/automated-tests/src/dali/utc-Dali-Animation.cpp index 5eddc14..698e12c 100644 --- a/automated-tests/src/dali/utc-Dali-Animation.cpp +++ b/automated-tests/src/dali/utc-Dali-Animation.cpp @@ -3455,9 +3455,9 @@ int UtcDaliAnimationAnimateByActorOrientatioN(void) TestApplication application; Actor actor = Actor::New(); - actor.SetOrientation(Quaternion(0.0f, Vector3::YAXIS)); + actor.SetOrientation( Quaternion( Dali::ANGLE_0, Vector3::YAXIS ) ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(0.0f, Vector3::YAXIS), ROTATION_EPSILON, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion( Dali::ANGLE_0, Vector3::YAXIS ), ROTATION_EPSILON, TEST_LOCATION ); // Build the animation float durationSeconds(1.0f); @@ -3512,9 +3512,9 @@ int UtcDaliAnimationAnimateByActorOrientationAlphaFunctioN(void) TestApplication application; Actor actor = Actor::New(); - actor.SetOrientation(Quaternion(0.0f, Vector3::YAXIS)); + actor.SetOrientation( Quaternion( Dali::ANGLE_0, Vector3::YAXIS ) ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(0.0f, Vector3::YAXIS), ROTATION_EPSILON, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion( Dali::ANGLE_0, Vector3::YAXIS ), ROTATION_EPSILON, TEST_LOCATION ); // Build the animation float durationSeconds(1.0f); @@ -3569,9 +3569,9 @@ int UtcDaliAnimationAnimateByActorOrientationAlphaFunctionTimePeriodP(void) TestApplication application; Actor actor = Actor::New(); - actor.SetOrientation(Quaternion(0.0f, Vector3::YAXIS)); + actor.SetOrientation( Quaternion( Dali::ANGLE_0, Vector3::YAXIS ) ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(0.0f, Vector3::YAXIS), ROTATION_EPSILON, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion( Dali::ANGLE_0, Vector3::YAXIS ), ROTATION_EPSILON, TEST_LOCATION ); // Build the animation float durationSeconds(1.0f); @@ -6038,9 +6038,9 @@ int UtcDaliAnimationAnimateToActorOrientationAngleAxisP(void) TestApplication application; Actor actor = Actor::New(); - actor.SetOrientation(Quaternion(0.0f, Vector3::YAXIS)); + actor.SetOrientation(Quaternion( Dali::ANGLE_0, Vector3::YAXIS ) ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(0.0f, Vector3::YAXIS), ROTATION_EPSILON, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion( Dali::ANGLE_0, Vector3::YAXIS ), ROTATION_EPSILON, TEST_LOCATION ); // Build the animation float durationSeconds(1.0f); @@ -6095,9 +6095,9 @@ int UtcDaliAnimationAnimateToActorOrientationQuaternioN(void) TestApplication application; Actor actor = Actor::New(); - actor.SetOrientation(Quaternion(0.0f, Vector3::YAXIS)); + actor.SetOrientation(Quaternion( Dali::ANGLE_0, Vector3::YAXIS ) ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(0.0f, Vector3::YAXIS), ROTATION_EPSILON, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion( Dali::ANGLE_0, Vector3::YAXIS ), ROTATION_EPSILON, TEST_LOCATION ); // Build the animation float durationSeconds(1.0f); @@ -6153,9 +6153,9 @@ int UtcDaliAnimationAnimateToActorOrientationAlphaFunctioN(void) TestApplication application; Actor actor = Actor::New(); - actor.SetOrientation(Quaternion(0.0f, Vector3::YAXIS)); + actor.SetOrientation(Quaternion( Dali::ANGLE_0, Vector3::YAXIS ) ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(0.0f, Vector3::YAXIS), ROTATION_EPSILON, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(0.0f), Vector3::YAXIS), ROTATION_EPSILON, TEST_LOCATION ); // Build the animation float durationSeconds(1.0f); @@ -6210,9 +6210,9 @@ int UtcDaliAnimationAnimateToActorOrientationTimePeriodP(void) TestApplication application; Actor actor = Actor::New(); - actor.SetOrientation(Quaternion(0.0f, Vector3::YAXIS)); + actor.SetOrientation(Quaternion( Dali::ANGLE_0, Vector3::YAXIS ) ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(0.0f, Vector3::YAXIS), ROTATION_EPSILON, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion( Dali::ANGLE_0, Vector3::YAXIS ), ROTATION_EPSILON, TEST_LOCATION ); // Build the animation float durationSeconds(1.0f); @@ -6271,9 +6271,9 @@ int UtcDaliAnimationAnimateToActorOrientationAlphaFunctionTimePeriodP(void) TestApplication application; Actor actor = Actor::New(); - actor.SetOrientation(Quaternion(0.0f, Vector3::YAXIS)); + actor.SetOrientation(Quaternion( Dali::ANGLE_0, Vector3::YAXIS ) ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(0.0f, Vector3::YAXIS), ROTATION_EPSILON, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion( Dali::ANGLE_0, Vector3::YAXIS ), ROTATION_EPSILON, TEST_LOCATION ); // Build the animation float durationSeconds(1.0f); @@ -7051,7 +7051,7 @@ int UtcDaliAnimationKeyFrames05P(void) try { - keyFrames.Add(0.7f, Quaternion(1.717f, Vector3::XAXIS)); + keyFrames.Add(0.7f, Quaternion(Radian(1.717f), Vector3::XAXIS)); } catch (Dali::DaliException& e) { @@ -7068,12 +7068,12 @@ int UtcDaliAnimationKeyFrames06P(void) KeyFrames keyFrames = KeyFrames::New(); DALI_TEST_EQUALS(keyFrames.GetType(), Property::NONE, TEST_LOCATION); - keyFrames.Add(0.0f, Quaternion(1.717f, Vector3::XAXIS)); - keyFrames.Add(0.2f, Quaternion(2.0f, Vector3::XAXIS)); - keyFrames.Add(0.4f, Quaternion(3.0f, Vector3::ZAXIS)); - keyFrames.Add(0.6f, Quaternion(4.0f, Vector3(1.0f, 1.0f, 1.0f))); + keyFrames.Add(0.0f, Quaternion(Radian(1.717f), Vector3::XAXIS)); + keyFrames.Add(0.2f, Quaternion(Radian(2.0f), Vector3::XAXIS)); + keyFrames.Add(0.4f, Quaternion(Radian(3.0f), Vector3::ZAXIS)); + keyFrames.Add(0.6f, Quaternion(Radian(4.0f), Vector3(1.0f, 1.0f, 1.0f))); keyFrames.Add(0.8f, AngleAxis(Degree(90), Vector3::XAXIS)); - keyFrames.Add(1.0f, Quaternion(3.0f, Vector3::YAXIS)); + keyFrames.Add(1.0f, Quaternion(Radian(3.0f), Vector3::YAXIS)); DALI_TEST_EQUALS(keyFrames.GetType(), Property::ROTATION, TEST_LOCATION); @@ -7556,7 +7556,7 @@ int UtcDaliAnimationAnimateBetweenActorOrientation01P(void) application.Render(static_cast(durationSeconds*500.0f)+1); application.SendNotification(); - Quaternion check = Quaternion::FromAxisAngle(Vector4::ZAXIS, Radian(Degree(60))); + Quaternion check( Radian(Degree(60)), Vector3::ZAXIS ); DALI_TEST_EQUALS( actor.GetCurrentOrientation(), check, 0.001f, TEST_LOCATION ); finishCheck.CheckSignalReceived(); @@ -7604,22 +7604,22 @@ int UtcDaliAnimationAnimateBetweenActorOrientation02P(void) application.Render(static_cast(durationSeconds*250.0f)/* 25% progress */); application.SendNotification(); - check = Quaternion::FromAxisAngle(Vector4::XAXIS, Radian(Degree(90))); + check = Quaternion( Radian(Degree(90)), Vector3::XAXIS ); DALI_TEST_EQUALS( actor.GetCurrentOrientation(), check, 0.001f, TEST_LOCATION ); application.Render(static_cast(durationSeconds*250.0f)/* 50% progress */); application.SendNotification(); - check = Quaternion::FromAxisAngle(Vector4::XAXIS, Radian(Degree(120))); + check = Quaternion( Radian(Degree(120)), Vector3::XAXIS ); DALI_TEST_EQUALS( actor.GetCurrentOrientation(), check, 0.001f, TEST_LOCATION ); application.Render(static_cast(durationSeconds*250.0f)/* 75% progress */); application.SendNotification(); - check = Quaternion::FromAxisAngle(Vector4(0.5f, 0.5f, 0.0f, 0.0f), Radian(Degree(101.5))); + check = Quaternion( Radian(Degree(101.5)), Vector3(0.5f, 0.5f, 0.0f) ); DALI_TEST_EQUALS( actor.GetCurrentOrientation(), check, 0.001f, TEST_LOCATION ); application.Render(static_cast(durationSeconds*250.0f)+1/* 100% progress */); application.SendNotification(); - check = Quaternion::FromAxisAngle(Vector4::YAXIS, Radian(Degree(120))); + check = Quaternion( Radian(Degree(120)), Vector3::YAXIS ); DALI_TEST_EQUALS( actor.GetCurrentOrientation(), check, 0.001f, TEST_LOCATION ); // We did expect the animation to finish @@ -7665,7 +7665,7 @@ int UtcDaliAnimationAnimateBetweenActorOrientation01CubicP(void) application.Render(static_cast(durationSeconds*500.0f)+1); application.SendNotification(); - Quaternion check = Quaternion::FromAxisAngle(Vector4::ZAXIS, Radian(Degree(60))); + Quaternion check( Radian(Degree(60)), Vector3::ZAXIS ); DALI_TEST_EQUALS( actor.GetCurrentOrientation(), check, 0.001f, TEST_LOCATION ); finishCheck.CheckSignalReceived(); @@ -7714,22 +7714,22 @@ int UtcDaliAnimationAnimateBetweenActorOrientation02CubicP(void) application.Render(static_cast(durationSeconds*250.0f)/* 25% progress */); application.SendNotification(); - check = Quaternion::FromAxisAngle(Vector4::XAXIS, Radian(Degree(90))); + check = Quaternion( Radian(Degree(90)), Vector3::XAXIS ); DALI_TEST_EQUALS( actor.GetCurrentOrientation(), check, 0.001f, TEST_LOCATION ); application.Render(static_cast(durationSeconds*250.0f)/* 50% progress */); application.SendNotification(); - check = Quaternion::FromAxisAngle(Vector4::XAXIS, Radian(Degree(120))); + check = Quaternion( Radian(Degree(120)), Vector3::XAXIS ); DALI_TEST_EQUALS( actor.GetCurrentOrientation(), check, 0.001f, TEST_LOCATION ); application.Render(static_cast(durationSeconds*250.0f)/* 75% progress */); application.SendNotification(); - check = Quaternion::FromAxisAngle(Vector4(0.5f, 0.5f, 0.0f, 0.0f), Radian(Degree(101.5))); + check = Quaternion( Radian(Degree(101.5)), Vector3(0.5f, 0.5f, 0.0f ) ); DALI_TEST_EQUALS( actor.GetCurrentOrientation(), check, 0.001f, TEST_LOCATION ); application.Render(static_cast(durationSeconds*250.0f)+1/* 100% progress */); application.SendNotification(); - check = Quaternion::FromAxisAngle(Vector4::YAXIS, Radian(Degree(120))); + check = Quaternion( Radian(Degree(120)), Vector3::YAXIS ); DALI_TEST_EQUALS( actor.GetCurrentOrientation(), check, 0.001f, TEST_LOCATION ); // We did expect the animation to finish diff --git a/automated-tests/src/dali/utc-Dali-Degree.cpp b/automated-tests/src/dali/utc-Dali-Degree.cpp index be2cbd0..5bf1f1e 100644 --- a/automated-tests/src/dali/utc-Dali-Degree.cpp +++ b/automated-tests/src/dali/utc-Dali-Degree.cpp @@ -25,22 +25,18 @@ int UtcDaliDegreeConstructors01(void) // Default constructor, does not initialise the value Degree degree0( 0.0f ); - // Test float assignment operator - degree0 = 180.0f; - DALI_TEST_EQUALS( float(degree0), 180.0f, 0.001f, TEST_LOCATION ); + // Test assignment operator + degree0 = Degree(180.0f); + DALI_TEST_EQUALS( degree0.degree, 180.0f, 0.001f, TEST_LOCATION ); // Constructor from float value Degree degree1( 180.0f ); - DALI_TEST_EQUALS( float(degree1), 180.0f, 0.001f, TEST_LOCATION ); + DALI_TEST_EQUALS( degree1.degree, 180.0f, 0.001f, TEST_LOCATION ); // Constructor from a Radian Degree degree2( Radian( Math::PI ) ); - DALI_TEST_EQUALS( float(degree2), 180.0f, 0.001f, TEST_LOCATION ); + DALI_TEST_EQUALS( degree2.degree, 180.0f, 0.001f, TEST_LOCATION ); - // Assignment from Radian - Degree degree3( 0.0f ); - degree3 = Radian( Math::PI ); - DALI_TEST_EQUALS( float(degree3), 180.0f, 0.001f, TEST_LOCATION ); END_TEST; } @@ -49,7 +45,7 @@ int UtcDaliDegreeComparison01(void) { TestApplication application; - // Comparison between radians + // Comparison between degrees Degree degree0( 90.0f ); Degree degree1( 90.0f ); Degree degree2( 180.0f ); @@ -62,43 +58,19 @@ int UtcDaliDegreeComparison01(void) Degree degree4( 90.0f ); Radian radian0( Math::PI ); - DALI_TEST_CHECK( degree3 == radian0 ); - DALI_TEST_CHECK( degree4 != radian0 ); + DALI_TEST_CHECK( degree3 == Degree(radian0) ); + DALI_TEST_CHECK( degree4 != Degree(radian0) ); // Comparison with float Degree degree5( 90.0f ); - DALI_TEST_CHECK( degree5 == 90.0f ); - DALI_TEST_CHECK( degree5 != 180.0f ); + DALI_TEST_CHECK( degree5.degree == 90.0f ); + DALI_TEST_CHECK( degree5.degree != 180.0f ); END_TEST; } - -// test case for cast operators -int UtcDaliDegreeCastOperators01(void) -{ - TestApplication application; // Exceptions require TestApplication - - Degree degree0( 180.0f ); - - const float& value0( degree0 ); - DALI_TEST_EQUALS( value0, 180.0f, 0.001f, TEST_LOCATION ); - - degree0 = 90.0f; - DALI_TEST_EQUALS( value0, 90.0f, 0.001f, TEST_LOCATION ); - - float& value1( degree0 ); - DALI_TEST_EQUALS( value1, 90.0f, 0.001f, TEST_LOCATION ); - - value1 = 180.0f; - DALI_TEST_EQUALS( float(degree0), 180.0f, 0.001f, TEST_LOCATION ); - END_TEST; -} - - - -int UtcDaliDegreeCastOperatorEquals(void) +int UtcDaliDegreeOperatorEquals(void) { TestApplication application; @@ -112,7 +84,7 @@ int UtcDaliDegreeCastOperatorEquals(void) END_TEST; } -int UtcDaliDegreeCastOperatorNotEquals(void) +int UtcDaliDegreeOperatorNotEquals(void) { TestApplication application; @@ -125,27 +97,3 @@ int UtcDaliDegreeCastOperatorNotEquals(void) DALI_TEST_EQUALS(a != c, true, TEST_LOCATION); END_TEST; } - -int UtcDaliDegreeCastOperatorLessThan(void) -{ - TestApplication application; - - Degree a(45.0f); - Degree b(90.0f); - Degree c(180.0f); - Degree d(360.0f); - Degree e(-180.0f); - - DALI_TEST_EQUALS(a < a, false, TEST_LOCATION); - DALI_TEST_EQUALS(a < b, true, TEST_LOCATION); - DALI_TEST_EQUALS(a < c, true, TEST_LOCATION); - DALI_TEST_EQUALS(a < d, true, TEST_LOCATION); - DALI_TEST_EQUALS(a < e, false, TEST_LOCATION); - - DALI_TEST_EQUALS(b < a, false, TEST_LOCATION); - DALI_TEST_EQUALS(b < b, false, TEST_LOCATION); - DALI_TEST_EQUALS(c < b, false, TEST_LOCATION); - DALI_TEST_EQUALS(d < b, false, TEST_LOCATION); - DALI_TEST_EQUALS(e < b, true, TEST_LOCATION); - END_TEST; -} diff --git a/automated-tests/src/dali/utc-Dali-Matrix.cpp b/automated-tests/src/dali/utc-Dali-Matrix.cpp index d612fbb..5146acb 100644 --- a/automated-tests/src/dali/utc-Dali-Matrix.cpp +++ b/automated-tests/src/dali/utc-Dali-Matrix.cpp @@ -92,10 +92,10 @@ int UtcDaliMatrixOrthoNormalize0(void) for (int i=0;i<1000;++i) { float f = i; - Vector4 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f), 0.0f); + Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f) ); axis.Normalize(); - m.SetTransformComponents( Vector3::ONE, Quaternion(1.0f, axis), Vector3::ZERO ); + m.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), Vector3::ZERO ); m.OrthoNormalize(); } @@ -118,13 +118,13 @@ int UtcDaliMatrixOrthoNormalize1(void) for (int i=0;i<1000;++i) { float f = i; - Vector4 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f), 0.0f); + Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f)); axis.Normalize(); Vector3 center(10.0f, 15.0f, 5.0f); Matrix m0; m0.SetIdentity(); - m0.SetTransformComponents( Vector3::ONE, Quaternion(1.0f, axis), center ); + m0.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), center ); Matrix m1(m0); m1.OrthoNormalize(); @@ -145,13 +145,13 @@ int UtcDaliMatrixInvert01(void) for (int i=0;i<1000;++i) { float f = i; - Vector4 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f), 0.0f); + Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f)); axis.Normalize(); Vector3 center(f, cosf(f) * 100.0f, cosf(f*0.5f) * 50.0f); Matrix m0; m0.SetIdentity(); - m0.SetTransformComponents( Vector3::ONE, Quaternion(1.0f, axis), center ); + m0.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), center ); Matrix m1(m0); m1.Invert(); @@ -184,13 +184,13 @@ int UtcDaliMatrixInvertTransform01(void) for (int i=0;i<1000;++i) { float f = i; - Vector4 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f), 0.0f); + Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f)); axis.Normalize(); Vector3 center(f, cosf(f) * 100.0f, cosf(f*0.5f) * 50.0f); Matrix m0; m0.SetIdentity(); - m0.SetTransformComponents( Vector3::ONE, Quaternion(1.0f, axis), center ); + m0.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), center ); Matrix m1; m0.InvertTransform(m1); @@ -635,8 +635,8 @@ int UtcDaliMatrixSetTransformComponents01(void) Matrix m1(rotation1); Matrix result1(false); - Vector4 vForward4(vForward.x, vForward.y, vForward.z, 0.0f); - result1.SetTransformComponents( Vector3::ONE, Quaternion(Radian(Degree(angle)), vForward4), Vector3::ZERO ); + Vector3 vForward3(vForward.x, vForward.y, vForward.z); + result1.SetTransformComponents( Vector3::ONE, Quaternion(Radian(Degree(angle)), vForward3), Vector3::ZERO ); DALI_TEST_EQUALS(m1, result1, 0.001, TEST_LOCATION); diff --git a/automated-tests/src/dali/utc-Dali-PropertyValue.cpp b/automated-tests/src/dali/utc-Dali-PropertyValue.cpp index c6d462f..6b2ebe3 100644 --- a/automated-tests/src/dali/utc-Dali-PropertyValue.cpp +++ b/automated-tests/src/dali/utc-Dali-PropertyValue.cpp @@ -293,7 +293,7 @@ int UtcDaliPropertyValueConstructors02(void) value = Property::Value( AngleAxis( Radian(Math::PI_2), Vector3::XAXIS )); value.Get(aa); Quaternion r8(Radian(Degree(aa.angle)), aa.axis); - DALI_TEST_EQUALS(r8, Quaternion(Math::PI_2, Vector3::XAXIS), 0.001, TEST_LOCATION); + DALI_TEST_EQUALS(r8, Quaternion(Radian(Math::PI_2), Vector3::XAXIS), 0.001, TEST_LOCATION); std::string s = "no"; value = Property::Value("yes"); diff --git a/automated-tests/src/dali/utc-Dali-Quaternion.cpp b/automated-tests/src/dali/utc-Dali-Quaternion.cpp index fbd663b..a2c48f4 100644 --- a/automated-tests/src/dali/utc-Dali-Quaternion.cpp +++ b/automated-tests/src/dali/utc-Dali-Quaternion.cpp @@ -51,10 +51,9 @@ int UtcDaliQuaternionCtor02(void) { TestApplication application; // Reset all test adapter return codes - Quaternion r(M_PI/2.0f, Vector4(1.0f, 2.0f, 3.0f, M_PI/3.0f)); + Quaternion r( Radian(Math::PI_2), Vector3( 1.0f, 2.0f, 3.0f )); // This will be normalised: - DALI_TEST_EQUALS(r.AsVector().w, 0.707f, 0.001, TEST_LOCATION); DALI_TEST_EQUALS(r.AsVector().x, 0.189f, 0.001, TEST_LOCATION); DALI_TEST_EQUALS(r.AsVector().y, 0.378f, 0.001, TEST_LOCATION); DALI_TEST_EQUALS(r.AsVector().z, 0.567f, 0.001, TEST_LOCATION); @@ -67,19 +66,19 @@ int UtcDaliQuaternionCtor03(void) TestApplication application; // Reset all test adapter return codes // Test from euler angles - Quaternion e1(Radian(Degree(45)), 0.0f, 0.0f); + Quaternion e1( Radian(Degree(45)), Radian(0.0f), Radian(0.0f) ); Vector4 r1(0.383f, 0.0f, 0.0f, 0.924f); - Quaternion e2(0.0f, Radian(Degree(75)), 0.0f); + Quaternion e2( Radian(0.0f), Radian(Degree(75)), Radian(0.0f) ); Vector4 r2(0.0f, 0.609f, 0.0f, 0.793f); - Quaternion e3(0.0f, 0.0f, Radian(Degree(135))); + Quaternion e3( Radian(0.0f), Radian(0.0f), Radian(Degree(135)) ); Vector4 r3(0.0f, 0.0f, 0.924f, 0.383f); - Quaternion e4(Radian(Degree(71)), Radian(Degree(36)), Radian(Degree(27))); + Quaternion e4(Radian(Degree(71)), Radian(Degree(36)), Radian(Degree(27)) ); Vector4 r4(0.478f, 0.374f, 0.006f, 0.795f); - Quaternion e5(Radian(Degree(-31)), Radian(Degree(-91)), Radian(Degree(-173))); + Quaternion e5(Radian(Degree(-31)), Radian(Degree(-91)), Radian(Degree(-173)) ); Vector4 r5(-0.697f, 0.145f, -0.686f, -0.149f); DALI_TEST_EQUALS(e1.AsVector(), r1, 0.001, TEST_LOCATION); @@ -91,27 +90,15 @@ int UtcDaliQuaternionCtor03(void) } -int UtcDaliQuaternionFromAxisAngle(void) -{ - TestApplication application; // Reset all test adapter return codes - - Quaternion q = Quaternion::FromAxisAngle(Vector4(1.0f, 2.0f, 3.0f, M_PI/3.0f), M_PI/2.0f); - - Quaternion r(0.707f, 0.189f, 0.378f, 0.567f); - - DALI_TEST_EQUALS(q, r, 0.001, TEST_LOCATION); - END_TEST; -} - int UtcDaliQuaternionToAxisAngle01(void) { TestApplication application; // Reset all test adapter return codes Quaternion q(0.932f, 1.1f, 3.4f, 2.7f); - float angle; + Radian angle; Vector3 axis; bool converted = q.ToAxisAngle(axis, angle); DALI_TEST_EQUALS(converted, true, TEST_LOCATION); - DALI_TEST_EQUALS(angle, 0.74f, 0.01f, TEST_LOCATION); + DALI_TEST_EQUALS(angle.radian, 0.74f, 0.01f, TEST_LOCATION); DALI_TEST_EQUALS(axis.x, 3.03f, 0.01f, TEST_LOCATION); DALI_TEST_EQUALS(axis.y, 9.38f, 0.01f, TEST_LOCATION); DALI_TEST_EQUALS(axis.z, 7.45f, 0.01f, TEST_LOCATION); @@ -122,15 +109,14 @@ int UtcDaliQuaternionToAxisAngle02(void) { TestApplication application; // Reset all test adapter return codes Quaternion q(0.932f, 1.1f, 3.4f, 2.7f); - float angle; - Vector4 axis; + Radian angle; + Vector3 axis; bool converted = q.ToAxisAngle(axis, angle); DALI_TEST_EQUALS(converted, true, TEST_LOCATION); - DALI_TEST_EQUALS(angle, 0.74f, 0.01f, TEST_LOCATION); + DALI_TEST_EQUALS(angle.radian, 0.74f, 0.01f, TEST_LOCATION); DALI_TEST_EQUALS(axis.x, 3.03f, 0.01f, TEST_LOCATION); DALI_TEST_EQUALS(axis.y, 9.38f, 0.01f, TEST_LOCATION); DALI_TEST_EQUALS(axis.z, 7.45f, 0.01f, TEST_LOCATION); - DALI_TEST_EQUALS(axis.w, 0.0f, 0.01f, TEST_LOCATION); END_TEST; } @@ -139,11 +125,11 @@ int UtcDaliQuaternionToAxisAngle03(void) { TestApplication application; // Reset all test adapter return codes Quaternion q(1, 2, 3, 4); - float angle; + Radian angle; Vector3 axis; bool converted = q.ToAxisAngle(axis, angle); DALI_TEST_EQUALS(converted, false, TEST_LOCATION); - DALI_TEST_EQUALS(angle, 0.0f, 0.01f, TEST_LOCATION); + DALI_TEST_EQUALS(angle.radian, 0.0f, 0.01f, TEST_LOCATION); DALI_TEST_EQUALS(axis.x, 0.0f, 0.01f, TEST_LOCATION); DALI_TEST_EQUALS(axis.y, 0.0f, 0.01f, TEST_LOCATION); DALI_TEST_EQUALS(axis.z, 0.0f, 0.01f, TEST_LOCATION); @@ -154,15 +140,14 @@ int UtcDaliQuaternionToAxisAngle04(void) { TestApplication application; // Reset all test adapter return codes Quaternion q(1, 2, 3, 4); - float angle; - Vector4 axis; + Radian angle; + Vector3 axis; bool converted = q.ToAxisAngle(axis, angle); DALI_TEST_EQUALS(converted, false, TEST_LOCATION); - DALI_TEST_EQUALS(angle, 0.0f, 0.01f, TEST_LOCATION); + DALI_TEST_EQUALS(angle.radian, 0.0f, 0.01f, TEST_LOCATION); DALI_TEST_EQUALS(axis.x, 0.0f, 0.01f, TEST_LOCATION); DALI_TEST_EQUALS(axis.y, 0.0f, 0.01f, TEST_LOCATION); DALI_TEST_EQUALS(axis.z, 0.0f, 0.01f, TEST_LOCATION); - DALI_TEST_EQUALS(axis.w, 0.0f, 0.01f, TEST_LOCATION); END_TEST; } @@ -200,7 +185,7 @@ int UtcDaliQuaternionToMatrix01(void) { TestApplication application; // Reset all test adapter return codes - Quaternion q(0.69813, Vector4(1.0f, 0.0f, 0.0f, 0.0f)); // 40 degree rotation around X axis + Quaternion q( Radian(0.69813), Vector3(1.0f, 0.0f, 0.0f) ); // 40 degree rotation around X axis // Result calculated using a different maths library (with appropriate row/col ordering) @@ -220,7 +205,7 @@ int UtcDaliQuaternionToMatrix02(void) TestApplication application; // Reset all test adapter return codes // rotation around arbitrary axis - Quaternion q2(-1.23918f, Vector4(7.0f, -13.0f, 11.0f, 0.0f)); + Quaternion q2( Radian(-1.23918f), Vector3(7.0f, -13.0f, 11.0f) ); float els[] = { 0.423f, -0.746f, -0.514f, 0.00f, 0.384f, 0.662f, -0.644f, 0.00f, @@ -775,7 +760,7 @@ int UtcDaliQuaternionExp03(void) { TestApplication app; - Quaternion q(0.0f, Vector3(5.0f, 6.0f, 7.0f)); + Quaternion q( Radian( 0.0f ), Vector3(5.0f, 6.0f, 7.0f) ); // q.w is non-zero. Should assert. try @@ -794,7 +779,7 @@ int UtcDaliQuaternionExp03(void) int UtcDaliQuaternionLog01(void) { TestApplication application; // Reset all test adapter return codes - Quaternion q(Math::PI*0.73f, Vector3(2,3,4)); + Quaternion q( Radian( Math::PI*0.73f ), Vector3(2,3,4) ); Quaternion q2 = q; q2.Normalize(); @@ -848,8 +833,8 @@ int UtcDaliQuaternionSlerp01(void) { TestApplication application; - Quaternion q1(M_PI/4.0f, Vector4(0.0f, 0.0f, 1.0f, 0.0f)); - Quaternion q2(-M_PI/4.0f, Vector4(0.0f, 0.0f, 1.0f, 0.0f)); + Quaternion q1(Radian(M_PI/4.0f), Vector3(0.0f, 0.0f, 1.0f)); + Quaternion q2(Radian(-M_PI/4.0f), Vector3(0.0f, 0.0f, 1.0f)); Quaternion q = Quaternion::Slerp(q1, q2, 0.0f); DALI_TEST_EQUALS(q, q1, 0.001, TEST_LOCATION); @@ -859,11 +844,11 @@ int UtcDaliQuaternionSlerp01(void) // @ 25%, will be at M_PI/8 q = Quaternion::Slerp(q1, q2, 0.25f); - Vector4 axis; - float angle; + Vector3 axis; + Radian angle; bool converted = q.ToAxisAngle(axis, angle); DALI_TEST_EQUALS(converted, true, TEST_LOCATION); - DALI_TEST_EQUALS(angle, Math::PI/8.0f, 0.001, TEST_LOCATION); + DALI_TEST_EQUALS(angle.radian, Math::PI/8.0f, 0.001, TEST_LOCATION); DALI_TEST_EQUALS(axis.x, 0.0f, 0.001, TEST_LOCATION); DALI_TEST_EQUALS(axis.y, 0.0f, 0.001, TEST_LOCATION); DALI_TEST_EQUALS(axis.z, 1.0f, 0.001, TEST_LOCATION); @@ -876,8 +861,8 @@ int UtcDaliQuaternionSlerp02(void) { TestApplication application; - Quaternion q1(M_PI/6, Vector3(0.0f, 0.0f, 1.0f)); - Quaternion q2(M_PI/2, Vector3(0.0f, 0.0f, 1.0f)); + Quaternion q1( Dali::ANGLE_30, Vector3(0.0f, 0.0f, 1.0f)); + Quaternion q2( Dali::ANGLE_90, Vector3(0.0f, 0.0f, 1.0f)); Quaternion q = Quaternion::Slerp(q1, q2, 0.0f); @@ -890,7 +875,7 @@ int UtcDaliQuaternionSlerp02(void) // @ 50%, will be at M_PI/3 around z q = Quaternion::Slerp(q1, q2, 0.5f); - Quaternion r( M_PI/3, Vector3( 0.0f, 0.0f, 1.0f)); + Quaternion r( Dali::ANGLE_120, Vector3( 0.0f, 0.0f, 1.0f)); DALI_TEST_EQUALS( q, r, 0.001, TEST_LOCATION ); END_TEST; } @@ -910,8 +895,8 @@ int UtcDaliQuaternionSlerp03(void) DALI_TEST_EQUALS(q, q2, 0.001, TEST_LOCATION); q = Quaternion::Slerp(q1, q2, 0.05f); - Vector4 axis; - float angle; + Vector3 axis; + Radian angle; bool converted = q.ToAxisAngle(axis, angle); DALI_TEST_EQUALS(converted, true, TEST_LOCATION); @@ -937,11 +922,11 @@ int UtcDaliQuaternionSlerp04(void) DALI_TEST_EQUALS(q, q2, 0.001, TEST_LOCATION); q = Quaternion::Slerp(q1, q2, 0.5f); - Vector4 axis; - float angle; + Vector3 axis; + Radian angle; bool converted = q.ToAxisAngle(axis, angle); DALI_TEST_EQUALS(converted, true, TEST_LOCATION); - DALI_TEST_EQUALS(angle, float(Radian(Degree(125))), 0.01f, TEST_LOCATION); + DALI_TEST_EQUALS(angle.radian, float(Radian(Degree(125))), 0.01f, TEST_LOCATION); DALI_TEST_EQUALS(axis.x, 0.0f, 0.01, TEST_LOCATION); DALI_TEST_EQUALS(axis.y, 0.0f, 0.01, TEST_LOCATION); DALI_TEST_EQUALS(axis.z, 1.0f, 0.01, TEST_LOCATION); @@ -954,8 +939,8 @@ int UtcDaliQuaternionSlerpNoInvert01(void) { TestApplication application; - Quaternion q1(M_PI/4.0f, Vector4(0.0f, 0.0f, 1.0f, 0.0f)); - Quaternion q2(-M_PI/4.0f, Vector4(0.0f, 0.0f, 1.0f, 0.0f)); + Quaternion q1( Dali::ANGLE_45, Vector3(0.0f, 0.0f, 1.0f)); + Quaternion q2(-Dali::ANGLE_45, Vector3(0.0f, 0.0f, 1.0f)); Quaternion q = Quaternion::SlerpNoInvert(q1, q2, 0.0f); DALI_TEST_EQUALS(q, q1, 0.001, TEST_LOCATION); @@ -965,11 +950,11 @@ int UtcDaliQuaternionSlerpNoInvert01(void) // @ 25%, will be at M_PI/8 q = Quaternion::SlerpNoInvert(q1, q2, 0.25f); - Vector4 axis; - float angle; + Vector3 axis; + Radian angle; bool converted = q.ToAxisAngle(axis, angle); DALI_TEST_EQUALS(converted, true, TEST_LOCATION); - DALI_TEST_EQUALS(angle, Math::PI/8.0f, 0.001, TEST_LOCATION); + DALI_TEST_EQUALS(angle.radian, Math::PI/8.0f, 0.001, TEST_LOCATION); DALI_TEST_EQUALS(axis.x, 0.0f, 0.001, TEST_LOCATION); DALI_TEST_EQUALS(axis.y, 0.0f, 0.001, TEST_LOCATION); DALI_TEST_EQUALS(axis.z, 1.0f, 0.001, TEST_LOCATION); @@ -991,11 +976,11 @@ int UtcDaliQuaternionSlerpNoInvert02(void) DALI_TEST_EQUALS(q, q2, 0.001, TEST_LOCATION); q = Quaternion::SlerpNoInvert(q1, q2, 0.5f); - Vector4 axis; - float angle; + Vector3 axis; + Radian angle; bool converted = q.ToAxisAngle(axis, angle); DALI_TEST_EQUALS(converted, true, TEST_LOCATION); - DALI_TEST_EQUALS(angle, float(Radian(Degree(125))), 0.01f, TEST_LOCATION); + DALI_TEST_EQUALS(angle.radian, float(Radian(Degree(125))), 0.01f, TEST_LOCATION); DALI_TEST_EQUALS(axis.x, 0.0f, 0.01, TEST_LOCATION); DALI_TEST_EQUALS(axis.y, 0.0f, 0.01, TEST_LOCATION); DALI_TEST_EQUALS(axis.z, 1.0f, 0.01, TEST_LOCATION); @@ -1019,7 +1004,7 @@ int UtcDaliQuaternionSquad(void) // Don't know what actual value should be, but can make some informed guesses. q = Quaternion::Squad(q1, q2, q1out, q2in, 0.5f); - float angle; + Radian angle; Vector3 axis; q.Normalize(); q.ToAxisAngle(axis, angle); @@ -1029,7 +1014,7 @@ int UtcDaliQuaternionSquad(void) q = -q; // Might get negative quat q.ToAxisAngle(axis, angle); } - float deg = Degree(Radian(angle)); + float deg = Degree(angle).degree; DALI_TEST_CHECK(deg >= 0 && deg <= 90); DALI_TEST_CHECK(axis.y > 0); DALI_TEST_CHECK(axis.z > 0); @@ -1040,8 +1025,8 @@ int UtcDaliAngleBetween(void) { TestApplication application; // Reset all test adapter return codes - Quaternion q1(Radian(Degree(45)), 0.0f, 0.0f); - Quaternion q2(Radian(Degree(47)), 0.0f, 0.0f); + Quaternion q1( ANGLE_45, ANGLE_0, ANGLE_0 ); + Quaternion q2(Radian(Degree(47)), ANGLE_0, ANGLE_0 ); DALI_TEST_EQUALS(Quaternion::AngleBetween(q1, q2), fabsf(Radian(Degree(45)) - Radian(Degree(47))), 0.001f, TEST_LOCATION); Quaternion q3(Radian(Degree(80)), Vector3::YAXIS); @@ -1080,7 +1065,7 @@ int UtcDaliQuaternionOStreamOperator(void) std::ostringstream oss; - Quaternion quaternion(M_PI, Vector3::YAXIS); + Quaternion quaternion( Dali::ANGLE_180, Vector3::YAXIS ); oss << quaternion; diff --git a/automated-tests/src/dali/utc-Dali-Radian.cpp b/automated-tests/src/dali/utc-Dali-Radian.cpp index c463a4c..b869fd1 100644 --- a/automated-tests/src/dali/utc-Dali-Radian.cpp +++ b/automated-tests/src/dali/utc-Dali-Radian.cpp @@ -63,8 +63,8 @@ int UtcDaliRadianComparison01(void) Radian radian4( Math::PI_2 ); Degree degree0( 180.0f ); - DALI_TEST_CHECK( radian3 == degree0 ); - DALI_TEST_CHECK( radian4 != degree0 ); + DALI_TEST_CHECK( radian3 == Radian(degree0) ); + DALI_TEST_CHECK( radian4 != Radian(degree0) ); // Comparison with float Radian radian5( Math::PI_2 ); @@ -83,16 +83,16 @@ int UtcDaliRadianCastOperators01(void) Radian radian0( Math::PI ); - const float& value0( radian0 ); + const float& value0( radian0.radian ); DALI_TEST_EQUALS( value0, Math::PI, 0.001f, TEST_LOCATION ); radian0 = Math::PI_2; DALI_TEST_EQUALS( value0, Math::PI_2, 0.001f, TEST_LOCATION ); - float& value1( radian0 ); + float value1( radian0 ); DALI_TEST_EQUALS( value1, Math::PI_2, 0.001f, TEST_LOCATION ); - value1 = Math::PI; + radian0 = Math::PI; DALI_TEST_EQUALS( float(radian0), Math::PI, 0.001f, TEST_LOCATION ); END_TEST; } @@ -106,9 +106,10 @@ int UtcDaliRadianCastOperatorEquals(void) Radian b(Math::PI_2); Radian c(Math::PI); - DALI_TEST_EQUALS(a == a, true, TEST_LOCATION); - DALI_TEST_EQUALS(a == b, true, TEST_LOCATION); - DALI_TEST_EQUALS(a == c, false, TEST_LOCATION); + DALI_TEST_EQUALS( a == a, true, TEST_LOCATION ); + DALI_TEST_EQUALS( a == b, true, TEST_LOCATION ); + DALI_TEST_EQUALS( a == c, false, TEST_LOCATION ); + DALI_TEST_EQUALS( Degree(c) == c, true, TEST_LOCATION ); END_TEST; } @@ -120,9 +121,10 @@ int UtcDaliRadianCastOperatorNotEquals(void) Radian b(Math::PI_2); Radian c(Math::PI); - DALI_TEST_EQUALS(a != a, false, TEST_LOCATION); - DALI_TEST_EQUALS(a != b, false, TEST_LOCATION); - DALI_TEST_EQUALS(a != c, true, TEST_LOCATION); + DALI_TEST_EQUALS( a != a, false, TEST_LOCATION ); + DALI_TEST_EQUALS( a != b, false, TEST_LOCATION ); + DALI_TEST_EQUALS( a != c, true, TEST_LOCATION ); + DALI_TEST_EQUALS( Degree(a) != c, true, TEST_LOCATION ); END_TEST; } @@ -148,8 +150,13 @@ int UtcDaliRadianCastOperatorLessThan(void) DALI_TEST_EQUALS(d < b, false, TEST_LOCATION); DALI_TEST_EQUALS(e < b, true, TEST_LOCATION); - DALI_TEST_EQUALS(Radian(Math::PI_2) < Degree(180.0f), true, TEST_LOCATION); - DALI_TEST_EQUALS(Radian(Math::PI_2) < Degree(90.0f), false, TEST_LOCATION); - DALI_TEST_EQUALS(Radian(Math::PI_2) < Degree(45.0f), false, TEST_LOCATION); + DALI_TEST_EQUALS( Radian(Math::PI_2) < Degree(180.0f), true, TEST_LOCATION); + DALI_TEST_EQUALS( Radian(Math::PI_2) < Degree(90.0f), false, TEST_LOCATION); + DALI_TEST_EQUALS( Radian(Math::PI_2) > Degree(45.0f), true, TEST_LOCATION); + + DALI_TEST_EQUALS( Degree(180.0f) > Radian(Math::PI_2), true, TEST_LOCATION); + DALI_TEST_EQUALS( Degree(90.0f) > Radian(Math::PI_2), false, TEST_LOCATION); + DALI_TEST_EQUALS( Degree(45.0f) < Radian(Math::PI_2), true, TEST_LOCATION); + END_TEST; } diff --git a/automated-tests/src/dali/utc-Dali-Vector3.cpp b/automated-tests/src/dali/utc-Dali-Vector3.cpp index 68b99bf..09ec357 100644 --- a/automated-tests/src/dali/utc-Dali-Vector3.cpp +++ b/automated-tests/src/dali/utc-Dali-Vector3.cpp @@ -487,7 +487,7 @@ int UtcDaliVector3Rotate(void) TestApplication application; Vector3 vec3(Vector3::YAXIS); - Quaternion rotation(Math::PI_2, Vector3::ZAXIS); + Quaternion rotation( Dali::ANGLE_90, Vector3::ZAXIS ); Vector3 result(-Vector3::XAXIS); vec3 *= rotation; DALI_TEST_EQUALS( vec3, result, 0.001, TEST_LOCATION ); diff --git a/dali/integration-api/debug.cpp b/dali/integration-api/debug.cpp index 8d4d60f..1185139 100644 --- a/dali/integration-api/debug.cpp +++ b/dali/integration-api/debug.cpp @@ -299,11 +299,11 @@ std::string QuaternionToString(const Quaternion& q, size_t precision, size_t ind std::ostringstream oss; Vector3 axis; - float angle; + Radian angle; q.ToAxisAngle(axis, angle); oss << std::setw(indent+3) << std::setfill(' ') << std::setprecision(precision) << std::right; - oss << ""; + oss << ""; return oss.str(); } diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index ccb920a..edbc52d 100644 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -839,10 +839,10 @@ PositionInheritanceMode Actor::GetPositionInheritanceMode() const void Actor::SetOrientation( const Radian& angle, const Vector3& axis ) { - Vector4 normalizedAxis( axis.x, axis.y, axis.z, 0.0f ); + Vector3 normalizedAxis( axis.x, axis.y, axis.z ); normalizedAxis.Normalize(); - Quaternion orientation( Quaternion::FromAxisAngle( normalizedAxis, angle ) ); + Quaternion orientation( angle, normalizedAxis ); SetOrientation( orientation ); } diff --git a/dali/internal/event/actors/camera-actor-impl.cpp b/dali/internal/event/actors/camera-actor-impl.cpp index 8201a17..fb40a16 100644 --- a/dali/internal/event/actors/camera-actor-impl.cpp +++ b/dali/internal/event/actors/camera-actor-impl.cpp @@ -155,7 +155,7 @@ CameraActorPtr CameraActor::New( const Size& size ) // By default Actors face in the positive Z direction in world space // CameraActors should face in the negative Z direction, towards the other actors - actor->SetOrientation( Quaternion( Math::PI, Vector3::YAXIS ) ); + actor->SetOrientation( Quaternion( Dali::ANGLE_180, Vector3::YAXIS ) ); return actor; } diff --git a/dali/internal/event/animation/progress-value.h b/dali/internal/event/animation/progress-value.h index 30b6877..1022e61 100644 --- a/dali/internal/event/animation/progress-value.h +++ b/dali/internal/event/animation/progress-value.h @@ -93,8 +93,8 @@ inline void Interpolate (Quaternion& result, const Quaternion& a, const Quaterni inline void Interpolate (AngleAxis& result, const AngleAxis& a, const AngleAxis& b, float progress) { - Quaternion q1(Radian(a.angle), a.axis); - Quaternion q2(Radian(b.angle), b.axis); + Quaternion q1(a.angle, a.axis); + Quaternion q2(b.angle, b.axis); Quaternion iq = Quaternion::Slerp(q1, q2, progress); iq.ToAxisAngle(result.axis, result.angle); diff --git a/dali/internal/event/common/stage-impl.cpp b/dali/internal/event/common/stage-impl.cpp index feb8ac8..9c9d6d7 100644 --- a/dali/internal/event/common/stage-impl.cpp +++ b/dali/internal/event/common/stage-impl.cpp @@ -291,7 +291,7 @@ void Stage::SetViewMode( ViewMode viewMode ) if( mViewMode == MONO ) { - mDefaultCamera->SetOrientation( Degree( 180.0f ), Vector3::YAXIS ); + mDefaultCamera->SetOrientation( Dali::ANGLE_180, Vector3::YAXIS ); mRenderTaskList->GetTask(0).SetSourceActor( Dali::Actor() ); //Create camera and RenderTask for left eye @@ -329,8 +329,7 @@ void Stage::SetViewMode( ViewMode viewMode ) mDefaultCamera->Remove( *mRightCamera.Get() ); mRightRenderTask.Reset(); mRightCamera.Reset(); - - mDefaultCamera->SetOrientation( Degree( 0.0f ), Vector3::YAXIS ); + mDefaultCamera->SetOrientation( Dali::ANGLE_0, Vector3::YAXIS ); mDefaultCamera->SetType( Dali::Camera::LOOK_AT_TARGET ); mRenderTaskList->GetTask(0).SetSourceActor( Dali::Layer(mRootLayer.Get()) ); @@ -349,13 +348,14 @@ void Stage::SetViewMode( ViewMode viewMode ) mLeftCamera->SetPerspectiveProjection( mSize, Vector2( 0.0f,stereoBase) ); mLeftCamera->SetAspectRatio( aspect ); - mLeftCamera->SetOrientation( Degree(-90.0f), Vector3::ZAXIS ); + + mLeftCamera->SetOrientation( -Dali::ANGLE_90, Vector3::ZAXIS ); mLeftCamera->SetPosition( Vector3( stereoBase, 0.0f, 0.0f ) ); mLeftRenderTask.SetViewport( Viewport(0, mSize.height * 0.5f, mSize.width, mSize.height * 0.5f) ); mRightCamera->SetPerspectiveProjection( mSize, Vector2( 0.0, -stereoBase) ); mRightCamera->SetAspectRatio( aspect ); - mRightCamera->SetOrientation( Degree(-90.0f), Vector3::ZAXIS ); + mRightCamera->SetOrientation( -Dali::ANGLE_90, Vector3::ZAXIS ); mRightCamera->SetPosition( Vector3(-stereoBase, 0.0f, 0.0f ) ); mRightRenderTask.SetViewport( Viewport(0, 0, mSize.width, mSize.height * 0.5f ) ); @@ -371,13 +371,13 @@ void Stage::SetViewMode( ViewMode viewMode ) mLeftCamera->SetPerspectiveProjection( Size( mSize.x * 0.5f, mSize.y ), Vector2(stereoBase,0.0f) ); mLeftCamera->SetFieldOfView( fov ); - mLeftCamera->SetOrientation( Degree(0.0f), Vector3::ZAXIS ); + mLeftCamera->SetOrientation( Dali::ANGLE_0, Vector3::ZAXIS ); mLeftCamera->SetPosition( Vector3( stereoBase, 0.0f, 0.0f ) ); mLeftRenderTask.SetViewport( Viewport(0, 0, mSize.width * 0.5f, mSize.height ) ); mRightCamera->SetPerspectiveProjection( Size( mSize.x * 0.5f, mSize.y ), Vector2(-stereoBase,0.0f) ); mRightCamera->SetFieldOfView( fov ); - mRightCamera->SetOrientation( Degree(0.0f), Vector3::ZAXIS ); + mRightCamera->SetOrientation( Dali::ANGLE_0, Vector3::ZAXIS ); mRightCamera->SetPosition( Vector3( -stereoBase, 0.0f, 0.0f ) ); mRightRenderTask.SetViewport( Viewport(mSize.width * 0.5f, 0, mSize.width * 0.5f, mSize.height ) ); diff --git a/dali/internal/event/events/pan-gesture-detector-impl.cpp b/dali/internal/event/events/pan-gesture-detector-impl.cpp index bf1e38c..7c114d2 100644 --- a/dali/internal/event/events/pan-gesture-detector-impl.cpp +++ b/dali/internal/event/events/pan-gesture-detector-impl.cpp @@ -70,15 +70,6 @@ SignalConnectorType signalConnector1( mType, SIGNAL_PAN_DETECTED, &PanGestureDet #if defined(DEBUG_ENABLED) Integration::Log::Filter* gLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_PAN_GESTURE_DETECTOR"); - -/** - * When debugging, helper for converting radians to degrees. - */ -inline float RadiansToDegrees( float radian ) -{ - return radian * 180.0f / Math::PI; -} - #endif /** @@ -180,7 +171,7 @@ void PanGestureDetector::AddAngle( Radian angle, Radian threshold ) angle = WrapInDomain( angle, -Math::PI, Math::PI ); - DALI_LOG_INFO( gLogFilter, Debug::Concise, "Angle Added: %.2f, Threshold: %.2f\n", RadiansToDegrees(angle), RadiansToDegrees(threshold) ); + DALI_LOG_INFO( gLogFilter, Debug::Concise, "Angle Added: %.2f, Threshold: %.2f\n", Degree(angle), Degree(threshold) ); AngleThresholdPair pair( angle, threshold ); mAngleContainer.push_back( pair ); @@ -252,7 +243,7 @@ bool PanGestureDetector::CheckAngleAllowed( Radian angle ) const DALI_LOG_INFO( gLogFilter, Debug::General, "AngleToCheck: %.2f, CompareWith: %.2f, Threshold: %.2f\n", - RadiansToDegrees(angle), RadiansToDegrees(angleAllowed), RadiansToDegrees(threshold) ); + Degree(angle.radian), Degree(angleAllowed), Degree(threshold) ); float relativeAngle( fabsf( WrapInDomain( angle - angleAllowed, -Math::PI, Math::PI ) ) ); if ( relativeAngle <= threshold ) diff --git a/dali/internal/event/events/pan-gesture-processor.cpp b/dali/internal/event/events/pan-gesture-processor.cpp index 441fb7d..e3cbcc2 100644 --- a/dali/internal/event/events/pan-gesture-processor.cpp +++ b/dali/internal/event/events/pan-gesture-processor.cpp @@ -521,12 +521,12 @@ bool PanGestureProcessor::CheckGestureDetector( GestureDetector* detector, Actor if ( displacement.y >= 0.0f ) { // Quadrant 2 - angle += Math::PI; + angle.radian += Math::PI; } else { // Quadrant 3 - angle -= Math::PI; + angle.radian -= Math::PI; } } diff --git a/dali/internal/update/animation/scene-graph-animator.h b/dali/internal/update/animation/scene-graph-animator.h index b8d5f58..68326c5 100644 --- a/dali/internal/update/animation/scene-graph-animator.h +++ b/dali/internal/update/animation/scene-graph-animator.h @@ -638,8 +638,8 @@ struct AnimateToBoolean : public AnimatorFunctionBase struct RotateByAngleAxis : public AnimatorFunctionBase { RotateByAngleAxis(const Radian& angleRadians, const Vector3& axis) - : mAngleRadians(angleRadians), - mAxis(axis.x, axis.y, axis.z, 0.0f) + : mAngleRadians( angleRadians ), + mAxis(axis.x, axis.y, axis.z) { } @@ -653,8 +653,8 @@ struct RotateByAngleAxis : public AnimatorFunctionBase return rotation; } - float mAngleRadians; - Vector4 mAxis; + Radian mAngleRadians; + Vector3 mAxis; }; struct RotateToQuaternion : public AnimatorFunctionBase diff --git a/dali/internal/update/manager/update-manager-debug.cpp b/dali/internal/update/manager/update-manager-debug.cpp index 44326ca..1c21fe4 100644 --- a/dali/internal/update/manager/update-manager-debug.cpp +++ b/dali/internal/update/manager/update-manager-debug.cpp @@ -54,9 +54,8 @@ void PrintNodes( const Node& node, BufferIndex updateBufferIndex, int level ) const Vector3& fullPos = node.GetWorldPosition(updateBufferIndex); const Quaternion& rotation = node.GetOrientation(updateBufferIndex); Vector3 axis; - float angle; + Radian angle; rotation.ToAxisAngle(axis, angle); - angle = angle * 180.0f / Math::PI; std::string nodeName= DALI_LOG_GET_OBJECT_STRING((&node)); @@ -68,9 +67,9 @@ void PrintNodes( const Node& node, BufferIndex updateBufferIndex, int level ) oss << std::setprecision(2) << std::setiosflags(mask) << std::setw(level*2) << std::setfill(' ') << ""; oss << "Node " << nodeName << " " << &node - << " Pos (" << position.x << ", " << position.y << ", " << position.z << ")" - << " FullPos (" << fullPos.x << ", " << fullPos.y << ", " << fullPos.z << ")" - << " Rot (" << angle << "deg <" << axis.x << ", " << axis.y << ", " << axis.z << ">)" + << " Position (" << position.x << ", " << position.y << ", " << position.z << ")" + << " WorldPosition (" << fullPos.x << ", " << fullPos.y << ", " << fullPos.z << ")" + << " Orientation (" << Degree(angle).degree << "degrees <" << axis.x << ", " << axis.y << ", " << axis.z << ">)" << " Scale (" << scale.x << ", " << scale.y << ", " << scale.z << ")" << std::endl; diff --git a/dali/public-api/actors/actor.cpp b/dali/public-api/actors/actor.cpp index 1b31452..335be73 100644 --- a/dali/public-api/actors/actor.cpp +++ b/dali/public-api/actors/actor.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -260,11 +259,6 @@ PositionInheritanceMode Actor::GetPositionInheritanceMode() const return GetImplementation(*this).GetPositionInheritanceMode(); } -void Actor::SetOrientation(const Degree& angle, const Vector3& axis) -{ - GetImplementation(*this).SetOrientation(Radian(angle), axis); -} - void Actor::SetOrientation(const Radian& angle, const Vector3& axis) { GetImplementation(*this).SetOrientation(angle, axis); @@ -275,11 +269,6 @@ void Actor::SetOrientation(const Quaternion& orientation) GetImplementation(*this).SetOrientation(orientation); } -void Actor::RotateBy(const Degree& angle, const Vector3& axis) -{ - GetImplementation(*this).RotateBy(Radian(angle), axis); -} - void Actor::RotateBy(const Radian& angle, const Vector3& axis) { GetImplementation(*this).RotateBy(angle, axis); diff --git a/dali/public-api/actors/actor.h b/dali/public-api/actors/actor.h index 9373414..5c35143 100644 --- a/dali/public-api/actors/actor.h +++ b/dali/public-api/actors/actor.h @@ -2,7 +2,7 @@ #define __DALI_ACTOR_H__ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -38,12 +39,9 @@ class Actor; } class Actor; -class Animation; -class Constraint; struct Degree; class Quaternion; class Layer; -struct Radian; struct KeyEvent; struct TouchEvent; struct HoverEvent; @@ -762,7 +760,10 @@ public: * @param [in] angle The new orientation angle in degrees. * @param [in] axis The new axis of orientation. */ - void SetOrientation(const Degree& angle, const Vector3& axis); + void SetOrientation( const Degree& angle, const Vector3& axis ) + { + SetOrientation( Radian( angle ), axis ); + } /** * @brief Sets the orientation of the Actor. @@ -792,7 +793,10 @@ public: * @param[in] angle The angle to the rotation to combine with the existing orientation. * @param[in] axis The axis of the rotation to combine with the existing orientation. */ - void RotateBy(const Degree& angle, const Vector3& axis); + void RotateBy( const Degree& angle, const Vector3& axis ) + { + RotateBy( Radian( angle ), axis ); + } /** * @brief Apply a relative rotation to an actor. diff --git a/dali/public-api/animation/animation.cpp b/dali/public-api/animation/animation.cpp index 9b9bdaa..251929e 100644 --- a/dali/public-api/animation/animation.cpp +++ b/dali/public-api/animation/animation.cpp @@ -21,10 +21,6 @@ // INTERNAL INCLUDES #include #include -#include -#include -#include -#include #include #include #include diff --git a/dali/public-api/common/constants.h b/dali/public-api/common/constants.h index 2f98174..52e082e 100644 --- a/dali/public-api/common/constants.h +++ b/dali/public-api/common/constants.h @@ -24,7 +24,6 @@ // INTERNAL INCLUDES #include #include -#include namespace Dali { @@ -117,9 +116,11 @@ DALI_IMPORT_API extern const float MACHINE_EPSILON_1000; ///< Epsilon for valu DALI_IMPORT_API extern const float MACHINE_EPSILON_10000; ///< Epsilon for values near 10000 // float is preferred to double for performance on ARM targets -static const float PI = static_cast(M_PI); ///< Constant representing PI -static const float PI_2 = static_cast(M_PI_2); ///< Constant representing PI/2 -static const float PI_4 = static_cast(M_PI_4); ///< Constant representing PI/4 +static const float PI = static_cast(M_PI); ///< Constant representing PI +static const float PI_2 = static_cast(M_PI_2); ///< Constant representing PI/2 +static const float PI_4 = static_cast(M_PI_4); ///< Constant representing PI/4 +static const float PI_OVER_180 = Dali::Math::PI/180.0f; ///< Constant used to convert degree to radian +static const float ONE80_OVER_PI = 180.0f/Dali::Math::PI; ///< Constant used to convert radian to degree } // namespace Math diff --git a/dali/public-api/file.list b/dali/public-api/file.list index e2040a9..2c14ec6 100644 --- a/dali/public-api/file.list +++ b/dali/public-api/file.list @@ -64,13 +64,11 @@ public_api_src_files = \ $(public_api_src_dir)/images/nine-patch-image.cpp \ $(public_api_src_dir)/images/resource-image.cpp \ $(public_api_src_dir)/images/native-image.cpp \ - $(public_api_src_dir)/math/angle-axis.cpp \ $(public_api_src_dir)/math/compile-time-math.cpp \ $(public_api_src_dir)/math/degree.cpp \ $(public_api_src_dir)/math/matrix.cpp \ $(public_api_src_dir)/math/matrix3.cpp \ $(public_api_src_dir)/math/quaternion.cpp \ - $(public_api_src_dir)/math/radian.cpp \ $(public_api_src_dir)/math/vector2.cpp \ $(public_api_src_dir)/math/vector3.cpp \ $(public_api_src_dir)/math/vector4.cpp \ diff --git a/dali/public-api/math/angle-axis.cpp b/dali/public-api/math/angle-axis.cpp deleted file mode 100644 index 26f813b..0000000 --- a/dali/public-api/math/angle-axis.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// CLASS HEADER -#include - -// INTERNAL INCLUDES -#include - -namespace Dali -{ - -AngleAxis::AngleAxis() -: angle(0.0f), - axis(0.0f, 0.0f, 0.0f) -{ -} - -AngleAxis::AngleAxis( Degree initialAngle, Vector3 initialAxis ) -: angle( initialAngle ), - axis( initialAxis ) -{ -} - -AngleAxis::AngleAxis( Radian initialAngle, Vector3 initialAxis ) -: angle( initialAngle ), - axis( initialAxis ) -{ -} - - -} // namespace Dali diff --git a/dali/public-api/math/angle-axis.h b/dali/public-api/math/angle-axis.h index 245fc05..c41ad53 100644 --- a/dali/public-api/math/angle-axis.h +++ b/dali/public-api/math/angle-axis.h @@ -2,7 +2,7 @@ #define __DALI_ANGLE_AXIS_H__ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ // INTERNAL INCLUDES #include +#include #include namespace Dali @@ -33,13 +34,15 @@ struct Radian; * This is slightly easier to understand than quaternions for handling rotations * of objects. Both elements should be non-zero to correctly describe a rotation. */ -struct DALI_IMPORT_API AngleAxis +struct AngleAxis { /** * @brief Create an angle-axis pair. - * */ - AngleAxis(); + AngleAxis() + : angle(0.0f), + axis(0.0f, 0.0f, 0.0f) + { } /** * @brief Create an angle-axis pair. @@ -47,7 +50,10 @@ struct DALI_IMPORT_API AngleAxis * @param[in] initialAngle The initial angle in degrees. * @param[in] initialAxis The initial axis. */ - AngleAxis( Degree initialAngle, Vector3 initialAxis ); + AngleAxis( Degree initialAngle, Vector3 initialAxis ) + : angle( initialAngle ), + axis( initialAxis ) + { } /** * @brief Create an angle-axis pair. @@ -55,12 +61,18 @@ struct DALI_IMPORT_API AngleAxis * @param[in] initialAngle The initial angle in radians. * @param[in] initialAxis The initial axis. */ - AngleAxis( Radian initialAngle, Vector3 initialAxis ); + AngleAxis( Radian initialAngle, Vector3 initialAxis ) + : angle( initialAngle ), + axis( initialAxis ) + { } - Degree angle; ///< The angle in degrees + Radian angle; ///< The angle in radians Vector3 axis; ///< The axis + }; +// compiler generated destructor, copy constructor and assignment operators are ok as this class is POD + } // namespace Dali #endif // __DALI_ANGLE_AXIS_H__ diff --git a/dali/public-api/math/degree.cpp b/dali/public-api/math/degree.cpp index 1e7d5ae..3e56ea3 100644 --- a/dali/public-api/math/degree.cpp +++ b/dali/public-api/math/degree.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,62 +19,14 @@ #include // INTERNAL INCLUDES -#include #include -namespace -{ -const float ONE80_OVER_PI = 180.0f/Dali::Math::PI; -} - namespace Dali { -Degree::Degree( float value ) -: mValue( value ) -{ -} - -Degree::Degree( const Radian& radian ) -: mValue( radian * ONE80_OVER_PI ) -{ -} - -bool Degree::operator==( const Degree& rhs ) const -{ - return fabsf( mValue - rhs.mValue ) < GetRangedEpsilon( mValue, rhs.mValue ); -} - -bool Degree::operator!=( const Degree& rhs ) const -{ - return !(this->operator==(rhs)); -} - -bool Degree::operator<( const Degree& rhs ) const -{ - return mValue < rhs.mValue; -} - -Degree& Degree::operator=( const float value ) -{ - mValue = value; - return *this; -} - -Degree& Degree::operator=( const Radian& rhs ) -{ - mValue = rhs * ONE80_OVER_PI; - return *this; -} - -Degree::operator const float&() const -{ - return mValue; -} - -Degree::operator float&() +Degree::Degree( Radian radian ) +: degree( radian * Math::ONE80_OVER_PI ) { - return mValue; } } // namespace Dali diff --git a/dali/public-api/math/degree.h b/dali/public-api/math/degree.h index 4a9f1b8..5cec5f1 100644 --- a/dali/public-api/math/degree.h +++ b/dali/public-api/math/degree.h @@ -2,7 +2,7 @@ #define __DALI_DEGREE_H__ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,13 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES +#include #include +#include namespace Dali { @@ -31,81 +36,87 @@ struct Radian; * * This reduces ambiguity when using methods which accept angles in degrees or radians. */ -struct DALI_IMPORT_API Degree +struct Degree { /** - * @brief Create an angle in degrees. - * - * @param[in] value The initial value in degrees. + * @brief default constructor, initialises to 0. */ - explicit Degree( float value ); + Degree() + : degree( 0.f ) + { } /** - * @brief Create an angle in degrees from an angle in radians. + * @brief Create an angle in degrees. * - * @param[in] value The initial value in radians. + * @param[in] value The initial value in degrees. */ - Degree( const Radian& value ); + explicit Degree( float value ) + : degree( value ) + { } /** - * @brief Compare equality between two degrees. + * @brief Create an angle in degrees from a Radian. * - * @param[in] rhs Degree to compare to - * @return true if the value is identical + * @param[in] value The initial value in Radians. */ - bool operator==( const Degree& rhs ) const; + DALI_EXPORT_API Degree( Radian value ); - /** - * @brief Compare inequality between two degrees. - * - * @param[in] rhs Degree to compare to - * @return true if the value is not identical - */ - bool operator!=( const Degree& rhs ) const; +public: - /** - * @brief Compare two degrees. - * - * @param[in] rhs Degree to compare to - * @return true if this is less than the value - */ - bool operator<( const Degree& rhs ) const; + // member data + float degree; ///< The value in degrees - /** - * @brief Assign an angle from a float value. - * - * @param[in] value Float value in degrees - * @return a reference to this - */ - Degree& operator=( const float value ); +}; - /** - * @brief Assign an angle in radians to a Degree. - * - * @param[in] rhs Radian to get the value from - * @return a reference to this - */ - Degree& operator=( const Radian& rhs ); +// compiler generated destructor, copy constructor and assignment operators are ok as this class is POD - /** - * @brief Cast operator to const float reference - */ - operator const float&() const; +/** + * @brief Compare equality between two degrees. + * + * @param[in] lhs Degree to compare + * @param[in] rhs Degree to compare to + * @return true if the values are identical + */ +inline bool operator==( const Degree& lhs, const Degree& rhs ) +{ + return fabsf( lhs.degree - rhs.degree ) < Math::MACHINE_EPSILON_1000; // expect degree angles to be between 0 and 1000 +} - /** - * @brief Cast operator to float reference. - */ - operator float&(); +/** + * @brief Compare inequality between two degrees. + * + * @param[in] lhs Degree to compare + * @param[in] rhs Degree to compare to + * @return true if the values are not identical + */ +inline bool operator!=( const Degree& lhs, const Degree& rhs ) +{ + return !( operator==( lhs, rhs ) ); +} -private: - // member data - float mValue; ///< The value in degrees +/** + * @brief Clamp a radian value + * @param angle to clamp + * @param min value + * @param max value + * @return the resulting radian + */ +inline Degree Clamp( Degree angle, float min, float max ) +{ + return Degree( Clamp( angle.degree, min, max ) ); +} - /** - * @brief Disable the default constructor. - */ - Degree(); -}; +/** + * @brief Stream a degree value + * @param [in] ostream The output stream to use. + * @param [in] angle in Degree. + * @return The output stream. + */ +inline std::ostream& operator<<( std::ostream& ostream, Degree angle ) +{ + ostream << angle.degree; + return ostream; +} } // namespace Dali diff --git a/dali/public-api/math/quaternion.cpp b/dali/public-api/math/quaternion.cpp index 5442444..daa8960 100644 --- a/dali/public-api/math/quaternion.cpp +++ b/dali/public-api/math/quaternion.cpp @@ -40,27 +40,27 @@ const Quaternion Quaternion::IDENTITY; * Default Constructor */ Quaternion::Quaternion() - : mVector(0.0f, 0.0f, 0.0f, 1.0f) + : mVector( 0.0f, 0.0f, 0.0f, 1.0f ) { } -Quaternion::Quaternion(float cosThetaBy2, float iBySineTheta, float jBySineTheta, float kBySineTheta) : - mVector(iBySineTheta, jBySineTheta, kBySineTheta, cosThetaBy2) +Quaternion::Quaternion( float cosThetaBy2, float iBySineTheta, float jBySineTheta, float kBySineTheta ) : + mVector( iBySineTheta, jBySineTheta, kBySineTheta, cosThetaBy2 ) { } -Quaternion::Quaternion(const Vector4& vector) +Quaternion::Quaternion( const Vector4& vector ) { mVector = vector; } -Quaternion::Quaternion(float angle, const Vector3 &axis) +Quaternion::Quaternion( Radian angle, const Vector3& axis ) { MATH_INCREASE_BY(PerformanceMonitor::FLOAT_POINT_MULTIPLY,4); Vector3 tmpAxis = axis; tmpAxis.Normalize(); - const float halfAngle = angle * 0.5f; + const float halfAngle = angle.radian * 0.5f; const float sinThetaByTwo = sinf(halfAngle); const float cosThetaByTwo = cosf(halfAngle); mVector.x = tmpAxis.x * sinThetaByTwo; @@ -69,27 +69,12 @@ Quaternion::Quaternion(float angle, const Vector3 &axis) mVector.w = cosThetaByTwo; } -Quaternion::Quaternion(float theta, const Vector4 &axis) +Quaternion::Quaternion( Radian pitch, Radian yaw, Radian roll ) { - MATH_INCREASE_BY(PerformanceMonitor::FLOAT_POINT_MULTIPLY,4); - - Vector4 tmpAxis = axis; - tmpAxis.Normalize(); - const float halfTheta = theta * 0.5f; - const float sinThetaByTwo = sinf(halfTheta); - const float cosThetaByTwo = cosf(halfTheta); - mVector.x = tmpAxis.x * sinThetaByTwo; - mVector.y = tmpAxis.y * sinThetaByTwo; - mVector.z = tmpAxis.z * sinThetaByTwo; - mVector.w = cosThetaByTwo; -} - -Quaternion::Quaternion(float x, float y, float z) -{ - SetEuler(x,y,z); + SetEuler( pitch, yaw, roll ); } -Quaternion::Quaternion(const Matrix& matrix) +Quaternion::Quaternion( const Matrix& matrix ) { Vector3 xAxis( matrix.GetXAxis() ); Vector3 yAxis( matrix.GetYAxis() ); @@ -129,11 +114,6 @@ Quaternion::Quaternion( const Vector3& v0, const Vector3& v1 ) } } -Quaternion Quaternion::FromAxisAngle(const Vector4 &axis, float angle) -{ - return Quaternion(angle, axis); -} - Quaternion::~Quaternion() { } @@ -148,12 +128,12 @@ bool Quaternion::IsIdentity() const ( fabsf( mVector.z ) < Math::MACHINE_EPSILON_10 ) ); } -bool Quaternion::ToAxisAngle(Vector3 &axis, float &angle) const +bool Quaternion::ToAxisAngle(Vector3& axis, Radian& angle) const { angle = acosf(mVector.w); bool converted = false; // pre-compute to save time - const float sine = sinf( angle ); + const float sine = sinf( angle.radian ); // If sine(angle) is zero, conversion is not possible @@ -166,38 +146,24 @@ bool Quaternion::ToAxisAngle(Vector3 &axis, float &angle) const axis.x = mVector.x*sinf_theta_inv; axis.y = mVector.y*sinf_theta_inv; axis.z = mVector.z*sinf_theta_inv; - angle*=2.0f; + angle.radian *= 2.0f; converted = true; } return converted; } -bool Quaternion::ToAxisAngle(Vector4 &axis, float &angle) const -{ - Vector3 axis3; - bool converted = ToAxisAngle(axis3, angle); - if(converted) - { - axis.x = axis3.x; - axis.y = axis3.y; - axis.z = axis3.z; - axis.w = 0; - } - return converted; -} - const Vector4& Quaternion::AsVector() const { return mVector; } -void Quaternion::SetEuler(float x, float y, float z) +void Quaternion::SetEuler( Radian pitch, Radian yaw, Radian roll ) { MATH_INCREASE_BY(PerformanceMonitor::FLOAT_POINT_MULTIPLY,19); - const float halfX = 0.5f * x; - const float halfY = 0.5f * y; - const float halfZ = 0.5f * z; + const float halfX = 0.5f * pitch.radian; + const float halfY = 0.5f * yaw.radian; + const float halfZ = 0.5f * roll.radian; float cosX2 = cosf(halfX); float cosY2 = cosf(halfY); @@ -229,17 +195,17 @@ Vector4 Quaternion::EulerAngles() const return euler; } -const Quaternion Quaternion::operator +(const Quaternion &other) const +const Quaternion Quaternion::operator+( const Quaternion& other ) const { return Quaternion(mVector + other.mVector); } -const Quaternion Quaternion::operator -(const Quaternion &other) const +const Quaternion Quaternion::operator-( const Quaternion& other ) const { return Quaternion(mVector - other.mVector); } -const Quaternion Quaternion::operator *(const Quaternion &other) const +const Quaternion Quaternion::operator*( const Quaternion& other ) const { MATH_INCREASE_BY(PerformanceMonitor::FLOAT_POINT_MULTIPLY,12); @@ -249,52 +215,50 @@ const Quaternion Quaternion::operator *(const Quaternion &other) const mVector.x * other.mVector.y - mVector.y * other.mVector.x + mVector.w * other.mVector.z + mVector.z * other.mVector.w); } -Vector3 Quaternion::operator *(const Vector3& v) const +Vector3 Quaternion::operator*( const Vector3& other ) const { - // nVidia SDK implementation - Vector3 uv, uuv; Vector3 qvec(mVector.x, mVector.y, mVector.z); - uv = qvec.Cross(v); - uuv = qvec.Cross(uv); + Vector3 uv = qvec.Cross( other ); + Vector3 uuv = qvec.Cross(uv); uv *= (2.0f * mVector.w); uuv *= 2.0f; - return v + uv + uuv; + return other + uv + uuv; } -const Quaternion Quaternion::operator /(const Quaternion &q) const +const Quaternion Quaternion::operator/( const Quaternion& q ) const { Quaternion p(q); p.Invert(); return *this * p; } -const Quaternion Quaternion::operator *(float scale) const +const Quaternion Quaternion::operator*( float scale ) const { return Quaternion(mVector*scale); } -const Quaternion Quaternion::operator /(float scale) const +const Quaternion Quaternion::operator/( float scale ) const { return Quaternion(mVector/scale); } -Quaternion Quaternion::operator -() const +Quaternion Quaternion::operator-() const { return Quaternion(-mVector.w, -mVector.x, -mVector.y, -mVector.z); } -const Quaternion& Quaternion::operator +=(const Quaternion &q) +const Quaternion& Quaternion::operator+=( const Quaternion& q ) { mVector += q.mVector; return *this; } -const Quaternion& Quaternion::operator -=(const Quaternion &q) +const Quaternion& Quaternion::operator-=( const Quaternion& q ) { mVector -= q.mVector; return *this; } -const Quaternion& Quaternion::operator *=(const Quaternion &q) +const Quaternion& Quaternion::operator*=( const Quaternion& q ) { MATH_INCREASE_BY(PerformanceMonitor::FLOAT_POINT_MULTIPLY,12); @@ -307,17 +271,17 @@ const Quaternion& Quaternion::operator *=(const Quaternion &q) return *this; } -const Quaternion& Quaternion::operator *= (float scale) +const Quaternion& Quaternion::operator*=( float scale ) { mVector*=scale; return *this; } -const Quaternion& Quaternion::operator /= (float scale) +const Quaternion& Quaternion::operator/=( float scale ) { mVector/=scale; return *this; } -bool Quaternion::operator== (const Quaternion& rhs) const +bool Quaternion::operator==( const Quaternion& rhs ) const { return ( ( fabsf(mVector.x - rhs.mVector.x) < Math::MACHINE_EPSILON_1 && fabsf(mVector.y - rhs.mVector.y) < Math::MACHINE_EPSILON_1 && @@ -331,7 +295,7 @@ bool Quaternion::operator== (const Quaternion& rhs) const ); } -bool Quaternion::operator!= (const Quaternion& rhs) const +bool Quaternion::operator!=( const Quaternion& rhs ) const { return !operator==(rhs); } @@ -418,17 +382,17 @@ Quaternion Quaternion::Exp() const return ret; } -float Quaternion::Dot(const Quaternion &q1, const Quaternion &q2) +float Quaternion::Dot( const Quaternion& q1, const Quaternion& q2 ) { return q1.mVector.Dot4(q2.mVector); } -Quaternion Quaternion::Lerp(const Quaternion &q1, const Quaternion &q2, float t) +Quaternion Quaternion::Lerp(const Quaternion& q1, const Quaternion& q2, float t ) { return (q1*(1.0f-t) + q2*t).Normalized(); } -Quaternion Quaternion::Slerp(const Quaternion &q1, const Quaternion &q2, float progress) +Quaternion Quaternion::Slerp( const Quaternion& q1, const Quaternion& q2, float progress ) { Quaternion q3; float cosTheta = Quaternion::Dot(q1, q2); @@ -469,7 +433,7 @@ Quaternion Quaternion::Slerp(const Quaternion &q1, const Quaternion &q2, float p } } -Quaternion Quaternion::SlerpNoInvert(const Quaternion &q1, const Quaternion &q2, float t) +Quaternion Quaternion::SlerpNoInvert( const Quaternion& q1, const Quaternion& q2, float t ) { float cosTheta = Quaternion::Dot(q1, q2); @@ -486,21 +450,16 @@ Quaternion Quaternion::SlerpNoInvert(const Quaternion &q1, const Quaternion &q2, } } -Quaternion Quaternion::Squad( - const Quaternion &q1, // start - const Quaternion &q2, // end - const Quaternion &a, // ctrl pt for q1 - const Quaternion &b, // ctrl pt for q2 - float t) +Quaternion Quaternion::Squad( const Quaternion& start, const Quaternion& end, const Quaternion& ctrl1, const Quaternion& ctrl2, float t ) { MATH_INCREASE_BY(PerformanceMonitor::FLOAT_POINT_MULTIPLY,2); - Quaternion c = SlerpNoInvert(q1, q2, t); - Quaternion d = SlerpNoInvert(a, b, t); - return SlerpNoInvert(c, d, 2*t*(1-t)); + Quaternion c = SlerpNoInvert( start, end, t ); + Quaternion d = SlerpNoInvert( ctrl1, ctrl2, t ); + return SlerpNoInvert( c, d, 2*t*(1-t) ); } -float Quaternion::AngleBetween(const Quaternion &q1, const Quaternion &q2) +float Quaternion::AngleBetween( const Quaternion& q1, const Quaternion& q2 ) { Quaternion from(q1); Quaternion to(q2); @@ -516,17 +475,17 @@ float Quaternion::AngleBetween(const Quaternion &q1, const Quaternion &q2) return theta; } -Vector4 Quaternion::Rotate(const Vector4 &v) const +Vector4 Quaternion::Rotate( const Vector4& vector ) const { - Quaternion V(0.0f, v.x, v.y, v.z); + Quaternion V(0.0f, vector.x, vector.y, vector.z); Quaternion conjugate(*this); conjugate.Conjugate(); return (*this * V * conjugate).mVector; } -Vector3 Quaternion::Rotate(const Vector3 &v) const +Vector3 Quaternion::Rotate( const Vector3& vector ) const { - Quaternion V(0.0f, v.x, v.y, v.z); + Quaternion V(0.0f, vector.x, vector.y, vector.z); Quaternion conjugate(*this); conjugate.Conjugate(); return Vector3((*this * V * conjugate).mVector); @@ -578,15 +537,15 @@ void Quaternion::SetFromAxes( const Vector3& xAxis, const Vector3& yAxis, const Normalize(); } -std::ostream& operator<< (std::ostream& o, const Quaternion& quaternion) +std::ostream& operator<<( std::ostream& o, const Quaternion& quaternion ) { Vector3 axis; - float angleRadians; + Radian angleRadians; quaternion.ToAxisAngle( axis, angleRadians ); - Degree degrees = Radian(angleRadians); + Degree degrees = Radian( angleRadians ); - return o << "[ Axis: [" << axis.x << ", " << axis.y << ", " << axis.z << "], Angle: " << degrees << " degrees ]"; + return o << "[ Axis: [" << axis.x << ", " << axis.y << ", " << axis.z << "], Angle: " << degrees.degree << " degrees ]"; } } // namespace Dali diff --git a/dali/public-api/math/quaternion.h b/dali/public-api/math/quaternion.h index fa81e4c..f51188d 100644 --- a/dali/public-api/math/quaternion.h +++ b/dali/public-api/math/quaternion.h @@ -24,6 +24,7 @@ // INTERNAL INCLUDES #include #include +#include #include namespace Dali @@ -52,14 +53,14 @@ public: * @param[in] jBySineTheta * @param[in] kBySineTheta */ - Quaternion(float cosThetaBy2, float iBySineTheta, float jBySineTheta, float kBySineTheta); + Quaternion( float cosThetaBy2, float iBySineTheta, float jBySineTheta, float kBySineTheta ); /** * @brief Construct from a quaternion represented by a vector. * * @param[in] vector - x,y,z fields represent i,j,k coefficients, w represents cos(theta/2) */ - explicit Quaternion(const Vector4& vector); + explicit Quaternion( const Vector4& vector ); /** * @brief Constructor from an axis and angle. @@ -67,24 +68,16 @@ public: * @param[in] angle - the angle around the axis * @param[in] axis - the vector of the axis */ - Quaternion(float angle, const Vector3 &axis); - - /** - * @brief Constructor from an axis and angle. - * - * @param[in] theta - the angle of the axis - * @param[in] axis - the unit vector of the axis - */ - Quaternion(float theta, const Vector4 &axis); + Quaternion( Radian angle, const Vector3& axis ); /** * @brief Construct from Euler angles. * - * @param[in] x - the X axis euler angle (pitch) - * @param[in] y - the Y axis euler angle (yaw) - * @param[in] z - the Z axis euler angle (roll) + * @param[in] pitch + * @param[in] yaw + * @param[in] roll */ - Quaternion(float x, float y, float z); + Quaternion( Radian pitch, Radian yaw, Radian roll ); /** * @brief Construct from a matrix. @@ -112,15 +105,6 @@ public: explicit Quaternion( const Vector3& v0, const Vector3& v1 ); /** - * @brief Converts an axis + angle pair rotation to a Quaternion. - * - * @param[in] axis - * @param[in] angle - * @return the represented quaternion - */ - static Quaternion FromAxisAngle(const Vector4 &axis, float angle); - - /** * @brief Destructor, nonvirtual as this is not a base class. * */ @@ -141,19 +125,10 @@ public: * @brief Convert the quaternion to an axis/angle pair. * * @param[out] axis - * @param[out] angle + * @param[out] angle in radians * @return true if converted correctly */ - bool ToAxisAngle(Vector3 &axis, float &angle) const; - - /** - * @brief Convert the quaternion to an axis/angle pair. - * - * @param[out] axis - * @param[out] angle - * @return true if converted correctly - */ - bool ToAxisAngle(Vector4 &axis, float &angle) const; + bool ToAxisAngle( Vector3& axis, Radian& angle ) const; /** * @brief Return the quaternion as a vector. @@ -165,11 +140,11 @@ public: /** * @brief SetEuler sets the quaternion from the Euler angles applied in x, y, z order. * - * @param[in] x - the X axis euler angle (pitch) - * @param[in] y - the Y axis euler angle (yaw) - * @param[in] z - the Z axis euler angle (roll) + * @param[in] pitch + * @param[in] yaw + * @param[in] roll */ - void SetEuler(float x, float y, float z); + void SetEuler( Radian pitch, Radian yaw, Radian roll ); /** * @brief returns the Euler angles from a rotation Quaternion. @@ -184,7 +159,7 @@ public: * @param[in] other The quaternion to add * @return A quaternion containing the result of the addition */ - const Quaternion operator +(const Quaternion &other) const; + const Quaternion operator+( const Quaternion& other ) const; /** * @brief Subtraction operator. @@ -192,7 +167,7 @@ public: * @param[in] other The quaternion to subtract * @return A quaternion containing the result of the subtract */ - const Quaternion operator -(const Quaternion &other) const; + const Quaternion operator-( const Quaternion& other ) const; /** * @brief Multiplication operator. @@ -200,15 +175,15 @@ public: * @param[in] other The quaternion to multiply * @return A quaternion containing the result */ - const Quaternion operator *(const Quaternion &other) const; + const Quaternion operator*( const Quaternion& other ) const; /** * @brief Multiplication operator. * - * @param[in] v The vector to multiply + * @param[in] other The vector to multiply * @return A vector containing the result of the multiplication */ - Vector3 operator *(const Vector3& v) const; + Vector3 operator*( const Vector3& other ) const; /** * @brief Division operator. @@ -216,7 +191,7 @@ public: * @param[in] other a quaternion to divide by * @return A quaternion containing the result */ - const Quaternion operator /(const Quaternion &other) const; + const Quaternion operator/( const Quaternion& other ) const; /** * @brief Scale operator. @@ -224,7 +199,7 @@ public: * @param[in] scale A value to scale by * @return A quaternion containing the result */ - const Quaternion operator *(float scale) const; + const Quaternion operator*( float scale ) const; /** * @brief Scale operator. @@ -232,14 +207,14 @@ public: * @param[in] scale A value to scale by * @return A quaternion containing the result */ - const Quaternion operator /(float scale) const; + const Quaternion operator/( float scale ) const; /** * @brief Unary Negation operator. * * @return A quaternion containing the negated result */ - Quaternion operator -() const; + Quaternion operator-() const; /** * @brief Addition with Assignment operator. @@ -247,7 +222,7 @@ public: * @param[in] other The quaternion to add * @return itself */ - const Quaternion &operator +=(const Quaternion &other); + const Quaternion& operator+=( const Quaternion& other ); /** * @brief Subtraction with Assignment operator. @@ -255,7 +230,7 @@ public: * @param[in] other The quaternion to subtract * @return itself */ - const Quaternion &operator -=(const Quaternion &other); + const Quaternion& operator-=( const Quaternion& other ); /** * @brief Multiplication with Assignment operator. @@ -263,7 +238,7 @@ public: * @param[in] other The quaternion to multiply * @return itself */ - const Quaternion &operator *=(const Quaternion &other); + const Quaternion& operator*=( const Quaternion& other ); /** * @brief Scale with Assignment operator. @@ -271,7 +246,7 @@ public: * @param[in] scale the value to scale by * @return itself */ - const Quaternion &operator *= (float scale); + const Quaternion& operator*=( float scale ); /** * @brief Scale with Assignment operator. @@ -279,7 +254,7 @@ public: * @param[in] scale the value to scale by * @return itself */ - const Quaternion &operator /= (float scale); + const Quaternion& operator/=( float scale ); /** * @brief Equality operator. @@ -287,7 +262,7 @@ public: * @param[in] rhs The quaterion to compare with. * @return True if the quaternions are equal. */ - bool operator== (const Quaternion& rhs) const; + bool operator==( const Quaternion& rhs ) const; /** * @brief Inequality operator. @@ -295,7 +270,7 @@ public: * @param[in] rhs The quaterion to compare with. * @return True if the quaternions are not equal. */ - bool operator!= (const Quaternion& rhs) const; + bool operator!=( const Quaternion& rhs ) const; /** * @brief Return the length of the quaternion. @@ -357,7 +332,7 @@ public: * @param[in] q2 - the second quaternion * @return the dot product of the two quaternions */ - static float Dot(const Quaternion &q1, const Quaternion &q2); + static float Dot( const Quaternion &q1, const Quaternion &q2 ); /** * @brief Linear Interpolation (using a straight line between the two quaternions). @@ -367,7 +342,7 @@ public: * @param[in] t - a progress value between 0 and 1 * @return the interpolated quaternion */ - static Quaternion Lerp(const Quaternion &q1, const Quaternion &q2, float t); + static Quaternion Lerp( const Quaternion &q1, const Quaternion &q2, float t ); /** * @brief Spherical Linear Interpolation (using the shortest arc of a great circle between @@ -378,7 +353,7 @@ public: * @param[in] progress - a progress value between 0 and 1 * @return the interpolated quaternion */ - static Quaternion Slerp(const Quaternion &q1, const Quaternion &q2, float progress); + static Quaternion Slerp( const Quaternion &q1, const Quaternion &q2, float progress ); /** * @brief This version of Slerp, used by Squad, does not check for theta > 90. @@ -388,19 +363,19 @@ public: * @param[in] t - a progress value between 0 and 1 * @return the interpolated quaternion */ - static Quaternion SlerpNoInvert(const Quaternion &q1, const Quaternion &q2, float t); + static Quaternion SlerpNoInvert( const Quaternion &q1, const Quaternion &q2, float t ); /** * @brief Spherical Cubic Interpolation. * - * @param[in] q1 - the start quaternion - * @param[in] q2 - the end quaternion - * @param[in] a - the control quaternion for q1 - * @param[in] b - the control quaternion for q2 + * @param[in] start - the start quaternion + * @param[in] end - the end quaternion + * @param[in] ctrl1 - the control quaternion for q1 + * @param[in] ctrl2 - the control quaternion for q2 * @param[in] t - a progress value between 0 and 1 * @return the interpolated quaternion */ - static Quaternion Squad(const Quaternion &q1,const Quaternion &q2,const Quaternion &a,const Quaternion &b,float t); + static Quaternion Squad( const Quaternion& start, const Quaternion& end, const Quaternion& ctrl1, const Quaternion& ctrl2, float t ); /** * @brief Returns the shortest angle between two quaternions in Radians. @@ -409,23 +384,23 @@ public: * @param[in] q2 - the second quaternion * @return the angle between the two quaternions. */ - static float AngleBetween(const Quaternion &q1, const Quaternion &q2); + static float AngleBetween( const Quaternion& q1, const Quaternion& q2 ); /** * @brief Rotate v by this Quaternion (Quaternion must be unit). * - * @param[in] v - a vector to rotate + * @param[in] vector a vector to rotate * @return the rotated vector */ - Vector4 Rotate(const Vector4 &v) const; + Vector4 Rotate( const Vector4& vector ) const; /** * @brief Rotate v by this Quaternion (Quaternion must be unit). * - * @param[in] v - a vector to rotate + * @param[in] vector a vector to rotate * @return the rotated vector */ - Vector3 Rotate(const Vector3 &v) const; + Vector3 Rotate( const Vector3& vector ) const; private: diff --git a/dali/public-api/math/radian.cpp b/dali/public-api/math/radian.cpp deleted file mode 100644 index 5206ab7..0000000 --- a/dali/public-api/math/radian.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// CLASS HEADER -#include - -// INTERNAL INCLUDES -#include -#include - -namespace -{ -const float PI_OVER_180 = Dali::Math::PI/180.0f; -} - -namespace Dali -{ - -Radian::Radian( float value ) -: mValue( value ) -{ -} - -Radian::Radian( const Degree& degree ) -: mValue( degree * PI_OVER_180 ) -{ -} - -bool Radian::operator==( const Radian& rhs ) const -{ - return fabsf( mValue - rhs.mValue ) < GetRangedEpsilon( mValue, rhs.mValue ); -} - -bool Radian::operator!=( const Radian& rhs ) const -{ - return !(this->operator==(rhs)); -} - -bool Radian::operator<( const Radian& rhs ) const -{ - return mValue < rhs.mValue; -} - -Radian& Radian::operator=( const float value ) -{ - mValue = value; - return *this; -} - -Radian& Radian::operator=( const Degree& rhs ) -{ - mValue = rhs * PI_OVER_180; - return *this; -} - -Radian::operator const float&() const -{ - return mValue; -} - -Radian::operator float&() -{ - return mValue; -} - -} // namespace Dali diff --git a/dali/public-api/math/radian.h b/dali/public-api/math/radian.h index 8f18845..586ca2d 100644 --- a/dali/public-api/math/radian.h +++ b/dali/public-api/math/radian.h @@ -2,7 +2,7 @@ #define __DALI_RADIAN_H__ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,58 +18,49 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES +#include #include +#include +#include namespace Dali { -struct Degree; - /** * @brief An angle in radians. * * This reduces ambiguity when using methods which accept angles in degrees or radians. */ -struct DALI_IMPORT_API Radian +struct Radian { /** - * @brief Create an angle in radians. - * - * @param[in] value The initial value in radians. + * @brief default constructor, initialises to 0. */ - explicit Radian( float value ); + Radian() + : radian( 0.f ) + { } /** - * @brief Create an angle in radians from an angle in degrees. - * - * @param[in] value The initial value in degrees. - */ - Radian( const Degree& value ); - - /** - * @brief Compare equality between two radians. - * - * @param[in] rhs Radian to compare to - * @return true if the value is identical - */ - bool operator==( const Radian& rhs ) const; - - /** - * @brief Compare inequality between two radians. + * @brief Create an angle in radians. * - * @param[in] rhs Radian to compare to - * @return true if the value is not identical + * @param[in] value The initial value in radians. */ - bool operator!=( const Radian& rhs ) const; + explicit Radian( float value ) + : radian( value ) + { } /** - * @brief Compare two radians. + * @brief Create an angle in radians from an angle in degrees. * - * @param[in] rhs Radian to compare to - * @return true if this is less than the value + * @param[in] degree The initial value in degrees. */ - bool operator<( const Radian& rhs ) const; + Radian( Degree degree ) + : radian( degree.degree * Math::PI_OVER_180 ) + { } /** * @brief Assign an angle from a float value. @@ -77,34 +68,244 @@ struct DALI_IMPORT_API Radian * @param[in] value Float value in radians * @return a reference to this object */ - Radian& operator=( const float value ); + Radian& operator=( float value ) + { + radian = value; + return *this; + } /** - * @brief Assign an angle in degrees to a Radian. + * @brief Assign an angle from a Degree value. * - * @param[in] rhs Degree to get the value from + * @param[in] degree The value in degrees. * @return a reference to this object */ - Radian& operator=( const Degree& rhs ); + Radian& operator=( Degree degree ) + { + radian = degree.degree * Math::PI_OVER_180; + return *this; + } /** - * @brief Cast operator to const float reference. + * @brief Conversion to float + * @return the float value of this Radian */ - operator const float&() const; + operator float() const + { + return radian; + } - /** - * @brief Cast operator to float reference. - */ - operator float&(); +public: -private: // member data - float mValue; ///< The value in radians + float radian; ///< The value in radians - // disable default constructor - Radian(); }; +// compiler generated destructor, copy constructor and assignment operators are ok as this class is POD + +// useful constant angles +static const Radian ANGLE_360 = Radian( Math::PI * 2.00f ); ///< 360 degree turn in radians +static const Radian ANGLE_315 = Radian( Math::PI * 1.75f ); ///< 315 degree turn in radians +static const Radian ANGLE_270 = Radian( Math::PI * 1.50f );///< 270 degree turn in radians +static const Radian ANGLE_225 = Radian( Math::PI * 1.25f ); ///< 225 degree turn in radians +static const Radian ANGLE_180 = Radian( Math::PI ); ///< 180 degree turn in radians +static const Radian ANGLE_135 = Radian( Math::PI * 0.75f ); ///< 135 degree turn in radians +static const Radian ANGLE_120 = Radian( Math::PI / 3.00f ); ///< 120 degree turn in radians +static const Radian ANGLE_90 = Radian( Math::PI_2 ); ///< 90 degree turn in radians +static const Radian ANGLE_45 = Radian( Math::PI_4 ); ///< 45 degree turn in radians +static const Radian ANGLE_30 = Radian( Math::PI / 6.00f ); ///< 30 degree turn in radians +static const Radian ANGLE_0 = Radian( 0.0f ); ///< 0 degree turn in radians + +/** + * @brief Compare equality between two radians. + * + * @param[in] lhs Radian to compare + * @param[in] rhs Radian to compare to + * @return true if the values are identical + */ +inline bool operator==( Radian lhs, Radian rhs ) +{ + return fabsf( lhs.radian - rhs.radian ) < Math::MACHINE_EPSILON_10; // expect Radian angles to be between 0 and 10 (multiplies of Math::PI) +} + +/** + * @brief Compare inequality between two radians. + * + * @param[in] lhs Radian to compare + * @param[in] rhs Radian to compare to + * @return true if the values are not identical + */ +inline bool operator!=( Radian lhs, Radian rhs ) +{ + return !( operator==( lhs, rhs ) ); +} + +/** + * @brief Compare equality between a radian and degree. + * + * @param[in] lhs Radian to compare + * @param[in] rhs Degree to compare to + * @return true if the values are identical + */ +inline bool operator==( Radian lhs, Degree rhs ) +{ + return fabsf( lhs.radian - Radian( rhs ).radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999 +} + +/** + * @brief Compare inequality between a radian and a degree. + * + * @param[in] lhs Radian to compare + * @param[in] rhs Degree to compare to + * @return true if the values are not identical + */ +inline bool operator!=( Radian lhs, Degree rhs ) +{ + return !( operator==( lhs, rhs ) ); +} + +/** + * @brief Compare equality between a degree and a radian. + * + * @param[in] lhs Degree to compare + * @param[in] rhs Radian to compare to + * @return true if the values are identical + */ +inline bool operator==( Degree lhs, Radian rhs ) +{ + return fabsf( Radian( lhs ).radian - rhs.radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999 +} + +/** + * @brief Compare inequality between a degree and a radian. + * + * @param[in] lhs Degree to compare + * @param[in] rhs Radian to compare to + * @return true if the values are not identical + */ +inline bool operator!=( Degree lhs, Radian rhs ) +{ + return !( operator==( lhs, rhs ) ); +} + +/** + * @brief Compare greater than between two radians + * + * @param[in] lhs Radian to compare + * @param[in] rhs Radian to compare to + * @return true if lhs is greater than rhs + */ +inline bool operator>( Radian lhs, Radian rhs ) +{ + return lhs.radian > rhs.radian; +} + +/** + * @brief Compare greater than between a radian and a degree. + * + * @param[in] lhs Radian to compare + * @param[in] rhs Degree to compare to + * @return true if lhs is greater than rhs + */ +inline bool operator>( Radian lhs, Degree rhs ) +{ + return lhs.radian > Radian(rhs).radian; +} + +/** + * @brief Compare greater than between a radian and a degree. + * + * @param[in] lhs Radian to compare + * @param[in] rhs Degree to compare to + * @return true if lhs is greater than rhs + */ +inline bool operator>( Degree lhs, Radian rhs ) +{ + return Radian(lhs).radian > rhs.radian; +} + +/** + * @brief Compare less than between two radians. + * + * @param[in] lhs Radian to compare + * @param[in] rhs Radian to compare to + * @return true if lhs is less than rhs + */ +inline bool operator<( Radian lhs, Radian rhs ) +{ + return lhs.radian < rhs.radian; +} + +/** + * @brief Compare less than between a radian and a degree. + * + * @param[in] lhs Radian to compare + * @param[in] rhs Degree to compare to + * @return true if lhs is less than rhs + */ +inline bool operator<( Radian lhs, Degree rhs ) +{ + return lhs.radian < Radian(rhs).radian; +} + +/** + * @brief Compare less than between a degree and a radian. + * + * @param[in] lhs Degree to compare + * @param[in] rhs Radian to compare to + * @return true if lhs is less than rhs + */ +inline bool operator<( Degree lhs, Radian rhs ) +{ + return Radian(lhs).radian < rhs.radian; +} + +/** + * @brief Multiply Radian with a float + * + * @param[in] lhs Radian to multiply + * @param[in] rhs float to multiply + * @return result of the multiplication + */ +inline Radian operator*( Radian lhs, float rhs ) +{ + return Radian( lhs.radian * rhs ); +} + +/** + * @brief Negate the radian + * @return The negative angle + */ +inline Radian operator-( Radian in ) +{ + return Radian( -in.radian ); +} + +/** + * @brief Clamp a radian value + * @param angle to clamp + * @param min value + * @param max value + * @return the resulting radian + */ +inline Radian Clamp( Radian angle, float min, float max ) +{ + return Radian( Clamp( angle.radian, min, max ) ); +} + +/** + * @brief Stream a radian value + * @param [in] ostream The output stream to use. + * @param [in] angle in Radian. + * @return The output stream. + */ +inline std::ostream& operator<<( std::ostream& ostream, Radian angle ) +{ + ostream << angle.radian; + return ostream; +} + } // namespace Dali #endif // __DALI_RADIAN_H__ diff --git a/dali/public-api/object/property-value.cpp b/dali/public-api/object/property-value.cpp index 8bffbc3..3b0359f 100644 --- a/dali/public-api/object/property-value.cpp +++ b/dali/public-api/object/property-value.cpp @@ -396,7 +396,7 @@ Property::Value::Value(Type type) case Property::ROTATION: { - mImpl = new Impl( Quaternion(0.f, Vector4::YAXIS) ); + mImpl = new Impl( Quaternion( Radian(0.f), Vector3::YAXIS) ); break; } @@ -631,9 +631,7 @@ void Property::Value::Get(AngleAxis& angleAxisValue) const { Quaternion quaternion = AnyCast(mImpl->mValue); - Radian angleRadians(0.0f); - quaternion.ToAxisAngle( angleAxisValue.axis, angleRadians ); - angleAxisValue.angle = angleRadians; + quaternion.ToAxisAngle( angleAxisValue.axis, angleAxisValue.angle ); } else { -- 2.7.4