DirectX向量与矩阵
2015-04-22 12:28
141 查看
配置vs2013项目属性的VC++目录:
比如DirectX SDK安装目录是D:\Program Files (x86)\Microsoft DirectX SDK (June 2010)
则包含目录和库目录配置如下:
/* Include */
$(VC_IncludePath);$(WindowsSDK_IncludePath);D:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include
/* Lib */
$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);D:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;$(LibraryPath)
使用Lib可以在 项目属性-链接器-输入-附加依赖项 中添加或者在程序中使用预处理指令#pragma comment( comment-type ,["commentstring"] )。
比如DirectX SDK安装目录是D:\Program Files (x86)\Microsoft DirectX SDK (June 2010)
则包含目录和库目录配置如下:
/* Include */
$(VC_IncludePath);$(WindowsSDK_IncludePath);D:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include
/* Lib */
$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);D:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;$(LibraryPath)
使用Lib可以在 项目属性-链接器-输入-附加依赖项 中添加或者在程序中使用预处理指令#pragma comment( comment-type ,["commentstring"] )。
#include <d3dx10.h> #include <iostream> using namespace std; #pragma comment(lib, "d3dx10.lib") ostream& operator<<(ostream& os, D3DXVECTOR4& v) { os << "(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")"; return os; } ostream& operator<<(ostream& os, D3DXMATRIX& m) { for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) os << m(i, j) << " "; os << endl; } return os; } ostream& operator<<(ostream& os, D3DXVECTOR3& v) { os << "(" << v.x << ", " << v.y << ", " << v.z << ")"; return os; } int main() { // Using constructor, D3DXVECTOR3(FLOAT x, FLOAT y, FLOAT z); D3DXVECTOR3 u(1.0f, 2.0f, 3.0f); // Using constructor, D3DXVECTOR3(CONST FLOAT *); float x[3] = { -2.0f, 1.0f, -3.0f }; D3DXVECTOR3 v(x); // Using constructor, D3DXVECTOR3() {}; D3DXVECTOR3 a, b, c, d, e; // Vector addition: D3DXVECTOR3 operator + a = u + v; // Vector subtraction: D3DXVECTOR3 operator - b = u - v; // Scalar multiplication: D3DXVECTOR3 operator * c = u * 10; // ||u|| float L = D3DXVec3Length(&u); // d = u / ||u|| D3DXVec3Normalize(&d, &u); // s = u dot v float s = D3DXVec3Dot(&u, &v); // e = u x v D3DXVec3Cross(&e, &u, &v); cout << "u = " << u << endl; cout << "v = " << v << endl; cout << "a = u + v = " << a << endl; cout << "b = u - v = " << b << endl; cout << "c = u * 10 = " << c << endl; cout << "d = u / ||u|| = " << d << endl; cout << "e = u x v = " << e << endl; cout << "L = ||u|| = " << L << endl; cout << "s = u.v = " << s << endl; cout << endl; D3DXMATRIX A(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 1.0f, 2.0f, 3.0f, 1.0f); D3DXMATRIX B; D3DXMatrixIdentity(&B); // matrix-matrix multiplication D3DXMATRIX C = A*B; D3DXMATRIX D, E, F; D3DXMatrixTranspose(&D, &A); D3DXMatrixInverse(&E, 0, &A); F = A * E; D3DXVECTOR4 P(2.0f, 2.0f, 2.0f, 1.0f); D3DXVECTOR4 Q(2.0f, 2.0f, 2.0f, 0.0f); D3DXVECTOR4 R, S; D3DXVec4Transform(&R, &P, &A); D3DXVec4Transform(&S, &Q, &A); cout << "A = " << endl << A << endl; cout << "B = " << endl << B << endl; cout << "C = A*B = " << endl << C << endl; cout << "D = transpose(A)= " << endl << D << endl; cout << "E = inverse(A) = " << endl << E << endl; cout << "F = A*E = " << endl << F << endl; cout << "P = " << P << endl; cout << "Q = " << Q << endl; cout << "R = P*A = " << R << endl; cout << "S = Q*A = " << S << endl; return 0; }
相关文章推荐
- 机器学习-矩阵向量求导
- 矩阵-DirectX与OpenGL的不同
- 从零单排入门机器学习:Octave/matlab的常用知识之矩阵和向量
- 常用的向量矩阵求导公式
- 矩阵中的数学旋转公式 转换到 C++中函数 替换DirectX 9.0中D3DXMatrixRotationAxis函数
- 矩阵和向量的乘法顺序
- Eigen之矩阵、向量、标量的操作运算
- 矩阵及其变换、特征值与特征向量的物理意义
- 矩阵是怎样变换向量的
- 常见向量范数和矩阵范数
- R:向量和矩阵的线性代数运算
- 简单的Tensoflow(1):创建两个向量并进行矩阵相乘
- 矩阵-DirectX与OpenGL的不同
- IOS中的矩阵和向量运算
- 矩阵是怎样变换向量的
- 【MPI学习笔记】1:并行化向量和矩阵的乘积
- “为什么DirectX里表示三维坐标要建一个4*4的矩阵?”
- 幂法求矩阵的最大特征值和对应特征向量
- 线性代数入门(2) - 矩阵,向量
- (转)思考:矩阵及变换,以及矩阵在DirectX和OpenGL中的运用问题:左乘/右乘,行优先/列优先,...