www.pudn.com > Game_11.rar > Terrain.h


// Terrain.h: interface for the CTerrain class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#if !defined(AFX_TERRAIN_H__B938095A_A40E_4063_8D13_F9E35DBA767A__INCLUDED_) 
#define AFX_TERRAIN_H__B938095A_A40E_4063_8D13_F9E35DBA767A__INCLUDED_ 
#include  
#include  
 
#if _MSC_VER > 1000 
#pragma once 
#endif // _MSC_VER > 1000 
 
#define D3DFVF_TERRAIN	D3DFVF_XYZ|D3DFVF_TEX1	//坐标信息 
#define MAX_INTERSECTIONS 16 
class CTerrain   
{ 
 
protected: 
	struct D3DVERTEX 
	{ 
		float	x,y,z;									//坐标信息 
		float	tu,tv; 
	}; 
	struct INTERSECTION 
	{ 
		DWORD dwFace;                 // mesh face that was intersected 
		FLOAT fBary1, fBary2;         // barycentric coords of intersection 
		FLOAT fDist;                  // distance from ray origin to intersection 
//		FLOAT tu, tv;                 // texture coords of intersection 
	}; 
protected: 
 
	LPDIRECT3DDEVICE9		m_pDevice; 
	LPDIRECT3DTEXTURE9		m_pTexture;				//材质 
	LPDIRECT3DVERTEXBUFFER9	m_pVB; 
	LPDIRECT3DINDEXBUFFER9	m_pIB; 
 
	D3DVECTOR				m_vPos; 
 
	 
	long	nCol,nRow; 
	float	m_maxHeight; 
	float	m_CellWidth; 
	BYTE	*m_pHeightData; 
 
 
public: 
	CTerrain(LPDIRECT3DDEVICE9 pDevice, 
		D3DVECTOR position); 
 
	CreateTerrain(char* strTerrain, 
		char* strTexture, float cellWidth,float height=800); 
 
	BOOL	IntersectTriangle( const D3DXVECTOR3& orig, 
                                       const D3DXVECTOR3& dir, D3DXVECTOR3& v0, 
                                       D3DXVECTOR3& v1, D3DXVECTOR3& v2, 
                                       FLOAT* t, FLOAT* u, FLOAT* v ); 
	LRESULT	Pick(POINT ptCursor, D3DXVECTOR3 *vRet, 
					   float ScreenWidth,float ScreendHeight); 
 
	float GetHeight(float x,float z); 
	void Render(); 
	virtual ~CTerrain(); 
	void SetMatrix(); 
 
	INTERSECTION m_IntersectionArray[MAX_INTERSECTIONS]; // Intersection info 
 
}; 
 
#endif // !defined(AFX_TERRAIN_H__B938095A_A40E_4063_8D13_F9E35DBA767A__INCLUDED_)