D3DXVec3项目需要一半的对象位置
D3DXVec3Project requiring half the object position
我只是在写一些代码来测试D3DXVec3Project函数,试图让它将文本对齐到三维位置。
3D到2D代码:
D3DXVECTOR3 ToScreenSpace(D3DXVECTOR3 position)
{
D3DXVECTOR3 out;
D3DVIEWPORT9 view;
D3DXMATRIX matView;
D3DXMATRIX matWorld;
D3DXMATRIX matProj;
D3DXMATRIX worldPos;
D3DXMATRIX worldRotX;
D3DXMATRIX worldRotY;
D3DXMATRIX worldRotZ;
D3DXMATRIX worldScl;
graphicsDevice->GetViewport(&view); //view in debug is showing all the correct values.
graphicsDevice->GetTransform(D3DTS_VIEW, &matView); //view is set each frame from the camera
graphicsDevice->GetTransform(D3DTS_PROJECTION, &matProj); //this is set once in the scene manager
D3DXMatrixTranslation(&matWorld, position.x, position.y, position.z); //uses the given position for the world matrix
D3DXVec3Project(&out, &position, &view, &matProj, &matView, &matWorld);
return out;
}
测试代码:D3DXVECTOR3试验;test.x=90;test.y=0;test。z=70;test=ToScreenSpace(测试);
RECT rct;
rct.left = test.x;
rct.right=test.x + 650;
rct.top = test.y;
rct.bottom=rct.top + 20;
m_font->DrawText(NULL, L"Hello World", -1, &rct, 0, fontColor );
问题是,无论在test.xyz中放置什么值,都会提供两倍的屏幕空间坐标。
即,为了使ToScreenSpace将文本正确地与3D空间50,0,50对齐,我需要给文本值25,0,25。90,10,70?45,5,35等
我只是想知道为什么会出现这种情况。
获得两倍数量的原因是,您使用一个值翻倍的世界矩阵来转换有问题的点。只需将单位矩阵作为世界矩阵提供给D3DXVec3Project
函数。
相关文章:
- 如何使用cudaMallocManaged在指针位置初始化对象?(C++)
- 无法获取webot::PositionSensor对象中位置传感器的值
- 使用迭代器时如何访问对象在向量中的位置?
- 如何根据C++在同一内存位置重新初始化 C# 中的对象(还是自动完成)?
- 在C++代码中搜索对象的实例化位置
- 在特定内存位置构造 c++ 对象
- delete如何知道对象在内存中的起始位置
- 在 DLL 中嵌入 Python:Py_DECREF列表对象时访问冲突读取位置
- 在C++标准中记录对象的内存布局的哪个位置?
- QT:即使在static_cast后也无法在主窗口中设置对象的位置
- 将光标位置存储在类对象中(ncurses c++)
- 如果访问对象,则指向的对象内部的指针会更改内存位置
- 如何在3D世界中获得对象相对于父母的绝对位置
- 如何在C 2D向量中找到对象(而不是int)的位置
- 从文件对象的当前位置删除字符
- 将对象位置与网格对齐
- D3DXVec3项目需要一半的对象位置
- Cocos 2dx 人像模式对象位置混乱
- 如何使用Qt的QGLWidget准确更新OpenGL中的对象位置?
- 运算符重载-如何更改对象位置