Water.cpp
上传用户:cydong117
上传日期:2009-11-10
资源大小:638k
文件大小:21k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. #include "StdAfx.h"
  2. CWater::CWater()
  3. {
  4. Init(RGB(220, 220, 220));
  5. }
  6. CWater::~CWater()
  7. {
  8. }
  9. VOID CWater::Init(DWORD dwLightColor)
  10. {
  11. m_dwLightColor = dwLightColor;
  12. m_bShowFog = FALSE;
  13. for ( INT nCntY = 0; nCntY < (WATER_NUM_CNTY_LIGHTTILE+1); nCntY++ )
  14. {
  15. for ( INT nCntX = 0; nCntX < (WATER_NUM_CNTX_LIGHTTILE+1); nCntX++ )
  16. {
  17. FLOAT az = (FLOAT)GetRandomNum(0, 17);
  18. m_avLight[nCntY][nCntX] = D3DLVERTEX(D3DVECTOR((FLOAT)(WATER_TILE_START_XPOS+(nCntX*WATER_TILE_WIDTH)), (FLOAT)(-WATER_TILE_START_YPOS-(nCntY*WATER_TILE_HEIGHT)), az),
  19.         m_dwLightColor, RGB(0, 0, 0), (FLOAT)((FLOAT)nCntX/(FLOAT)WATER_NUM_CNTX_LIGHTTILE), (FLOAT)((FLOAT)nCntY/(FLOAT)WATER_NUM_CNTY_LIGHTTILE));
  20. }
  21. }
  22. memcpy(m_avSaveLight, m_avLight, sizeof(D3DLVERTEX)*(WATER_NUM_CNTY_LIGHTTILE+1)*(WATER_NUM_CNTX_LIGHTTILE+1));
  23. // 鸥老弃府帮狼 牢郸胶 积己.
  24.     WORD* pwIndex = m_pwLightIndices;
  25. for ( nCntY = 0; nCntY < WATER_NUM_CNTY_LIGHTTILE; nCntY++ )
  26. {
  27. for ( INT nCntX = 0; nCntX < WATER_NUM_CNTX_LIGHTTILE; nCntX++ )
  28. {
  29. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);  
  30. *pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
  31. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
  32. *pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
  33. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);  
  34. *pwIndex++ = (nCntX)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
  35. }
  36. }
  37. m_bCurrTexIdx = 0;
  38. CHAR* szFileList[] = 
  39. {
  40. "Water00.bmp",
  41. "Water01.bmp",
  42. "Water02.bmp",
  43. "Water03.bmp",
  44. "Water04.bmp",
  45. "Water05.bmp",
  46. "Water06.bmp",
  47. "Water07.bmp",
  48. "Water08.bmp",
  49. "Water09.bmp",
  50. "Water10.bmp",
  51. "Water11.bmp",
  52. "Water12.bmp",
  53. "Water13.bmp",
  54. "Water14.bmp",
  55. "Water15.bmp",
  56. "Water16.bmp",
  57. "Water17.bmp",
  58. "Water18.bmp",
  59. "Water19.bmp",
  60. "Water20.bmp",
  61. "Water21.bmp",
  62. "Water22.bmp",
  63. "Water23.bmp",
  64. "Water24.bmp",
  65. "Water25.bmp",
  66. };
  67. for ( INT nCnt = 0; nCnt < 26; nCnt++ )
  68. {
  69. strcpy(m_szWater[nCnt], szFileList[nCnt]);
  70. D3DTextr_CreateTextureFromFile(m_szWater[nCnt]);
  71. D3DTextr_Restore(m_szWater[nCnt], g_xMainWnd.Get3DDevice());
  72. }
  73. }
  74. VOID CWater::ChangeLightColor(DWORD dwColor)
  75. {
  76. if ( m_dwLightColor != dwColor )
  77. {
  78. for ( INT nCntY = 0; nCntY < WATER_NUM_CNTY_LIGHTTILE+1; nCntY++ )
  79. {
  80. for ( INT nCntX = 0; nCntX < WATER_NUM_CNTX_LIGHTTILE+1; nCntX++ )
  81. {
  82. m_avLight[nCntY][nCntX].color = dwColor;
  83. }
  84. }
  85. m_dwLightColor = dwColor;
  86. memcpy(m_avSaveLight, m_avLight, sizeof(D3DLVERTEX)*(WATER_NUM_CNTY_LIGHTTILE+1)*(WATER_NUM_CNTX_LIGHTTILE+1));
  87. }
  88. }
  89. VOID CWater::ClearSavedLightColor()
  90. {
  91. memcpy(m_avLight, m_avSaveLight, sizeof(D3DLVERTEX)*(WATER_NUM_CNTY_LIGHTTILE+1)*(WATER_NUM_CNTX_LIGHTTILE+1));
  92. }
  93. BOOL CWater::GetScreenPosToLightTile(INT nX, INT nY, INT* nTileX, INT* nTileY)
  94. {
  95. *nTileX = (nX - WATER_TILE_START_XPOS) / WATER_TILE_WIDTH;
  96. *nTileY = (nY - WATER_TILE_START_YPOS) / WATER_TILE_HEIGHT;
  97. return TRUE;
  98. }
  99. BOOL CWater::SetLightRadiusWithRing(INT XLightPos, INT YLightPos, 
  100.    INT nSmallRadius, 
  101.    INT nSmallRed, INT nSmallGreen, INT nSmallBlue, 
  102.    INT nLargeRadius,
  103.    INT nLargeRed, INT nLargeGreen, INT nLargeBlue)
  104. {
  105. INT nX, nY;
  106. GetScreenPosToLightTile(XLightPos, YLightPos, &nX, &nY);
  107. INT nStartTileX = nX - nLargeRadius;
  108. INT nStartTileY = nY - nLargeRadius;
  109. INT nEndTileX = nX + nLargeRadius + 1;
  110. INT nEndTileY = nY + nLargeRadius + 1;
  111. // y甫 绵栏肺 秦辑 俩 绢滴款 何盒阑 备茄促.(x焊促 y啊 歹 利栏骨肺)
  112. nLargeRadius = (nLargeRadius*WATER_TILE_HEIGHT);
  113. nSmallRadius = (nSmallRadius*WATER_TILE_HEIGHT);
  114. DOUBLE rLengthCnt = 0;
  115. INT nSelectedRedValue = 0; 
  116. INT nSelectedGreenValue = 0;
  117. INT nSelectedBlueValue = 0;
  118. if ( nStartTileX < 0 ) nStartTileX = 0;
  119. if ( nStartTileY < 0 ) nStartTileY = 0;
  120. if ( nEndTileX > WATER_NUM_CNTX_LIGHTTILE+1 ) nEndTileX = WATER_NUM_CNTX_LIGHTTILE+1;
  121. if ( nEndTileY > WATER_NUM_CNTY_LIGHTTILE+1 ) nEndTileY = WATER_NUM_CNTY_LIGHTTILE+1;
  122. for ( INT nCntY = nStartTileY; nCntY < nEndTileY; nCntY++ )
  123. {
  124. for ( INT nCntX = nStartTileX; nCntX < nEndTileX; nCntX++ )
  125. {
  126. rLengthCnt = sqrt((XLightPos-(nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS))*(XLightPos-(nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS)) + 
  127.    (YLightPos-(nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS))*(YLightPos-(nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS)));
  128. if ( nCntX < WATER_NUM_CNTX_LIGHTTILE && nCntY < WATER_NUM_CNTY_LIGHTTILE )
  129. {
  130. // 器牢飘痢阑 器窃窍瘤 臼绰 谅窍. 器牢飘痢阑 器窃窍瘤 臼绰 快惑.
  131. if ( (nCntX > nX && nCntY < nY) || (nCntX < nX && nCntY > nY) )
  132. {
  133. WORD* pwIndex = ((WORD*)m_pwLightIndices+(nCntX+nCntY*(WATER_NUM_CNTX_LIGHTTILE))*6);
  134. *pwIndex++ = (nCntX)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
  135. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);  
  136. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
  137. *pwIndex++ = (nCntX)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
  138. *pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
  139. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
  140. }
  141. else
  142. {
  143. WORD* pwIndex = ((WORD*)m_pwLightIndices+(nCntX+nCntY*(WATER_NUM_CNTX_LIGHTTILE))*6);
  144. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);  
  145. *pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
  146. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
  147. *pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
  148. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);  
  149. *pwIndex++ = (nCntX)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
  150. }
  151. }
  152. if ( rLengthCnt < nSmallRadius )
  153. {
  154. nSelectedRedValue = nSmallRed - INT((nSmallRed*rLengthCnt)/(nLargeRadius));
  155. nSelectedGreenValue = nSmallGreen - INT((nSmallGreen*rLengthCnt)/(nLargeRadius));
  156. nSelectedBlueValue = nSmallBlue - INT((nSmallBlue*rLengthCnt)/(nLargeRadius));
  157. }
  158. else if ( rLengthCnt >= nSmallRadius && rLengthCnt <= nLargeRadius )
  159. {
  160. nSelectedRedValue = nLargeRed - INT((nLargeRed*rLengthCnt)/(nLargeRadius));
  161. nSelectedGreenValue = nLargeGreen - INT((nLargeGreen*rLengthCnt)/(nLargeRadius));
  162. nSelectedBlueValue = nLargeBlue - INT((nLargeBlue*rLengthCnt)/(nLargeRadius));
  163. }
  164. else
  165. {
  166. nSelectedRedValue = nSelectedGreenValue = nSelectedBlueValue = 0;
  167. }
  168. if ( nSelectedRedValue  < 0 ) nSelectedRedValue = 0;
  169. if ( nSelectedGreenValue < 0 ) nSelectedGreenValue = 0;
  170. if ( nSelectedBlueValue  < 0 ) nSelectedBlueValue = 0;
  171. if ( m_avLight[nCntY][nCntX].color == 0 )
  172. m_avLight[nCntY][nCntX].color = RGB(nSelectedRedValue, nSelectedGreenValue, nSelectedBlueValue); 
  173. else
  174. {
  175. nSelectedRedValue += (INT)RGB_GETBLUE(m_avLight[nCntY][nCntX].color);
  176. nSelectedGreenValue += (INT)RGB_GETGREEN(m_avLight[nCntY][nCntX].color);
  177. nSelectedBlueValue += (INT)RGB_GETRED(m_avLight[nCntY][nCntX].color);
  178. if ( nSelectedRedValue  > 255 ) nSelectedRedValue = 255;
  179. if ( nSelectedGreenValue > 255 ) nSelectedGreenValue = 255;
  180. if ( nSelectedBlueValue  > 255 ) nSelectedBlueValue = 255;
  181. m_avLight[nCntY][nCntX].color =  RGB(nSelectedRedValue, nSelectedGreenValue, nSelectedBlueValue);
  182. }
  183. }
  184. }
  185. return TRUE;
  186. }
  187. BOOL CWater::SetLightRadiusWithCircle(INT XLightPos, INT YLightPos, INT nRadius, 
  188.  INT nRedValue, INT nGreenValue, INT nBlueValue, 
  189.  FLOAT rDrakRate)
  190. {
  191. INT nX, nY;
  192. GetScreenPosToLightTile(XLightPos, YLightPos, &nX, &nY);
  193. INT nStartTileX = nX - nRadius;
  194. INT nStartTileY = nY - nRadius;
  195. INT nEndTileX = nX + nRadius + 1;
  196. INT nEndTileY = nY + nRadius + 1;
  197. // y甫 绵栏肺 秦辑 俩 绢滴款 何盒阑 备茄促.(x焊促 y啊 歹 利栏骨肺)
  198. nRadius = (nRadius*WATER_TILE_HEIGHT);
  199. DOUBLE rLengthCnt = 0;
  200. INT nSelectedRedValue = 0; 
  201. INT nSelectedGreenValue = 0;
  202. INT nSelectedBlueValue = 0;
  203. if ( nStartTileX < 0 ) nStartTileX = 0;
  204. if ( nStartTileY < 0 ) nStartTileY = 0;
  205. if ( nEndTileX > WATER_NUM_CNTX_LIGHTTILE+1 ) nEndTileX = WATER_NUM_CNTX_LIGHTTILE+1;
  206. if ( nEndTileY > WATER_NUM_CNTY_LIGHTTILE+1 ) nEndTileY = WATER_NUM_CNTY_LIGHTTILE+1;
  207. for ( INT nCntY = nStartTileY; nCntY < nEndTileY; nCntY++ )
  208. {
  209. for ( INT nCntX = nStartTileX; nCntX < nEndTileX; nCntX++ )
  210. {
  211. rLengthCnt = sqrt((XLightPos-(nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS))*(XLightPos-(nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS)) + 
  212.    (YLightPos-(nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS))*(YLightPos-(nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS)));
  213. if ( nCntX < WATER_NUM_CNTX_LIGHTTILE && nCntY < WATER_NUM_CNTY_LIGHTTILE )
  214. {
  215. // 器牢飘痢阑 器窃窍瘤 臼绰 谅窍. 器牢飘痢阑 器窃窍瘤 臼绰 快惑.
  216. if ( (nCntX > nX && nCntY < nY) || (nCntX < nX && nCntY > nY) )
  217. {
  218. WORD* pwIndex = ((WORD*)m_pwLightIndices+(nCntX+nCntY*(WATER_NUM_CNTX_LIGHTTILE))*6);
  219. *pwIndex++ = (nCntX)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
  220. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);  
  221. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
  222. *pwIndex++ = (nCntX)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
  223. *pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
  224. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
  225. }
  226. else
  227. {
  228. WORD* pwIndex = ((WORD*)m_pwLightIndices+(nCntX+nCntY*(WATER_NUM_CNTX_LIGHTTILE))*6);
  229. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);  
  230. *pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
  231. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
  232. *pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
  233. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);  
  234. *pwIndex++ = (nCntX)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
  235. }
  236. }
  237. /* RECT rc;
  238. SetRect(&rc,
  239.    (nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS),
  240.    (nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS),
  241.    (nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS+WATER_TILE_WIDTH),
  242.    (nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS+WATER_TILE_HEIGHT));
  243. g_xMainWnd.DrawWithGDI(rc, NULL, RGB(0, 255, 255), 1);
  244. */
  245. if ( rLengthCnt <= nRadius )
  246. {
  247. nSelectedRedValue = nRedValue - INT((nRedValue*rLengthCnt*rDrakRate)/(nRadius));
  248. nSelectedGreenValue = nGreenValue - INT((nGreenValue*rLengthCnt*rDrakRate)/(nRadius));
  249. nSelectedBlueValue = nBlueValue - INT((nBlueValue*rLengthCnt*rDrakRate)/(nRadius));
  250. /* SetRect(&rc,
  251.    (nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS),
  252.    (nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS),
  253.    (nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS+2),
  254.    (nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS+2));
  255. g_xMainWnd.DrawWithGDI(rc, NULL, RGB(255, 0, 0), 1);
  256. */ }
  257. else
  258. {
  259. nSelectedRedValue = nSelectedGreenValue = nSelectedBlueValue = 0;
  260. }
  261. if ( nSelectedRedValue  < 0 ) nSelectedRedValue = 0;
  262. if ( nSelectedGreenValue < 0 ) nSelectedGreenValue = 0;
  263. if ( nSelectedBlueValue  < 0 ) nSelectedBlueValue = 0;
  264. if ( m_avLight[nCntY][nCntX].color == 0 )
  265. m_avLight[nCntY][nCntX].color = RGB(nSelectedRedValue, nSelectedGreenValue, nSelectedBlueValue); 
  266. else
  267. {
  268. nSelectedRedValue += (INT)RGB_GETBLUE(m_avLight[nCntY][nCntX].color);
  269. nSelectedGreenValue += (INT)RGB_GETGREEN(m_avLight[nCntY][nCntX].color);
  270. nSelectedBlueValue += (INT)RGB_GETRED(m_avLight[nCntY][nCntX].color);
  271. if ( nSelectedRedValue  > 255 ) nSelectedRedValue = 255;
  272. if ( nSelectedGreenValue > 255 ) nSelectedGreenValue = 255;
  273. if ( nSelectedBlueValue  > 255 ) nSelectedBlueValue = 255;
  274. m_avLight[nCntY][nCntX].color =  RGB(nSelectedRedValue, nSelectedGreenValue, nSelectedBlueValue);
  275. }
  276. }
  277. }
  278. return TRUE;
  279. }
  280. BOOL CWater::SetLightRadiusWithElipse(INT XLightPos, INT YLightPos, INT nXRadius, INT nYRadius, 
  281.  INT nRedValue, INT nGreenValue, INT nBlueValue, 
  282.  FLOAT rDrakRate)
  283. {
  284. INT nX, nY;
  285. GetScreenPosToLightTile(XLightPos, YLightPos, &nX, &nY);
  286. INT nStartTileX = nX - nXRadius;
  287. INT nStartTileY = nY - nYRadius;
  288. INT nEndTileX = nX + nXRadius + 1;
  289. INT nEndTileY = nY + nYRadius + 1;
  290. FLOAT rXRadius = (FLOAT)(nXRadius*WATER_TILE_WIDTH);
  291. FLOAT rYRadius = (FLOAT)(nYRadius*WATER_TILE_HEIGHT);
  292. INT   nRadius  = 0;
  293. if ( rXRadius > rYRadius )
  294. {
  295. nRadius = (INT)rXRadius;
  296. }
  297. else
  298. {
  299. nRadius = (INT)rYRadius;
  300. }
  301. DOUBLE rLengthCnt = 0;
  302. INT nSelectedRedValue = 0; 
  303. INT nSelectedGreenValue = 0; 
  304. INT nSelectedBlueValue = 0; 
  305. if ( nStartTileX < 0 ) nStartTileX = 0;
  306. if ( nStartTileY < 0 ) nStartTileY = 0;
  307. if ( nEndTileX > WATER_NUM_CNTX_LIGHTTILE+1 ) nEndTileX = WATER_NUM_CNTX_LIGHTTILE+1;
  308. if ( nEndTileY > WATER_NUM_CNTY_LIGHTTILE+1 ) nEndTileY = WATER_NUM_CNTY_LIGHTTILE+1;
  309. for ( INT nCntY = nStartTileY; nCntY < nEndTileY; nCntY++ )
  310. {
  311. for ( INT nCntX = nStartTileX; nCntX < nEndTileX; nCntX++ )
  312. {
  313. if ( nCntX < WATER_NUM_CNTX_LIGHTTILE && nCntY < WATER_NUM_CNTY_LIGHTTILE )
  314. {
  315. // 器牢飘痢阑 器窃窍瘤 臼绰 谅窍. 器牢飘痢阑 器窃窍瘤 臼绰 快惑.
  316. if ( (nCntX > nX && nCntY < nY) || (nCntX < nX && nCntY > nY) )
  317. {
  318. WORD* pwIndex = ((WORD*)m_pwLightIndices+(nCntX+nCntY*(WATER_NUM_CNTX_LIGHTTILE))*6);
  319. *pwIndex++ = (nCntX)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
  320. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);  
  321. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
  322. *pwIndex++ = (nCntX)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
  323. *pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
  324. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
  325. }
  326. else
  327. {
  328. WORD* pwIndex = ((WORD*)m_pwLightIndices+(nCntX+nCntY*(WATER_NUM_CNTX_LIGHTTILE))*6);
  329. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);  
  330. *pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
  331. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
  332. *pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
  333. *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);  
  334. *pwIndex++ = (nCntX)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
  335. }
  336. }
  337. /* RECT rc;
  338. SetRect(&rc,
  339.    (nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS),
  340.    (nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS),
  341.    (nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS+WATER_TILE_WIDTH),
  342.    (nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS+WATER_TILE_HEIGHT));
  343. g_xMainWnd.DrawWithGDI(rc, NULL, RGB(0, 255, 255), 1);
  344. */
  345. INT nCurrCntXRate, nCurrCntYRate;
  346. if ( rXRadius > rYRadius )
  347. {
  348. nCurrCntXRate = nCntX;
  349. nCurrCntYRate = nCntY + (INT)((nCntY-nY)*(FLOAT)(rXRadius/rYRadius-1.0f));
  350. }
  351. else if ( rXRadius < rYRadius )
  352. {
  353. nCurrCntXRate = nCntX + (INT)((nCntX-nX)*(FLOAT)(rYRadius/rXRadius-1.0f));
  354. nCurrCntYRate = nCntY;
  355. }
  356. else
  357. {
  358. nCurrCntXRate = nCntX;
  359. nCurrCntYRate = nCntY;
  360. }
  361. rLengthCnt = sqrt((XLightPos-(nCurrCntXRate*WATER_TILE_WIDTH+WATER_TILE_START_XPOS))*(XLightPos-(nCurrCntXRate*WATER_TILE_WIDTH+WATER_TILE_START_XPOS)) + 
  362.    (YLightPos-(nCurrCntYRate*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS))*(YLightPos-(nCurrCntYRate*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS)));
  363. /* SetRect(&rc,
  364.    (XLightPos),
  365.    (YLightPos),
  366.    (XLightPos+5),
  367.    (YLightPos+5));
  368. g_xMainWnd.DrawWithGDI(rc, NULL, RGB(255, 0, 0), 1);
  369. */
  370. if ( rLengthCnt <= nRadius )
  371. {
  372. nSelectedRedValue = nRedValue - INT((nRedValue*rLengthCnt*rDrakRate)/(nRadius));
  373. nSelectedGreenValue = nGreenValue - INT((nGreenValue*rLengthCnt*rDrakRate)/(nRadius));
  374. nSelectedBlueValue = nBlueValue - INT((nBlueValue*rLengthCnt*rDrakRate)/(nRadius));
  375. /* SetRect(&rc,
  376.    (nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS),
  377.    (nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS),
  378.    (nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS+2),
  379.    (nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS+2));
  380. g_xMainWnd.DrawWithGDI(rc, NULL, RGB(255, 0, 0), 1);
  381. */ }
  382. else
  383. {
  384. nSelectedRedValue = nSelectedGreenValue = nSelectedBlueValue = 0;
  385. }
  386. if ( nSelectedRedValue  < 0 ) nSelectedRedValue = 0;
  387. if ( nSelectedGreenValue < 0 ) nSelectedGreenValue = 0;
  388. if ( nSelectedBlueValue  < 0 ) nSelectedBlueValue = 0;
  389. if ( m_avLight[nCntY][nCntX].color == 0 )
  390. m_avLight[nCntY][nCntX].color = RGB(nSelectedRedValue, nSelectedGreenValue, nSelectedBlueValue); 
  391. else
  392. {
  393. if ( nSelectedRedValue < (INT)RGB_GETBLUE(m_avLight[nCntY][nCntX].color) )
  394. nSelectedRedValue = (INT)RGB_GETBLUE(m_avLight[nCntY][nCntX].color);
  395. if ( nSelectedGreenValue < (INT)RGB_GETGREEN(m_avLight[nCntY][nCntX].color) )
  396. nSelectedGreenValue = (INT)RGB_GETGREEN(m_avLight[nCntY][nCntX].color);
  397. if ( nSelectedBlueValue < (INT)RGB_GETRED(m_avLight[nCntY][nCntX].color) )
  398. nSelectedBlueValue = (INT)RGB_GETRED(m_avLight[nCntY][nCntX].color);
  399. m_avLight[nCntY][nCntX].color =  RGB(nSelectedRedValue, nSelectedGreenValue, nSelectedBlueValue);
  400. }
  401. }
  402. }
  403. return TRUE;
  404. }
  405. VOID CWater::ShowLightFog(BOOL bShowFog)
  406. {
  407. if ( g_xMainWnd.Get3DDevice() )
  408. {
  409. if( SUCCEEDED(g_xMainWnd.Get3DDevice()->BeginScene()) )
  410. {
  411. D3DVECTOR vTrans;
  412. D3DMATRIX matTrans;
  413. D3DMATRIX matWorldOriginal;
  414. g_xMainWnd.Get3DDevice()->GetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal);
  415. // if ( bShowFog )
  416. // SetLightRadiusWithElipse(400, 242, 6, 6, 230, 230, 230);
  417. // SetLightRadiusWithElipse(400, 242, 1, 1, 230, 230, 230);
  418. // SetLightRadiusWithCircle(400, 242, 8, 230, 230, 230);
  419. /* SetLightRadiusWithCircle(586, 248, 3, 230, 230, 230);
  420. SetLightRadiusWithCircle(604, 248, 3, 230, 230, 230);
  421. */// SetLightRadiusWithRing(400, 242, 7, 230, 230, 230, 8, 230, 230, 230);
  422. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
  423. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_SRCBLEND,  D3DBLEND_ZERO);
  424. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_SRCCOLOR);
  425. /* BYTE bOpa = 255;
  426. D3DMATERIAL7 mtrl;
  427. D3DUtil_InitMaterial(mtrl, 
  428.  (FLOAT)255/255.0f,
  429.  (FLOAT)255/255.0f,
  430.  (FLOAT)255/255.0f);
  431. mtrl.diffuse.a = (bOpa+1)/255.0f;
  432. g_xMainWnd.Get3DDevice()->SetMaterial(&mtrl);
  433. SetBlendRenderState(g_xMainWnd.Get3DDevice(), _BLEND_NORMAL, mtrl);
  434. */
  435. vTrans.x = -400; vTrans.y = 300; vTrans.z = 0;
  436. D3DUtil_SetTranslateMatrix(matTrans, vTrans);
  437. g_xMainWnd.Get3DDevice()->SetTransform(D3DTRANSFORMSTATE_WORLD, &matTrans);
  438. // g_xMainWnd.Get3DDevice()->SetTexture(0, NULL);
  439. static int a = 0;
  440. static int b = 0;
  441. static float scrlcnt = 0.0f;
  442. if ( scrlcnt >= WATER_NUM_CNTX_LIGHTTILE ) scrlcnt = 0;
  443. a++;
  444. if ( a >= 1 )
  445. {
  446. for ( INT nCntY = 0; nCntY < (WATER_NUM_CNTY_LIGHTTILE+1); nCntY++ )
  447. {
  448. FLOAT av = (FLOAT)((FLOAT)nCntY/(FLOAT)WATER_NUM_CNTY_LIGHTTILE);
  449. for ( INT nCntX = 0; nCntX < (WATER_NUM_CNTX_LIGHTTILE+1); nCntX++ )
  450. {
  451. FLOAT au = (FLOAT)((FLOAT)nCntX/(FLOAT)WATER_NUM_CNTX_LIGHTTILE) + scrlcnt;
  452. if ( au > 1 ) au = 1-au;
  453. FLOAT az = m_avLight[nCntY][nCntX].z;
  454. if ( b > 10 )
  455. {
  456. // az = (FLOAT)GetRandomNum(0, 50);
  457. }
  458. FLOAT ax = /*(FLOAT)GetRandomNum(0, 10) + */(FLOAT)(WATER_TILE_START_XPOS+(nCntX*WATER_TILE_WIDTH));
  459. FLOAT ay = /*(FLOAT)GetRandomNum(0, 1) + */(FLOAT)(-WATER_TILE_START_YPOS-(nCntY*WATER_TILE_HEIGHT));
  460. // if ( av > 1 ) av = 1-av;
  461. m_avLight[nCntY][nCntX] = D3DLVERTEX(D3DVECTOR(ax, ay, az),
  462.     m_dwLightColor, RGB(0, 0, 0), au, av);
  463. }
  464. }
  465. memcpy(m_avSaveLight, m_avLight, sizeof(D3DLVERTEX)*(WATER_NUM_CNTY_LIGHTTILE+1)*(WATER_NUM_CNTX_LIGHTTILE+1));
  466. a = 0;
  467. }
  468. scrlcnt += 0.0006f;
  469. if ( b > 10 )
  470. {
  471. b = 0;
  472. }
  473. b++;
  474. g_xMainWnd.Get3DDevice()->SetTexture(0, D3DTextr_GetSurface(m_szWater[m_bCurrTexIdx]));
  475. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE);
  476. g_xMainWnd.Get3DDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
  477.   D3DFVF_LVERTEX,
  478.   m_avLight, WATER_NUM_LIGHTTILE_VERTICES, 
  479.   m_pwLightIndices, WATER_NUM_LIGHTTILE_INDICES, NULL );
  480. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_LIGHTING, TRUE);
  481. // ResetBlendenderState(g_xMainWnd.Get3DDevice());
  482. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_SRCBLEND,  D3DBLEND_ONE);
  483. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO);
  484. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
  485. g_xMainWnd.Get3DDevice()->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal);
  486. g_xMainWnd.Get3DDevice()->EndScene();
  487. }
  488. }
  489. }