Ellipse always in the center of the screen

Jun 10, 2011 at 12:21 AM
Edited Jun 10, 2011 at 12:21 AM

Hi,

I am new to this. I want my ellipse to appear at bottom left hand corner .  With the following code It is always starts at the center of the window             
I tried changing flyBallPhysicsSprite.BodyObject.Position = new Vector2(0,0); to something other than 0,0. If I do that I cannot see the ellipse at all.

I always want the objec to be at 0,0 when the force is applied. . Any Idea?

Thanks

 

  

 

private void Show(Point endPoint)
        {
            Ellipse es = new Ellipse{Name="es" + (counter++).ToString(), Width=20,Height=20,Fill=new SolidColorBrush(Colors.Black), Visibility=Visibility.Visible};         
            Canvas.SetLeft(es,0);
            Canvas.SetTop(es,300);
            LayoutRoot.Children.Add(es);
            Point point = endPoint;
            double num3 = (point.X - startPoint.X);
            double num4 = -(point.Y - startPoint.Y);
           
            Vector2 force = new Vector2((float)(num3 * 250.0), (float)(num4 * 250.0));

            BehaviorCollection bc1 = Interaction.GetBehaviors(es);
            PhysicsObjectBehavior b1 = new PhysicsObjectBehavior();
            b1.FrictionCoefficient = 0.1d;
            b1.Mass = .8d;           
            b1.RestitutionCoefficient = 0.2d;
            b1.BoundaryElement = es.Name;
            bc1.Add(b1);
            PhysicsObjectMain m1 = (PhysicsObjectMain)es.GetValue(PhysicsObjectMain.PhysicsObjectProperty);
            PhysicsSprite flyBallPhysicsSprite = _physicsController.AddPhysicsBody(m1);
            if (flyBallPhysicsSprite != null)
            {                
                flyBallPhysicsSprite.BodyObject.LinearVelocity = new Vector2(0f, 0f);
                flyBallPhysicsSprite.BodyObject.Position = new Vector2(0,0);
                flyBallPhysicsSprite.BodyObject.ApplyForce(force);
                flyBallPhysicsSprite.BodyObject.ApplyTorque(3500f);
                         
            }
            
        }
Jun 10, 2011 at 12:48 AM

I think you need to convert the screen position to world co-ords. Where the point value is where you want it on screen.

 

flyBallPhysicsSprite.BodyObject.Position = _physicsController.ScreenToWorld(new System.Windows.Point(0, 450));

 

 

Jun 10, 2011 at 1:21 AM

Spruce,

Thanks, that worked.

I have another question. I dont see the eliipse moving ( it might be too fast or slow). How to figure how much force is needed).

Jun 10, 2011 at 1:39 AM

Yeah, i'd say your force is to high. I'd say bring it right down to maybe 2-3.

Jun 10, 2011 at 4:31 AM

You are right. It was high.

Thanks