Using the new XMVECTOR and XMFLOAT3 classes what is the best way to get the distance between 2 points? I couldn't find a function that does it in XMVector* family of functions so I came up with the following :
float distance(const XMFLOAT3& v1,const XMFLOAT3& v2)
{
XMVECTOR vector1 = XMLoadFloat3(&v1);
XMVECTOR vector2 = XMLoadFloat3(&v2);
XMVECTOR vectorSub = XMVectorSubtract(vector1,vector2);
XMVECTOR length = XMVector3Length(vectorSub);
float distance = 0.0f;
XMStoreFloat(&distance,length);
return distance;
}
Will this be faster than a normal Vector3 class with just 3 floats for x,y,z and then using sqrt because it uses intrinsic optimizations? Namely :
float Distance(const Vector3& point1,const Vector3& point2)
{
float distance = sqrt( (point1.x - point2.x) * (point1.x - point2.x) +
(point1.y - point2.y) * (point1.y - point2.y) +
(point1.z - point2.z) * (point1.z - point2.z) );
return distance;
}