C++ Direct2D Matrix transformation mirror
Pergunta
I am currently learning DirectX (SDK of June 2010) and am drawing bitmaps to screen. Now I want to be able to do transformations on these images, and fail to mirror the images along the x- or y- axis.
Before drawing, I am able to set a transformation matrix that will be applied to the drawing operations. Though DirectX is using the D2D1_MATRIX_3x2_F type, according to MSDN, only a 2x2 part of this matrix is used for transformations. For example, the matrix { [1, 0], [0, 1], [0, 0] } is the identity matrix that causes everything to be displayed naturally.
As I understand it, a matrix transformation to mirror my image along the x-axis should look like this: { [1, 0], [0, -1], [0, 0] }, and along the y-axis it would then be { [-1, 0], [0, 1], [0, 0] }. If I use these matrices for the transformation however, I get a black screen.
The problem for me is, that I am kind of stuck at this point without ideas what this problem could be caused by, or rather whether it is caused by a logical error in the mathematics behind this, or the implementation itself. Unfortunately, I could not find any material on this, besides a one line comment that "mirroring has to be done with matrix transformations" in the header file of the Direct2D RenderTarget.
The source code I am currently using for testing this is:
D2D1_MATRIX_3X2_F m;
m._11 = 1; m._12 = 0;
m._21 = 0; m._22 = -1;
m._31 = 0; m._32 = 0;
m_pDX2DRenderTarget->SetTransform( m );
Solução
I was completely mistaken about the third row of the matrix not being relevant. It is in fact the x-
and y-
offset for the transformation. The reason why I did not see anything after my transformation is that, after applying a mirror, not only the image itself will be mirrored, but also its position on screen.
For example, if I display an image so its top left edge will be at (100, 100)
, after applying the matrix transformation of a x-axis mirror, the top right edge of the image will be at (-100, 100)
. Since this is always out of the rendering area, it will not show.