资源简介
用directx实现的3d魔方小游戏,可以帮助初学者
代码片段和文件信息
//=============================================================================
// Name: CameraClass.cpp
// Des: 一个封装了实现虚拟摄像机的类的源文件
// 2013年 3月10日 Create by 浅墨
//=============================================================================
#include “Camera.h“
#ifndef WINDOW_WIDTH
#define WINDOW_WIDTH 800 //为窗口宽度定义的宏,以方便在此处修改窗口宽度
#define WINDOW_HEIGHT 600 //为窗口高度定义的宏,以方便在此处修改窗口高度
#endif
//-----------------------------------------------------------------------------
// Desc: 构造函数
//-----------------------------------------------------------------------------
CameraClass::CameraClass(IDirect3DDevice9 *pd3dDevice)
{
m_pd3dDevice = pd3dDevice;
m_vRightVector = D3DXVECTOR3(1.0f 0.0f 0.0f); // 默认右向量与X正半轴重合
m_vUpVector = D3DXVECTOR3(0.0f 1.0f 0.0f); // 默认上向量与Y正半轴重合
m_vLookVector = D3DXVECTOR3(0.0f 0.0f 1.0f); // 默认观察向量与Z正半轴重合
m_vCameraPosition = D3DXVECTOR3(0.0f -50.0f 0.0f); // 默认摄像机坐标为(0.0f 0.0f -250.0f)
m_vTargetPosition = D3DXVECTOR3(0.0f 0.0f 0.0f);//默认观察目标位置为(0.0f 0.0f 0.0f);
}
//-----------------------------------------------------------------------------
// Name:CameraClass::CalculateViewMatrix( )
// Desc: 根据给定的矩阵计算出取景变换矩阵
//-----------------------------------------------------------------------------
VOID CameraClass::CalculateViewMatrix(D3DXMATRIX *pMatrix)
{
//1.先把3个向量都规范化并使其相互垂直,成为一组正交矩阵
D3DXVec3Normalize(&m_vLookVector &m_vLookVector); //规范化观察分量
D3DXVec3Cross(&m_vUpVector &m_vLookVector &m_vRightVector); // 上向量与观察向量垂直
D3DXVec3Normalize(&m_vUpVector &m_vUpVector); // 规范化上向量
D3DXVec3Cross(&m_vRightVector &m_vUpVector &m_vLookVector); // 右向量与上向量垂直
D3DXVec3Normalize(&m_vRightVector &m_vRightVector); // 规范化右向量
// 2.创建出取景变换矩阵
//依次写出取景变换矩阵的第一行
pMatrix->_11 = m_vRightVector.x; // Rx
pMatrix->_12 = m_vUpVector.x; // Ux
pMatrix->_13 = m_vLookVector.x; // Lx
pMatrix->_14 = 0.0f;
//依次写出取景变换矩阵的第二行
pMatrix->_21 = m_vRightVector.y; // Ry
pMatrix->_22 = m_vUpVector.y; // Uy
pMatrix->_23 = m_vLookVector.y; // Ly
pMatrix->_24 = 0.0f;
//依次写出取景变换矩阵的第三行
pMatrix->_31 = m_vRightVector.z; // Rz
pMatrix->_32 = m_vUpVector.z; // Uz
pMatrix->_33 = m_vLookVector.z; // Lz
pMatrix->_34 = 0.0f;
//依次写出取景变换矩阵的第四行
pMatrix->_41 = -D3DXVec3Dot(&m_vRightVector &m_vCameraPosition); // -P*R
pMatrix->_42 = -D3DXVec3Dot(&m_vUpVector &m_vCameraPosition); // -P*U
pMatrix->_43 = -D3DXVec3Dot(&m_vLookVector &m_vCameraPosition); // -P*L
pMatrix->_44 = 1.0f;
}
//-----------------------------------------------------------------------------
// Name:CameraClass::SetTargetPosition( )
// Desc: 设置摄像机的观察位置
//-----------------------------------------------------------------------------
VOID CameraClass::SetTargetPosition(D3DXVECTOR3 *pLookat)
{
//先看看pLookat是否为默认值NULL
if (pLookat
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 20056 2008-08-13 01:29 MagicBox\Blue.bmp
文件 9578 2014-05-22 21:37 MagicBox\Camera.cpp
文件 1936 2014-05-22 21:37 MagicBox\Camera.h
文件 159406 2008-08-13 03:00 MagicBox\cube.ico
文件 20056 2008-08-13 01:29 MagicBox\Debug\Blue.bmp
文件 52414 2014-05-22 21:37 MagicBox\Debug\Camera.obj
文件 2390 2014-05-23 14:14 MagicBox\Debug\cl.command.1.tlog
文件 36750 2014-05-23 14:14 MagicBox\Debug\CL.read.1.tlog
文件 1940 2014-05-23 14:14 MagicBox\Debug\CL.write.1.tlog
文件 1259 2014-05-22 21:51 MagicBox\Debug\Cube.obj
文件 32724 2014-05-22 21:51 MagicBox\Debug\DirectInput.obj
文件 20056 2008-08-13 01:25 MagicBox\Debug\Green.bmp
文件 20056 2008-08-13 01:25 MagicBox\Debug\GreenBlue.bmp
文件 20056 2008-08-13 00:23 MagicBox\Debug\Inside.bmp
文件 20056 2008-08-13 01:42 MagicBox\Debug\Inside2.bmp
文件 2 2014-05-23 21:48 MagicBox\Debug\li
文件 2 2014-05-23 21:48 MagicBox\Debug\li
文件 2 2014-05-23 21:48 MagicBox\Debug\li
文件 2 2014-05-23 21:48 MagicBox\Debug\li
文件 2 2014-05-23 21:48 MagicBox\Debug\li
文件 2 2014-05-23 21:48 MagicBox\Debug\li
文件 2 2014-05-23 21:48 MagicBox\Debug\li
文件 2 2014-05-23 21:48 MagicBox\Debug\li
文件 2 2014-05-23 21:48 MagicBox\Debug\li
文件 2 2014-05-23 21:48 MagicBox\Debug\li
文件 2 2014-05-23 21:48 MagicBox\Debug\li
文件 2 2014-05-23 21:48 MagicBox\Debug\li
文件 2 2014-05-23 21:48 MagicBox\Debug\li
文件 2 2014-05-23 21:48 MagicBox\Debug\li
文件 2 2014-05-23 21:48 MagicBox\Debug\li
............此处省略253个文件信息
相关资源
- Real Time 3D Rendering with DirectX and HLSL
- DirectX9.0.exe
- 《DirectX+游戏开发终极指南》exe电子书
- MyGUI_3.2.0
- DirectX修复工具(DirectX Repair) V1.2 增
- 基于DirectX9.0c的坦克小游戏
- 《Introduction to 3D Game Programming with Di
- d3d11游戏编程入门(美)Allen+Wendy中英
- Introduction to 3D Game Programming with Direc
- 基于DirectX的简单GUI界面制作
- DirectX 自制游戏引擎
- Introduction to 3D Game Programming with Direc
- DirectX 高级动画制作书中源代码
- Real-Time -3D-Rendering-with-DirectX-and-HLSL
- DirectX11游戏编程入门(word+pdf)
- DirectX 11高级图形开发技术实战 免分
- Introduction to 3D Game Programming with Direc
- DX12龙书 Introduction to 3D Game Programming
- DirectX版俄罗斯方块(vs2010代码.
- DWGdirectX4.0
- directx_API
- DirectX 11 Low Poly Shader - DX11低多边形着
- DirectXDemo合集
- DirectX游戏开发之3D角色动起来
- XAudio2 by 冷崖
- 源代码
- DirectX实时渲染技术详解第二部分含源
- 红龙书最新版3d游戏开发基础DirectX1
- Introduction to 3D Game Programming with Dir
- 3d_game_programming_with_DirectX11.rar
评论
共有 条评论