matrixmapper.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWPhys *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/matrixmapper.h $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 6/21/01 10:22a $*
  31. * *
  32. * $Revision:: 7 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #ifndef MATRIXMAPPER_H
  38. #define MATRIXMAPPER_H
  39. #include "always.h"
  40. #include "bittype.h"
  41. #include "matrix4.h"
  42. #include "mapper.h"
  43. // Modified to use DX 8 texture matrices
  44. // Hector Yee 1/29/01
  45. /**
  46. ** MatrixMapperClass. Does the chore of computing the u-v coorinates for
  47. ** a projected texture. Note that this VP must be "baby-sat" by something
  48. ** external to ensure that its ViewToTexture transform is up-to-date. I
  49. ** use it in the TexProjectClass to implement projected textures.
  50. **
  51. ** NOTE: for projected textures, the equation for computing a valid ViewToTexture
  52. ** transform is as follows (assuming my usual column vectors, etc):
  53. ** -1
  54. ** ViewToTexture = Projection * Mwrld-shadow * Mwrld-camera
  55. */
  56. class MatrixMapperClass : public TextureMapperClass
  57. {
  58. W3DMPO_GLUE(MatrixMapperClass)
  59. public:
  60. enum {
  61. INVERT_DEPTH_GRADIENT = 0x00000001,
  62. };
  63. enum MappingType {
  64. ORTHO_PROJECTION = 0,
  65. PERSPECTIVE_PROJECTION,
  66. DEPTH_GRADIENT,
  67. NORMAL_GRADIENT
  68. };
  69. MatrixMapperClass(int stage);
  70. /*
  71. ** Interface
  72. */
  73. void Set_Flag(uint32 flag,bool onoff);
  74. bool Get_Flag(uint32 flag) const;
  75. void Set_Type(MappingType type);
  76. MappingType Get_Type(void);
  77. void Set_Texture_Transform(const Matrix3D & view_to_texture,float texsize);
  78. void Set_Texture_Transform(const Matrix4 & view_to_texture,float texsize);
  79. const Matrix4 & Get_Texture_Transform(void) const;
  80. void Set_Gradient_U_Coord(float coord) { GradientUCoord = coord; }
  81. float Get_Gradient_U_Coord(void) { return GradientUCoord; }
  82. void Compute_Texture_Coordinate(const Vector3 & point,Vector3 * set_stq);
  83. TextureMapperClass* Clone(void) const { WWASSERT(0); return NULL; }
  84. virtual void Apply(int uv_array_index);
  85. protected:
  86. void Update_View_To_Pixel_Transform(float texsize);
  87. uint32 Flags;
  88. MappingType Type;
  89. Matrix4 ViewToTexture;
  90. Matrix4 ViewToPixel;
  91. Vector3 ViewSpaceProjectionNormal;
  92. float GradientUCoord;
  93. };
  94. inline void MatrixMapperClass::Set_Flag(uint32 flag,bool onoff)
  95. {
  96. if (onoff) {
  97. Flags |= flag;
  98. } else {
  99. Flags &= ~flag;
  100. }
  101. }
  102. inline bool MatrixMapperClass::Get_Flag(uint32 flag) const
  103. {
  104. return (Flags & flag) == flag;
  105. }
  106. inline void MatrixMapperClass::Set_Type(MappingType type)
  107. {
  108. Type = type;
  109. }
  110. inline MatrixMapperClass::MappingType MatrixMapperClass::Get_Type(void)
  111. {
  112. return Type;
  113. }
  114. inline const Matrix4 & MatrixMapperClass::Get_Texture_Transform(void) const
  115. {
  116. return ViewToTexture;
  117. }
  118. #endif