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.

68 lines
1.5 KiB

  1. //===== Copyright � 1996-2007, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: a class for performing cube-mapped spherical sample lookups.
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //===========================================================================//
  9. #ifndef CUBEMAP_H
  10. #define CUBEMAP_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "tier0/platform.h"
  15. #include "tier1/utlmemory.h"
  16. #include "mathlib/mathlib.h"
  17. template<class T, int RES> struct CCubeMap
  18. {
  19. T m_Samples[6][RES][RES];
  20. public:
  21. FORCEINLINE void GetCoords( Vector const &vecNormalizedDirection, int &nX, int &nY, int &nFace )
  22. {
  23. // find largest magnitude component
  24. int nLargest = 0;
  25. int nAxis0 = 1;
  26. int nAxis1 = 2;
  27. if ( fabs( vecNormalizedDirection[1] ) > fabs( vecNormalizedDirection[0] ) )
  28. {
  29. nLargest = 1;
  30. nAxis0 = 0;
  31. nAxis1 = 2;
  32. }
  33. if ( fabs( vecNormalizedDirection[2] ) > fabs( vecNormalizedDirection[nLargest] ) )
  34. {
  35. nLargest = 2;
  36. nAxis0 = 0;
  37. nAxis1 = 1;
  38. }
  39. float flZ = vecNormalizedDirection[nLargest];
  40. if ( flZ < 0 )
  41. {
  42. flZ = - flZ;
  43. nLargest += 3;
  44. }
  45. nFace = nLargest;
  46. flZ = 1.0 / flZ;
  47. nX = RemapValClamped( vecNormalizedDirection[nAxis0] * flZ, -1, 1, 0, RES - 1 );
  48. nY = RemapValClamped( vecNormalizedDirection[nAxis1] * flZ, -1, 1, 0, RES - 1 );
  49. }
  50. FORCEINLINE T & GetSample( Vector const &vecNormalizedDirection )
  51. {
  52. int nX, nY, nFace;
  53. GetCoords( vecNormalizedDirection, nX, nY, nFace );
  54. return m_Samples[nFace][nX][nY];
  55. }
  56. };
  57. #endif // CUBEMAP_H