Bug fixes for 2d physics 92/298492/1
authorDavid Steele <david.steele@samsung.com>
Thu, 7 Sep 2023 14:15:46 +0000 (15:15 +0100)
committerDavid Steele <david.steele@samsung.com>
Thu, 7 Sep 2023 15:03:16 +0000 (16:03 +0100)
Ensure that empty function queue doesn't cause crash
Fix the actor / physics world rotation translation (due to mirroring
the Y coords)

Changed the order of the inclusion files to ensure that a clean build
picks up the version of headers in the dali-physics/third-party folder.

Change-Id: I8aad01f7b9292e2c29642e61966daa33117d1efb
Signed-off-by: David Steele <david.steele@samsung.com>
automated-tests/src/dali-physics2d/utc-Dali-PhysicsActor.cpp
automated-tests/src/dali-physics2d/utc-Dali-PhysicsAdaptor.cpp
build/tizen/dali-physics/CMakeLists.txt
dali-physics/internal/chipmunk-impl/chipmunk-physics-adaptor-impl.cpp
dali-physics/internal/physics-world-impl.cpp

index 855d686..91700fd 100644 (file)
@@ -372,7 +372,7 @@ int UtcDaliPhysics2DActorSetRotation1(void)
     // Warning - physics properties are never reflected in the event size cache.
     // Have to use GetCurrentProperty to see the updated values.
     Quaternion q = actor.GetCurrentProperty<Quaternion>(Actor::Property::ORIENTATION);
-    Quaternion expected(Degree(30), Vector3::ZAXIS);
+    Quaternion expected(Degree(-30), Vector3::ZAXIS);
     DALI_TEST_EQUALS(q, expected, 0.0001f, TEST_LOCATION);
   }
 
@@ -385,7 +385,7 @@ int UtcDaliPhysics2DActorSetRotation2(void)
 
   ToolkitTestApplication application;
   Matrix                 transform(false);
-  transform.SetIdentityAndScale(Vector3(2.0f, -2.0f, 1.0f));
+  transform.SetIdentityAndScale(Vector3(2.0f, 2.0f, 1.0f));
   Uint16Pair     size(640, 480);
   PhysicsAdaptor adaptor   = PhysicsAdaptor::New(transform, size);
   Actor          rootActor = adaptor.GetRootActor();
index b6ca868..92e5d22 100644 (file)
@@ -321,7 +321,8 @@ int UtcDaliPhysics2DAdaptorTranslateToPhysicsSpace2(void)
 
   // Rotation shouldn't change under this scale
   Quaternion q(Degree(30.0f), Vector3::XAXIS);
-  DALI_TEST_EQUALS(adaptor.TranslateToPhysicsSpace(q), q, 0.0001f, TEST_LOCATION);
+  Quaternion expected(Degree(30.0f), Vector3::XAXIS);
+  DALI_TEST_EQUALS(adaptor.TranslateToPhysicsSpace(q), expected, 0.0001f, TEST_LOCATION);
 
   END_TEST;
 }
