From b8fffef04ada896de41594b3ce44537f4aa11a3f Mon Sep 17 00:00:00 2001 From: notgiven688 <37874600+notgiven688@users.noreply.github.com> Date: Tue, 2 Jan 2024 21:29:09 +0100 Subject: [PATCH] Add optional activate parameter to world.AddShape (#90) --- src/Jitter2/Dynamics/RigidBody.cs | 2 +- src/Jitter2/World.cs | 11 ++--------- src/JitterDemo/Demos/Demo20.cs | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/Jitter2/Dynamics/RigidBody.cs b/src/Jitter2/Dynamics/RigidBody.cs index f2e320a2..05aa4e03 100644 --- a/src/Jitter2/Dynamics/RigidBody.cs +++ b/src/Jitter2/Dynamics/RigidBody.cs @@ -345,7 +345,7 @@ private void AttachToShape(Shape shape) } shape.UpdateWorldBoundingBox(); - World.AddShape(shape); + World.AddShape(shape, this.IsActive); } /// diff --git a/src/Jitter2/World.cs b/src/Jitter2/World.cs index ea06b0d5..f043a9de 100644 --- a/src/Jitter2/World.cs +++ b/src/Jitter2/World.cs @@ -377,21 +377,14 @@ internal void UpdateShape(Shape shape) /// /// Add a shape not associated with a rigid body to the world. /// - public void AddShape(Shape shape) + public void AddShape(Shape shape, bool active = true) { if (shape.IsRegistered) { throw new ArgumentException("Shape can not be added. Is the shape already registered?"); } - bool activate = true; - - if (shape.RigidBody != null) - { - activate = shape.RigidBody.IsActive; - } - - shapes.Add(shape, activate); + shapes.Add(shape, active); shape.UpdateWorldBoundingBox(); DynamicTree.AddProxy(shape); } diff --git a/src/JitterDemo/Demos/Demo20.cs b/src/JitterDemo/Demos/Demo20.cs index 72c580e0..c4cbb814 100644 --- a/src/JitterDemo/Demos/Demo20.cs +++ b/src/JitterDemo/Demos/Demo20.cs @@ -126,7 +126,7 @@ public void Build() // events generated by Jitter and add our own collision handling. Make the test shape // the dimensions of the octree. var testShape = new TransformedShape(new BoxShape(octree.Dimensions.Max - octree.Dimensions.Min), octree.Dimensions.Center); - world.NullBody.AddShape(testShape); + world.AddShape(testShape, false); world.BroadPhaseFilter = new CustomCollisionDetection(world, testShape, octree); }