www.pudn.com > Fog_D3D.zip > d3d_obj.h


#ifndef D3D_OBJ_H 
#define D3D_OBJ_H 
 
#include  
#include  
#include  
#include  
#include "vertex_types.h" 
#include "camera.h" 
 
const float kPi = 3.14159265f; 
const float kPiOver180 = kPi / 180.0f; 
 
#define DEG2RAD(x) (x * kPiOver180) // Converts degrees to radians 
 
// Creates an ARGB color 
#define ARGB(A, R, G, B) ( (int)((A & 0xFF) << 24 | \ 
								 (R & 0xFF) << 16 | \ 
								 (G & 0xFF) << 8 | \ 
								 (B & 0xFF)) ) 
								  
// Gets the A, R, G, and B from an ARGB color								  
#define GET_A(c) ((c >> 24) & 0xFF) 
#define GET_R(c) ((c >> 16) & 0xFF) 
#define GET_G(c) ((c >> 8) & 0xFF) 
#define GET_B(c) (c & 0xFF) 
 
const float kFOV = DEG2RAD(60); // Default Field Of View 
const float kNearClip = 1.0f; // Default Near Clip Plane 
const float kFarClip = 8192.0f; // Default Far Clip Plane 
 
// Here is our 3D Object to handle all of our 3D needs -- It will create our needed D3D interfaces 
// and allow us to render a list or vertices of a vertex type that we created 
class CD3DObj 
{ 
	public: 
 
		CD3DObj(); // Constructor 
 
		bool init(HWND hwnd); // Initializes our 3D Object 
		void initToDefaultParams(); // Initializes all parameters to a default value 
 
		void begin(); // Begins a scene 
		void end(); // Ends a scene 
 
		void setViewMatrix(const CCamera *camera); // Sets the view matrix based on "camera" 
		void setProjMatrix(); // Sets the projection matrix 
		void setWorldMatrix(int which, D3DXMATRIX *matrix); // Sets a world matrix 
		 
		// Fog methods -- Return true on success, false otherwise 
		bool setFogStatus(bool onOrOff); 
		bool setFogColor(int color); 
		bool setPixelFogMode(D3DFOGMODE mode); 
		bool setVertexFogMode(D3DFOGMODE mode); 
		bool setFogStart(float start); 
		bool setFogEnd(float end); 
		bool setFogDensity(float density); 
 
		// Renders the passed in vertex list using the passed in index list 
		bool render(SVertex *vList, int vertCount, WORD *iList, int indexCount); 
 
		// Clears the viewport's color and Z-buffer  
		bool clear(int color = D3DCOLOR_XRGB(0,0,0), float zDepth = 1.0f); 
 
		~CD3DObj(); // Deconstructor 
		 
	private: 
 
		// We'll use this to create other D3D objects/interfaces. 
		IDirect3D9 *d3d_interface; 
		 
		// We'll use this for all our rendering needs 
		IDirect3DDevice9 *d3d_device; 
 
		float fov; // Field of view 
		float aspect_ratio; // Aspect ratio 
		float near_clip; // Near clip plane 
		float far_clip; // Far clip plane 
		 
		HRESULT result; // Used for error checking 
 
		// We make the copy constructor and assignment operator private because 
		// we do NOT want anyone accidentally making a copy of this class 
		CD3DObj(const CD3DObj &obj) {} 
		CD3DObj& operator =(CD3DObj &obj) { return *this; } 
}; 
 
// Our global 3D object 
extern CD3DObj *g3D; 
 
#endif