Getting current body position

Nov 25, 2010 at 7:06 PM

Sorry if this is a basic question, but I am having difficulty finding an answer:


In C# WP7 Silverlight, how does one get the current Canvas.Top and Canvas.Left position of a Shape that is being drawn as a body in the Physics simulation?



Nov 25, 2010 at 9:38 PM

I'm not sure if I understand your question?

If you want to know how to draw an physics object using Silverlight this is one way of doing it:

//Scale object
                ScaleTransform ST = new ScaleTransform();
                ST.ScaleX = scaleX;
                ST.ScaleY = scaleY;
                RotateTransform RT = new RotateTransform();
                RT.Angle = compundFixture[0].Body.Rotation * (180 / Math.PI);
                //Move to correct location
                TranslateTransform TT = new TranslateTransform();
                TT.X = ConvertUnits.ToDisplayUnits(compundFixture[0].Body.Position.X) - image.ActualWidth / 2;
                TT.Y = ConvertUnits.ToDisplayUnits(compundFixture[0].Body.Position.Y) - image.ActualHeight / 2;

                TransformGroup transformGroup = new TransformGroup();


                image.RenderTransform = transformGroup;
                image.RenderTransformOrigin = new Point(0.5f, 0.5f);

Nov 26, 2010 at 9:29 PM
Edited Nov 26, 2010 at 9:30 PM

Hi, thanks.


My question is:

I have set up a basic Physics controller and I have a Shape object to which I have added a PhysicsObjectBehavior:



Rectangle _shape = new Rectangle();
BehaviorCollection behaviorCollection = Interaction.GetBehaviors(_shape);
PhysicsObjectBehavior pob = new PhysicsObjectBehavior(); 
_physicsController.AddPhysicsBody(_shape.GetValue(PhysicsObjectMain.PhysicsObjectProperty) as PhysicsObjectMain);            

... and when I run the application, the _shape object draws under control of the physics simulation as expected.  

What I would like to know, at any given time, are the coordinates of _shape in relation to its parent Canvas.


Dec 3, 2010 at 10:25 PM

Sorry but I have no experience with using Behaviours.

You should probably look at Andy's work:

This should give you insight how he does it.