www.pudn.com > terrainSimple.rar > SSZd3d.h


////////////////////////////////////////////////////////////////////////////////////////////////// 
//  
// File: SSZd3d.h 
//  
// Author: 哈尔滨顺时针电脑学校 电话:0451-86220686 
// 
// Desc: 顺时针的D3D的一些通用函数及数据结构 
//           
////////////////////////////////////////////////////////////////////////////////////////////////// 
 
#ifndef __d3dUtilityH__ 
#define __d3dUtilityH__ 
 
#include  
#include  
 
namespace d3d 
{ 
	 
 
	const D3DXCOLOR      WHITE( D3DCOLOR_XRGB(255, 255, 255) ); 
	const D3DXCOLOR      BLACK( D3DCOLOR_XRGB(  0,   0,   0) ); 
	const D3DXCOLOR        RED( D3DCOLOR_XRGB(255,   0,   0) ); 
	const D3DXCOLOR      GREEN( D3DCOLOR_XRGB(  0, 255,   0) ); 
	const D3DXCOLOR       BLUE( D3DCOLOR_XRGB(  0,   0, 255) ); 
	const D3DXCOLOR     YELLOW( D3DCOLOR_XRGB(255, 255,   0) ); 
	const D3DXCOLOR       CYAN( D3DCOLOR_XRGB(  0, 255, 255) ); 
	const D3DXCOLOR    MAGENTA( D3DCOLOR_XRGB(255,   0, 255) ); 
 
	// 
	// Lights 
	// 
 
	D3DLIGHT9 InitDirectionalLight(D3DXVECTOR3* direction, D3DXCOLOR* color); 
	D3DLIGHT9 InitPointLight(D3DXVECTOR3* position, D3DXCOLOR* color); 
	D3DLIGHT9 InitSpotLight(D3DXVECTOR3* position, D3DXVECTOR3* direction, D3DXCOLOR* color); 
 
	// 
	// Materials 
	// 
 
	D3DMATERIAL9 InitMtrl(D3DXCOLOR Ambient, D3DXCOLOR Diffuse, D3DXCOLOR Specular, D3DXCOLOR Emissive, float Power); 
 
	const D3DMATERIAL9 WHITE_MTRL  = InitMtrl(WHITE, WHITE, WHITE, BLACK, 2.0f); 
	const D3DMATERIAL9 RED_MTRL    = InitMtrl(RED, RED, RED, BLACK, 2.0f); 
	const D3DMATERIAL9 GREEN_MTRL  = InitMtrl(GREEN, GREEN, GREEN, BLACK, 2.0f); 
	const D3DMATERIAL9 BLUE_MTRL   = InitMtrl(BLUE, BLUE, BLUE, BLACK, 2.0f); 
	const D3DMATERIAL9 YELLOW_MTRL = InitMtrl(YELLOW, YELLOW, YELLOW, BLACK, 2.0f); 
 
	const D3DXCOLOR BEACH_SAND( D3DCOLOR_XRGB(255, 249, 157) ); 
	const D3DXCOLOR DESERT_SAND( D3DCOLOR_XRGB(250, 205, 135) ); 
 
	const D3DXCOLOR LIGHTGREEN( D3DCOLOR_XRGB( 60, 184, 120) ); 
	const D3DXCOLOR  PUREGREEN( D3DCOLOR_XRGB(  0, 166,  81) ); 
	const D3DXCOLOR  DARKGREEN( D3DCOLOR_XRGB(  0, 114,  54) ); 
 
	const D3DXCOLOR LIGHT_YELLOW_GREEN( D3DCOLOR_XRGB(124, 197, 118) ); 
	const D3DXCOLOR  PURE_YELLOW_GREEN( D3DCOLOR_XRGB( 57, 181,  74) ); 
	const D3DXCOLOR  DARK_YELLOW_GREEN( D3DCOLOR_XRGB( 25, 123,  48) ); 
 
	const D3DXCOLOR LIGHTBROWN(D3DCOLOR_XRGB(198, 156, 109)); 
	const D3DXCOLOR DARKBROWN( D3DCOLOR_XRGB(115, 100,  87)); 
	// 
	// Bounding Objects 
	// 
 
	struct BoundingBox 
	{ 
		BoundingBox(); 
 
		bool isPointInside(D3DXVECTOR3& p); 
 
		D3DXVECTOR3 _min; 
		D3DXVECTOR3 _max; 
	}; 
 
	struct BoundingSphere 
	{ 
		BoundingSphere(); 
 
		D3DXVECTOR3 _center; 
		float       _radius; 
	}; 
 
	// 
	// Constants 
	// 
 
	const float INFINITY = FLT_MAX; 
	const float EPSILON  = 0.001f; 
 
	// 
	// Drawing 
	// 
 
	// Function references "desert.bmp" internally.  This file must 
	// be in the working directory. 
	bool DrawBasicScene( 
		IDirect3DDevice9* device,// Pass in 0 for cleanup. 
		float scale);            // uniform scale  
 
	// 
	// Vertex Structures 
	// 
 
	struct Vertex 
	{ 
		Vertex(){} 
		Vertex(float x, float y, float z,  
			float nx, float ny, float nz, 
			float u, float v) 
		{ 
			_x  = x;  _y  = y;  _z  = z; 
			_nx = nx; _ny = ny; _nz = nz; 
			_u  = u;  _v  = v; 
		} 
		float _x, _y, _z; 
		float _nx, _ny, _nz; 
		float _u, _v; 
 
		static const DWORD FVF; 
	}; 
 
	// 
	// Randomness 
	// 
 
	// Desc: Return random float in [lowBound, highBound] interval. 
	float GetRandomFloat(float lowBound, float highBound); 
 
 
	// Desc: Returns a random vector in the bounds specified by min and max. 
	void GetRandomVector( 
		D3DXVECTOR3* out, 
		D3DXVECTOR3* min, 
		D3DXVECTOR3* max); 
 
	// 
	// Conversion 
	// 
	DWORD FtoDw(float f); 
 
	// 
	// Interpolation 
	// 
 
	float Lerp(float a, float b, float t); 
} 
 
#endif // __d3dUtilityH__