Leaked source code of windows server 2003
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.

246 lines
7.0 KiB

  1. //-----------------------------------------------------------------------------
  2. // File: material.cpp
  3. //
  4. // Desc: materials
  5. //
  6. // Copyright (c) 2000 Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #include "stdafx.h"
  9. // 24 tea materials (from teapots app)
  10. #define NUM_TEA_MATERIALS 24
  11. enum
  12. {
  13. EMERALD = 0,
  14. JADE,
  15. OBSIDIAN,
  16. PEARL,
  17. RUBY,
  18. TURQUOISE,
  19. BRASS,
  20. BRONZE,
  21. CHROME,
  22. COPPER,
  23. GOLD,
  24. SILVER,
  25. BLACK_PLASTIC,
  26. CYAN_PLASTIC,
  27. GREEN_PLASTIC,
  28. RED_PLASTIC,
  29. WHITE_PLASTIC,
  30. YELLOW_PLASTIC,
  31. BLACK_RUBBER,
  32. CYAN_RUBBER,
  33. GREEN_RUBBER,
  34. RED_RUBBER,
  35. WHITE_RUBBER,
  36. YELLOW_RUBBER
  37. };
  38. // 'white' materials, for texturing
  39. #define NUM_TEX_MATERIALS 4
  40. enum
  41. {
  42. BRIGHT_WHITE = NUM_TEA_MATERIALS,
  43. WHITE,
  44. WARM_WHITE,
  45. COOL_WHITE
  46. };
  47. #define NUM_GOOD_MATERIALS 16 // 'good' ones among the 24 tea materials
  48. int goodMaterials[NUM_GOOD_MATERIALS] = {
  49. EMERALD, JADE, PEARL, RUBY, TURQUOISE, BRASS, BRONZE,
  50. COPPER, GOLD, SILVER, CYAN_PLASTIC, WHITE_PLASTIC, YELLOW_PLASTIC,
  51. CYAN_RUBBER, GREEN_RUBBER, WHITE_RUBBER };
  52. // materials: emerald, jade, obsidian, pearl, ruby, turquoise
  53. // brass, bronze, chrome, copper, gold, silver
  54. // black, cyan, green, red, white, yellow plastic
  55. // black, cyan, green, red, white, yellow rubber
  56. //
  57. // description: ambient(RGB), diffuse(RGB), specular(RGB), shininess
  58. // 'tea' materials, from aux teapots program
  59. static float teaMaterialData[NUM_TEA_MATERIALS*10] =
  60. {
  61. // EMERALD = 0,
  62. 0.0215f, 0.1745f, 0.0215f, 0.07568f, 0.61424f, 0.07568f, 0.633f, 0.727811f, 0.633f, 0.6f,
  63. // JADE,
  64. 0.135f, 0.2225f, 0.1575f, 0.54f, 0.89f, 0.63f, 0.316228f, 0.316228f, 0.316228f, 0.1f,
  65. // OBSIDIAN,
  66. 0.05375f, 0.05f, 0.06625f, 0.18275f, 0.17f, 0.22525f, 0.332741f, 0.328634f, 0.346435f, 0.3f,
  67. // PEARL,
  68. 0.25f, 0.20725f, 0.20725f, 1.0f, 0.829f, 0.829f, 0.296648f, 0.296648f, 0.296648f, 0.088f,
  69. // RUBY,
  70. 0.1745f, 0.01175f, 0.01175f, 0.61424f, 0.04136f, 0.04136f, 0.727811f, 0.626959f, 0.626959f, 0.6f,
  71. // TURQUOISE,
  72. 0.1f, 0.18725f, 0.1745f, 0.396f, 0.74151f, 0.69102f, 0.297254f, 0.30829f, 0.306678f, 0.1f,
  73. // BRASS,
  74. 0.329412f, 0.223529f, 0.027451f, 0.780392f, 0.568627f, 0.113725f, 0.992157f, 0.941176f, 0.807843f, 0.21794872f,
  75. // BRONZE,
  76. 0.2125f, 0.1275f, 0.054f, 0.714f, 0.4284f, 0.18144f, 0.393548f, 0.271906f, 0.166721f, 0.2f,
  77. // CHROME,
  78. 0.25f, 0.25f, 0.25f, 0.4f, 0.4f, 0.4f, 0.774597f, 0.774597f, 0.774597f, 0.6f,
  79. // COPPER,
  80. 0.19125f, 0.0735f, 0.0225f, 0.7038f, 0.27048f, 0.0828f, 0.256777f, 0.137622f, 0.086014f, 0.1f,
  81. // GOLD,
  82. 0.24725f, 0.1995f, 0.0745f, 0.75164f, 0.60648f, 0.22648f, 0.628281f, 0.555802f, 0.366065f, 0.4f,
  83. // SILVER,
  84. 0.19225f, 0.19225f, 0.19225f, 0.50754f, 0.50754f, 0.50754f, 0.508273f, 0.508273f, 0.508273f, 0.4f,
  85. // BLACK_PLASTIC,
  86. 0.0f, 0.0f, 0.0f, 0.01f, 0.01f, 0.01f, 0.50f, 0.50f, 0.50f, .25f,
  87. // CYAN_PLASTIC,
  88. 0.0f, 0.1f, 0.06f, 0.0f, 0.50980392f, 0.50980392f, 0.50196078f, 0.50196078f, 0.50196078f, .25f,
  89. // GREEN_PLASTIC,
  90. 0.0f, 0.0f, 0.0f, 0.1f, 0.35f, 0.1f, 0.45f, 0.55f, 0.45f, .25f,
  91. // RED_PLASTIC,
  92. 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.7f, 0.6f, 0.6f, .25f,
  93. // WHITE_PLASTIC,
  94. 0.0f, 0.0f, 0.0f, 0.55f, 0.55f, 0.55f, 0.70f, 0.70f, 0.70f, .25f,
  95. // YELLOW_PLASTIC,
  96. 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.0f, 0.60f, 0.60f, 0.50f, .25f,
  97. // BLACK_RUBBER,
  98. 0.02f, 0.02f, 0.02f, 0.01f, 0.01f, 0.01f, 0.4f, 0.4f, 0.4f, .078125f,
  99. // CYAN_RUBBER,
  100. 0.0f, 0.05f, 0.05f, 0.4f, 0.5f, 0.5f, 0.04f, 0.7f, 0.7f, .078125f,
  101. // GREEN_RUBBER,
  102. 0.0f, 0.05f, 0.0f, 0.4f, 0.5f, 0.4f, 0.04f, 0.7f, 0.04f, .078125f,
  103. // RED_RUBBER,
  104. 0.05f, 0.0f, 0.0f, 0.5f, 0.4f, 0.4f, 0.7f, 0.04f, 0.04f, .078125f,
  105. // WHITE_RUBBER,
  106. 0.05f, 0.05f, 0.05f, 0.5f, 0.5f, 0.5f, 0.7f, 0.7f, 0.7f, .078125f,
  107. // YELLOW_RUBBER
  108. 0.05f, 0.05f, 0.0f, 0.5f, 0.5f, 0.4f, 0.7f, 0.7f, 0.04f, .078125f
  109. };
  110. // generally white materials for texturing
  111. static float texMaterialData[NUM_TEX_MATERIALS*10] =
  112. {
  113. // bright white
  114. 0.2f, 0.2f, 0.2f,
  115. 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f,
  116. // less bright white
  117. 0.2f, 0.2f, 0.2f,
  118. 0.9f, 0.9f, 0.9f, 0.9f, 0.9f, 0.9f, 0.5f,
  119. // warmish white
  120. 0.3f, 0.2f, 0.2f,
  121. 1.0f, 0.9f, 0.8f, 1.0f, 0.9f, 0.8f, 0.5f,
  122. // coolish white
  123. 0.2f, 0.2f, 0.3f,
  124. 0.8f, 0.9f, 1.0f, 0.8f, 0.9f, 1.0f, 0.5f
  125. };
  126. D3DMATERIAL8 g_Materials[NUM_TEA_MATERIALS + NUM_TEX_MATERIALS];
  127. //-----------------------------------------------------------------------------
  128. // Name: InitMaterials
  129. // Desc: Initialize MATERIAL structures with data
  130. // - Set alpha to 0.5 for all materials
  131. //-----------------------------------------------------------------------------
  132. void InitMaterials()
  133. {
  134. int i;
  135. float* pf;
  136. D3DMATERIAL8* pMat;
  137. pf = &teaMaterialData[0];
  138. for( i = 0; i < NUM_TEA_MATERIALS; i++ )
  139. {
  140. pMat = &g_Materials[i];
  141. pMat->Ambient.r = *pf++;
  142. pMat->Ambient.g = *pf++;
  143. pMat->Ambient.b = *pf++;
  144. pMat->Ambient.a = 1.0f;
  145. pMat->Diffuse.r = *pf++;
  146. pMat->Diffuse.g = *pf++;
  147. pMat->Diffuse.b = *pf++;
  148. pMat->Diffuse.a = 1.0f;
  149. pMat->Specular.r = *pf++;
  150. pMat->Specular.g = *pf++;
  151. pMat->Specular.b = *pf++;
  152. pMat->Specular.a = 1.0f;
  153. pMat->Power = 128* (*pf++);
  154. }
  155. pf = &texMaterialData[0];
  156. for( i = 0; i < NUM_TEX_MATERIALS; i++ )
  157. {
  158. pMat = &g_Materials[i+NUM_TEA_MATERIALS];
  159. pMat->Ambient.r = *pf++;
  160. pMat->Ambient.g = *pf++;
  161. pMat->Ambient.b = *pf++;
  162. pMat->Ambient.a = 1.0f;
  163. pMat->Diffuse.r = *pf++;
  164. pMat->Diffuse.g = *pf++;
  165. pMat->Diffuse.b = *pf++;
  166. pMat->Diffuse.a = 1.0f;
  167. pMat->Specular.r = *pf++;
  168. pMat->Specular.g = *pf++;
  169. pMat->Specular.b = *pf++;
  170. pMat->Specular.a = 1.0f;
  171. pMat->Power = *pf++;
  172. }
  173. }
  174. //-----------------------------------------------------------------------------
  175. // Name: RandomTeaMaterial
  176. // Desc: Select a random TeaMaterial
  177. //-----------------------------------------------------------------------------
  178. D3DMATERIAL8* RandomTeaMaterial()
  179. {
  180. int index = goodMaterials[ CPipesScreensaver::iRand(NUM_GOOD_MATERIALS) ];
  181. return &g_Materials[ index ];
  182. }
  183. //-----------------------------------------------------------------------------
  184. // Name: RandomTexMaterial
  185. // Desc: Select a random TexMaterial
  186. //-----------------------------------------------------------------------------
  187. D3DMATERIAL8* RandomTexMaterial()
  188. {
  189. int index = NUM_TEA_MATERIALS + CPipesScreensaver::iRand(NUM_TEX_MATERIALS);
  190. return &g_Materials[ index ];
  191. }