LitDev.LDPhysics.AddFixedShape C# (CSharp) Method

AddFixedShape() public static method

Add an existing SmallBasic shape to the physics engine as a fixed (non-dynamic) shape with friction and restitution that affects shapes that hit it.
public static AddFixedShape ( Primitive shapeName, Primitive friction, Primitive restitution ) : void
shapeName Primitive /// The name of the shape. ///
friction Primitive /// The shape friction (usually 0 to 1). ///
restitution Primitive /// The shape restitution or bounciness (usually 0 to 1). ///
return void
        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;
        }