Sphere.h
上传用户:whgydz
上传日期:2007-01-12
资源大小:2259k
文件大小:2k
源码类别:

其他书籍

开发平台:

HTML/CSS

  1. // Sphere.h: interface for the CSphere class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_SPHERE_H__FC705F3B_568E_4973_B608_B8F7700D9ECE__INCLUDED_)
  5. #define AFX_SPHERE_H__FC705F3B_568E_4973_B608_B8F7700D9ECE__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #include <d3dx8.h>
  10. #include "Base.h"
  11. //Define a FVF for our sphere
  12. #define SPHERE_D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)
  13. class CSphere : public CBase  
  14. {
  15. private:
  16. //Define a custom vertex for our sphere
  17. struct SPHERE_CUSTOMVERTEX
  18. {
  19. FLOAT x, y, z; //Position of vertex in 3D space
  20. FLOAT nx, ny, nz; //Lighting Normal
  21. FLOAT tu, tv; //Texture coordinates
  22. };
  23. public:
  24. bool SetMaterial(D3DCOLORVALUE rgbaDiffuse, D3DCOLORVALUE rgbaAmbient, D3DCOLORVALUE rgbaSpecular, D3DCOLORVALUE rgbaEmissive, float rPower);
  25. bool SetTexture(const char* szTextureFilePath);
  26. DWORD Render();
  27. CSphere(LPDIRECT3DDEVICE8 pD3DDevice, int nRings = 20, int nSegments = 20);
  28. virtual ~CSphere();
  29. private:
  30. bool CreateIndexBuffer();
  31. bool UpdateVertices();
  32. bool CreateVertexBuffer();
  33. LPDIRECT3DDEVICE8 m_pD3DDevice;
  34. LPDIRECT3DVERTEXBUFFER8 m_pVertexBuffer;
  35. LPDIRECT3DTEXTURE8 m_pTexture;
  36. D3DMATERIAL8 m_matMaterial;
  37. LPDIRECT3DINDEXBUFFER8 m_pIndexBuffer;
  38. int m_nRings;
  39. int m_nSegments;
  40. DWORD m_dwNumOfVertices;
  41. DWORD m_dwNumOfIndices;
  42. DWORD m_dwNumOfPolygons;
  43. };
  44. #endif // !defined(AFX_SPHERE_H__FC705F3B_568E_4973_B608_B8F7700D9ECE__INCLUDED_)