首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >3D空间中的DirectXTK spriteFont

3D空间中的DirectXTK spriteFont
EN

Stack Overflow用户
提问于 2015-10-16 02:00:12
回答 1查看 190关注 0票数 1

我希望使用DirectXTK在(50,0,0)处显示一个"X“,并关注一篇关于广告牌的文章。然而,我似乎没有把它弄对。谁能帮帮我。

代码语言:javascript
复制
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();

这看起来很有希望

代码语言:javascript
复制
XMVECTOR textPosition = XMVectorSet(50, 0, 0, 0);
wstring message = L"X";
textPosition = XMVector3Transform(textPosition, m_View);
textPosition = XMVector3Transform(textPosition, m_Projection);
XMFLOAT3 pos;
XMStoreFloat3(&pos, textPosition);
pos.x /= pos.z;
pos.y /= pos.z; 
pos.x = (pos.x + 1.0) * GetViewPort().Width  / 2.0;
pos.y = (-pos.y + 1.0) * GetViewPort().Height / 2.0;


m_spriteBatch->Begin();
m_font->DrawString(m_spriteBatch.get(), message.c_str(), XMFLOAT2(pos.x, pos.y), Colors::White, 0.0f, XMFLOAT2(0, 0), XMFLOAT2(0.5f, 0.5), SpriteEffects_None);     
m_spriteBatch->End();
EN

回答 1

Stack Overflow用户

发布于 2015-10-17 01:11:25

我认为应该遵循以下几点。

代码语言:javascript
复制
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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33155405

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档