2

I would like to get the dot product of two 3D vectors in float. But unfortunately the result is a vector, not a float. I trued to access it's elements using vector4_f32, but I get an error, that it's not a member of __m128

float res = XMVector3Dot(a, b).vector4_f32[0];

The [] operator is not defined on XMVECTOR

Iter Ator
  • 8,226
  • 20
  • 73
  • 164

1 Answers1

4

You can access individual elements of XMVECTOR by using XMVectorGetX, XMVectorGetY, XMVectorGetZ and XMVectorGetW. But remember, these are more likely expensive operations as DirectXMath uses SIMD instruction set. For more info:

1: XMVector3Dot performance

2: Expensive than expected

Asesh
  • 3,186
  • 2
  • 21
  • 31
  • 1
    You might also want to take a look at the [SimpleMath](https://github.com/Microsoft/DirectXTK/wiki/SimpleMath) wrapper for DirectXMath. – Chuck Walbourn Oct 21 '17 at 17:32