Iter Ator
Iter Ator

Reputation: 9299

How is it possible to get the float value from XMVECTOR? (DirectXMath)

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

Upvotes: 2

Views: 1895

Answers (1)

Asesh
Asesh

Reputation: 3361

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

Upvotes: 4

Related Questions