cuboid.h

来自「对游戏编程感兴趣的 朋友可以 下载下来看看 对DX讲解的很很详细」· C头文件 代码 · 共 62 行

H
62
字号
// Cuboid.h: interface for the CCuboid class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_CUBOID_H__AE25AF5F_AE56_48F5_99DC_47CAAA14F245__INCLUDED_)
#define AFX_CUBOID_H__AE25AF5F_AE56_48F5_99DC_47CAAA14F245__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <d3dx8.h>
#include "Helper.h"

//Define a FVF for our cubiods
#define CUBOID_D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)

class CCuboid
{
private:
	//Define a custom vertex for our cubiods
	struct CUBOID_CUSTOMVERTEX
	{
		FLOAT x, y, z;		//Position of vertex in 3D space
		FLOAT nx, ny, nz;	//Lighting Normal
		FLOAT tu, tv;		//Texture coordinates
	};

public:
	bool SetMaterial(D3DCOLORVALUE rgbaDiffuse, D3DCOLORVALUE rgbaAmbient, D3DCOLORVALUE rgbaSpecular, D3DCOLORVALUE rgbaEmissive, float rPower);
	bool SetTexture(const char* szTextureFilePath);
	bool SetPosition(float x, float y, float z);
	bool SetSize(float rWidth, float rHeight, float rDepth);
	DWORD Render();
	CCuboid(LPDIRECT3DDEVICE8 pD3DDevice, float x = 0.0, float y = 0.0, float z = 0.0);
	virtual ~CCuboid();

private:
	bool CreateIndexBuffer();
	D3DXVECTOR3 GetTriangeNormal(D3DXVECTOR3* vVertex1, D3DXVECTOR3* vVertex2, D3DXVECTOR3* vVertex3);
	bool UpdateVertices();
	HRESULT CreateVertexBuffer();
	LPDIRECT3DDEVICE8 m_pD3DDevice;
	LPDIRECT3DVERTEXBUFFER8 m_pVertexBuffer;
	LPDIRECT3DTEXTURE8 m_pTexture;
	D3DMATERIAL8 m_matMaterial;
	LPDIRECT3DINDEXBUFFER8 m_pIndexBuffer;	

	float m_rWidth;
	float m_rHeight;
	float m_rDepth;
	float m_rX;
	float m_rY;
	float m_rZ;

	DWORD m_dwNumOfVertices;	
	DWORD m_dwNumOfIndices;
	DWORD m_dwNumOfPolygons;
};

#endif // !defined(AFX_CUBOID_H__AE25AF5F_AE56_48F5_99DC_47CAAA14F245__INCLUDED_)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?