首页 > 代码库 > Direct3D游戏中的Matrix总结
Direct3D游戏中的Matrix总结
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总结
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。