@@ -330,52 +331,16 @@ int UtcDaliPhysics2DAdaptorTranslateToPhysicsSpace3(void)
 {
   ToolkitTestApplication application;
   Matrix                 transform(false);
-  tet_infoline("Test that using an inverted Y scale does nothing to rotation");
+  tet_infoline("Test that using an inverted Y scale inverts rotation");
 
   transform.SetIdentityAndScale(Vector3(1.0f, -1.0f, 1.0f));
   Uint16Pair     size(640, 480);
   PhysicsAdaptor adaptor = PhysicsAdaptor::New(transform, size);
 
   Quaternion q(Degree(30.0f), Vector3::ZAXIS);
-  Quaternion qp(Degree(30.0f), Vector3::ZAXIS);
+  Quaternion expected(Degree(-30.0f), Vector3::ZAXIS);
 
-  DALI_TEST_EQUALS(adaptor.TranslateToPhysicsSpace(q), qp, 0.0001f, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliPhysics2DAdaptorTranslateToPhysicsSpace4(void)
-{
-  ToolkitTestApplication application;
-  Matrix                 transform(false);
-  tet_infoline("Test that using an inverted Y scale does nothing to rotation");
-
-  transform.SetIdentityAndScale(Vector3(1.0f, -1.0f, 1.0f));
-  Uint16Pair     size(640, 480);
-  PhysicsAdaptor adaptor = PhysicsAdaptor::New(transform, size);
-
-  Quaternion q(Degree(30.0f), Vector3::XAXIS);
-  Quaternion qp(Degree(30.0f), Vector3::XAXIS);
-
-  DALI_TEST_EQUALS(adaptor.TranslateToPhysicsSpace(q), qp, 0.0001f, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliPhysics2DAdaptorTranslateToPhysicsSpace5(void)
-{
-  ToolkitTestApplication application;
-  Matrix                 transform(false);
-  tet_infoline("Test that using an inverted Y scale does nothing to rotation");
-
-  transform.SetIdentityAndScale(Vector3(1.0f, -1.0f, 1.0f));
-  Uint16Pair     size(640, 480);
-  PhysicsAdaptor adaptor = PhysicsAdaptor::New(transform, size);
-
-  Quaternion q(Degree(30.0f), Vector3::YAXIS);
-  Quaternion qp(Degree(30.0f), Vector3::YAXIS);
-
-  DALI_TEST_EQUALS(adaptor.TranslateToPhysicsSpace(q), qp, 0.0001f, TEST_LOCATION);
+  DALI_TEST_EQUALS(adaptor.TranslateToPhysicsSpace(q), expected, 0.0001f, TEST_LOCATION);
 
   END_TEST;
 }
index 00c482b..9c52173 100644 (file)
@@ -75,9 +75,12 @@ include(${physics_dir}/public-api/file.list)
 include(${physics_dir}/internal/file.list)
 
 set(prefix_include_dir "${prefix}/include")
-include_directories(${repo_root_dir}
+
+include_directories(BEFORE
+  ${repo_root_dir}
   "${prefix_include_dir}"
   "${repo_root_dir}/dali-physics/third-party/bullet3/src"
+  "${repo_root_dir}/dali-physics/third-party/chipmunk2d/include"
 )
 
 MESSAGE(STATUS "2D sources: ${physics2d_src_files}")
index 1a4ffb9..1f52062 100644 (file)
@@ -144,8 +144,22 @@ Vector3 ChipmunkPhysicsAdaptor::TranslateFromPhysicsSpace(Vector3 vector) const
 
 Quaternion ChipmunkPhysicsAdaptor::TranslateToPhysicsSpace(Quaternion orientation) const
 {
-  // It's complicated.
-  return orientation;
+  // Actors face outwards (+ve Z)
+  // In DALi world, +ve angle about +ve Z is clockwise.
+  // But, if physics is mirrored in Y axis, so +ve angle is anti-clockwise.
+
+  // Compute angle about Z axis
+  Vector3 axis;
+  Radian  angle;
+  orientation.ToAxisAngle(axis, angle);
+
+  // Check if Transform matrix is mirrored in X xor Y
+  if(std::signbit(mTransform.AsFloat()[0]) ^ std::signbit(mTransform.AsFloat()[5]))
+  {
+    return Quaternion(-angle, axis);
+  }
+
+  return Quaternion(angle, axis);
 }
 
 Quaternion ChipmunkPhysicsAdaptor::TranslateFromPhysicsSpace(Quaternion orientation) const
index cd43633..b0ca04d 100644 (file)
@@ -96,11 +96,11 @@ bool PhysicsWorld::OnUpdate(Dali::UpdateProxy& updateProxy, float elapsedSeconds
   if(mNotifySyncPoint != Dali::UpdateProxy::INVALID_SYNC &&
      mNotifySyncPoint == updateProxy.PopSyncPoint())
   {
-    do
+    while(!commandQueue.empty())
     {
       commandQueue.front()(); // Execute the queued methods
       commandQueue.pop();
-    } while(!commandQueue.empty());
+    }
 
     mNotifySyncPoint = Dali::UpdateProxy::INVALID_SYNC;
   }