Hi!
I created 4 rectangles in order to create a border around my application so the elements did not "fly away".
The time to startup the app was huge due to the calculation and initialization of the paths of the rectangles.
I did a little optimization in boundaryhelper so that Rectangles are treated specially:
In GetPointsForPath I added:
if (element is System.Windows.Shapes.Rectangle)
{
result.Add(new Point(left, top));
result.Add(new Point(left+width, top));
result.Add(new Point(left+width, top+height));
result.Add(new Point(left, top+height));
return result;
}
and in PhysicsSprite.xaml.cs I only allow the points optimization if it is not a Rectangle:
// let's clean up the number of points, for a little performance boost..
if (!(element is System.Windows.Shapes.Rectangle)) {...}
Another improvement could be made. In the rectangles case we could use a Rectangle instead of a Polygon:
BodyObject = BodyFactory.Instance.CreateBody(physicsSim, 0.5f, vertices.GetMomentOfInertia());
GeometryObject = GeomFactory.Instance.CreatePolygonGeom(physicsSim, BodyObject, vertices, 0);
could be replaced by somthing like:
BodyObject = BodyFactory.Instance.CreateRectangleBody(physicsSim, (float)width, (float)height, (float)(width * height) * .0001F);
GeometryObject = GeomFactory.Instance.CreateRectangleGeom(physicsSim, BodyObject, (float)width, (float)height);
bye,
Tiago Andrade e Silva
