0

I'm having trouble finding reliable documentation on what happens when you call the default constructor on an XMVECTOR.

MSDN says that the XMMATRIX default constructor does not initialize the variables to 0 (http://msdn.microsoft.com/en-us/library/windows/desktop/ee420023(v=vs.85).aspx). So my gut feeling is that the same is true for XMVECTOR, but unfortunately I cannot find this confirmation on the MSDN site.

Back to the original question:

// Trackball.h
class Trackball
{
    ...
    XMVECTOR m_eye;
    XMVECTOR m_position;
    XMVECTOR m_up;
    XMVECTOR m_rotateStart;
    XMVECTOR m_rotateEnd;
    ...
}

// Trackball.cpp
Trackball::Trackball(void) :
    ...
    m_eye(),
    m_rotateStart(),
    m_rotateEnd(),
    m_zoomStart(),
    m_zoomEnd(),
    m_panStart(),
    m_panEnd(),
    ...
{
}

But this just uses the default constructor to initialize the variable right? So if the above assumption that the default constructor does not initialize the members of XMVECTOR holds, then should I be doing this instead?:

// Trackball.cpp
Trackball::Trackball(void) :
    ...
    m_eye(XMVectorZero()),
    m_rotateStart(XMVectorZero()),
    m_rotateEnd(XMVectorZero()),
    m_zoomStart(XMVectorZero()),
    m_zoomEnd(XMVectorZero()),
    m_panStart(XMVectorZero()),
    m_panEnd(XMVectorZero()),
    ...
{
}

That looks ugly but may be right.

Thanks for reading and thanks for any help.

Dave
  • 356
  • 1
  • 7
Nico
  • 1,181
  • 2
  • 17
  • 35

1 Answers1

2

I think your way is correct, if you think it's ugly, you can put it in the constructor body, though it will lost some performance since initialize list only call copy constructor. if you want to see what the default constructor of XMVECTOR do, you can run your program in debug mode and look that in the watch window.

zdd
  • 8,258
  • 8
  • 46
  • 75
  • I'll empirically determine what the default constructor does soon, I just fear that the majority of the time it'll allocate memory that hasn't been used so I might get a false sense of security. Thanks for the thoughts! – Nico Jun 29 '13 at 14:55
  • 1
    When compiled using SSE intrinsics, XMVECTOR is a typedef for __m128. This is a fundamental type just like float or int and therefore has no constructor, its contents are as undefined as float or int would be without any initialisation. – Adam Miles Jun 29 '13 at 18:26
  • Yep, I definitely noticed that when poking around through intellisense. Thanks for the info! – Nico Jun 30 '13 at 21:35