Jump to content
  • Advertisement
Sign in to follow this  
matt77hias

DX11 XMVECTOR to float

This topic is 506 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);

 

Edited by matt77hias

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!