1

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?

1
  • Please show what you tried, what your sources are... Carefully read How to Ask before asking your next question.
    – J. Chomel
    Jan 3, 2017 at 13:48

3 Answers 3

1

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
  • 1
    My understanding was If I want something to be transformed then I should multiply transform matrix and calling settransform makes things transformed so settingtransform is multiply... I know im stupid. thanks Mar 15 at 5:46
0

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.

1
  • 1
    I'm pretty sure the initial transform is identity, otherwise you would always have to set a transform (which most applications probably don't) or otherwise the drawing would get messed up. Dec 31, 2016 at 7:11
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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