三维空间中的DirectXTK spriteFont
我希望使用DirectXTK在(50,0,0)处显示一个“X”,并在一篇关于公告牌的文章之后显示。然而,我似乎不正确。 谁能帮帮我吗三维空间中的DirectXTK spriteFont,directx,directxmath,Directx,Directxmath,我希望使用DirectXTK在(50,0,0)处显示一个“X”,并在一篇关于公告牌的文章之后显示。然而,我似乎不正确。 谁能帮帮我吗 XMVECTOR textPosition = XMVectorSet(50, 0, 0, 0); unique_ptr<BasicEffect> basicEffect(new BasicEffect(m_pd3dDevice)); unique_ptr<CommonStates> comm
XMVECTOR textPosition = XMVectorSet(50, 0, 0, 0);
unique_ptr<BasicEffect> basicEffect(new BasicEffect(m_pd3dDevice));
unique_ptr<CommonStates> commonStates(new CommonStates(m_pd3dDevice));
/*basicEffect->SetWorld(XMMatrixScaling(1,-1, 1) * XMMatrixTranslationFromVector(textPosition));*/
/* basicEffect->SetWorld( XMMatrixTranslationFromVector(textPosition));
basicEffect->SetView(m_View);*/
basicEffect->SetProjection(m_Projection);
basicEffect->SetTextureEnabled(true);
basicEffect->SetVertexColorEnabled(true);
basicEffect->Apply(m_pImmediateContext);
wstring message = L"X";
XMFLOAT2 textOrigin;
XMStoreFloat2(&textOrigin, m_font->MeasureString(message.c_str()));
const float textSize = 1.0f;
m_spriteBatch->Begin(SpriteSortMode_Deferred, nullptr, nullptr, commonStates->DepthRead(), commonStates->CullNone());
m_font->DrawString(m_spriteBatch.get(), message.c_str(), XMFLOAT2(0, 0), Colors::White, 0, textOrigin, XMFLOAT2(textSize, textSize), SpriteEffects_None, 0.0f);
m_spriteBatch->End();
我认为应该遵循以下几点
XMVECTOR mp = XMVector4Transform(textPosition, m_World);
XMVECTOR pt = XMVector3Project(mp, 0, 0, GetViewPort().Width, GetViewPort().Height, 0, 1, m_Projection, m_View, m_World);
XMFLOAT3 pos;
XMStoreFloat3(&pos, pt);
m_spriteBatch->Begin();
m_font->DrawString(m_spriteBatch.get(), message.c_str(), XMFLOAT2(pos.x, pos.y), Colors::LightGreen, 0.0f, XMFLOAT2(0, 0), XMFLOAT2(0.6f, 0.6));
m_spriteBatch->End();
我认为应该遵循以下几点
XMVECTOR mp = XMVector4Transform(textPosition, m_World);
XMVECTOR pt = XMVector3Project(mp, 0, 0, GetViewPort().Width, GetViewPort().Height, 0, 1, m_Projection, m_View, m_World);
XMFLOAT3 pos;
XMStoreFloat3(&pos, pt);
m_spriteBatch->Begin();
m_font->DrawString(m_spriteBatch.get(), message.c_str(), XMFLOAT2(pos.x, pos.y), Colors::LightGreen, 0.0f, XMFLOAT2(0, 0), XMFLOAT2(0.6f, 0.6));
m_spriteBatch->End();
使用DirectX工具包的
SpriteBatch
,您还可以通过使用SetRotation(DXGI_模式_旋转_未指定)来“关闭”最终视口缩放
然后,您可以在Begin
上提供完整的变换作为可选的transformationMatrix参数。使用DirectX工具包的SpriteBatch
您还可以使用SetRotation(DXGI_模式_ROTATION_未指定)来“关闭”最终视口缩放
然后,您可以在Begin
上提供完整的转换作为可选的transformationMatrix参数。