Skip to content

Commit

Permalink
Improve cloth demo
Browse files Browse the repository at this point in the history
  • Loading branch information
notgiven688 committed Oct 28, 2023
1 parent 982b2e9 commit 83b5344
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
29 changes: 19 additions & 10 deletions src/JitterDemo/Demos/Demo17.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ public void Build()

pg.ResetScene();

const int len = 30;
const float scale = 0.3f;

const int len = 40;
const float scale = 0.2f;
const int leno2 = len / 2;

List<JTriangle> tris = new();

for (int i = 0; i < len; i++)
Expand All @@ -40,12 +39,24 @@ public void Build()
JVector v1 = new JVector((-leno2 + e + 0) * scale, 6, (-leno2 + i + 1) * scale);
JVector v2 = new JVector((-leno2 + e + 1) * scale, 6, (-leno2 + i + 0) * scale);
JVector v3 = new JVector((-leno2 + e + 1) * scale, 6, (-leno2 + i + 1) * scale);
tris.Add(new JTriangle(v0, v1, v2));
tris.Add(new JTriangle(v1, v2, v3));
tris.Add(new JTriangle(v0, v2, v3));

bool even = (e + i) % 2 == 0;

if (even)
{
tris.Add(new JTriangle(v0, v1, v2));
tris.Add(new JTriangle(v1, v2, v3));
}
else
{
tris.Add(new JTriangle(v1, v3, v0));
tris.Add(new JTriangle(v3, v2, v0));
}
}
}


cloth = new SoftBodyCloth(world, tris);

var b0 = world.CreateRigidBody();
b0.Position = new JVector(-1, 10, 0);
b0.AddShape(new BoxShape(1));
Expand All @@ -60,8 +71,6 @@ public void Build()
b2.Position = new JVector(1, 11, 0);
b2.AddShape(new SphereShape(0.5f));

cloth = new SoftBodyCloth(world, tris);

world.DynamicTree.Filter = DynamicTreeCollisionFilter.Filter;
world.BroadPhaseFilter = new BroadPhaseCollisionFilter(world);

Expand Down
2 changes: 1 addition & 1 deletion src/JitterDemo/Demos/SoftBody/SoftBodyCloth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void Build()
foreach (var vertex in vertices)
{
RigidBody body = world.CreateRigidBody();
body.SetMassInertia(JMatrix.Identity * 1000, 0.1f);
body.SetMassInertia(JMatrix.Identity * 1000, 0.01f);
body.Position = vertex;
Vertices.Add(body);
}
Expand Down

0 comments on commit 83b5344

Please sign in to comment.