Concave sphere problems.
Posted: Wed Mar 16, 2011 5:41 pm
Looking through the demos and the notes I've decide to create a concave shape using the 'DynamicCompoundEntry' class.
Following the notes and your advice on triangles I have tried many ways to create a concave sphere composed of triangles but none of them have been successful.
The non recentered triangle without scaling will pass through walls also (maybe due to triangle sidedness?). If the triangle sidedness is a problem how can I contain objects inside a concave body and still have the outside of the concave body collide with the environment? Double sided triangles force the contained bodies outside the concave body.
The non recentered triangle can't be scaled without causing NaN errors in the space:
I am drawing the compound shape like so
How can I correctly create a concave sphere that can be scaled and drawn correctly?
Following the notes and your advice on triangles I have tried many ways to create a concave sphere composed of triangles but none of them have been successful.
Code: Select all
public ConcaveSphere(Game1 game, float radius)
{
this.game = game;
CustomModel model = game.Models["Sphere"];
int numTriangles = model.ModelData.Triangles.Length;
float scale = 2f * radius;
Matrix scaleTransform = new Matrix();
scaleTransform.M11 = scale;
scaleTransform.M12 = scale;
scaleTransform.M13 = scale;
scaleTransform.M21 = scale;
scaleTransform.M22 = scale;
scaleTransform.M23 = scale;
scaleTransform.M31 = scale;
scaleTransform.M32 = scale;
scaleTransform.M33 = scale;
scaleTransform.M44 = 1f;
List<DynamicCompoundEntry> triangles = new List<DynamicCompoundEntry>(numTriangles);
for (int i = 0; i < numTriangles; ++i)
{
// [Non Recentered Triangle]
TriangleShape tri = new TriangleShape();
tri.VertexA = model.ModelData.Triangles[i].A;
tri.VertexB = model.ModelData.Triangles[i].B;
tri.VertexC = model.ModelData.Triangles[i].C;
// [Scaled Non Recentered Triangle]
//tri.VertexA = Vector3.Transform(model.ModelData.Triangles[i].A, scaleTransform);
//tri.VertexB = Vector3.Transform(model.ModelData.Triangles[i].B, scaleTransform);
//tri.VertexC = Vector3.Transform(model.ModelData.Triangles[i].C, scaleTransform);
// [Recentered Triangle]
//Vector3 centre;
//TriangleShape tri = new TriangleShape(
// model.ModelData.Triangles[i].A,
// model.ModelData.Triangles[i].B,
// model.ModelData.Triangles[i].C,
// out centre
// );
//TriangleShape tri = new TriangleShape(
// Vector3.Transform(model.ModelData.Triangles[i].A, scaleTransform),
// Vector3.Transform(model.ModelData.Triangles[i].B, scaleTransform),
// Vector3.Transform(model.ModelData.Triangles[i].C, scaleTransform)
// );
tri.Sidedness = TriangleSidedness.Counterclockwise;
triangles.Add(
new DynamicCompoundEntry(
tri,
100f
)
);
}
body = new CompoundBody(triangles);
game.Space.Add(body);
}
The non recentered triangle can't be scaled without causing NaN errors in the space:
The recentered triangle will draw incorrectly but I am unsure as to how to reposition the triangle with the 'out center' parameter.Function does not accept floating point Not-a-Number values.
I am drawing the compound shape like so
Code: Select all
public void Draw()
{
int numShapes = compoundbody.Shapes.Count;
for (int i = 0; i < numShapes; ++i)
{
TriangleShape t = body.Shapes[i].Shape as TriangleShape;
Vector3 v0 = Vector3.Transform(t.VertexA, compoundbody.WorldTransform);
Vector3 v1 = Vector3.Transform(t.VertexB, compoundbody.WorldTransform);
Vector3 v2 = Vector3.Transform(t.VertexC, compoundbody.WorldTransform);
game.WireShapeDrawer.DrawWireTriangle(v0, v1, v2, Color.White);
}
}