Skip to content

Commit

Permalink
Add optional activate parameter to world.AddShape (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
notgiven688 authored Jan 2, 2024
1 parent fd70e86 commit b8fffef
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Jitter2/Dynamics/RigidBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ private void AttachToShape(Shape shape)
}

shape.UpdateWorldBoundingBox();
World.AddShape(shape);
World.AddShape(shape, this.IsActive);
}

/// <summary>
Expand Down
11 changes: 2 additions & 9 deletions src/Jitter2/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,21 +377,14 @@ internal void UpdateShape(Shape shape)
/// <summary>
/// Add a shape not associated with a rigid body to the world.
/// </summary>
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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/JitterDemo/Demos/Demo20.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b8fffef

Please sign in to comment.