Search code examples
windows-8directxwindows-store-appsdirectx-11directxmath

component-wise multiplication for 3d vectors in windows store app programming


How to do component-wise multiplication of two 3d vector? it seems MS didn't provide such functions in DirectXMath.h, what's Microsoft doing there? in the old SDKs(DX 10/9), I can make a product of two vectors directly as:

v3 = v1 * v2;

or multiply a vector by a scalar like:

v2 = v1 * 1.0f;

but now, there is no operator * for XMVECTOR type, so I can't do that. so I need to make the product manually as

v3 = (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z);

although it is not so difficult, I think DirectXMath should provide such a basic function.


Solution

  • The dot product can be achieved with XMVector*Dot method. MSDN link for dot3product.

    And the good page exists on msdn with methods list: MSDN

    Also, I think that Microsoft didn't make operator* override because it is not clear which product this operator should use - dot or cross product.