DirectX 11.2 in Windows 8.1: XMVectors
Again, XMVectors, I wrote a blog a year or so ago about the XMVectors. Now I will write again. Why? Do you think I write this only for you dear Reader? Nope, I write as I learn for me, but I do like to share with you.
In DirectX 11.2 which is the latest version of DirectX, I wrote a little ditty that goes like this, so just copy and paste into an empty source file and away you go. This is your first Direct X 11.2 3D program. Kind of boring, well we will need to spice this up a little. But not right now. Also, it is a very quick way to do vector math.
/*************************************/
Add the following line which
replaced xnamath.h */
#include <DirectXMath.h>
/**************************************
* for FLOAT definition add windows.h */
#include <windows.h>
/************************************/
#include <iostream>
using namespace std;
/***********************************
* You could Add the following line */
using namespace DirectX;
/*Although the using DirectX statement would be in general be considered bad form
but I would use it to make the code easier to read. Your Choice
It's dogma not religion */
/**************************************************************
Overload the "<<" operators so that we can use cout to
output XMVECTOR objects. */
ostream& operator<<(ostream& os, DirectX::FXMVECTOR v)
{
XMFLOAT4 dest;
DirectX::XMStoreFloat4(&dest, v);
os << "(" << dest.x << ", " << dest.y << ", " << dest.z << ", " << dest.w << ")";
return os;
}
int main()
{
cout.setf(ios_base::boolalpha);
// Check support for SSE2 (Pentium4, AMD K8, and above).
if( !DirectX::XMVerifyCPUSupport() )
{
cout << "DirectX math not supported" << endl;
return 0;
}
//Constants from DirectXMath.h,
//if you are using VS 2013,use right click on constant and then Peek Definition
XMVECTOR wVector = DirectX::XMVectorSet(
0.0f,
XM_PIDIV4, // XM_PIDIV4 is Pi divided by four
XM_PIDIV2, // XM_PIDIV2 is pi divided by 2
XM_PI // XM_PI is pi dividied by 1 (or just pi)
);
cout << "XMVectorCos(w) =\t " << DirectX::XMVectorCos(wVector) << endl;
cout << "XMVectorSin(w) =\t " << DirectX::XMVectorSin(wVector) << endl;
cout << "XMVectorArcTan(w) =\t " << DirectX::XMVectorATan(wVector) << endl;
return 0;
}