Advertisement

Do 2D games need World View Projection matrices?

Started by May 07, 2017 11:27 PM
1 comment, last by Khatharr 7 years, 7 months ago

Hello everyone,

I'm learning DirectX 11 and I see tutorials that make use of WVP matrices in order to transform an object from local/model coordinates to world coordinates, then to camera space, and finally to projection/clip space.

But all of these tutorials are aimed at 3D game development, and thus I am curious to know: do I need any of these transforms at all in 2D games?

Because there are only 2 axis, right? Aren't most objects in 2D games made out of primitives/quads, so there is no need to "import" models from different formats that belong to different coodinate systems?

I apologize if this is a silly question, and sorry for bad english.

Use of matrices in this way has nothing really to do with how many dimensions you're working with. One way or another, you still need to transform the stuff you're drawing into screen space. Using matrices, or using specifically world/view/projection matrices is just one way to do that. In 3d it's probably the most straightforward approach, but in a 2d scenario, your "projection" probably isn't doing anything, and if your camera only ever pans around, it might not be doing very much either. And again, if everything you draw is axis-aligned, never rotates, etc. then all of your math is potentially very simple.

Aren't most objects in 2D games made out of primitives/quads, so there is no need to "import" models from different formats that belong to different coodinate systems?

Objects in any game, 2d or 3d are going to be made out of primitive shapes on some level. In a 2d game you could get away with creating one quad and redrawing that same one with a different transform and texture on it. You don't need to "import a model" to just draw a textured quad. I'm not an expert in rendering though, so someone else I'm sure could recommend a better approach, or fill in the details that I don't know off the top of my head.

Advertisement

It's worth your time to learn the pipeline and the way that "3D" works as most of this understanding can be used to make 2D graphics faster or better. You can avoid having transform matrices, but you'd need to position your vertices in homogeneous space and then move them around manually. You could potentially use a transform matrix in h-space...

It would be simpler in the long run to just generate an orthographic projection matrix and build a wvp "normally". This will allow you to move the camera over the "2D" space and to work in pixel-sized coordinates. The view matrix moves the camera around, the world matrix moves your quads around, the orthographic projection makes everything look flat and converts from pixel-sized units into h-space coordinates. It really is the easiest way to go, and it makes a lot of special effects very easy to pull off.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

This topic is closed to new replies.

Advertisement