二进制 '-' : 'DirectX::XMVECTOR' 没有定义这个运算符或转换(从 xnamath 迁移到 DirectXMath 并不容易)
binary '-' : 'DirectX::XMVECTOR' does not define this operator or a conversion (migrating from xnamath to DirectXMath is not so easy)
我有一些使用xnamath.h
的DirectX C++代码。我想迁移到"全新"的DirectXMath
,所以我改变了:
#include <xnamath.h>
至
#include <DirectXMath.h>
我还添加了DirectX
命名空间,例如:
DirectX::XMFLOAT3 vector;
我已经为麻烦做好了准备,他们来了!
在编译过程中,我出现错误:
error C2676: binary '-' : 'DirectX::XMVECTOR' does not define this operator
or a conversion to a type acceptable to the predefined operator
对于适用于xnamth.h
的线路:
DirectX::XMVECTOR RayDir = CursorObjectSpace - RayOrigin;
我真的不知道如何修复它。我认为operator-
不再"不受支持",但是什么原因导致了这个错误,以及如何修复它?
这里是更复杂的源代码:
DirectX::XMVECTOR RayOrigin = DirectX::XMVectorSet(cPos.getX(), cPos.getY(), cPos.getZ(), 0.0f);
POINT mouse;
GetCursorPos(&mouse);
DirectX::XMVECTOR CursorScreenSpace = DirectX::XMVectorSet(mouse.x, mouse.y, 0.0f, 0.0f);
RECT windowRect;
GetWindowRect(*hwnd, &windowRect);
DirectX::XMVECTOR CursorObjectSpace = XMVector3Unproject( CursorScreenSpace, windowRect.left, windowRect.top, screenSize.getX(), screenSize.getY(), 0.0f, 1.0f, XMLoadFloat4x4(&activeCamera->getProjection()), XMLoadFloat4x4(&activeCamera->getView()), DirectX::XMMatrixIdentity());
DirectX::XMVECTOR RayDir = CursorObjectSpace - RayOrigin;
我在Windows7x64上工作,项目目标是x32调试,到目前为止它在xnamath.h
上运行良好。
工作解决方案将是:
DirectX::XMVECTOR RayDir = DirectX::XMVectorSet( //write more, do less..
DirectX::XMVectorGetX(CursorObjectSpace) - DirectX::XMVectorGetX(RayOrigin),
DirectX::XMVectorGetY(CursorObjectSpace) - DirectX::XMVectorGetY(RayOrigin),
DirectX::XMVectorGetZ(CursorObjectSpace) - DirectX::XMVectorGetZ(RayOrigin),
DirectX::XMVectorGetW(CursorObjectSpace) - DirectX::XMVectorGetW(RayOrigin)
); //oh my God, I'm so creepy solution
但与之前相比,这太令人毛骨悚然了,为xnamath
:工作
XMVECTOR RayDir = CursorObjectSpace - RayOrigin;
我真的不相信这是唯一的方法,我不能像上面那样只使用operator-
。
对于operator/
,我也有完全相同的问题。
Microsoft在DirectXMathVector.inl标头中提供运算符重载,该标头包含在DirectXMath.h的末尾。但是,为了能够使用它,您必须在尝试使用运算符的范围中具有"using namespace DirectX"。
例如:
void CalculateRayDirection(const DirectX::XMVECTOR& rayOrigin, DirectX::XMVECTOR& rayDirection)
{
using namespace DirectX;
POINT mouse;
GetCursorPos(&mouse);
XMVECTOR CursorScreenSpace = XMVectorSet(mouse.x, mouse.y, 0.0f, 0.0f);
rayDirection = CursorObjectSpace - rayOrigin;
}
XMVector的减号和除号运算符没有重载,因为XMVector不是类-它是用于SSE运算的__m128数据类型的typedef。
在升级到DirectXMath的过程中,微软打算通过使矢量运算"具有SSE功能"来加快矢量运算的速度。他们还提供了XMVectorSubtract等函数,让您在执行算术运算时使用SSE。
你可以在这里找到更多信息:http://msdn.microsoft.com/en-us/library/windows/desktop/ee415656(v=vs.85).aspx
- 将项目从 Debian 8 Xenomai 2.x 迁移到 Debain 9 Xenomai 3.x
- 从 MFC C++ 6.0 应用程序迁移到 VS 2005
- 将预处理器配置定义迁移到 constexpr,而不会造成内存膨胀
- 如何在 MSVC C++中迁移 x64 的 x86 代码
- "acceptor"在从TCP迁移到UDP时不是"boost::asio::ip::udp
- 将代码从 32 位迁移到 64 位时出现问题 Visual Studio 2010
- 如何在新设计中迁移需要几个额外参数的函数
- 如何将 C 函数指针迁移到C++?
- WDK 如何迁移到 v4 打印机驱动程序
- 迁移到 Visual Studio 2015 时 ATL 不起作用
- 从 calloc() 迁移到 new
- 如何将C++项目从 32 位迁移到 64 位以支持 MAC OS 10.14(莫哈韦)?
- 从固定函数迁移到 GLSL OpenGL:我应该如何修改我的视图(lookAt)矩阵和透视矩阵?
- C++从多线程 CPU 程序迁移到 GPU
- 自从迁移到 64 位以来,我在随机 glVertexAttribArray 调用中收到来自 nvoglv64.dll 的
- 如何管理和迁移C++库?
- 光纤可以在线程之间迁移吗?
- 将缓存线迁移到另一个核心
- 迁移 CMake 会导致多阶段 Docker 构建
- 二进制 '-' : 'DirectX::XMVECTOR' 没有定义这个运算符或转换(从 xnamath 迁移到 DirectXMath 并不容易)