w3d_util.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. ** Command & Conquer Renegade(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 : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/w3d_util.cpp $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 7/23/01 5:31p $*
  29. * *
  30. * $Revision:: 5 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "w3d_util.h"
  36. #include "vector3.h"
  37. #include "vector4.h"
  38. #include "quat.h"
  39. #include "shader.h"
  40. void W3dUtilityClass::Convert_Vector(const W3dVectorStruct & v,Vector3 * set)
  41. {
  42. set->X = v.X;
  43. set->Y = v.Y;
  44. set->Z = v.Z;
  45. }
  46. void W3dUtilityClass::Convert_Vector(const Vector3 & v,W3dVectorStruct * set)
  47. {
  48. set->X = v.X;
  49. set->Y = v.Y;
  50. set->Z = v.Z;
  51. }
  52. void W3dUtilityClass::Convert_Quaternion(const W3dQuaternionStruct & q,Quaternion * set)
  53. {
  54. set->X = q.Q[0];
  55. set->Y = q.Q[1];
  56. set->Z = q.Q[2];
  57. set->W = q.Q[3];
  58. }
  59. void W3dUtilityClass::Convert_Quaternion(const Quaternion & q,W3dQuaternionStruct * set)
  60. {
  61. set->Q[0] = q.X;
  62. set->Q[1] = q.Y;
  63. set->Q[2] = q.Z;
  64. set->Q[3] = q.W;
  65. }
  66. void W3dUtilityClass::Convert_Color(const W3dRGBStruct & rgb,Vector3 * set)
  67. {
  68. set->X = (float)rgb.R / 255.0f;
  69. set->Y = (float)rgb.G / 255.0f;
  70. set->Z = (float)rgb.B / 255.0f;
  71. }
  72. void W3dUtilityClass::Convert_Color(const Vector3 & v,W3dRGBStruct * color)
  73. {
  74. color->R = (uint8)(255.0f * v.X);
  75. color->G = (uint8)(255.0f * v.Y);
  76. color->B = (uint8)(255.0f * v.Z);
  77. color->pad = 0;
  78. }
  79. void W3dUtilityClass::Convert_Color(const W3dRGBAStruct & rgb,Vector4 * set)
  80. {
  81. set->X = (float)rgb.R / 255.0f;
  82. set->Y = (float)rgb.G / 255.0f;
  83. set->Z = (float)rgb.B / 255.0f;
  84. set->W = (float)rgb.A / 255.0f;
  85. }
  86. void W3dUtilityClass::Convert_Color(const Vector4 & v,W3dRGBAStruct * color)
  87. {
  88. color->R = (uint8)(255.0f * v.X);
  89. color->G = (uint8)(255.0f * v.Y);
  90. color->B = (uint8)(255.0f * v.Z);
  91. color->A = (uint8)(255.0f * v.W);
  92. }
  93. void W3dUtilityClass::Convert_Shader(const W3dShaderStruct & shader,ShaderClass * set)
  94. {
  95. set->Set_Depth_Compare ((ShaderClass::DepthCompareType)W3d_Shader_Get_Depth_Compare(&shader));
  96. set->Set_Depth_Mask ((ShaderClass::DepthMaskType)W3d_Shader_Get_Depth_Mask(&shader));
  97. set->Set_Color_Mask (ShaderClass::COLOR_WRITE_ENABLE);
  98. set->Set_Dst_Blend_Func ((ShaderClass::DstBlendFuncType)W3d_Shader_Get_Dest_Blend_Func(&shader));
  99. set->Set_Fog_Func (ShaderClass::FOG_DISABLE);
  100. set->Set_Primary_Gradient ((ShaderClass::PriGradientType)W3d_Shader_Get_Pri_Gradient(&shader));
  101. set->Set_Secondary_Gradient((ShaderClass::SecGradientType)W3d_Shader_Get_Sec_Gradient(&shader));
  102. set->Set_Src_Blend_Func ((ShaderClass::SrcBlendFuncType)W3d_Shader_Get_Src_Blend_Func(&shader));
  103. set->Set_Texturing ((ShaderClass::TexturingType)W3d_Shader_Get_Texturing(&shader));
  104. set->Set_Alpha_Test ((ShaderClass::AlphaTestType)W3d_Shader_Get_Alpha_Test(&shader));
  105. // Jani: No cull mode settings for w3d shader - problem?
  106. // set->Set_Dither_Mask (ShaderClass::DITHER_ENABLE);
  107. // The tools do not enable setting post-detail stuff, and in any case we probably wouldn't
  108. // want to confuse the artists with the distinction between detail and post-detail settings at
  109. // this point, so we just copy the detail settings into the post-detail settings.
  110. // set->Set_Post_Detail_Color_Func ((ShaderClass::DetailColorFuncType) W3d_Shader_Get_Post_Detail_Color_Func (&shader));
  111. // set->Set_Post_Detail_Alpha_Func ((ShaderClass::DetailAlphaFuncType) W3d_Shader_Get_Post_Detail_Alpha_Func (&shader));
  112. set->Set_Post_Detail_Color_Func ((ShaderClass::DetailColorFuncType) W3d_Shader_Get_Detail_Color_Func (&shader));
  113. set->Set_Post_Detail_Alpha_Func ((ShaderClass::DetailAlphaFuncType) W3d_Shader_Get_Detail_Alpha_Func (&shader));
  114. }
  115. void W3dUtilityClass::Convert_Shader(const ShaderClass & shader,W3dShaderStruct * set)
  116. {
  117. W3d_Shader_Reset(set);
  118. W3d_Shader_Set_Depth_Compare(set,shader.Get_Depth_Compare());
  119. W3d_Shader_Set_Depth_Mask(set,shader.Get_Depth_Mask());
  120. W3d_Shader_Set_Dest_Blend_Func(set,shader.Get_Dst_Blend_Func());
  121. W3d_Shader_Set_Pri_Gradient(set,shader.Get_Primary_Gradient());
  122. W3d_Shader_Set_Sec_Gradient(set,shader.Get_Secondary_Gradient());
  123. W3d_Shader_Set_Src_Blend_Func(set,shader.Get_Src_Blend_Func());
  124. W3d_Shader_Set_Texturing(set,shader.Get_Texturing());
  125. W3d_Shader_Set_Alpha_Test(set,shader.Get_Alpha_Test());
  126. W3d_Shader_Set_Post_Detail_Color_Func(set,shader.Get_Post_Detail_Color_Func());
  127. W3d_Shader_Set_Post_Detail_Alpha_Func(set,shader.Get_Post_Detail_Alpha_Func());
  128. }