Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.3 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #ifndef POLYHEDRON_H_
  9. #define POLYHEDRON_H_
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "mathlib/mathlib.h"
  14. struct Polyhedron_IndexedLine_t
  15. {
  16. unsigned short iPointIndices[2];
  17. };
  18. struct Polyhedron_IndexedLineReference_t
  19. {
  20. unsigned short iLineIndex;
  21. unsigned char iEndPointIndex; //since two polygons reference any one line, one needs to traverse the line backwards, this flags that behavior
  22. };
  23. struct Polyhedron_IndexedPolygon_t
  24. {
  25. unsigned short iFirstIndex;
  26. unsigned short iIndexCount;
  27. Vector polyNormal;
  28. };
  29. class CPolyhedron //made into a class because it's going virtual to support distinctions between temp and permanent versions
  30. {
  31. public:
  32. Vector *pVertices;
  33. Polyhedron_IndexedLine_t *pLines;
  34. Polyhedron_IndexedLineReference_t *pIndices;
  35. Polyhedron_IndexedPolygon_t *pPolygons;
  36. unsigned short iVertexCount;
  37. unsigned short iLineCount;
  38. unsigned short iIndexCount;
  39. unsigned short iPolygonCount;
  40. virtual ~CPolyhedron( void ) {};
  41. virtual void Release( void ) = 0;
  42. Vector Center( void ) const;
  43. };
  44. class CPolyhedron_AllocByNew : public CPolyhedron
  45. {
  46. public:
  47. virtual void Release( void );
  48. static CPolyhedron_AllocByNew *Allocate( unsigned short iVertices, unsigned short iLines, unsigned short iIndices, unsigned short iPolygons ); //creates the polyhedron along with enough memory to hold all it's data in a single allocation
  49. private:
  50. CPolyhedron_AllocByNew( void ) { }; //CPolyhedron_AllocByNew::Allocate() is the only way to create one of these.
  51. };
  52. CPolyhedron *GeneratePolyhedronFromPlanes( const float *pOutwardFacingPlanes, int iPlaneCount, float fOnPlaneEpsilon, bool bUseTemporaryMemory = false ); //be sure to polyhedron->Release()
  53. CPolyhedron *ClipPolyhedron( const CPolyhedron *pExistingPolyhedron, const float *pOutwardFacingPlanes, int iPlaneCount, float fOnPlaneEpsilon, bool bUseTemporaryMemory = false ); //this does NOT modify/delete the existing polyhedron
  54. CPolyhedron *GetTempPolyhedron( unsigned short iVertices, unsigned short iLines, unsigned short iIndices, unsigned short iPolygons ); //grab the temporary polyhedron. Avoids new/delete for quick work. Can only be in use by one chunk of code at a time
  55. #endif //#ifndef POLYHEDRON_H_