-1

Sorry for the dumb question .... but why this does not work ? To show the problem I wrote this simple code:

#include <windows.h> 
#include <DirectXMath.h>
#include <DirectXPackedVector.h>
#include <iostream>
using namespace std;
using namespace DirectX;
using namespace DirectX::PackedVector;

int main()
{
XMVECTOR c = XMVECTORSet(3.0f, 3.0f, 3.0f, 3.0f);

return 0;
}

VS answers "error C3861: 'XMVECTORSet': identifier not found"

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
cppstudent
  • 23
  • 4

2 Answers2

1

You should use XMVectorSet instead of XMVECTORSet(This function does not exist)

Function definition on msdn

mylibh
  • 153
  • 9
1

There are a number of ways to initialize a vectorized-constant for DirectXMath. XMVectorSet is best when the parameters are float variables not literal values.

XMVECTOR c = XMVectorSet( 3.f, 3.f, 3.f, .3f );

In the case of a literal constant, you are better off using:

const XMVECTORF32 c = { 3.f, 3.f, 3.f, 3.f };

clang will want you to write it as: const XMVECTORF32 c = { { { 3.f, 3.f, 3.f, 3f.f } } }; if you have -Wmissing-braces enabled.

Other options (again, not the best for literal values, but better for variables):

XMVECTOR c = XMVectorReplicate( 3.f );
float x = 3.f;
XMVECTOR c = XMVectorReplicatePtr(&x);
const XMVECTORF32 t = { 1.f, 2.f, 3.f, 4.f };
XMVECTOR c = XMVectorSplatZ(t);

The DirectXMath Programmer's Guide is a short read, and it covers a lot of use cases.

If you are new to DirectXMath, you should consider using the SimpleMath wrapper types for DirectXMath that is included in DirectX Tool Kit for DX11 / DX12.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • Thanks a lot, Chuck. May I ask another question ? Is there a way, always in DirectX, to initialise a vector with a number of elements different from 4 ? Just a curiosity. SimpleMath only ? – cppstudent Mar 13 '20 at 20:58
  • For 2 and 3 vectors, you just leave the unused values 0. – Chuck Walbourn Mar 13 '20 at 23:31