Advertisement

XMVECTOR to float

Started by July 27, 2017 01:27 PM
2 comments, last by MJP 7 years, 6 months ago

For vector operations which mathematically result in a single scalar f (such as XMVector3Length or XMPlaneDotCoord), which of the following extractions from an XMVECTOR is preferred:

1. The very explicit store operation


const XMVECTOR v = ...;
float f;
XMStoreFloat(&f, v);

2. A shorter but less explicit version (note that const can now be used explicitly)


const XMVECTOR v = ...;
const float f = XMVectorGetX(v);

 

🧙

It depends on the context.  The whole reason directx and a lot of physics engines and such use these SIMD Single instruction, multiple data type variables is to take advantage of SIMD operations (faster calculations!).  You should be doing all your calculations using these SIMD variables and methods and only "XMStore..." to store the variable in memory or in other words in your class or struct.  If you want to use the float outside of "storing" then the XMVectorGet... should be used.  Honestly they do the same thing, so this is really comes down to what ever you prefer.

Advertisement

XMVectorGetX() is fine, you don't need to store the whole vector if you don't want all of the components.

This topic is closed to new replies.

Advertisement