public void TestConstraintsBreakable() { // Make the ball and socket constraint breakable ShapeBase constraintBase = EditorManager.Scene.FindShapeByName("Ball and Socket"); Assert.IsTrue(constraintBase is HavokConstraintShape); HavokConstraintShape constraint = (HavokConstraintShape)constraintBase; constraint.TypeProperties.BreakableSettings.IsBreakable = true; constraint.TypeProperties.BreakableSettings.Threshold = 10; // Start the simulation EditorManager.EditorMode = EditorManager.Mode.EM_PLAYING_IN_EDITOR; TestManager.Helpers.ProcessEvents(); // Let the simulation run for 5 seconds DateTime timeBefore = DateTime.Now; while (true) { TimeSpan passedTime = DateTime.Now - timeBefore; if (passedTime.TotalSeconds > 10) { break; } TestManager.Helpers.ProcessEvents(); EditorManager.ActiveView.UpdateView(true); } try { // Since the test data are clean, they will not have the HavokEditorPlugin.EditorPlugin.PluginData file in scene.Layers folder // which means that the Unit Scale in the Physics panel will be derived from the Global Unit Scaling instead of being loaded from that file. // For this to be set correctly, the GlobalUnitScaling has to be 1. Assert.IsTrue(EditorManager.Settings.GlobalUnitScaling == 1, "GlobalUnitScaling is " + EditorManager.Settings.GlobalUnitScaling + " but should be 1 - Physics Constraints tests will not run properly"); // Check the Ball and Socket constraint ShapeBase basLower = EditorManager.Scene.FindShapeByName("Ball and Socket - Lower barrel"); Assert.IsNotNull(basLower, "Failed to find entity"); Vector3F lowerPos = new Vector3F(); Assert.IsTrue(basLower._engineInstance.GetPosition(ref lowerPos), "Failed to get position of entity"); Assert.IsTrue( (lowerPos.Z < 150), "Z-Position should be less than 150, but was {0}", new object[] { lowerPos.Z }); } finally { // Stop simulation EditorManager.EditorMode = EditorManager.Mode.EM_NONE; } }
public void TestConstraintsBreakable() { // Make the ball and socket constraint breakable ShapeBase constraintBase = EditorManager.Scene.FindShapeByName("Ball and Socket"); Assert.IsTrue(constraintBase is HavokConstraintShape); HavokConstraintShape constraint = (HavokConstraintShape)constraintBase; constraint.TypeProperties.BreakableSettings.IsBreakable = true; constraint.TypeProperties.BreakableSettings.Threshold = 10; // Start the simulation EditorManager.EditorMode = EditorManager.Mode.EM_PLAYING_IN_EDITOR; TestManager.Helpers.ProcessEvents(); // Let the simulation run for 5 seconds DateTime timeBefore = DateTime.Now; while (true) { TimeSpan passedTime = DateTime.Now - timeBefore; if (passedTime.TotalSeconds > 10) { break; } TestManager.Helpers.ProcessEvents(); } try { // Check the Ball and Socket constraint ShapeBase basLower = EditorManager.Scene.FindShapeByName("Ball and Socket - Lower barrel"); Assert.IsNotNull(basLower, "Failed to find entity"); Vector3F lowerPos = new Vector3F(); Assert.IsTrue(basLower._engineInstance.GetPosition(ref lowerPos), "Failed to get position of entity"); Assert.IsTrue( (lowerPos.Z < 150), "Z-Position should be less than 150, but was {0}", new object[] { lowerPos.Z }); } finally { // Stop simulation EditorManager.EditorMode = EditorManager.Mode.EM_NONE; } }