This project has moved and is read-only. For the latest updates, please go here.

MKS->pixel conversion

Topics: Developer Forum
Mar 14, 2011 at 4:21 PM
Edited Mar 14, 2011 at 4:21 PM

Hi to all,

(this is my first post here, and my first work with XNA too).

Recently, I've tried to get in work basic sprite management with XNA and Farseer simulations. All went good, but I've encountered
some problems with that stuffs about conversion from MKS to pixel format. I've searched throught the forum and found some answers, but
still I didn't get how it works

Can someone point out or maybe posts basic simple code that shows up of to convert MKS->pixel, with a static sprite stuffs in it?

Mar 14, 2011 at 5:00 PM

okk, I found the new Hello XNA in the svn-base, I'm going to study it!

Mar 14, 2011 at 5:00 PM

Hi Archedius, check out this video tutorial . It is Box2D which Farseer is a port of. It may give you some insight and answer some questions. Tell me if this helps if not will try and assist further.

Mar 14, 2011 at 5:22 PM

Hi, very thanks for the reply, it helps a lot! :)

Standing on what I've understood from video, I must define some kind of arbitrary ratio, then divide every measurement with that ratio, is it right?
(I've founded indeed some of this logic in the new Hello XNA code too)

Tomorrow, in the very morning, I will try to do some coding in this way, and tell the world about the results!

Mar 15, 2011 at 2:00 PM

Okay, I've got it. I've resolved the coordinate problem using the method graphics.GraphicsDevice.Viewport.Project(worldVector, projection, view, worldTransform), and passing the vector calculated in this way to Draw(...) function in the place of body.Position.

Well, still remains the dimension problem. In order to know the corrisponding pixel need to fill 1m (standing on what I've seen in the video), I've settled the following: es. 1m = 15 pixel. Than, I've scaled the world matrix by an arbitrary value to make corrisponding a rect of 1m heigth with a 15 pixel Sprite (in my case that value was 1.5, something like view = Matrix.CreateScale(1.5f)).

Am I doing right?


(I hope i make myself clear, my english is little wobbly!)

Mar 18, 2011 at 2:23 PM

I explained how it works here:

Mar 22, 2011 at 3:05 PM

Very thanks, now I've fully undestood the way to do coordinates conversion.