Pārlūkot izejas kodu

Ability to specify up axis and override layers for LoadSnapshotTest

Jorrit Rouwe 3 gadi atpakaļ
vecāks
revīzija
ab85142716

+ 0 - 2
Jolt/Physics/Constraints/ConstraintPart/RotationEulerConstraintPart.h

@@ -79,7 +79,6 @@ public:
 	/// @param inAxisY1 Reference axis Y for body 1
 	/// @param inAxisX2 Reference axis X for body 2
 	/// @param inAxisY2 Reference axis Y for body 2
-	/// @return 
 	static Quat					sGetInvInitialOrientationXY(Vec3Arg inAxisX1, Vec3Arg inAxisY1, Vec3Arg inAxisX2, Vec3Arg inAxisY2)
 	{
 		// Store inverse of initial rotation from body 1 to body 2 in body 1 space:
@@ -121,7 +120,6 @@ public:
 	/// @param inAxisZ1 Reference axis Z for body 1
 	/// @param inAxisX2 Reference axis X for body 2
 	/// @param inAxisZ2 Reference axis Z for body 2
-	/// @return 
 	static Quat					sGetInvInitialOrientationXZ(Vec3Arg inAxisX1, Vec3Arg inAxisZ1, Vec3Arg inAxisX2, Vec3Arg inAxisZ2)
 	{
 		// See comment at sGetInvInitialOrientationXY

+ 36 - 1
Samples/Tests/Tools/LoadSnapshotTest.cpp

@@ -6,7 +6,9 @@
 #include <Tests/Tools/LoadSnapshotTest.h>
 #include <Jolt/Physics/PhysicsScene.h>
 #include <Jolt/Core/StreamWrapper.h>
+#include <Application/DebugUI.h>
 #include <Utils/Log.h>
+#include <Layers.h>
 
 JPH_IMPLEMENT_RTTI_VIRTUAL(LoadSnapshotTest) 
 { 
@@ -23,6 +25,39 @@ void LoadSnapshotTest::Initialize()
 	PhysicsScene::PhysicsSceneResult result = PhysicsScene::sRestoreFromBinaryState(wrapper);
 	if (result.HasError())
 		FatalError(result.GetError().c_str());
+	Ref<PhysicsScene> scene = result.Get();
 
-	result.Get()->CreateBodies(mPhysicsSystem);
+	// Determine quaternion that rotates the world so that up is Y
+	Quat up_rotation;
+	switch (sUpAxis)
+	{
+	case 0:		up_rotation = Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI);	break;
+	case 2:		up_rotation = Quat::sRotation(Vec3::sAxisX(), -0.5f * JPH_PI);	break;
+	default:	up_rotation = Quat::sIdentity();								break;
+	}
+
+	for (BodyCreationSettings &settings : scene->GetBodies())
+	{
+		if (sOverrideLayers)
+		{
+			// Override the layer so that all static objects are in the non-moving layer and everything else is in the moving layer
+			if (settings.mMotionType == EMotionType::Static)
+				settings.mObjectLayer = Layers::NON_MOVING;
+			else
+				settings.mObjectLayer = Layers::MOVING;
+		}
+
+		// Rotate the body so that it matches Y is up
+		settings.mPosition = up_rotation * settings.mPosition;
+		settings.mRotation = up_rotation * settings.mRotation;
+	}
+
+	scene->CreateBodies(mPhysicsSystem);
+}
+
+void LoadSnapshotTest::CreateSettingsMenu(DebugUI *inUI, UIElement *inSubMenu)
+{
+	inUI->CreateComboBox(inSubMenu, "Up Axis", { "X", "Y", "Z" }, sUpAxis, [](int inItem) { sUpAxis = inItem; });
+	inUI->CreateCheckBox(inSubMenu, "Override Object Layers", sOverrideLayers, [](UICheckBox::EState inState) { sOverrideLayers = inState == UICheckBox::STATE_CHECKED; });
+	inUI->CreateTextButton(inSubMenu, "Accept Changes", [=]() { RestartTest(); });
 }

+ 8 - 0
Samples/Tests/Tools/LoadSnapshotTest.h

@@ -13,4 +13,12 @@ public:
 
 	// See: Test
 	virtual void		Initialize() override;
+
+	// Optional settings menu
+	virtual bool		HasSettingsMenu() const override							{ return true; }
+	virtual void		CreateSettingsMenu(DebugUI *inUI, UIElement *inSubMenu) override;
+
+private:
+	inline static bool	sOverrideLayers = false;
+	inline static int	sUpAxis = 1;				// 0 = x, 1 = y, 2 = z
 };