我正在尝试迁移到 directxmath,但是新代码给我带来了一些麻烦..
class Vec3 : public XMFLOAT3
{
public:
inline float Length() { return XMVector3Length(this); }
inline Vec3 *Normalize() { return static_cast<Vec3 *>( XMVector3Normalize(this, this)); }
inline float Dot(const Vec3 &b) { return XMVector3Dot(this, &b); }
inline Vec3 Cross(const Vec3 &b) const;
Vec3(XMFLOAT3 &v3) { x = v3.x; y = v3.y; z = v3.z; }
Vec3() : XMFLOAT3() { XMVectorZero(); }
Vec3(const float _x, const float _y, const float _z) { x=_x; y=_y; z=_z; }
Vec3(const double _x, const double _y, const double _z) { x = (float)_x; y = (float)_y; z = (float)_z; }
inline Vec3(const class Vec4 &v4);
};
旧代码如下所示:
class Vec3 : public D3DXVECTOR3
{
public:
inline float Length() { return D3DXVec3Length(this); }
inline Vec3 *Normalize() { return static_cast<Vec3 *(D3DXVec3Normalize(this, this)); }
inline float Dot(const Vec3 &b) { return D3DXVec3Dot(this, &b); }
inline Vec3 Cross(const Vec3 &b) const;
Vec3(D3DXVECTOR3 &v3) { x = v3.x; y = v3.y; z = v3.z; }
Vec3() : D3DXVECTOR3() { x = 0; y = 0; z = 0; }
Vec3(const float _x, const float _y, const float _z) { x=_x; y=_y; z=_z; }
Vec3(const double _x, const double _y, const double _z) { x = (float)_x; y = (float)_y; z = (float)_z; }
inline Vec3(const class Vec4 &v4);
};
所以,我现在遇到的问题是 XMVector3Length 无法从 Vec3* 转换为 _m128
编辑:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb205510%28v=vs.85%29.aspx
似乎返回类型更改为向量,结果相同,而不仅仅是一个浮点数。