Sign up ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

My objects have a location in world coordinates (basically 1.0f is a meter). If I simply draw my objects using their world coordinates, each meter will correspond to a pixel. Obviously that's not what I want.

Now, I don't want to have to apply a transformation to each and every object's position when I draw them. As I happen to be using XNA, and spritebatch allows a Matrix to be passed in as an argument in it's begin method, I was wondering if there is a way to pass the World to Pixel transformation in there. Any suggestions?

So far Matrix.CreateScale(new Vector3(zoom, zoom, 1)) puts the objects in their proper spot, but it also scales up the sprites. Is there a way to transform the position without enlarging the sprite?


share|improve this question
Have you tried using a value below 1 but above zero for zoom? Something like 1/zoom is probably what you want. (edit: damnit why do old Questions keep popping up in my Question feed, sorry for bumping) – PeterT Sep 8 '13 at 12:54

1 Answer 1

In my custom physics engine, I have a similar issue. Instead of using matrices, I created some utility template classes, and they do the job well.

constexpr float pixelsToMeters{100.f};
template<typename T> constexpr T toPixels(T mMeters) { return mMeters / pixelsToMeters; }
template<typename T> constexpr T toMeters(T mPixels) { return mPixels * pixelsToMeters; }

You can also create overloads/specialization for Vector2 or any other data structure you use.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.