我是Direct 2D的新手,有点迷失。 我试图旋转一个对象,但我正在做的方式,它旋转整个游戏屏幕而不是一个对象。我对于如何处理旋转特定对象毫无头绪。我希望我提供了足够的信息,但如果没有,请告诉我。如果这是一个愚蠢的简单问题,我很抱歉。 任何帮助都感激不尽。
void SpriteSheet::Draw(bool rotate)
{
ID2D1Effect *chromakeyEffect = NULL;
ID2D1Effect *scaleit = NULL;
ID2D1Effect * rotation = NULL;
D2D1_POINT_2F ptss = { 50, 50 };
D2D1_VECTOR_3F vec{ -5.0f, -500.0f, 100.0f };
D2D1_VECTOR_3F vector{ 0.0f, 1.0f, 0.0f };
// this is the rotating part
if (rotate)
{
//D2D1::Matrix3x2F::Identity()._11;
gfx->GetRenderTarget()->SetTransform(
D2D1::Matrix3x2F::Rotation(20, D2D1::Point2F(100, 100)));
}
gfx->GetDeviceContext()->CreateEffect(CLSID_D2D1ChromaKey, &chromakeyEffect);
gfx->GetDeviceContext()->CreateEffect(CLSID_D2D1Scale, &scaleit);
gfx->GetDeviceContext()->CreateEffect(CLSID_D2D12DAffineTransform, &rotation);
// applying chroma key
chromakeyEffect->SetInput(0, bmp);
chromakeyEffect->SetValue(D2D1_CHROMAKEY_PROP_COLOR, vector);
chromakeyEffect->SetValue(D2D1_CHROMAKEY_PROP_TOLERANCE, 0.8f);
chromakeyEffect->SetValue(D2D1_CHROMAKEY_PROP_INVERT_ALPHA, false);
chromakeyEffect->SetValue(D2D1_CHROMAKEY_PROP_FEATHER, false);
// scale the object
scaleit->SetInputEffect(0, chromakeyEffect);
//scaleit->SetValue(D2D1_SCALE_PROP_BORDER_MODE, vec);
//scaleit->SetValue(D2D1_SCALE_PROP_CENTER_POINT, D2D1::Vector2F(1.0f, 1.0f));
scaleit->SetValue(D2D1_SCALE_PROP_SCALE, D2D1::Vector2F(0.50f, 0.50f));
// draw it on screen
gfx->GetDeviceContext()->DrawImage(scaleit, ptss);
if (chromakeyEffect) chromakeyEffect->Release();
}
答案 0 :(得分:0)
刚刚遇到了旋转矩阵,这就解决了这个问题。我正在进行比例效果并对其应用旋转。
if(rotate)
{
rotation->SetInputEffect(0, scaleit);
D2D1_MATRIX_3X2_F matrix = D2D1::Matrix3x2F::Rotation(98, D2D1::Point2F(50, 40));
rotation->SetValue(D2D1_2DAFFINETRANSFORM_PROP_TRANSFORM_MATRIX, matrix);
}