This project is read-only.

How to create an elipsse shaped PhysicsCanvas?

Feb 4, 2013 at 12:51 PM
Hi,

Im trying to create an ellipse shaped PhysicsCanvas. The goal is to create a bowl shape with a little ball in it. something like a labyrinth game in a bowl.

How do it get the correct ellipse shape for my 'world'?

thanks a million
Feb 4, 2013 at 2:13 PM
Do you mean that this is a top-down view of the game, and the ball should get pulled to the center of the bowl shape? If so, then you would need a magnetic behavior.

I haven't added magnets yet to Physics Helper XAML, but the older "Physics Helper for Blend" had a Magnet Behavior. The core is pretty simple, I pasted it below...
    void _controller_TimerLoop(object source)
    {
        if (sprite == null) return;

        foreach (PhysicsMagnetBehavior other in worldMagnets)
        {

            if (other == this || other.sprite.BodyObject == null) continue;

            Vector2 force = other.sprite.BodyObject.Position - this.sprite.BodyObject.Position;

            if (force.Length() < (this.MaxDistance + other.MaxDistance))
            {
                force = 5000 * force * (1 / (float)System.Math.Pow(force.LengthSquared(), this.FallOff + other.FallOff)) * (float)(this.Magnetism + other.Magnetism);

                this.sprite.BodyObject.ApplyForceAtWorldPoint(force, other.sprite.BodyObject.Position);
            }
        }
    }
Feb 4, 2013 at 2:22 PM
Hi Andy,

Thats exactly what im building. I have the magnetic behaviour pretty much working using the balls position and setting the horizontal gravity and vertical gravity but im going to implement youre solution.

The question really was how to mold the PhysicsCanvas into an ellipse shape as its an square by default..? I was hoping that by molding the canvas in the shape of an ellipse i wont have to make all sorts of bounds to keep the ball in the bowl...

Frank
Mar 7, 2013 at 4:07 PM
I solved it btw bij drawing an ellipse in code. I created a usercontrol named bound that gets set on the screen
            for (double step = 0; step <= (2 * Math.PI); step += 0.015)
            {
                pointX = offsetX + (width / 4) * Math.Cos(step);
                pointY = offsetY + (height / 4) * Math.Sin(step);
               

                //ADD OBJECT here, dont forget to add an object manually to close the gap between the last en first object
             }