码迷,mamicode.com
首页 > 其他好文 > 详细

Direct3D游戏中的Matrix总结

时间:2014-11-07 14:31:42      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   color   ar   os   使用   

DirectX使用的是左手坐标系,Opengl使用的是右手坐标系

----------------------------------------------------------

正交矩阵


D3DXMATRIX* D3DXMatrixOrthoLH(
  _Inout_  D3DXMATRIX *pOut,//Pointer to the resulting D3DXMATRIX.
  _In_     FLOAT w,      //Width of the view volume.
  _In_     FLOAT h,     //Height of the view volume.
  _In_     FLOAT zn,     //Minimum z-value of the view volume which is referred to as z-near.
  _In_     FLOAT zf      //Maximum z-value of the view volume which is referred to as z-far.
);

立体矩阵

D3DXMATRIX* D3DXMatrixPerspectiveFovLH(
  _Inout_  D3DXMATRIX *pOut,//Pointer to the D3DXMATRIX structure that is the result of the operation.
  _In_     FLOAT fovy,     //Field of view in the y direction, in radians.(弧度)
  _In_     FLOAT Aspect,   //Aspect ratio, defined as view space width divided by height.(width/height)
  _In_     FLOAT zn,     //Z-value of the near view-plane.
  _In_     FLOAT zf      //Z-value of the far view-plane.
);

世界矩阵

D3DXMATRIX* D3DXMatrixTranslation(
  _Inout_  D3DXMATRIX *pOut,//Pointer to the D3DXMATRIX structure that is the result of the operation.
  _In_     FLOAT x,      //X-coordinate offset.
  _In_     FLOAT y,      //Y-coordinate offset.
  _In_     FLOAT z       //Z-coordinate offset.
);

视图矩阵

D3DXMATRIX* D3DXMatrixLookAtLH(
  _Inout_  D3DXMATRIX *pOut,      //Pointer to the D3DXMATRIX structure that is the result of the operation.
  _In_     const D3DXVECTOR3 *pEye,  //Pointer to the D3DXVECTOR3 structure that defines the eye point. This value is used in translation.
  _In_     const D3DXVECTOR3 *pAt,  //Pointer to the D3DXVECTOR3 structure that defines the camera look-at target.
  _In_     const D3DXVECTOR3 *pUp   //to the D3DXVECTOR3 structure that defines the current world‘s up, usually [0, 1, 0].
);

代码如下

//设置立体矩阵
D3DXMatrixOrthoLH(&g_ortho, WINDOW_WIDTH, WINDOW_HEIGHT, 0.1f, 1000.0f);
g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &g_ortho);
//设置立体矩阵
D3DXMatrixPerspectiveFovLH(&g_projection, D3DX_PI / 4, (float)WINDOW_WIDTH / WINDOW_HEIGHT, 0.1f, 1000.0f);
g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &g_projection);
//设置世界矩阵
D3DXMatrixTranslation(&g_worldMatrix, world_x, world_y, world_z);
g_pd3dDevice->SetTransform(D3DTS_WORLD, &g_worldMatrix);
//设置视图矩阵
D3DXVECTOR3 cameraPos(view_x, view_y, view_z);
D3DXVECTOR3 lookAtPos(world_x, world_y, world_z);
D3DXVECTOR3 upDir(0.0f, 1.0f, 0.0f);
D3DXMatrixLookAtLH(&g_viewMatrix, &cameraPos, &lookAtPos, &upDir);
g_pd3dDevice->SetTransform(D3DTS_VIEW, &g_viewMatrix);

 

Direct3D游戏中的Matrix总结

标签:des   style   blog   http   io   color   ar   os   使用   

原文地址:http://www.cnblogs.com/Susake/p/4081034.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!