Multiplication with identity matrix in Direct2D - why?

366 views Asked by At

I'm using C++. I saw [here](-here I should add the link-) the code below on MSDN:

m_pRenderTarget->BeginDraw();
m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));

I wonder why they multiply with the identity matrix. It makes no change: I * A = A if A * B = C. I * C = C, not C * I = A, so it's not C * I = A, but my friend said if I SetTransform(identity), rendertarget becomes initial state.

Why do they multiply with the identity matrix?

3

There are 3 answers

1
J. Chomel On BEST ANSWER

I saw here this syntax is to be used when one wants to To remove the current transform

They say if you have:

 pRenderTarget->SetTransform(
    D2D1::Matrix3x2F::Rotation(20, D2D1::Point2F(100,100)));

The transform is applied to all subsequent drawing operations until you call SetTransform again. To remove the current transform, call SetTransform with the identity matrix, which is returned by the Matrix3x2F::Identity function.

pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
1
Indiana Kernick On

The initial transform maybe be zero or it may be garbage (uninitialized) or it could even be identity but we dont know. So you should set it to identity so that you know what the transform is. Regardless of what the initial transform actually is you should assume that it is unitialized and assign it a value before you use it.

0
Rick Brewster On

SetTransform should not be confused with something like MultiplyTransform (which doesn't exist). You are setting the transform, not appending to it. In Direct2D, it's up to you to do push/pop style matrix manipulation.