《DirectX 12 3D游戏开发实战》第二章练习答案
作为学习记录。
/**
* 练习的最后两题代码比较乱,按部就班的思路,没有技巧性,
* 但也遇到不少问题,花了很长时间。
**/
#include <Windows.h>
#include <DirectXMath.h>
#include <DirectXPackedVector.h>
#include <iostream>
#include <vector>
using namespace std;
using namespace DirectX;
using namespace DirectX::PackedVector;
ostream& XM_CALLCONV operator<<(ostream& os, FXMVECTOR v)
{
XMFLOAT4 dest;
XMStoreFloat4(&dest, v);
cout << "(" << dest.x << ", " << dest.y << ", "
<< dest.z << ", " << dest.w << ")";
return os;
}
ostream& XM_CALLCONV operator<<(ostream& os, FXMMATRIX m)
{
for (int i = 0; i < 4; ++i) {
os << XMVectorGetX(m.r[i]) << "\t";
os << XMVectorGetY(m.r[i]) << "\t";
os << XMVectorGetZ(m.r[i]) << "\t";
os << XMVectorGetW(m.r[i]) << endl;
}
return os;
}
void p1()
{
XMMATRIX A(-2.0f, 0.0f, 0.0f, 0.0f,
1.0f, 3.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f);
XMMATRIX X = 1 / 2.0 * (A - 2 / 3.0 * A);
cout << "X = " << endl << X << endl;
}
void p2()
{
XMMATRIX aA(-2.0f, 0.0f, 3.0f, 0.0f,
4.0f, 1.0f, -1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f);
XMMATRIX aB(2.0f, -1.0f, 0.0f, 0.0f,
0.0f, 6.0f, 0.0f, 0.0f<