资源简介
DirectX做的地月系模型并且附加一个高度图地形源代码
实现了雾化和简单的按键操作。
代码片段和文件信息
#include “Camera.h“
#include
#include “.\camera.h“
#define new VNEW
CCamera::CCamera() :
m_fNear(0.f)
m_fFar(0.f)
m_fFOV(0.f)
m_fAspect(0.f)
m_bIsRot(false)
m_bIsTrans(false)
m_fCameraYawAngle(0.f)
m_fCameraPitchAngle(0.f)
m_vDelta(0.f 0.f 0.f)
m_fVelocity(0.01f)
m_fMaxPitch(D3DX_PI*0.49f)
m_fMinPitch(-D3DX_PI*0.49f)
{
m_EyePos = D3DXVECTOR3(0.f 0.f 0.f);
m_LookAt = D3DXVECTOR3(0.f 0.f 1.f);
m_Up = D3DXVECTOR3(0.f 1.f 0.f);
}
CCamera::~CCamera()
{
}
void CCamera::SetViewParams( D3DXVECTOR3 &pos D3DXVECTOR3 &lookat D3DXVECTOR3 &up )
{
m_EyePos = pos;
m_LookAt = lookat;
m_Up = up;
m_Direction = m_LookAt - m_EyePos;
D3DXVec3Cross( &m_Right &m_Up &m_Direction );
D3DXMatrixLookAtLH(&m_ViewTrans &m_EyePos &m_LookAt &m_Up);
D3DXMATRIX mInvView;
D3DXMatrixInverse( &mInvView NULL &m_ViewTrans );
D3DXVECTOR3* pZBasis = (D3DXVECTOR3*) &mInvView._31;
m_fCameraYawAngle = atan2f( pZBasis->x pZBasis->z );
float fLen = sqrtf(pZBasis->z*pZBasis->z + pZBasis->x*pZBasis->x);
m_fCameraPitchAngle = -atan2f( pZBasis->y fLen );
}
void CCamera::SetProjParams( float fFOV float fAspect float fNear float fFar )
{
m_fFOV = fFOV;
m_fAspect = fAspect;
m_fNear = fNear;
m_fFar = fFar;
D3DXMatrixPerspectiveFovLH( &m_ProjTrans m_fFOV m_fAspect m_fNear m_fFar );
}
void CCamera::SetOrthoProjParams( float w float h float fNear float fFar )
{
D3DXMatrixOrthoLH( &m_ProjTrans w h fNear fFar );
}
const D3DXMATRIX *CCamera::GetViewTrans() const
{
return &m_ViewTrans;
}
const D3DXMATRIX *CCamera::GetProjTrans() const
{
return &m_ProjTrans;
}
void CCamera::SetMoveVelocity( float fVelocity )
{
m_fVelocity = fVelocity;
}
LRESULT CCamera::HandleMessage(HWND hWnd UINT msg WPARAM wParam LPARAM lParam)
{
//m_vDelta = D3DXVECTOR3(0.f 0.f 0.f);
// setcapture getcursorPos
switch( msg )
{
case WM_LBUTTONDOWN:
{
m_bIsRot = true;
SetCapture(hWnd);
GetCursorPos(&m_LastPoint);
}
break;
case WM_LBUTTONUP:
{
m_bIsRot = false;
ReleaseCapture();
}
break;
}
return 0;
}
void CCamera::ProcessKey()
{
static float fPreTime = static_cast(timeGetTime());
float fCurrentTime = static_cast(timeGetTime());
float fElapsedTime = (fCurrentTime - fPreTime)*0.001f;
m_vDelta = D3DXVECTOR3(0.f 0.f 0.f);
float fVelocity = m_fVelocity * fElapsedTime;
if( GetKeyState(‘W‘) & 0x8000 )
{
m_bIsTrans = true;
m_vDelta.z += fVelocity;
}
if( GetKeyState(‘S‘) & 0x8000 )
{
m_bIsTrans = true;
m_vDelta.z -= fVelocity;
}
if( GetKeyState(‘A‘) & 0x8000 )
{
m_bIsTrans = true;
m_vDelta.x -= fVelocity;
}
if( GetKeyState(‘D‘) & 0x8000 )
{
m_bIsTrans = true;
m_vDelta.x += fVelocity;
}
if( GetKeyState(VK_HOME) & 0x8000 )
{
m_bIsTrans = true;
m_vDelta.y += fVelocity;
}
if( GetKeyState(VK_END) & 0x8000 )
{
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 116134 2007-07-27 11:03 DXproject\bin\banana.png
文件 518233 2007-07-27 11:41 DXproject\bin\Blue hills.png
文件 176128 2008-10-31 11:27 DXproject\bin\DXproject.exe
文件 109640 2008-10-31 10:32 DXproject\bin\earth.X
文件 20941 2004-03-28 22:48 DXproject\bin\grass.jpg
文件 109636 2008-10-31 10:32 DXproject\bin\moon.X
文件 109636 2008-10-31 10:33 DXproject\bin\sun.X
文件 659053 2008-08-22 16:44 DXproject\bin\Sunset.png
文件 66616 2008-10-21 14:38 DXproject\bin\Terrain_256.bmp
..A..H. 11264 2008-10-21 15:50 DXproject\DXproject.suo
文件 4752 2008-10-21 14:12 DXproject\src\Camera.cpp
文件 2732 2008-10-21 14:12 DXproject\src\Camera.h
文件 24190 2008-10-21 15:50 DXproject\src\directx.ico
文件 42388 2008-10-31 11:25 DXproject\src\DXproject.aps
文件 1076224 2008-12-10 20:06 DXproject\src\DXproject.ncb
文件 1690 2008-10-21 15:50 DXproject\src\DXproject.rc
文件 907 2008-10-20 08:32 DXproject\src\DXproject.sln
..A..H. 10240 2008-12-10 20:06 DXproject\src\DXproject.suo
文件 3822 2008-10-31 10:35 DXproject\src\DXproject.vcproj
文件 5266 2008-12-10 20:06 DXproject\src\Game.cpp
文件 3064 2008-12-10 20:06 DXproject\src\MeshModle.cpp
文件 935 2008-12-10 20:02 DXproject\src\MeshModle.h
文件 452 2008-10-21 15:50 DXproject\src\resource.h
文件 3396 2008-12-10 20:03 DXproject\src\Terrain.cpp
文件 937 2008-12-10 20:00 DXproject\src\Terrain.h
目录 0 2008-10-31 11:43 DXproject\bin
目录 0 2008-12-10 20:06 DXproject\src
目录 0 2008-10-31 11:43 DXproject
----------- --------- ---------- ----- ----
3078276 28
............此处省略1个文件信息
评论
共有 条评论