public static void AddFixedShape(Primitive shapeName, Primitive friction, Primitive restitution)
{
float posXS, posYS, sizeXS, sizeYS;
string success;
Type GraphicsWindowType = typeof(GraphicsWindow);
Dictionary<string, UIElement> _objectsMap;
UIElement obj;
Utilities.doUpdates();
Shapes.Rotate(shapeName, _Engine.getShapeAngle(shapeName)); // Create the SB transform
Utilities.doUpdates();
try
{
_objectsMap = (Dictionary<string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
if (!_objectsMap.TryGetValue((string)shapeName, out obj))
{
Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
return;
}
InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
{
try
{
Rect rect = new Rect(obj.RenderSize);
rect.Offset(System.Windows.Media.VisualTreeHelper.GetOffset(obj));
sizeXS = (float)rect.Width / 2.0f;
sizeYS = (float)rect.Height / 2.0f;
posXS = (float)rect.Left + sizeXS;
posYS = (float)rect.Top + sizeYS;
_Engine.addSprite(shapeName, posXS, posYS, sizeXS, sizeYS, friction, restitution, 1.0f, spriteType.FIXED);
return "True";
}
catch (Exception ex)
{
Utilities.OnError(Utilities.GetCurrentMethod(), ex);
return "False";
}
});
success = FastThread.InvokeWithReturn(ret).ToString();
}
catch (Exception ex)
{
Utilities.OnError(Utilities.GetCurrentMethod(), ex);
return;
}
return;
}