matrixmapper.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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:: Kenny Mitchell *
  29. * *
  30. * $Modtime:: 06/26/02 4:04p $*
  31. * *
  32. * $Revision:: 8 $*
  33. * *
  34. * 06/26/02 KM Matrix name change to avoid MAX conflicts *
  35. *---------------------------------------------------------------------------------------------*
  36. * Functions: *
  37. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  38. #ifndef MATRIXMAPPER_H
  39. #define MATRIXMAPPER_H
  40. #include "always.h"
  41. #include "bittype.h"
  42. #include "matrix4.h"
  43. #include "mapper.h"
  44. // Modified to use DX 8 texture matrices
  45. // Hector Yee 1/29/01
  46. /**
  47. ** MatrixMapperClass. Does the chore of computing the u-v coorinates for
  48. ** a projected texture. Note that this VP must be "baby-sat" by something
  49. ** external to ensure that its ViewToTexture transform is up-to-date. I
  50. ** use it in the TexProjectClass to implement projected textures.
  51. **
  52. ** NOTE: for projected textures, the equation for computing a valid ViewToTexture
  53. ** transform is as follows (assuming my usual column vectors, etc):
  54. ** -1
  55. ** ViewToTexture = Projection * Mwrld-shadow * Mwrld-camera
  56. */
  57. class MatrixMapperClass : public TextureMapperClass
  58. {
  59. W3DMPO_GLUE(MatrixMapperClass)
  60. public:
  61. enum {
  62. INVERT_DEPTH_GRADIENT = 0x00000001,
  63. };
  64. enum MappingType {
  65. ORTHO_PROJECTION = 0,
  66. PERSPECTIVE_PROJECTION,
  67. DEPTH_GRADIENT,
  68. NORMAL_GRADIENT
  69. };
  70. MatrixMapperClass(int stage);
  71. /*
  72. ** Interface
  73. */
  74. void Set_Flag(uint32 flag,bool onoff);
  75. bool Get_Flag(uint32 flag) const;
  76. void Set_Type(MappingType type);
  77. MappingType Get_Type(void);
  78. void Set_Texture_Transform(const Matrix3D & view_to_texture,float texsize);
  79. void Set_Texture_Transform(const Matrix4x4 & view_to_texture,float texsize);
  80. const Matrix4x4 & Get_Texture_Transform(void) const;
  81. void Set_Gradient_U_Coord(float coord) { GradientUCoord = coord; }
  82. float Get_Gradient_U_Coord(void) { return GradientUCoord; }
  83. void Compute_Texture_Coordinate(const Vector3 & point,Vector3 * set_stq);
  84. TextureMapperClass* Clone(void) const { WWASSERT(0); return NULL; }
  85. virtual void Apply(int uv_array_index);
  86. virtual void Calculate_Texture_Matrix(Matrix4x4 &tex_matrix);
  87. protected:
  88. void Update_View_To_Pixel_Transform(float texsize);
  89. uint32 Flags;
  90. MappingType Type;
  91. Matrix4x4 ViewToTexture;
  92. Matrix4x4 ViewToPixel;
  93. Vector3 ViewSpaceProjectionNormal;
  94. float GradientUCoord;
  95. };
  96. /*
  97. ** CompositeMatrixMapperClass - this is a matrix mapper which contains a pointer to another mapper
  98. ** inside it. When applied, it gets the texture matrix from the internal mapper and composites
  99. ** it with it's own matrix, then applies that. It sets the texture source to camera space
  100. ** position. The idea is to use some transformation of the camera space position (like a planar
  101. ** projection) as the 'input coordinates' to some other mapper like a linear offset mapper
  102. ** which usually uses actual texture coordinates as input. If the internal mapper is NULL, it
  103. ** simply applies it's own matrix.
  104. */
  105. class CompositeMatrixMapperClass : public MatrixMapperClass
  106. {
  107. public:
  108. CompositeMatrixMapperClass(TextureMapperClass *internal_mapper, unsigned int stage);
  109. CompositeMatrixMapperClass(const CompositeMatrixMapperClass & src);
  110. virtual ~CompositeMatrixMapperClass(void);
  111. virtual TextureMapperClass *Clone(void) const { return NEW_REF( CompositeMatrixMapperClass, (*this)); }
  112. virtual void Apply(int uv_array_index);
  113. virtual void Calculate_Texture_Matrix(Matrix4x4 &tex_matrix);
  114. protected:
  115. TextureMapperClass *InternalMapper;
  116. };
  117. inline void MatrixMapperClass::Set_Flag(uint32 flag,bool onoff)
  118. {
  119. if (onoff) {
  120. Flags |= flag;
  121. } else {
  122. Flags &= ~flag;
  123. }
  124. }
  125. inline bool MatrixMapperClass::Get_Flag(uint32 flag) const
  126. {
  127. return (Flags & flag) == flag;
  128. }
  129. inline void MatrixMapperClass::Set_Type(MappingType type)
  130. {
  131. Type = type;
  132. }
  133. inline MatrixMapperClass::MappingType MatrixMapperClass::Get_Type(void)
  134. {
  135. return Type;
  136. }
  137. inline const Matrix4x4 & MatrixMapperClass::Get_Texture_Transform(void) const
  138. {
  139. return ViewToTexture;
  140. }
  141. #endif