Domanda

I am starting to experiment with some DirectX type stuff, and I had a question about the scaling matrices. If I set my view matrix to:

XMMatrixTranspose(XMMatrixIdentity() * XMMatrixScaling(1.0f,2.0f,1.0f))

Then everything (a centered square) on the y-axis appears twice as big, which is what I expect. If I set it to a negative number, ala:

XMMatrixScaling(1.0f,-2.0f,1.0f)

Then everything disappears. In fact, if I set any value of the scale matrix to < 0 then nothing shows up. I was expecting that the image would just be 'flipped' along the corresponding axis, but it just doesn't show up at all. Is it possible to use negative values when scaling, or am I just doing something completely wrong ??

È stato utile?

Soluzione

This is caused by back-face culling and clipping. Assuming you have culling enabled (on by default), when you set the scale of the x or y axis to negative, it flips the winding order of all the triangles. This causes all the triangles to be considered "backwards" and the GPU doesn't draw them. Assuming you have no other transformation matrices applied, and the square is in the x-y plane, flipping the z sign doesn't cause the triangles to be back-facing, but rather just causes the square to be outside the viewport (e.g. moving from z = 0.5, halfway inside the veiwport depth range, to z = -0.5, outside the viewport depth range).

Back-face culling is a performance optimization since most 3D scenes have closed geometry (or at least, they don't let you see the open parts). This means that every backward facing triangle should have a front facing triangle that covers it, so there's no point in drawing the backward ones. This sometimes isn't always true though, if you've ever played a game and gotten too close to a rock or wall, and been able to see through the whole object, that's because you've clipped through the front, and since the other side is back-facing, it doesn't get drawn.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top