afCamera.cpp
资源名称:AirForce.rar [点击查看]
上传用户:kaiguan
上传日期:2007-10-28
资源大小:1074k
文件大小:3k
源码类别:
其他游戏
开发平台:
Visual C++
- // afCamera.cpp: implementation of the afCamera class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "afCamera.h"
- #include "afPlane.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- afCamera::afCamera()
- {
- // Set attributes for the view matrix
- D3DXVECTOR3 vEyePt(0.0f,0.0f,0.0f);
- D3DXVECTOR3 vLookatPt(0.0f,0.0f,1.0f);
- D3DXVECTOR3 vUpVec(0.0f,1.0f,0.0f);
- SetViewParams( vEyePt, vLookatPt, vUpVec );
- // Set attributes for the projection matrix
- SetProjParams( D3DX_PI/4, 1.0f, 1.0f, 1000.0f );
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- VOID afCamera::SetViewParams( D3DXVECTOR3 &vEyePt, D3DXVECTOR3& vLookatPt,
- D3DXVECTOR3& vUpVec )
- {
- // Set attributes for the view matrix
- m_vEyePt = vEyePt;
- m_vLookatPt = vLookatPt;
- m_vUpVec = vUpVec;
- D3DXVECTOR3 vDir = m_vLookatPt - m_vEyePt;
- D3DXVec3Normalize( &m_vView, &vDir );
- D3DXVec3Cross( &m_vCross, &m_vView, &m_vUpVec );
- D3DXMatrixLookAtLH( &m_matView, &m_vEyePt, &m_vLookatPt, &m_vUpVec );
- D3DXMatrixInverse( &m_matBillboard, NULL, &m_matView );
- m_matBillboard._41 = 0.0f;
- m_matBillboard._42 = 0.0f;
- m_matBillboard._43 = 0.0f;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- VOID afCamera::SetProjParams( FLOAT fFOV, FLOAT fAspect, FLOAT fNearPlane,
- FLOAT fFarPlane )
- {
- // Set attributes for the projection matrix
- m_fFOV = fFOV;
- m_fAspect = fAspect;
- m_fNearPlane = fNearPlane;
- m_fFarPlane = fFarPlane;
- D3DXMatrixPerspectiveFovLH( &m_matProj, fFOV, fAspect, fNearPlane, fFarPlane );
- }
- bool afCamera::getUpdateVisibility()
- {
- return m_updateVisibility;
- }
- void afCamera::SetUpdateVisibility(bool visible)
- {
- m_updateVisibility=visible;
- }
- void afCamera::createClippingPlanes(afPlane nPlanes[6])
- {
- float nx,ny,nz;
- // near plane
- nPlanes[0].set(0.0f, 0.0f, -1.0f, -m_fNearPlane);
- // far plane
- nPlanes[1].set(0.0f, 0.0f, 1.0f, m_fFarPlane);
- nx = (float)cos(GetFOVX()/2.0f);
- nz = (float)sin(GetFOVX()/2.0f);
- // right plane
- nPlanes[2].set(nx, 0.0f, -nz, 0.0f);
- // left plane
- nPlanes[3].set(-nx, 0.0f, -nz, 0.0f);
- ny = (float)cos(GetFOVY()/2.0f);
- nz = (float)sin(GetFOVY()/2.0f);
- // up plane
- nPlanes[4].set(0.0f, ny, -nz, 0.0f);
- // down plane
- nPlanes[5].set(0.0f, -ny, -nz, 0.0f);
- }