quad.cpp 109 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493
  1. //---------------------------------------------------------------------------
  2. //
  3. // Quad.cpp -- File contains class code for the Terrain Quads
  4. //
  5. // MechCommander 2
  6. //
  7. //---------------------------------------------------------------------------//
  8. // Copyright (C) Microsoft Corporation. All rights reserved. //
  9. //===========================================================================//
  10. //---------------------------------------------------------------------------
  11. // Include Files
  12. #ifndef QUAD_H
  13. #include "quad.h"
  14. #endif
  15. #ifndef VERTEX_H
  16. #include "vertex.h"
  17. #endif
  18. #ifndef TERRAIN_H
  19. #include "terrain.h"
  20. #endif
  21. #ifndef CAMERA_H
  22. #include "camera.h"
  23. #endif
  24. #ifndef DBASEGUI_H
  25. #include "dbasegui.h"
  26. #endif
  27. #ifndef CELINE_H
  28. #include "celine.h"
  29. #endif
  30. #ifndef MOVE_H
  31. #include "move.h"
  32. #endif
  33. #define SELECTION_COLOR 0xffff7fff
  34. #define HIGHLIGHT_COLOR 0xff00ff00
  35. //---------------------------------------------------------------------------
  36. float TerrainQuad::rainLightLevel = 1.0f;
  37. DWORD TerrainQuad::lighteningLevel = 0;
  38. DWORD TerrainQuad::mineTextureHandle = 0xffffffff;
  39. DWORD TerrainQuad::blownTextureHandle = 0xffffffff;
  40. extern bool drawTerrainGrid;
  41. extern bool drawLOSGrid;
  42. //---------------------------------------------------------------------------
  43. //---------------------------------------------------------------------------
  44. // Class TerrainQuad
  45. long TerrainQuad::init (VertexPtr v0, VertexPtr v1, VertexPtr v2, VertexPtr v3)
  46. {
  47. vertices[0] = v0;
  48. vertices[1] = v1;
  49. vertices[2] = v2;
  50. vertices[3] = v3;
  51. return(NO_ERR);
  52. }
  53. float twoFiveFive = 255.0;
  54. #define HUD_DEPTH 0.0001f //HUD Objects draw over everything else.
  55. extern float cosineEyeHalfFOV;
  56. extern DWORD BaseVertexColor;
  57. extern bool useShadows;
  58. extern bool useFog;
  59. extern long sprayFrame;
  60. bool useWaterInterestTexture = true;
  61. bool useOverlayTexture = true;
  62. long numTerrainFaces = 0;
  63. extern float MaxMinUV;
  64. extern float leastZ;
  65. extern float leastW;
  66. extern float mostZ;
  67. extern float mostW;
  68. extern float leastWY;
  69. extern float mostWY;
  70. //---------------------------------------------------------------------------
  71. void TerrainQuad::setupTextures (void)
  72. {
  73. if (mineTextureHandle == 0xffffffff)
  74. {
  75. FullPathFileName mineTextureName;
  76. mineTextureName.init(texturePath,"defaults\\mine_00",".tga");
  77. mineTextureHandle = mcTextureManager->loadTexture(mineTextureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  78. }
  79. if (blownTextureHandle == 0xffffffff)
  80. {
  81. FullPathFileName mineTextureName;
  82. mineTextureName.init(texturePath,"defaults\\minescorch_00",".tga");
  83. blownTextureHandle = mcTextureManager->loadTexture(mineTextureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  84. }
  85. if (!Terrain::terrainTextures2)
  86. {
  87. if (uvMode == BOTTOMRIGHT)
  88. {
  89. long clipped1 = vertices[0]->clipInfo + vertices[1]->clipInfo + vertices[2]->clipInfo;
  90. long clipped2 = vertices[0]->clipInfo + vertices[2]->clipInfo + vertices[3]->clipInfo;
  91. if (clipped1 || clipped2)
  92. {
  93. {
  94. terrainHandle = Terrain::terrainTextures->getTextureHandle((vertices[0]->pVertex->textureData & 0x0000ffff));
  95. DWORD terrainDetailData = Terrain::terrainTextures->setDetail(1,0);
  96. if (terrainDetailData != 0xfffffff)
  97. terrainDetailHandle = Terrain::terrainTextures->getTextureHandle(terrainDetailData);
  98. else
  99. terrainDetailHandle = 0xffffffff;
  100. overlayHandle = 0xffffffff;
  101. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWSOLID);
  102. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWSOLID);
  103. mcTextureManager->addTriangle(terrainDetailHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  104. mcTextureManager->addTriangle(terrainDetailHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  105. }
  106. //--------------------------------------------------------------------
  107. //Mine Information
  108. long rowCol = vertices[0]->posTile;
  109. long tileR = rowCol>>16;
  110. long tileC = rowCol & 0x0000ffff;
  111. if (GameMap)
  112. {
  113. mineResult.init();
  114. long cellPos = 0;
  115. for (long cellR = 0; cellR < MAPCELL_DIM; cellR++)
  116. {
  117. for (long cellC = 0; cellC < MAPCELL_DIM; cellC++,cellPos++)
  118. {
  119. long actualCellRow = tileR * MAPCELL_DIM + cellR;
  120. long actualCellCol = tileC * MAPCELL_DIM + cellC;
  121. DWORD localResult = 0;
  122. if (GameMap->inBounds(actualCellRow, actualCellCol))
  123. localResult = GameMap->getMine(actualCellRow, actualCellCol);
  124. if (localResult == 1)
  125. {
  126. mcTextureManager->get_gosTextureHandle(mineTextureHandle);
  127. mcTextureManager->addTriangle(mineTextureHandle, MC2_DRAWALPHA);
  128. mcTextureManager->addTriangle(mineTextureHandle, MC2_DRAWALPHA);
  129. mineResult.setMine(cellPos,localResult);
  130. }
  131. else if (localResult == 2)
  132. {
  133. mcTextureManager->get_gosTextureHandle(blownTextureHandle);
  134. mcTextureManager->addTriangle(blownTextureHandle, MC2_DRAWALPHA);
  135. mcTextureManager->addTriangle(blownTextureHandle, MC2_DRAWALPHA);
  136. mineResult.setMine(cellPos,localResult);
  137. }
  138. }
  139. }
  140. }
  141. }
  142. else
  143. {
  144. terrainHandle = 0xffffffff;
  145. waterHandle = 0xffffffff;
  146. waterDetailHandle = 0xffffffff;
  147. terrainDetailHandle = 0xffffffff;
  148. overlayHandle = 0xffffffff;
  149. }
  150. }
  151. else
  152. {
  153. long clipped1 = vertices[0]->clipInfo + vertices[1]->clipInfo + vertices[3]->clipInfo;
  154. long clipped2 = vertices[1]->clipInfo + vertices[2]->clipInfo + vertices[3]->clipInfo;
  155. if (clipped1 || clipped2)
  156. {
  157. {
  158. terrainHandle = Terrain::terrainTextures->getTextureHandle((vertices[0]->pVertex->textureData & 0x0000ffff));
  159. DWORD terrainDetailData = Terrain::terrainTextures->setDetail(1,0);
  160. if (terrainDetailData != 0xfffffff)
  161. terrainDetailHandle = Terrain::terrainTextures->getTextureHandle(terrainDetailData);
  162. else
  163. terrainDetailHandle = 0xffffffff;
  164. overlayHandle = 0xffffffff;
  165. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWSOLID);
  166. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWSOLID);
  167. mcTextureManager->addTriangle(terrainDetailHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  168. mcTextureManager->addTriangle(terrainDetailHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  169. }
  170. //--------------------------------------------------------------------
  171. //Mine Information
  172. long rowCol = vertices[0]->posTile;
  173. long tileR = rowCol>>16;
  174. long tileC = rowCol & 0x0000ffff;
  175. if (GameMap)
  176. {
  177. long cellPos = 0;
  178. mineResult.init();
  179. for (long cellR = 0; cellR < MAPCELL_DIM; cellR++)
  180. {
  181. for (long cellC = 0; cellC < MAPCELL_DIM; cellC++,cellPos++)
  182. {
  183. long actualCellRow = tileR * MAPCELL_DIM + cellR;
  184. long actualCellCol = tileC * MAPCELL_DIM + cellC;
  185. DWORD localResult = 0;
  186. if (GameMap->inBounds(actualCellRow, actualCellCol))
  187. localResult = GameMap->getMine(actualCellRow, actualCellCol);
  188. if (localResult == 1)
  189. {
  190. mcTextureManager->get_gosTextureHandle(mineTextureHandle);
  191. mcTextureManager->addTriangle(mineTextureHandle,MC2_DRAWALPHA);
  192. mcTextureManager->addTriangle(mineTextureHandle,MC2_DRAWALPHA);
  193. mineResult.setMine(cellPos,localResult);
  194. }
  195. else if (localResult == 2)
  196. {
  197. mcTextureManager->get_gosTextureHandle(blownTextureHandle);
  198. mcTextureManager->addTriangle(blownTextureHandle,MC2_DRAWALPHA);
  199. mcTextureManager->addTriangle(blownTextureHandle,MC2_DRAWALPHA);
  200. mineResult.setMine(cellPos,localResult);
  201. }
  202. }
  203. }
  204. }
  205. }
  206. else
  207. {
  208. terrainHandle = 0xffffffff;
  209. waterHandle = 0xffffffff;
  210. waterDetailHandle = 0xffffffff;
  211. terrainDetailHandle = 0xffffffff;
  212. overlayHandle = 0xffffffff;
  213. }
  214. }
  215. }
  216. else //New single bitmap on the terrain.
  217. {
  218. if (uvMode == BOTTOMRIGHT)
  219. {
  220. long clipped1 = vertices[0]->clipInfo + vertices[1]->clipInfo + vertices[2]->clipInfo;
  221. long clipped2 = vertices[0]->clipInfo + vertices[2]->clipInfo + vertices[3]->clipInfo;
  222. if (clipped1 || clipped2)
  223. {
  224. isCement = Terrain::terrainTextures->isCement(vertices[0]->pVertex->textureData & 0x0000ffff);
  225. bool isAlpha = Terrain::terrainTextures->isAlpha(vertices[0]->pVertex->textureData & 0x0000ffff);
  226. if (!isCement)
  227. {
  228. terrainHandle = Terrain::terrainTextures2->getTextureHandle(vertices[0],vertices[2],&uvData);
  229. terrainDetailHandle = Terrain::terrainTextures2->getDetailHandle();
  230. overlayHandle = 0xffffffff;
  231. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWSOLID);
  232. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWSOLID);
  233. if (terrainDetailHandle != 0xffffffff)
  234. {
  235. mcTextureManager->addTriangle(terrainDetailHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  236. mcTextureManager->addTriangle(terrainDetailHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  237. }
  238. }
  239. else //This cement in the old Universe, pull the old texture and display it
  240. {
  241. if (isAlpha) //This should be treated as an overlay. Do so. Draw overlay AFTER new terrain in same square!!
  242. {
  243. overlayHandle = Terrain::terrainTextures->getTextureHandle(vertices[0]->pVertex->textureData & 0x0000ffff);
  244. terrainHandle = Terrain::terrainTextures2->getTextureHandle(vertices[1],vertices[3],&uvData);
  245. terrainDetailHandle = Terrain::terrainTextures2->getDetailHandle();
  246. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWSOLID);
  247. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWSOLID);
  248. if (terrainDetailHandle != 0xffffffff)
  249. {
  250. mcTextureManager->addTriangle(terrainDetailHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  251. mcTextureManager->addTriangle(terrainDetailHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  252. }
  253. mcTextureManager->addTriangle(overlayHandle,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  254. mcTextureManager->addTriangle(overlayHandle,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  255. }
  256. else //Otherwise, its solid cement. Save some draw cycles!!
  257. {
  258. terrainHandle = Terrain::terrainTextures->getTextureHandle(vertices[0]->pVertex->textureData & 0x0000ffff);
  259. terrainDetailHandle = 0xffffffff; //Cement has NO detail!!
  260. overlayHandle = 0xffffffff;
  261. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  262. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  263. }
  264. }
  265. //--------------------------------------------------------------------
  266. //Mine Information
  267. long rowCol = vertices[0]->posTile;
  268. long tileR = rowCol>>16;
  269. long tileC = rowCol & 0x0000ffff;
  270. if (GameMap)
  271. {
  272. long cellPos = 0;
  273. mineResult.init();
  274. for (long cellR = 0; cellR < MAPCELL_DIM; cellR++)
  275. {
  276. for (long cellC = 0; cellC < MAPCELL_DIM; cellC++,cellPos++)
  277. {
  278. long actualCellRow = tileR * MAPCELL_DIM + cellR;
  279. long actualCellCol = tileC * MAPCELL_DIM + cellC;
  280. DWORD localResult = 0;
  281. if (GameMap->inBounds(actualCellRow, actualCellCol))
  282. localResult = GameMap->getMine(actualCellRow, actualCellCol);
  283. if (localResult == 1)
  284. {
  285. mcTextureManager->get_gosTextureHandle(mineTextureHandle);
  286. mcTextureManager->addTriangle(mineTextureHandle,MC2_DRAWALPHA);
  287. mcTextureManager->addTriangle(mineTextureHandle,MC2_DRAWALPHA);
  288. mineResult.setMine(cellPos,localResult);
  289. }
  290. else if (localResult == 2)
  291. {
  292. mcTextureManager->get_gosTextureHandle(blownTextureHandle);
  293. mcTextureManager->addTriangle(blownTextureHandle,MC2_DRAWALPHA);
  294. mcTextureManager->addTriangle(blownTextureHandle,MC2_DRAWALPHA);
  295. mineResult.setMine(cellPos,localResult);
  296. }
  297. }
  298. }
  299. }
  300. }
  301. else
  302. {
  303. overlayHandle = 0xffffffff;
  304. terrainHandle = 0xffffffff;
  305. waterHandle = 0xffffffff;
  306. waterDetailHandle = 0xffffffff;
  307. terrainDetailHandle = 0xffffffff;
  308. }
  309. }
  310. else
  311. {
  312. long clipped1 = vertices[0]->clipInfo + vertices[1]->clipInfo + vertices[3]->clipInfo;
  313. long clipped2 = vertices[1]->clipInfo + vertices[2]->clipInfo + vertices[3]->clipInfo;
  314. if (clipped1 || clipped2)
  315. {
  316. isCement = Terrain::terrainTextures->isCement(vertices[0]->pVertex->textureData & 0x0000ffff);
  317. bool isAlpha = Terrain::terrainTextures->isAlpha(vertices[0]->pVertex->textureData & 0x0000ffff);
  318. if (!isCement)
  319. {
  320. terrainHandle = Terrain::terrainTextures2->getTextureHandle(vertices[1],vertices[3],&uvData);
  321. terrainDetailHandle = Terrain::terrainTextures2->getDetailHandle();
  322. overlayHandle = 0xffffffff;
  323. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWSOLID);
  324. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWSOLID);
  325. mcTextureManager->addTriangle(terrainDetailHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  326. mcTextureManager->addTriangle(terrainDetailHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  327. }
  328. else //This cement in the old Universe, pull the old texture and display it
  329. {
  330. if (isAlpha) //This should be treated as an overlay. Do so. Draw overlay AFTER new terrain in same square!!
  331. {
  332. overlayHandle = Terrain::terrainTextures->getTextureHandle(vertices[0]->pVertex->textureData & 0x0000ffff);
  333. terrainHandle = Terrain::terrainTextures2->getTextureHandle(vertices[1],vertices[3],&uvData);
  334. terrainDetailHandle = Terrain::terrainTextures2->getDetailHandle();
  335. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWSOLID);
  336. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWSOLID);
  337. mcTextureManager->addTriangle(terrainDetailHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  338. mcTextureManager->addTriangle(terrainDetailHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  339. mcTextureManager->addTriangle(overlayHandle,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  340. mcTextureManager->addTriangle(overlayHandle,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  341. }
  342. else //Otherwise, its solid cement. Save some draw cycles!!
  343. {
  344. terrainHandle = Terrain::terrainTextures->getTextureHandle(vertices[0]->pVertex->textureData & 0x0000ffff);
  345. terrainDetailHandle = 0xffffffff; //Cement has NO detail!!
  346. overlayHandle = 0xffffffff;
  347. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  348. mcTextureManager->addTriangle(terrainHandle,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  349. }
  350. }
  351. //--------------------------------------------------------------------
  352. //Mine Information
  353. long rowCol = vertices[0]->posTile;
  354. long tileR = rowCol>>16;
  355. long tileC = rowCol & 0x0000ffff;
  356. if (GameMap)
  357. {
  358. long cellPos = 0;
  359. mineResult.init();
  360. for (long cellR = 0; cellR < MAPCELL_DIM; cellR++)
  361. {
  362. for (long cellC = 0; cellC < MAPCELL_DIM; cellC++,cellPos++)
  363. {
  364. long actualCellRow = tileR * MAPCELL_DIM + cellR;
  365. long actualCellCol = tileC * MAPCELL_DIM + cellC;
  366. DWORD localResult = 0;
  367. if (GameMap->inBounds(actualCellRow, actualCellCol))
  368. localResult = GameMap->getMine(actualCellRow, actualCellCol);
  369. if (localResult == 1)
  370. {
  371. mcTextureManager->get_gosTextureHandle(mineTextureHandle);
  372. mcTextureManager->addTriangle(mineTextureHandle,MC2_DRAWALPHA);
  373. mcTextureManager->addTriangle(mineTextureHandle,MC2_DRAWALPHA);
  374. mineResult.setMine(cellPos,localResult);
  375. }
  376. else if (localResult == 2)
  377. {
  378. mcTextureManager->get_gosTextureHandle(blownTextureHandle);
  379. mcTextureManager->addTriangle(blownTextureHandle,MC2_DRAWALPHA);
  380. mcTextureManager->addTriangle(blownTextureHandle,MC2_DRAWALPHA);
  381. mineResult.setMine(cellPos,localResult);
  382. }
  383. }
  384. }
  385. }
  386. }
  387. else
  388. {
  389. terrainHandle = 0xffffffff;
  390. waterHandle = 0xffffffff;
  391. waterDetailHandle = 0xffffffff;
  392. terrainDetailHandle = 0xffffffff;
  393. overlayHandle = 0xffffffff;
  394. }
  395. }
  396. }
  397. //-----------------------------------------
  398. // NEW(tm) water texture code here.
  399. if ((vertices[0]->pVertex->water & 1) ||
  400. (vertices[1]->pVertex->water & 1) ||
  401. (vertices[2]->pVertex->water & 1) ||
  402. (vertices[3]->pVertex->water & 1))
  403. {
  404. Stuff::Vector3D vertex3D(vertices[0]->vx,vertices[0]->vy,Terrain::waterElevation);
  405. Stuff::Vector4D screenPos;
  406. long clipped1 = vertices[0]->clipInfo + vertices[1]->clipInfo + vertices[2]->clipInfo;
  407. long clipped2 = vertices[0]->clipInfo + vertices[2]->clipInfo + vertices[3]->clipInfo;
  408. if (uvMode != BOTTOMRIGHT)
  409. {
  410. clipped1 = vertices[0]->clipInfo + vertices[1]->clipInfo + vertices[3]->clipInfo;
  411. clipped2 = vertices[1]->clipInfo + vertices[2]->clipInfo + vertices[3]->clipInfo;
  412. }
  413. float negCos = Terrain::frameCos * -1.0;
  414. float ourCos = Terrain::frameCos;
  415. if (!(vertices[0]->calcThisFrame & 2))
  416. {
  417. if (clipped1 || clipped2)
  418. {
  419. if (vertices[0]->pVertex->water & 128)
  420. {
  421. vertices[0]->wAlpha = -Terrain::frameCosAlpha;
  422. ourCos = negCos;
  423. }
  424. else if (vertices[0]->pVertex->water & 64)
  425. {
  426. vertices[0]->wAlpha = Terrain::frameCosAlpha;
  427. ourCos = Terrain::frameCos;
  428. }
  429. vertex3D.z = ourCos + Terrain::waterElevation;
  430. bool clipData = false;
  431. clipData = eye->projectZ(vertex3D,screenPos);
  432. bool isVisible = Terrain::IsGameSelectTerrainPosition(vertex3D) || drawTerrainGrid;
  433. if (!isVisible)
  434. {
  435. clipData = false;
  436. vertices[0]->hazeFactor = 1.0f;
  437. }
  438. if (eye->usePerspective)
  439. vertices[0]->clipInfo = clipData;
  440. else
  441. vertices[0]->clipInfo = clipData;
  442. vertices[0]->wx = screenPos.x;
  443. vertices[0]->wy = screenPos.y;
  444. vertices[0]->wz = screenPos.z;
  445. vertices[0]->ww = screenPos.w;
  446. vertices[0]->calcThisFrame |= 2;
  447. if (clipData)
  448. {
  449. if (screenPos.z < leastZ)
  450. {
  451. leastZ = screenPos.z;
  452. }
  453. if (screenPos.z > mostZ)
  454. {
  455. mostZ = screenPos.z;
  456. }
  457. if (screenPos.w < leastW)
  458. {
  459. leastW = screenPos.w;
  460. leastWY = screenPos.y;
  461. }
  462. if (screenPos.w > mostW)
  463. {
  464. mostW = screenPos.w;
  465. mostWY = screenPos.y;
  466. }
  467. }
  468. }
  469. }
  470. if (!(vertices[1]->calcThisFrame & 2))
  471. {
  472. if (clipped1 || clipped2)
  473. {
  474. if (vertices[1]->pVertex->water & 128)
  475. {
  476. vertices[1]->wAlpha = -Terrain::frameCosAlpha;
  477. ourCos = negCos;
  478. }
  479. else if (vertices[1]->pVertex->water & 64)
  480. {
  481. vertices[1]->wAlpha = Terrain::frameCosAlpha;
  482. ourCos = Terrain::frameCos;
  483. }
  484. vertex3D.z = ourCos + Terrain::waterElevation;
  485. vertex3D.x = vertices[1]->vx;
  486. vertex3D.y = vertices[1]->vy;
  487. bool clipData = false;
  488. clipData = eye->projectZ(vertex3D,screenPos);
  489. bool isVisible = Terrain::IsGameSelectTerrainPosition(vertex3D) || drawTerrainGrid;
  490. if (!isVisible)
  491. {
  492. clipData = false;
  493. vertices[1]->hazeFactor = 1.0f;
  494. }
  495. if (eye->usePerspective)
  496. vertices[1]->clipInfo = clipData; //onScreen;
  497. else
  498. vertices[1]->clipInfo = clipData;
  499. vertices[1]->wx = screenPos.x;
  500. vertices[1]->wy = screenPos.y;
  501. vertices[1]->wz = screenPos.z;
  502. vertices[1]->ww = screenPos.w;
  503. vertices[1]->calcThisFrame |= 2;
  504. if (clipData)
  505. {
  506. if (screenPos.z < leastZ)
  507. {
  508. leastZ = screenPos.z;
  509. }
  510. if (screenPos.z > mostZ)
  511. {
  512. mostZ = screenPos.z;
  513. }
  514. if (screenPos.w < leastW)
  515. {
  516. leastW = screenPos.w;
  517. leastWY = screenPos.y;
  518. }
  519. if (screenPos.w > mostW)
  520. {
  521. mostW = screenPos.w;
  522. mostWY = screenPos.y;
  523. }
  524. }
  525. }
  526. }
  527. if (!(vertices[2]->calcThisFrame & 2))
  528. {
  529. if (clipped1 || clipped2)
  530. {
  531. if (vertices[2]->pVertex->water & 128)
  532. {
  533. vertices[2]->wAlpha = -Terrain::frameCosAlpha;
  534. ourCos = negCos;
  535. }
  536. else if (vertices[2]->pVertex->water & 64)
  537. {
  538. vertices[2]->wAlpha = Terrain::frameCosAlpha;
  539. ourCos = Terrain::frameCos;
  540. }
  541. vertex3D.z = ourCos + Terrain::waterElevation;
  542. vertex3D.x = vertices[2]->vx;
  543. vertex3D.y = vertices[2]->vy;
  544. bool clipData = false;
  545. clipData = eye->projectZ(vertex3D,screenPos);
  546. bool isVisible = Terrain::IsGameSelectTerrainPosition(vertex3D) || drawTerrainGrid;
  547. if (!isVisible)
  548. {
  549. clipData = false;
  550. vertices[2]->hazeFactor = 1.0f;
  551. }
  552. if (eye->usePerspective)
  553. vertices[2]->clipInfo = clipData; //onScreen;
  554. else
  555. vertices[2]->clipInfo = clipData;
  556. vertices[2]->wx = screenPos.x;
  557. vertices[2]->wy = screenPos.y;
  558. vertices[2]->wz = screenPos.z;
  559. vertices[2]->ww = screenPos.w;
  560. vertices[2]->calcThisFrame |= 2;
  561. if (clipData)
  562. {
  563. if (screenPos.z < leastZ)
  564. {
  565. leastZ = screenPos.z;
  566. }
  567. if (screenPos.z > mostZ)
  568. {
  569. mostZ = screenPos.z;
  570. }
  571. if (screenPos.w < leastW)
  572. {
  573. leastW = screenPos.w;
  574. leastWY = screenPos.y;
  575. }
  576. if (screenPos.w > mostW)
  577. {
  578. mostW = screenPos.w;
  579. mostWY = screenPos.y;
  580. }
  581. }
  582. }
  583. }
  584. if (!(vertices[3]->calcThisFrame & 2))
  585. {
  586. if (clipped1 || clipped2)
  587. {
  588. if (vertices[3]->pVertex->water & 128)
  589. {
  590. vertices[3]->wAlpha = -Terrain::frameCosAlpha;
  591. ourCos = negCos;
  592. }
  593. else if (vertices[3]->pVertex->water & 64)
  594. {
  595. vertices[3]->wAlpha = Terrain::frameCosAlpha;
  596. ourCos = Terrain::frameCos;
  597. }
  598. vertex3D.z = ourCos + Terrain::waterElevation;
  599. vertex3D.x = vertices[3]->vx;
  600. vertex3D.y = vertices[3]->vy;
  601. bool clipData = false;
  602. clipData = eye->projectZ(vertex3D,screenPos);
  603. bool isVisible = Terrain::IsGameSelectTerrainPosition(vertex3D) || drawTerrainGrid;
  604. if (!isVisible)
  605. {
  606. clipData = false;
  607. vertices[3]->hazeFactor = 1.0f;
  608. }
  609. if (eye->usePerspective)
  610. vertices[3]->clipInfo = clipData; //onScreen;
  611. else
  612. vertices[3]->clipInfo = clipData;
  613. vertices[3]->wx = screenPos.x;
  614. vertices[3]->wy = screenPos.y;
  615. vertices[3]->wz = screenPos.z;
  616. vertices[3]->ww = screenPos.w;
  617. vertices[3]->calcThisFrame |= 2;
  618. if (clipData)
  619. {
  620. if (screenPos.z < leastZ)
  621. {
  622. leastZ = screenPos.z;
  623. }
  624. if (screenPos.z > mostZ)
  625. {
  626. mostZ = screenPos.z;
  627. }
  628. if (screenPos.w < leastW)
  629. {
  630. leastW = screenPos.w;
  631. leastWY = screenPos.y;
  632. }
  633. if (screenPos.w > mostW)
  634. {
  635. mostW = screenPos.w;
  636. mostWY = screenPos.y;
  637. }
  638. }
  639. }
  640. }
  641. if (clipped1 || clipped2)
  642. {
  643. if (!Terrain::terrainTextures2)
  644. {
  645. DWORD waterDetailData = Terrain::terrainTextures->setDetail(0,sprayFrame);
  646. waterHandle = Terrain::terrainTextures->getTextureHandle(MapData::WaterTXMData & 0x0000ffff);
  647. waterDetailHandle = Terrain::terrainTextures->getDetailHandle(waterDetailData & 0x0000ffff);
  648. }
  649. else
  650. {
  651. waterHandle = Terrain::terrainTextures2->getWaterTextureHandle();
  652. waterDetailHandle = Terrain::terrainTextures2->getWaterDetailHandle(sprayFrame);
  653. }
  654. mcTextureManager->addTriangle(waterHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  655. mcTextureManager->addTriangle(waterHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  656. mcTextureManager->addTriangle(waterDetailHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  657. mcTextureManager->addTriangle(waterDetailHandle,MC2_ISTERRAIN | MC2_DRAWALPHA);
  658. }
  659. else
  660. {
  661. waterHandle = 0xffffffff;
  662. waterDetailHandle = 0xffffffff;
  663. }
  664. }
  665. else
  666. {
  667. waterHandle = 0xffffffff;
  668. waterDetailHandle = 0xffffffff;
  669. }
  670. if (terrainHandle != 0xffffffff)
  671. {
  672. //-----------------------------------------------------
  673. // FOG time.
  674. float fogStart = eye->fogStart;
  675. float fogFull = eye->fogFull;
  676. //-----------------------------------------------------
  677. // Process Vertex 0 if not already done
  678. if (!(vertices[0]->calcThisFrame & 1))
  679. {
  680. DWORD specR=0, specG=0, specB=0;
  681. DWORD lightr=0xff,lightg=0xff,lightb=0xff;
  682. if (Environment.Renderer != 3)
  683. {
  684. //------------------------------------------------------------
  685. float lightIntensity = vertices[0]->pVertex->vertexNormal * eye->lightDirection;
  686. unsigned char shadow = vertices[0]->pVertex->shadow;
  687. if (shadow && lightIntensity > 0.2f)
  688. {
  689. lightIntensity = 0.2f;
  690. }
  691. lightr = eye->getLightRed(lightIntensity);
  692. lightg = eye->getLightGreen(lightIntensity);
  693. lightb = eye->getLightBlue(lightIntensity);
  694. if (BaseVertexColor)
  695. {
  696. lightr += ((BaseVertexColor>>16) & 0x000000ff);
  697. if (lightr > 0xff)
  698. lightr = 0xff;
  699. lightg += ((BaseVertexColor>>8) & 0x000000ff);
  700. if (lightg > 0xff)
  701. lightg = 0xff;
  702. lightb += (BaseVertexColor & 0x000000ff);
  703. if (lightb > 0xff)
  704. lightb = 0xff;
  705. }
  706. if (rainLightLevel < 1.0f)
  707. {
  708. lightr = (float)lightr * rainLightLevel;
  709. lightb = (float)lightb * rainLightLevel;
  710. lightg = (float)lightg * rainLightLevel;
  711. }
  712. if (lighteningLevel > 0x0)
  713. {
  714. specR = specG = specB = lighteningLevel;
  715. }
  716. vertices[0]->lightRGB = lightb + (lightr<<16) + (lightg << 8) + (0xff << 24);
  717. //First two light are already factored into the above equations!
  718. for (long i=2;i<eye->getNumTerrainLights();i++)
  719. {
  720. TG_LightPtr thisLight = eye->getTerrainLight(i);
  721. if (thisLight)
  722. {
  723. // if (useShadows)
  724. {
  725. if ((thisLight->lightType == TG_LIGHT_POINT) ||
  726. (thisLight->lightType == TG_LIGHT_SPOT) ||
  727. (thisLight->lightType == TG_LIGHT_TERRAIN))
  728. {
  729. Stuff::Point3D vertexToLight;
  730. vertexToLight.x = vertices[0]->vx;
  731. vertexToLight.y = vertices[0]->vy;
  732. vertexToLight.z = vertices[0]->pVertex->elevation;
  733. vertexToLight -= thisLight->position;
  734. float length = vertexToLight.GetApproximateLength();
  735. float falloff = 1.0f;
  736. if (thisLight->GetFalloff(length, falloff))
  737. {
  738. float red,green,blue;
  739. red = float((thisLight->GetaRGB()>>16) & 0x000000ff) * falloff;
  740. green = float((thisLight->GetaRGB()>>8) & 0x000000ff) * falloff;
  741. blue = float((thisLight->GetaRGB()) & 0x000000ff) * falloff;
  742. specR += (DWORD)red;
  743. specG += (DWORD)green;
  744. specB += (DWORD)blue;
  745. if (specR > 255)
  746. specR = 255;
  747. if (specG > 255)
  748. specG = 255;
  749. if (specB > 255)
  750. specB = 255;
  751. }
  752. }
  753. }
  754. }
  755. }
  756. }
  757. vertices[0]->lightRGB = lightb + (lightr<<16) + (lightg << 8) + (0xff << 24);
  758. vertices[0]->fogRGB = (0xff<<24) + (specR<<16) + (specG << 8) + (specB);
  759. //Fog
  760. DWORD fogResult = 0xff;
  761. if (!(vertices[0]->calcThisFrame & 1))
  762. {
  763. if (useFog)
  764. {
  765. if (vertices[0]->pVertex->elevation < fogStart)
  766. {
  767. float fogFactor = fogStart - vertices[0]->pVertex->elevation;
  768. if (fogFactor < 0.0)
  769. {
  770. fogResult = 0xff;
  771. }
  772. else
  773. {
  774. fogFactor /= (fogStart - fogFull);
  775. if (fogFactor <= 1.0)
  776. {
  777. fogFactor *= fogFactor;
  778. fogFactor = 1.0 - fogFactor;
  779. fogFactor *= 256.0;
  780. }
  781. else
  782. {
  783. fogFactor = 256.0;
  784. }
  785. fogResult = float2long(fogFactor);
  786. }
  787. }
  788. else
  789. {
  790. fogResult = 0xff;
  791. }
  792. vertices[0]->fogRGB = (fogResult<<24) + (specR<<16) + (specG << 8) + (specB);
  793. }
  794. }
  795. //-------------------
  796. // Distance FOG now.
  797. if (vertices[0]->hazeFactor != 0.0f)
  798. {
  799. float fogFactor = 1.0 - vertices[0]->hazeFactor;
  800. DWORD distFog = float2long(fogFactor * 255.0f);
  801. if (distFog < fogResult)
  802. fogResult = distFog;
  803. vertices[0]->fogRGB = (fogResult<<24) + (specR<<16) + (specG << 8) + (specB);
  804. }
  805. vertices[0]->calcThisFrame |= 1;
  806. }
  807. //-----------------------------------------------------
  808. // Process Vertex 1 if not already done
  809. if (!(vertices[1]->calcThisFrame & 1))
  810. {
  811. DWORD specR=0, specG=0, specB=0;
  812. DWORD lightr=0xff,lightg=0xff,lightb=0xff;
  813. if (Environment.Renderer != 3)
  814. {
  815. float lightIntensity = vertices[1]->pVertex->vertexNormal * eye->lightDirection;
  816. unsigned char shadow = vertices[1]->pVertex->shadow;
  817. if (shadow && lightIntensity > 0.2f)
  818. {
  819. lightIntensity = 0.2f;
  820. }
  821. lightr = eye->getLightRed(lightIntensity);
  822. lightg = eye->getLightGreen(lightIntensity);
  823. lightb = eye->getLightBlue(lightIntensity);
  824. if (BaseVertexColor)
  825. {
  826. lightr += ((BaseVertexColor>>16) & 0x000000ff);
  827. if (lightr > 0xff)
  828. lightr = 0xff;
  829. lightg += ((BaseVertexColor>>8) & 0x000000ff);
  830. if (lightg > 0xff)
  831. lightg = 0xff;
  832. lightb += (BaseVertexColor & 0x000000ff);
  833. if (lightb > 0xff)
  834. lightb = 0xff;
  835. }
  836. if (rainLightLevel < 1.0f)
  837. {
  838. lightr = (float)lightr * rainLightLevel;
  839. lightb = (float)lightb * rainLightLevel;
  840. lightg = (float)lightg * rainLightLevel;
  841. }
  842. if (lighteningLevel > 0x0)
  843. {
  844. specR = specG = specB = lighteningLevel;
  845. }
  846. vertices[1]->lightRGB = lightb + (lightr<<16) + (lightg << 8) + (0xff << 24);
  847. //First two light are already factored into the above equations!
  848. for (long i=2;i<eye->getNumTerrainLights();i++)
  849. {
  850. TG_LightPtr thisLight = eye->getTerrainLight(i);
  851. if (thisLight)
  852. {
  853. // if (useShadows)
  854. {
  855. if ((thisLight->lightType == TG_LIGHT_POINT) ||
  856. (thisLight->lightType == TG_LIGHT_SPOT) ||
  857. (thisLight->lightType == TG_LIGHT_TERRAIN))
  858. {
  859. Stuff::Point3D vertexToLight;
  860. vertexToLight.x = vertices[1]->vx;
  861. vertexToLight.y = vertices[1]->vy;
  862. vertexToLight.z = vertices[1]->pVertex->elevation;
  863. vertexToLight -= thisLight->position;
  864. float length = vertexToLight.GetApproximateLength();
  865. float falloff = 1.0f;
  866. if (thisLight->GetFalloff(length, falloff))
  867. {
  868. float red,green,blue;
  869. red = float((thisLight->GetaRGB()>>16) & 0x000000ff) * falloff;
  870. green = float((thisLight->GetaRGB()>>8) & 0x000000ff) * falloff;
  871. blue = float((thisLight->GetaRGB()) & 0x000000ff) * falloff;
  872. specR += (DWORD)red;
  873. specG += (DWORD)green;
  874. specB += (DWORD)blue;
  875. if (specR > 255)
  876. specR = 255;
  877. if (specG > 255)
  878. specG = 255;
  879. if (specB > 255)
  880. specB = 255;
  881. }
  882. }
  883. }
  884. }
  885. }
  886. }
  887. vertices[1]->lightRGB = lightb + (lightr<<16) + (lightg << 8) + (0xff << 24);
  888. vertices[1]->fogRGB = (0xff<<24) + (specR<<16) + (specG << 8) + (specB);
  889. //Fog
  890. DWORD fogResult = 0xff;
  891. if (Environment.Renderer != 3)
  892. {
  893. if (useFog)
  894. {
  895. if (vertices[1]->pVertex->elevation < fogStart)
  896. {
  897. float fogFactor = fogStart - vertices[1]->pVertex->elevation;
  898. if (fogFactor < 0.0)
  899. {
  900. fogResult = 0xff;
  901. }
  902. else
  903. {
  904. fogFactor /= (fogStart - fogFull);
  905. if (fogFactor <= 1.0)
  906. {
  907. fogFactor *= fogFactor;
  908. fogFactor = 1.0 - fogFactor;
  909. fogFactor *= 256.0;
  910. }
  911. else
  912. {
  913. fogFactor = 256.0;
  914. }
  915. fogResult = float2long(fogFactor);
  916. }
  917. }
  918. else
  919. {
  920. fogResult = 0xff;
  921. }
  922. vertices[1]->fogRGB = (fogResult<<24) + (specR<<16) + (specG << 8) + (specB);
  923. }
  924. }
  925. //-------------------
  926. // Distance FOG now.
  927. if (vertices[1]->hazeFactor != 0.0f)
  928. {
  929. float fogFactor = 1.0 - vertices[1]->hazeFactor;
  930. DWORD distFog = float2long(fogFactor * 255.0);
  931. if (distFog < fogResult)
  932. fogResult = distFog;
  933. vertices[1]->fogRGB = (fogResult<<24) + (specR<<16) + (specG << 8) + (specB);
  934. }
  935. vertices[1]->calcThisFrame |= 1;
  936. }
  937. //-----------------------------------------------------
  938. // Process Vertex 2 if not already done
  939. if (!(vertices[2]->calcThisFrame & 1))
  940. {
  941. DWORD specR=0, specG=0, specB=0;
  942. DWORD lightr=0xff,lightg=0xff,lightb=0xff;
  943. if (Environment.Renderer != 3)
  944. {
  945. float lightIntensity = vertices[2]->pVertex->vertexNormal * eye->lightDirection;
  946. unsigned char shadow = vertices[2]->pVertex->shadow;
  947. if (shadow && lightIntensity > 0.2f)
  948. {
  949. lightIntensity = 0.2f;
  950. }
  951. lightr = eye->getLightRed(lightIntensity);
  952. lightg = eye->getLightGreen(lightIntensity);
  953. lightb = eye->getLightBlue(lightIntensity);
  954. if (BaseVertexColor)
  955. {
  956. lightr += ((BaseVertexColor>>16) & 0x000000ff);
  957. if (lightr > 0xff)
  958. lightr = 0xff;
  959. lightg += ((BaseVertexColor>>8) & 0x000000ff);
  960. if (lightg > 0xff)
  961. lightg = 0xff;
  962. lightb += (BaseVertexColor & 0x000000ff);
  963. if (lightb > 0xff)
  964. lightb = 0xff;
  965. }
  966. if (rainLightLevel < 1.0f)
  967. {
  968. lightr = (float)lightr * rainLightLevel;
  969. lightb = (float)lightb * rainLightLevel;
  970. lightg = (float)lightg * rainLightLevel;
  971. }
  972. if (lighteningLevel > 0x0)
  973. {
  974. specR = specG = specB = lighteningLevel;
  975. }
  976. vertices[2]->lightRGB = lightb + (lightr<<16) + (lightg << 8) + (0xff << 24);
  977. //First two light are already factored into the above equations!
  978. for (long i=2;i<eye->getNumTerrainLights();i++)
  979. {
  980. TG_LightPtr thisLight = eye->getTerrainLight(i);
  981. if (thisLight)
  982. {
  983. // if (useShadows)
  984. {
  985. if ((thisLight->lightType == TG_LIGHT_POINT) ||
  986. (thisLight->lightType == TG_LIGHT_SPOT) ||
  987. (thisLight->lightType == TG_LIGHT_TERRAIN))
  988. {
  989. Stuff::Point3D vertexToLight;
  990. vertexToLight.x = vertices[2]->vx;
  991. vertexToLight.y = vertices[2]->vy;
  992. vertexToLight.z = vertices[2]->pVertex->elevation;
  993. vertexToLight -= thisLight->position;
  994. float length = vertexToLight.GetApproximateLength();
  995. float falloff = 1.0f;
  996. if (thisLight->GetFalloff(length, falloff))
  997. {
  998. float red,green,blue;
  999. red = float((thisLight->GetaRGB()>>16) & 0x000000ff) * falloff;
  1000. green = float((thisLight->GetaRGB()>>8) & 0x000000ff) * falloff;
  1001. blue = float((thisLight->GetaRGB()) & 0x000000ff) * falloff;
  1002. specR += (DWORD)red;
  1003. specG += (DWORD)green;
  1004. specB += (DWORD)blue;
  1005. if (specR > 255)
  1006. specR = 255;
  1007. if (specG > 255)
  1008. specG = 255;
  1009. if (specB > 255)
  1010. specB = 255;
  1011. }
  1012. }
  1013. }
  1014. }
  1015. }
  1016. }
  1017. vertices[2]->lightRGB = lightb + (lightr<<16) + (lightg << 8) + (0xff << 24);
  1018. vertices[2]->fogRGB = (0xff<<24) + (specR<<16) + (specG << 8) + (specB);
  1019. //Fog
  1020. DWORD fogResult = 0xff;
  1021. if (Environment.Renderer != 3)
  1022. {
  1023. if (useFog)
  1024. {
  1025. if (vertices[2]->pVertex->elevation < fogStart)
  1026. {
  1027. float fogFactor = fogStart - vertices[2]->pVertex->elevation;
  1028. if ((fogFactor < 0.0) || (0.0 == (fogStart - fogFull)))
  1029. {
  1030. fogResult = 0xff;
  1031. }
  1032. else
  1033. {
  1034. fogFactor /= (fogStart - fogFull);
  1035. if (fogFactor <= 1.0)
  1036. {
  1037. fogFactor *= fogFactor;
  1038. fogFactor = 1.0 - fogFactor;
  1039. fogFactor *= 256.0;
  1040. }
  1041. else
  1042. {
  1043. fogFactor = 256.0;
  1044. }
  1045. fogResult = float2long(fogFactor);
  1046. }
  1047. }
  1048. else
  1049. {
  1050. fogResult = 0xff;
  1051. }
  1052. vertices[2]->fogRGB = (fogResult<<24) + (specR<<16) + (specG << 8) + (specB);
  1053. }
  1054. }
  1055. //-------------------
  1056. // Distance FOG now.
  1057. if (vertices[2]->hazeFactor != 0.0f)
  1058. {
  1059. float fogFactor = 1.0 - vertices[2]->hazeFactor;
  1060. DWORD distFog = float2long(fogFactor * 255.0f);
  1061. if (distFog < fogResult)
  1062. fogResult = distFog;
  1063. vertices[2]->fogRGB = (fogResult<<24) + (specR<<16) + (specG << 8) + (specB);
  1064. }
  1065. vertices[2]->calcThisFrame |= 1;
  1066. }
  1067. //-----------------------------------------------------
  1068. // Process Vertex 3 if not already done
  1069. if (!(vertices[3]->calcThisFrame & 1))
  1070. {
  1071. DWORD specR=0, specG=0, specB=0;
  1072. DWORD lightr=0xff,lightg=0xff,lightb=0xff;
  1073. if (Environment.Renderer != 3)
  1074. {
  1075. float lightIntensity = vertices[3]->pVertex->vertexNormal * eye->lightDirection;
  1076. unsigned char shadow = vertices[3]->pVertex->shadow;
  1077. if (shadow && lightIntensity > 0.2f)
  1078. {
  1079. lightIntensity = 0.2f;
  1080. }
  1081. lightr = eye->getLightRed(lightIntensity);
  1082. lightg = eye->getLightGreen(lightIntensity);
  1083. lightb = eye->getLightBlue(lightIntensity);
  1084. if (BaseVertexColor)
  1085. {
  1086. lightr += ((BaseVertexColor>>16) & 0x000000ff);
  1087. if (lightr > 0xff)
  1088. lightr = 0xff;
  1089. lightg += ((BaseVertexColor>>8) & 0x000000ff);
  1090. if (lightg > 0xff)
  1091. lightg = 0xff;
  1092. lightb += (BaseVertexColor & 0x000000ff);
  1093. if (lightb > 0xff)
  1094. lightb = 0xff;
  1095. }
  1096. if (rainLightLevel < 1.0f)
  1097. {
  1098. lightr = (float)lightr * rainLightLevel;
  1099. lightb = (float)lightb * rainLightLevel;
  1100. lightg = (float)lightg * rainLightLevel;
  1101. }
  1102. if (lighteningLevel > 0x0)
  1103. {
  1104. specR = specG = specB = lighteningLevel;
  1105. }
  1106. vertices[3]->lightRGB = lightb + (lightr<<16) + (lightg << 8) + (0xff << 24);
  1107. //First two light are already factored into the above equations!
  1108. for (long i=2;i<eye->getNumTerrainLights();i++)
  1109. {
  1110. TG_LightPtr thisLight = eye->getTerrainLight(i);
  1111. if (thisLight)
  1112. {
  1113. // if (useShadows)
  1114. {
  1115. if ((thisLight->lightType == TG_LIGHT_POINT) ||
  1116. (thisLight->lightType == TG_LIGHT_SPOT) ||
  1117. (thisLight->lightType == TG_LIGHT_TERRAIN))
  1118. {
  1119. Stuff::Point3D vertexToLight;
  1120. vertexToLight.x = vertices[3]->vx;
  1121. vertexToLight.y = vertices[3]->vy;
  1122. vertexToLight.z = vertices[3]->pVertex->elevation;
  1123. vertexToLight -= thisLight->position;
  1124. float length = vertexToLight.GetApproximateLength();
  1125. float falloff = 1.0f;
  1126. if (thisLight->GetFalloff(length, falloff))
  1127. {
  1128. float red,green,blue;
  1129. red = float((thisLight->GetaRGB()>>16) & 0x000000ff) * falloff;
  1130. green = float((thisLight->GetaRGB()>>8) & 0x000000ff) * falloff;
  1131. blue = float((thisLight->GetaRGB()) & 0x000000ff) * falloff;
  1132. specR += (DWORD)red;
  1133. specG += (DWORD)green;
  1134. specB += (DWORD)blue;
  1135. if (specR > 255)
  1136. specR = 255;
  1137. if (specG > 255)
  1138. specG = 255;
  1139. if (specB > 255)
  1140. specB = 255;
  1141. }
  1142. }
  1143. }
  1144. }
  1145. }
  1146. }
  1147. vertices[3]->lightRGB = lightb + (lightr<<16) + (lightg << 8) + (0xff << 24);
  1148. vertices[3]->fogRGB = (0xff<<24) + (specR<<16) + (specG << 8) + (specB);
  1149. //Fog
  1150. DWORD fogResult = 0xff;
  1151. if (Environment.Renderer != 3)
  1152. {
  1153. if (useFog)
  1154. {
  1155. if (vertices[3]->pVertex->elevation < fogStart)
  1156. {
  1157. float fogFactor = fogStart - vertices[3]->pVertex->elevation;
  1158. if (fogFactor < 0.0)
  1159. {
  1160. fogResult = 0xff;
  1161. }
  1162. else
  1163. {
  1164. fogFactor /= (fogStart - fogFull);
  1165. if (fogFactor <= 1.0)
  1166. {
  1167. fogFactor *= fogFactor;
  1168. fogFactor = 1.0 - fogFactor;
  1169. fogFactor *= 256.0;
  1170. }
  1171. else
  1172. {
  1173. fogFactor = 256.0;
  1174. }
  1175. fogResult = float2long(fogFactor);
  1176. }
  1177. }
  1178. else
  1179. {
  1180. fogResult = 0xff;
  1181. }
  1182. }
  1183. }
  1184. //-------------------
  1185. // Distance FOG now.
  1186. if (vertices[3]->hazeFactor != 0.0f)
  1187. {
  1188. float fogFactor = 1.0 - vertices[3]->hazeFactor;
  1189. DWORD distFog = float2long(fogFactor * 255.0f);
  1190. if (distFog < fogResult)
  1191. fogResult = distFog;
  1192. vertices[3]->fogRGB = (fogResult<<24) + (specR<<16) + (specG << 8) + (specB);
  1193. }
  1194. vertices[3]->calcThisFrame |= 1;
  1195. }
  1196. }
  1197. }
  1198. #define TERRAIN_DEPTH_FUDGE 0.001f
  1199. //---------------------------------------------------------------------------
  1200. void TerrainQuad::draw (void)
  1201. {
  1202. if (terrainHandle != 0xffffffff)
  1203. {
  1204. numTerrainFaces++;
  1205. //---------------------------------------
  1206. // GOS 3D draw Calls now!
  1207. gos_VERTEX gVertex[3];
  1208. float minU = 0.00f;
  1209. float maxU = 0.9999f;
  1210. float minV = 0.00f;
  1211. float maxV = 0.9999f;
  1212. float oldminU = 0.0078125f;
  1213. float oldmaxU = 0.9921875f;
  1214. float oldminV = 0.0078125f;
  1215. float oldmaxV = 0.9921875f;
  1216. if (Terrain::terrainTextures2 && !(overlayHandle == 0xffffffff && isCement))
  1217. {
  1218. minU = uvData.minU;
  1219. minV = uvData.minV;
  1220. maxU = uvData.maxU;
  1221. maxV = uvData.maxV;
  1222. }
  1223. Stuff::Point3D camPosition;
  1224. camPosition = *TG_Shape::cameraOrigin;
  1225. if (uvMode == BOTTOMRIGHT)
  1226. {
  1227. //--------------------------
  1228. // Top Triangle
  1229. DWORD lightRGB0 = vertices[0]->lightRGB;
  1230. DWORD lightRGB1 = vertices[1]->lightRGB;
  1231. DWORD lightRGB2 = vertices[2]->lightRGB;
  1232. if (Terrain::terrainTextures2 && (!Terrain::terrainTextures->isCement(vertices[0]->pVertex->textureData & 0x0000ffff)
  1233. || Terrain::terrainTextures->isAlpha(vertices[0]->pVertex->textureData & 0x0000ffff)))
  1234. lightRGB0 = lightRGB1 = lightRGB2 = 0xffffffff;
  1235. lightRGB0 = vertices[0]->pVertex->selected ? SELECTION_COLOR : lightRGB0;
  1236. lightRGB1 = vertices[1]->pVertex->selected ? SELECTION_COLOR : lightRGB1;
  1237. lightRGB2 = vertices[2]->pVertex->selected ? SELECTION_COLOR : lightRGB2;
  1238. gVertex[0].x = vertices[0]->px;
  1239. gVertex[0].y = vertices[0]->py;
  1240. gVertex[0].z = vertices[0]->pz + TERRAIN_DEPTH_FUDGE;
  1241. gVertex[0].rhw = vertices[0]->pw;
  1242. gVertex[0].u = minU;
  1243. gVertex[0].v = minV;
  1244. gVertex[0].argb = lightRGB0;
  1245. gVertex[0].frgb = vertices[0]->fogRGB;
  1246. gVertex[1].x = vertices[1]->px;
  1247. gVertex[1].y = vertices[1]->py;
  1248. gVertex[1].z = vertices[1]->pz + TERRAIN_DEPTH_FUDGE;
  1249. gVertex[1].rhw = vertices[1]->pw;
  1250. gVertex[1].u = maxU;
  1251. gVertex[1].v = minV;
  1252. gVertex[1].argb = lightRGB1;
  1253. gVertex[1].frgb = vertices[1]->fogRGB;
  1254. gVertex[2].x = vertices[2]->px;
  1255. gVertex[2].y = vertices[2]->py;
  1256. gVertex[2].z = vertices[2]->pz + TERRAIN_DEPTH_FUDGE;
  1257. gVertex[2].rhw = vertices[2]->pw;
  1258. gVertex[2].u = maxU;
  1259. gVertex[2].v = maxV;
  1260. gVertex[2].argb = lightRGB2;
  1261. gVertex[2].frgb = vertices[2]->fogRGB;
  1262. if ((gVertex[0].z >= 0.0f) &&
  1263. (gVertex[0].z < 1.0f) &&
  1264. (gVertex[1].z >= 0.0f) &&
  1265. (gVertex[1].z < 1.0f) &&
  1266. (gVertex[2].z >= 0.0f) &&
  1267. (gVertex[2].z < 1.0f))
  1268. {
  1269. {
  1270. if ((terrainDetailHandle == 0xffffffff) && (overlayHandle == 0xffffffff) && isCement)
  1271. mcTextureManager->addVertices(terrainHandle,gVertex,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  1272. else
  1273. mcTextureManager->addVertices(terrainHandle,gVertex,MC2_ISTERRAIN | MC2_DRAWSOLID);
  1274. //--------------------------------------------------------------
  1275. // Draw the Overlay Texture if it exists.
  1276. if (useOverlayTexture && (overlayHandle != 0xffffffff))
  1277. {
  1278. //Uses EXACT same coords as the above normal texture.
  1279. // Just replace the UVs and the texture handle!!
  1280. gos_VERTEX oVertex[3];
  1281. memcpy(oVertex,gVertex,sizeof(gos_VERTEX)*3);
  1282. oVertex[0].u = oldminU;
  1283. oVertex[0].v = oldminV;
  1284. oVertex[1].u = oldmaxU;
  1285. oVertex[1].v = oldminV;
  1286. oVertex[2].u = oldmaxU;
  1287. oVertex[2].v = oldmaxV;
  1288. //Light the overlays!!
  1289. oVertex[0].argb = vertices[0]->lightRGB;
  1290. oVertex[1].argb = vertices[1]->lightRGB;
  1291. oVertex[2].argb = vertices[2]->lightRGB;
  1292. mcTextureManager->addVertices(overlayHandle,oVertex,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  1293. }
  1294. //----------------------------------------------------
  1295. // Draw the detail Texture
  1296. if (useWaterInterestTexture && (terrainDetailHandle != 0xffffffff))
  1297. {
  1298. gos_VERTEX sVertex[3];
  1299. memcpy(sVertex,gVertex,sizeof(gos_VERTEX)*3);
  1300. float tilingFactor = Terrain::terrainTextures->getDetailTilingFactor(1);
  1301. if (Terrain::terrainTextures2)
  1302. tilingFactor = Terrain::terrainTextures2->getDetailTilingFactor();
  1303. float oneOverTf = tilingFactor / Terrain::worldUnitsMapSide;
  1304. sVertex[0].u = (vertices[0]->vx - Terrain::mapTopLeft3d.x) * oneOverTf;
  1305. sVertex[0].v = (Terrain::mapTopLeft3d.y - vertices[0]->vy) * oneOverTf;
  1306. sVertex[1].u = (vertices[1]->vx - Terrain::mapTopLeft3d.x) * oneOverTf;
  1307. sVertex[1].v = (Terrain::mapTopLeft3d.y - vertices[1]->vy) * oneOverTf;
  1308. sVertex[2].u = (vertices[2]->vx - Terrain::mapTopLeft3d.x) * oneOverTf;
  1309. sVertex[2].v = (Terrain::mapTopLeft3d.y - vertices[2]->vy) * oneOverTf;
  1310. if ((sVertex[0].u > MaxMinUV) ||
  1311. (sVertex[0].v > MaxMinUV) ||
  1312. (sVertex[1].u > MaxMinUV) ||
  1313. (sVertex[1].v > MaxMinUV) ||
  1314. (sVertex[2].u > MaxMinUV) ||
  1315. (sVertex[2].v > MaxMinUV))
  1316. {
  1317. //If any are out range, move 'em back in range by adjustfactor.
  1318. float maxU = fmax(sVertex[0].u,fmax(sVertex[1].u,sVertex[2].u));
  1319. maxU = floor(maxU - (MaxMinUV-1.0f));
  1320. float maxV = fmax(sVertex[0].v,fmax(sVertex[1].v,sVertex[2].v));
  1321. maxV = floor(maxV - (MaxMinUV-1.0f));
  1322. sVertex[0].u -= maxU;
  1323. sVertex[1].u -= maxU;
  1324. sVertex[2].u -= maxU;
  1325. sVertex[0].v -= maxV;
  1326. sVertex[1].v -= maxV;
  1327. sVertex[2].v -= maxV;
  1328. }
  1329. //Light the Detail Texture
  1330. if (Terrain::terrainTextures2)
  1331. {
  1332. sVertex[0].argb =
  1333. sVertex[1].argb =
  1334. sVertex[2].argb = 0xffffffff;
  1335. }
  1336. mcTextureManager->addVertices(terrainDetailHandle,sVertex,MC2_ISTERRAIN | MC2_DRAWALPHA);
  1337. }
  1338. }
  1339. }
  1340. //--------------------------
  1341. //Bottom Triangle
  1342. //
  1343. // gVertex[0] same as above gVertex[0].
  1344. // gVertex[1] is same as above gVertex[2].
  1345. // gVertex[2] is calced from vertex[3].
  1346. DWORD lightRGB3 = vertices[3]->lightRGB;
  1347. if (Terrain::terrainTextures2 && (!Terrain::terrainTextures->isCement(vertices[0]->pVertex->textureData & 0x0000ffff)
  1348. || Terrain::terrainTextures->isAlpha(vertices[0]->pVertex->textureData & 0x0000ffff)))
  1349. lightRGB3 = 0xffffffff;
  1350. lightRGB3 = vertices[3]->pVertex->selected ? SELECTION_COLOR : lightRGB3;
  1351. gVertex[1].x = gVertex[2].x;
  1352. gVertex[1].y = gVertex[2].y;
  1353. gVertex[1].z = gVertex[2].z;
  1354. gVertex[1].rhw = gVertex[2].rhw;
  1355. gVertex[1].u = gVertex[2].u;
  1356. gVertex[1].v = gVertex[2].v;
  1357. gVertex[1].argb = gVertex[2].argb;
  1358. gVertex[1].frgb = gVertex[2].frgb;
  1359. gVertex[2].x = vertices[3]->px;
  1360. gVertex[2].y = vertices[3]->py;
  1361. gVertex[2].z = vertices[3]->pz + TERRAIN_DEPTH_FUDGE;
  1362. gVertex[2].rhw = vertices[3]->pw;
  1363. gVertex[2].u = minU;
  1364. gVertex[2].v = maxV;
  1365. gVertex[2].argb = lightRGB3;
  1366. gVertex[2].frgb = vertices[3]->fogRGB;
  1367. if ((gVertex[0].z >= 0.0f) &&
  1368. (gVertex[0].z < 1.0f) &&
  1369. (gVertex[1].z >= 0.0f) &&
  1370. (gVertex[1].z < 1.0f) &&
  1371. (gVertex[2].z >= 0.0f) &&
  1372. (gVertex[2].z < 1.0f))
  1373. {
  1374. {
  1375. if ((terrainDetailHandle == 0xffffffff) && (overlayHandle == 0xffffffff) && isCement)
  1376. mcTextureManager->addVertices(terrainHandle,gVertex,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  1377. else
  1378. mcTextureManager->addVertices(terrainHandle,gVertex,MC2_ISTERRAIN | MC2_DRAWSOLID);
  1379. //--------------------------------------------------------------
  1380. // Draw the Overlay Texture if it exists.
  1381. if (useOverlayTexture && (overlayHandle != 0xffffffff))
  1382. {
  1383. //Uses EXACT same coords as the above normal texture.
  1384. // Just replace the UVs and the texture handle!!
  1385. //Uses EXACT same coords as the above normal texture.
  1386. // Just replace the UVs and the texture handle!!
  1387. gos_VERTEX oVertex[3];
  1388. memcpy(oVertex,gVertex,sizeof(gos_VERTEX)*3);
  1389. oVertex[0].u = oldminU;
  1390. oVertex[0].v = oldminV;
  1391. oVertex[1].u = oldmaxU;
  1392. oVertex[1].v = oldmaxV;
  1393. oVertex[2].u = oldminU;
  1394. oVertex[2].v = oldmaxV;
  1395. //Light the overlays!!
  1396. oVertex[0].argb = vertices[0]->lightRGB;
  1397. oVertex[1].argb = vertices[2]->lightRGB;
  1398. oVertex[2].argb = vertices[3]->lightRGB;
  1399. mcTextureManager->addVertices(overlayHandle,oVertex,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  1400. }
  1401. //----------------------------------------------------
  1402. // Draw the detail Texture
  1403. if (useWaterInterestTexture && (terrainDetailHandle != 0xffffffff))
  1404. {
  1405. gos_VERTEX sVertex[3];
  1406. memcpy(sVertex,gVertex,sizeof(gos_VERTEX)*3);
  1407. float tilingFactor = Terrain::terrainTextures->getDetailTilingFactor(1);
  1408. if (Terrain::terrainTextures2)
  1409. tilingFactor = Terrain::terrainTextures2->getDetailTilingFactor();
  1410. float oneOverTF = tilingFactor / Terrain::worldUnitsMapSide;
  1411. sVertex[0].u = (vertices[0]->vx - Terrain::mapTopLeft3d.x) * oneOverTF;
  1412. sVertex[0].v = (Terrain::mapTopLeft3d.y - vertices[0]->vy) * oneOverTF;
  1413. sVertex[1].u = (vertices[2]->vx - Terrain::mapTopLeft3d.x) * oneOverTF;
  1414. sVertex[1].v = (Terrain::mapTopLeft3d.y - vertices[2]->vy) * oneOverTF;
  1415. sVertex[2].u = (vertices[3]->vx - Terrain::mapTopLeft3d.x) * oneOverTF;
  1416. sVertex[2].v = (Terrain::mapTopLeft3d.y - vertices[3]->vy) * oneOverTF;
  1417. if ((sVertex[0].u > MaxMinUV) ||
  1418. (sVertex[0].v > MaxMinUV) ||
  1419. (sVertex[1].u > MaxMinUV) ||
  1420. (sVertex[1].v > MaxMinUV) ||
  1421. (sVertex[2].u > MaxMinUV) ||
  1422. (sVertex[2].v > MaxMinUV))
  1423. {
  1424. //If any are out range, move 'em back in range by adjustfactor.
  1425. float maxU = fmax(sVertex[0].u,fmax(sVertex[1].u,sVertex[2].u));
  1426. maxU = floor(maxU - (MaxMinUV-1.0f));
  1427. float maxV = fmax(sVertex[0].v,fmax(sVertex[1].v,sVertex[2].v));
  1428. maxV = floor(maxV - (MaxMinUV-1.0f));
  1429. sVertex[0].u -= maxU;
  1430. sVertex[1].u -= maxU;
  1431. sVertex[2].u -= maxU;
  1432. sVertex[0].v -= maxV;
  1433. sVertex[1].v -= maxV;
  1434. sVertex[2].v -= maxV;
  1435. }
  1436. //Light the Detail Texture
  1437. if (Terrain::terrainTextures2)
  1438. {
  1439. sVertex[0].argb =
  1440. sVertex[1].argb =
  1441. sVertex[2].argb = 0xffffffff;
  1442. }
  1443. mcTextureManager->addVertices(terrainDetailHandle,sVertex,MC2_ISTERRAIN | MC2_DRAWALPHA);
  1444. }
  1445. }
  1446. }
  1447. }
  1448. else if (uvMode == BOTTOMLEFT)
  1449. {
  1450. //------------------------------
  1451. // Top Triangle.
  1452. DWORD lightRGB0 = vertices[0]->lightRGB;
  1453. DWORD lightRGB1 = vertices[1]->lightRGB;
  1454. DWORD lightRGB3 = vertices[3]->lightRGB;
  1455. if (Terrain::terrainTextures2 && (!Terrain::terrainTextures->isCement(vertices[0]->pVertex->textureData & 0x0000ffff)
  1456. || Terrain::terrainTextures->isAlpha(vertices[0]->pVertex->textureData & 0x0000ffff)))
  1457. lightRGB0 = lightRGB1 = lightRGB3 = 0xffffffff;
  1458. lightRGB0 = vertices[0]->pVertex->selected ? SELECTION_COLOR : lightRGB0;
  1459. lightRGB1 = vertices[1]->pVertex->selected ? SELECTION_COLOR : lightRGB1;
  1460. lightRGB3 = vertices[3]->pVertex->selected ? SELECTION_COLOR : lightRGB3;
  1461. gVertex[0].x = vertices[0]->px;
  1462. gVertex[0].y = vertices[0]->py;
  1463. gVertex[0].z = vertices[0]->pz + TERRAIN_DEPTH_FUDGE;
  1464. gVertex[0].rhw = vertices[0]->pw;
  1465. gVertex[0].u = minU;
  1466. gVertex[0].v = minV;
  1467. gVertex[0].argb = lightRGB0;
  1468. gVertex[0].frgb = vertices[0]->fogRGB;
  1469. gVertex[1].x = vertices[1]->px;
  1470. gVertex[1].y = vertices[1]->py;
  1471. gVertex[1].z = vertices[1]->pz + TERRAIN_DEPTH_FUDGE;
  1472. gVertex[1].rhw = vertices[1]->pw;
  1473. gVertex[1].u = maxU;
  1474. gVertex[1].v = minV;
  1475. gVertex[1].argb = lightRGB1;
  1476. gVertex[1].frgb = vertices[1]->fogRGB;
  1477. gVertex[2].x = vertices[3]->px;
  1478. gVertex[2].y = vertices[3]->py;
  1479. gVertex[2].z = vertices[3]->pz + TERRAIN_DEPTH_FUDGE;
  1480. gVertex[2].rhw = vertices[3]->pw;
  1481. gVertex[2].u = minU;
  1482. gVertex[2].v = maxV;
  1483. gVertex[2].argb = lightRGB3;
  1484. gVertex[2].frgb = vertices[3]->fogRGB;
  1485. if ((gVertex[0].z >= 0.0f) &&
  1486. (gVertex[0].z < 1.0f) &&
  1487. (gVertex[1].z >= 0.0f) &&
  1488. (gVertex[1].z < 1.0f) &&
  1489. (gVertex[2].z >= 0.0f) &&
  1490. (gVertex[2].z < 1.0f))
  1491. {
  1492. {
  1493. if ((terrainDetailHandle == 0xffffffff) && (overlayHandle == 0xffffffff) && isCement)
  1494. mcTextureManager->addVertices(terrainHandle,gVertex,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  1495. else
  1496. mcTextureManager->addVertices(terrainHandle,gVertex,MC2_ISTERRAIN | MC2_DRAWSOLID);
  1497. //----------------------------------------------------
  1498. // Draw the detail Texture
  1499. if (useWaterInterestTexture && (terrainDetailHandle != 0xffffffff))
  1500. {
  1501. gos_VERTEX sVertex[3];
  1502. memcpy(sVertex,gVertex,sizeof(gos_VERTEX)*3);
  1503. float tilingFactor = Terrain::terrainTextures->getDetailTilingFactor(1);
  1504. if (Terrain::terrainTextures2)
  1505. tilingFactor = Terrain::terrainTextures2->getDetailTilingFactor();
  1506. float oneOverTF = tilingFactor / Terrain::worldUnitsMapSide;
  1507. sVertex[0].u = (vertices[0]->vx - Terrain::mapTopLeft3d.x) * oneOverTF;
  1508. sVertex[0].v = (Terrain::mapTopLeft3d.y - vertices[0]->vy) * oneOverTF;
  1509. sVertex[1].u = (vertices[1]->vx - Terrain::mapTopLeft3d.x) * oneOverTF;
  1510. sVertex[1].v = (Terrain::mapTopLeft3d.y - vertices[1]->vy) * oneOverTF;
  1511. sVertex[2].u = (vertices[3]->vx - Terrain::mapTopLeft3d.x) * oneOverTF;
  1512. sVertex[2].v = (Terrain::mapTopLeft3d.y - vertices[3]->vy) * oneOverTF;
  1513. if ((sVertex[0].u > MaxMinUV) ||
  1514. (sVertex[0].v > MaxMinUV) ||
  1515. (sVertex[1].u > MaxMinUV) ||
  1516. (sVertex[1].v > MaxMinUV) ||
  1517. (sVertex[2].u > MaxMinUV) ||
  1518. (sVertex[2].v > MaxMinUV))
  1519. {
  1520. //If any are out range, move 'em back in range by adjustfactor.
  1521. float maxU = fmax(sVertex[0].u,fmax(sVertex[1].u,sVertex[2].u));
  1522. maxU = floor(maxU - (MaxMinUV-1.0f));
  1523. float maxV = fmax(sVertex[0].v,fmax(sVertex[1].v,sVertex[2].v));
  1524. maxV = floor(maxV - (MaxMinUV-1.0f));
  1525. sVertex[0].u -= maxU;
  1526. sVertex[1].u -= maxU;
  1527. sVertex[2].u -= maxU;
  1528. sVertex[0].v -= maxV;
  1529. sVertex[1].v -= maxV;
  1530. sVertex[2].v -= maxV;
  1531. }
  1532. //Light the Detail Texture
  1533. if (Terrain::terrainTextures2)
  1534. {
  1535. sVertex[0].argb =
  1536. sVertex[1].argb =
  1537. sVertex[2].argb = 0xffffffff;
  1538. }
  1539. mcTextureManager->addVertices(terrainDetailHandle,sVertex,MC2_ISTERRAIN | MC2_DRAWALPHA);
  1540. }
  1541. //--------------------------------------------------------------
  1542. // Draw the Overlay Texture if it exists.
  1543. if (useOverlayTexture && (overlayHandle != 0xffffffff))
  1544. {
  1545. //Uses EXACT same coords as the above normal texture.
  1546. // Just replace the UVs and the texture handle!!
  1547. gos_VERTEX oVertex[3];
  1548. memcpy(oVertex,gVertex,sizeof(gos_VERTEX)*3);
  1549. oVertex[0].u = oldminU;
  1550. oVertex[0].v = oldminV;
  1551. oVertex[1].u = oldmaxU;
  1552. oVertex[1].v = oldminV;
  1553. oVertex[2].u = oldminU;
  1554. oVertex[2].v = oldmaxV;
  1555. //Light the overlays!!
  1556. oVertex[0].argb = vertices[0]->lightRGB;
  1557. oVertex[1].argb = vertices[1]->lightRGB;
  1558. oVertex[2].argb = vertices[3]->lightRGB;
  1559. mcTextureManager->addVertices(overlayHandle,oVertex,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  1560. }
  1561. }
  1562. }
  1563. //---------------------------------------
  1564. // Bottom Triangle.
  1565. // gVertex[0] is same as above gVertex[1]
  1566. // gVertex[1] is new and calced from vertex[2].
  1567. // gVertex[2] is same as above.
  1568. DWORD lightRGB2 = vertices[2]->lightRGB;
  1569. if (Terrain::terrainTextures2 && (!Terrain::terrainTextures->isCement(vertices[0]->pVertex->textureData & 0x0000ffff)
  1570. || Terrain::terrainTextures->isAlpha(vertices[0]->pVertex->textureData & 0x0000ffff)))
  1571. lightRGB2 = 0xffffffff;
  1572. lightRGB2 = vertices[2]->pVertex->selected ? SELECTION_COLOR : lightRGB2;
  1573. gVertex[0].x = gVertex[1].x;
  1574. gVertex[0].y = gVertex[1].y;
  1575. gVertex[0].z = gVertex[1].z;
  1576. gVertex[0].rhw = gVertex[1].rhw;
  1577. gVertex[0].u = gVertex[1].u;
  1578. gVertex[0].v = gVertex[1].v;
  1579. gVertex[0].argb = gVertex[1].argb;
  1580. gVertex[0].frgb = gVertex[1].frgb;
  1581. gVertex[1].x = vertices[2]->px;
  1582. gVertex[1].y = vertices[2]->py;
  1583. gVertex[1].z = vertices[2]->pz + TERRAIN_DEPTH_FUDGE;
  1584. gVertex[1].rhw = vertices[2]->pw;
  1585. gVertex[1].u = maxU;
  1586. gVertex[1].v = maxV;
  1587. gVertex[1].argb = lightRGB2;
  1588. gVertex[1].frgb = vertices[2]->fogRGB;
  1589. if ((gVertex[0].z >= 0.0f) &&
  1590. (gVertex[0].z < 1.0f) &&
  1591. (gVertex[1].z >= 0.0f) &&
  1592. (gVertex[1].z < 1.0f) &&
  1593. (gVertex[2].z >= 0.0f) &&
  1594. (gVertex[2].z < 1.0f))
  1595. {
  1596. {
  1597. if ((terrainDetailHandle == 0xffffffff) && (overlayHandle == 0xffffffff) && isCement)
  1598. mcTextureManager->addVertices(terrainHandle,gVertex,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  1599. else
  1600. mcTextureManager->addVertices(terrainHandle,gVertex,MC2_ISTERRAIN | MC2_DRAWSOLID);
  1601. //----------------------------------------------------
  1602. // Draw the detail Texture
  1603. if (useWaterInterestTexture && (terrainDetailHandle != 0xffffffff))
  1604. {
  1605. gos_VERTEX sVertex[3];
  1606. memcpy(sVertex,gVertex,sizeof(gos_VERTEX)*3);
  1607. float tilingFactor = Terrain::terrainTextures->getDetailTilingFactor(1);
  1608. if (Terrain::terrainTextures2)
  1609. tilingFactor = Terrain::terrainTextures2->getDetailTilingFactor();
  1610. float oneOverTf = tilingFactor / Terrain::worldUnitsMapSide;
  1611. sVertex[0].u = (vertices[1]->vx - Terrain::mapTopLeft3d.x) * oneOverTf;
  1612. sVertex[0].v = (Terrain::mapTopLeft3d.y - vertices[1]->vy) * oneOverTf;
  1613. sVertex[1].u = (vertices[2]->vx - Terrain::mapTopLeft3d.x) * oneOverTf;
  1614. sVertex[1].v = (Terrain::mapTopLeft3d.y - vertices[2]->vy) * oneOverTf;
  1615. sVertex[2].u = (vertices[3]->vx - Terrain::mapTopLeft3d.x) * oneOverTf ;
  1616. sVertex[2].v = (Terrain::mapTopLeft3d.y - vertices[3]->vy) * oneOverTf ;
  1617. if ((sVertex[0].u > MaxMinUV) ||
  1618. (sVertex[0].v > MaxMinUV) ||
  1619. (sVertex[1].u > MaxMinUV) ||
  1620. (sVertex[1].v > MaxMinUV) ||
  1621. (sVertex[2].u > MaxMinUV) ||
  1622. (sVertex[2].v > MaxMinUV))
  1623. {
  1624. //If any are out range, move 'em back in range by adjustfactor.
  1625. float maxU = fmax(sVertex[0].u,fmax(sVertex[1].u,sVertex[2].u));
  1626. maxU = floor(maxU - (MaxMinUV-1.0f));
  1627. float maxV = fmax(sVertex[0].v,fmax(sVertex[1].v,sVertex[2].v));
  1628. maxV = floor(maxV - (MaxMinUV-1.0f));
  1629. sVertex[0].u -= maxU;
  1630. sVertex[1].u -= maxU;
  1631. sVertex[2].u -= maxU;
  1632. sVertex[0].v -= maxV;
  1633. sVertex[1].v -= maxV;
  1634. sVertex[2].v -= maxV;
  1635. }
  1636. //Light the Detail Texture
  1637. if (Terrain::terrainTextures2)
  1638. {
  1639. sVertex[0].argb =
  1640. sVertex[1].argb =
  1641. sVertex[2].argb = 0xffffffff;
  1642. }
  1643. mcTextureManager->addVertices(terrainDetailHandle,sVertex,MC2_ISTERRAIN | MC2_DRAWALPHA);
  1644. }
  1645. //--------------------------------------------------------------
  1646. // Draw the Overlay Texture if it exists.
  1647. if (useOverlayTexture && (overlayHandle != 0xffffffff))
  1648. {
  1649. //Uses EXACT same coords as the above normal texture.
  1650. // Just replace the UVs and the texture handle!!
  1651. gos_VERTEX oVertex[3];
  1652. memcpy(oVertex,gVertex,sizeof(gos_VERTEX)*3);
  1653. oVertex[0].u = oldmaxU;
  1654. oVertex[0].v = oldminV;
  1655. oVertex[1].u = oldmaxU;
  1656. oVertex[1].v = oldmaxV;
  1657. oVertex[2].u = oldminU;
  1658. oVertex[2].v = oldmaxV;
  1659. //Light the overlays!!
  1660. oVertex[0].argb = vertices[1]->lightRGB;
  1661. oVertex[1].argb = vertices[2]->lightRGB;
  1662. oVertex[2].argb = vertices[3]->lightRGB;
  1663. mcTextureManager->addVertices(overlayHandle,oVertex,MC2_ISTERRAIN | MC2_DRAWALPHA | MC2_ISCRATERS);
  1664. }
  1665. }
  1666. }
  1667. }
  1668. }
  1669. #ifdef _DEBUG
  1670. if (selected )
  1671. {
  1672. drawLine();
  1673. selected = FALSE;
  1674. }
  1675. #endif
  1676. }
  1677. extern float elevationAnimation;
  1678. #define SKY_FUDGE (1.0f / 60000.0f)
  1679. #define WATER_ALPHA 0x1fffffff
  1680. extern float cloudScrollX;
  1681. extern float cloudScrollY;
  1682. //---------------------------------------------------------------------------
  1683. void TerrainQuad::drawWater (void)
  1684. {
  1685. float cloudOffsetX = cos(360.0f * DEGREES_TO_RADS * 32.0f * cloudScrollX) * 0.1f;
  1686. float cloudOffsetY = sin(360.0f * DEGREES_TO_RADS * 32.0f * cloudScrollY) * 0.1f;
  1687. float sprayOffsetX = cloudScrollX * 10.0f;
  1688. float sprayOffsetY = cloudScrollY * 10.0f;
  1689. //Gotta be able to run the untextured maps!!!
  1690. float oneOverWaterTF = 1.0f / 64.0f;
  1691. float oneOverTF = 1.0f / 64.0f;
  1692. if (Terrain::terrainTextures2)
  1693. {
  1694. oneOverWaterTF = (Terrain::terrainTextures2->getWaterDetailTilingFactor() / Terrain::worldUnitsMapSide);
  1695. oneOverTF = (Terrain::terrainTextures2->getWaterTextureTilingFactor() / Terrain::worldUnitsMapSide);
  1696. }
  1697. if (waterHandle != 0xffffffff)
  1698. {
  1699. numTerrainFaces++;
  1700. //---------------------------------------
  1701. // GOS 3D draw Calls now!
  1702. float minU = 0.0f;
  1703. float maxU = 0.9999999f;
  1704. float minV = 0.0f;
  1705. float maxV = 0.9999999f;
  1706. //-----------------------------------------------------
  1707. // FOG time. Set Render state to FOG on!
  1708. if (useFog)
  1709. {
  1710. DWORD fogColor = eye->fogColor;
  1711. gos_SetRenderState( gos_State_Fog, (int)&fogColor);
  1712. }
  1713. else
  1714. {
  1715. gos_SetRenderState( gos_State_Fog, 0);
  1716. }
  1717. gos_VERTEX gVertex[3];
  1718. if (uvMode == BOTTOMRIGHT)
  1719. {
  1720. //--------------------------
  1721. // Top Triangle
  1722. gVertex[0].x = vertices[0]->wx;
  1723. gVertex[0].y = vertices[0]->wy;
  1724. gVertex[0].z = vertices[0]->wz + TERRAIN_DEPTH_FUDGE;
  1725. gVertex[0].rhw = vertices[0]->ww;
  1726. gVertex[0].u = minU + cloudOffsetX;
  1727. gVertex[0].v = minV + cloudOffsetY;
  1728. gVertex[0].argb = vertices[0]->pVertex->selected ? SELECTION_COLOR : vertices[0]->lightRGB;
  1729. gVertex[0].frgb = vertices[0]->fogRGB;
  1730. gVertex[1].x = vertices[1]->wx;
  1731. gVertex[1].y = vertices[1]->wy;
  1732. gVertex[1].z = vertices[1]->wz + TERRAIN_DEPTH_FUDGE;
  1733. gVertex[1].rhw = vertices[1]->ww;
  1734. gVertex[1].u = maxU + cloudOffsetX;
  1735. gVertex[1].v = minV + cloudOffsetY;
  1736. gVertex[1].argb = vertices[1]->pVertex->selected ? SELECTION_COLOR : vertices[1]->lightRGB;
  1737. gVertex[1].frgb = vertices[1]->fogRGB;
  1738. gVertex[2].x = vertices[2]->wx;
  1739. gVertex[2].y = vertices[2]->wy;
  1740. gVertex[2].z = vertices[2]->wz + TERRAIN_DEPTH_FUDGE;
  1741. gVertex[2].rhw = vertices[2]->ww;
  1742. gVertex[2].u = maxU + cloudOffsetX;
  1743. gVertex[2].v = maxV + cloudOffsetY;
  1744. gVertex[2].argb = vertices[2]->pVertex->selected ? SELECTION_COLOR : vertices[2]->lightRGB;
  1745. gVertex[2].frgb = vertices[2]->fogRGB;
  1746. gVertex[0].u = (vertices[0]->vx - Terrain::mapTopLeft3d.x) * oneOverTF + cloudOffsetX;
  1747. gVertex[0].v = (Terrain::mapTopLeft3d.y - vertices[0]->vy) * oneOverTF + cloudOffsetY;
  1748. gVertex[1].u = (vertices[1]->vx - Terrain::mapTopLeft3d.x) * oneOverTF + cloudOffsetX;
  1749. gVertex[1].v = (Terrain::mapTopLeft3d.y - vertices[1]->vy) * oneOverTF + cloudOffsetY;
  1750. gVertex[2].u = (vertices[2]->vx - Terrain::mapTopLeft3d.x) * oneOverTF + cloudOffsetX;
  1751. gVertex[2].v = (Terrain::mapTopLeft3d.y - vertices[2]->vy) * oneOverTF + cloudOffsetY;
  1752. if ((gVertex[0].z >= 0.0f) &&
  1753. (gVertex[0].z < 1.0f) &&
  1754. (gVertex[1].z >= 0.0f) &&
  1755. (gVertex[1].z < 1.0f) &&
  1756. (gVertex[2].z >= 0.0f) &&
  1757. (gVertex[2].z < 1.0f))
  1758. {
  1759. {
  1760. //-----------------------------------------------------------------------------
  1761. // Reject Any triangle which has vertices off screeen in software for now.
  1762. // Do real cliping in geometry layer for software and hardware that needs it!
  1763. if (waterHandle != 0xffffffff)
  1764. {
  1765. DWORD alphaMode0 = Terrain::alphaMiddle;
  1766. DWORD alphaMode1 = Terrain::alphaMiddle;
  1767. DWORD alphaMode2 = Terrain::alphaMiddle;
  1768. if (vertices[0]->pVertex->elevation >= (Terrain::waterElevation - MapData::alphaDepth) )
  1769. {
  1770. alphaMode0 = Terrain::alphaEdge;
  1771. }
  1772. if (vertices[1]->pVertex->elevation >= (Terrain::waterElevation - MapData::alphaDepth) )
  1773. {
  1774. alphaMode1 = Terrain::alphaEdge;
  1775. }
  1776. if (vertices[2]->pVertex->elevation >= (Terrain::waterElevation - MapData::alphaDepth) )
  1777. {
  1778. alphaMode2 = Terrain::alphaEdge;
  1779. }
  1780. if (vertices[0]->pVertex->elevation <= (Terrain::waterElevation - (MapData::alphaDepth * 3.0f)) )
  1781. {
  1782. alphaMode0 = Terrain::alphaDeep;
  1783. }
  1784. if (vertices[1]->pVertex->elevation <= (Terrain::waterElevation - (MapData::alphaDepth * 3.0f)) )
  1785. {
  1786. alphaMode1 = Terrain::alphaDeep;
  1787. }
  1788. if (vertices[2]->pVertex->elevation <= (Terrain::waterElevation - (MapData::alphaDepth * 3.0f)) )
  1789. {
  1790. alphaMode2 = Terrain::alphaDeep;
  1791. }
  1792. gVertex[0].argb = (vertices[0]->lightRGB & 0x00ffffff) + alphaMode0;
  1793. gVertex[1].argb = (vertices[1]->lightRGB & 0x00ffffff) + alphaMode1;
  1794. gVertex[2].argb = (vertices[2]->lightRGB & 0x00ffffff) + alphaMode2;
  1795. if ((gVertex[0].u > MaxMinUV) ||
  1796. (gVertex[0].v > MaxMinUV) ||
  1797. (gVertex[1].u > MaxMinUV) ||
  1798. (gVertex[1].v > MaxMinUV) ||
  1799. (gVertex[2].u > MaxMinUV) ||
  1800. (gVertex[2].v > MaxMinUV))
  1801. {
  1802. //If any are out range, move 'em back in range by adjustfactor.
  1803. float maxU = fmax(gVertex[0].u,fmax(gVertex[1].u,gVertex[2].u));
  1804. maxU = floor(maxU - (MaxMinUV-1.0f));
  1805. float maxV = fmax(gVertex[0].v,fmax(gVertex[1].v,gVertex[2].v));
  1806. maxV = floor(maxV - (MaxMinUV-1.0f));
  1807. gVertex[0].u -= maxU;
  1808. gVertex[1].u -= maxU;
  1809. gVertex[2].u -= maxU;
  1810. gVertex[0].v -= maxV;
  1811. gVertex[1].v -= maxV;
  1812. gVertex[2].v -= maxV;
  1813. }
  1814. if (alphaMode0 + alphaMode1 + alphaMode2)
  1815. {
  1816. mcTextureManager->addVertices(waterHandle,gVertex,MC2_ISTERRAIN | MC2_DRAWALPHA);
  1817. }
  1818. }
  1819. //----------------------------------------------------
  1820. // Draw the sky reflection on the water.
  1821. if (useWaterInterestTexture && (waterDetailHandle != 0xffffffff))
  1822. {
  1823. gos_VERTEX sVertex[3];
  1824. memcpy(sVertex,gVertex,sizeof(gos_VERTEX)*3);
  1825. sVertex[0].u = ((vertices[0]->vx - Terrain::mapTopLeft3d.x) * oneOverWaterTF) + sprayOffsetX;
  1826. sVertex[0].v = ((Terrain::mapTopLeft3d.y - vertices[0]->vy) * oneOverWaterTF) + sprayOffsetY;
  1827. sVertex[1].u = ((vertices[1]->vx - Terrain::mapTopLeft3d.x) * oneOverWaterTF) + sprayOffsetX;
  1828. sVertex[1].v = ((Terrain::mapTopLeft3d.y - vertices[1]->vy) * oneOverWaterTF) + sprayOffsetY;
  1829. sVertex[2].u = ((vertices[2]->vx - Terrain::mapTopLeft3d.x) * oneOverWaterTF) + sprayOffsetX;
  1830. sVertex[2].v = ((Terrain::mapTopLeft3d.y - vertices[2]->vy) * oneOverWaterTF) + sprayOffsetY;
  1831. sVertex[0].argb = (sVertex[0].argb & 0xff000000) + 0xffffff;
  1832. sVertex[1].argb = (sVertex[1].argb & 0xff000000) + 0xffffff;
  1833. sVertex[2].argb = (sVertex[2].argb & 0xff000000) + 0xffffff;
  1834. mcTextureManager->addVertices(waterDetailHandle,sVertex,MC2_ISTERRAIN | MC2_DRAWALPHA);
  1835. }
  1836. }
  1837. }
  1838. //--------------------------
  1839. //Bottom Triangle
  1840. //
  1841. // gVertex[0] same as above gVertex[0].
  1842. // gVertex[1] is same as above gVertex[2].
  1843. // gVertex[2] is calced from vertex[3].
  1844. gVertex[1].x = gVertex[2].x;
  1845. gVertex[1].y = gVertex[2].y;
  1846. gVertex[1].z = gVertex[2].z;
  1847. gVertex[1].rhw = gVertex[2].rhw;
  1848. gVertex[1].u = gVertex[2].u;
  1849. gVertex[1].v = gVertex[2].v;
  1850. gVertex[1].argb = gVertex[2].argb;
  1851. gVertex[1].frgb = gVertex[2].frgb;
  1852. gVertex[2].x = vertices[3]->wx;
  1853. gVertex[2].y = vertices[3]->wy;
  1854. gVertex[2].z = vertices[3]->wz + TERRAIN_DEPTH_FUDGE;
  1855. gVertex[2].rhw = vertices[3]->ww;
  1856. gVertex[2].u = minU + cloudOffsetX;
  1857. gVertex[2].v = maxV + cloudOffsetY;
  1858. gVertex[2].argb = vertices[3]->pVertex->selected ? SELECTION_COLOR : vertices[3]->lightRGB;
  1859. gVertex[2].frgb = vertices[3]->fogRGB;
  1860. gVertex[0].u = (vertices[0]->vx - Terrain::mapTopLeft3d.x) * oneOverTF + cloudOffsetX;
  1861. gVertex[0].v = (Terrain::mapTopLeft3d.y - vertices[0]->vy) * oneOverTF + cloudOffsetY;
  1862. gVertex[1].u = (vertices[2]->vx - Terrain::mapTopLeft3d.x) * oneOverTF + cloudOffsetX;
  1863. gVertex[1].v = (Terrain::mapTopLeft3d.y - vertices[2]->vy) * oneOverTF + cloudOffsetY;
  1864. gVertex[2].u = (vertices[3]->vx - Terrain::mapTopLeft3d.x) * oneOverTF + cloudOffsetX;
  1865. gVertex[2].v = (Terrain::mapTopLeft3d.y - vertices[3]->vy) * oneOverTF + cloudOffsetY;
  1866. if ((gVertex[0].z >= 0.0f) &&
  1867. (gVertex[0].z < 1.0f) &&
  1868. (gVertex[1].z >= 0.0f) &&
  1869. (gVertex[1].z < 1.0f) &&
  1870. (gVertex[2].z >= 0.0f) &&
  1871. (gVertex[2].z < 1.0f))
  1872. {
  1873. {
  1874. //-----------------------------------------------------------------------------
  1875. // Reject Any triangle which has vertices off screeen in software for now.
  1876. // Do real cliping in geometry layer for software and hardware that needs it!
  1877. if (waterHandle != 0xffffffff)
  1878. {
  1879. DWORD alphaMode0 = Terrain::alphaMiddle;
  1880. DWORD alphaMode1 = Terrain::alphaMiddle;
  1881. DWORD alphaMode2 = Terrain::alphaMiddle;
  1882. if (vertices[0]->pVertex->elevation >= (Terrain::waterElevation - MapData::alphaDepth) )
  1883. {
  1884. alphaMode0 = Terrain::alphaEdge;
  1885. }
  1886. if (vertices[2]->pVertex->elevation >= (Terrain::waterElevation - MapData::alphaDepth) )
  1887. {
  1888. alphaMode1 = Terrain::alphaEdge;
  1889. }
  1890. if (vertices[3]->pVertex->elevation >= (Terrain::waterElevation - MapData::alphaDepth) )
  1891. {
  1892. alphaMode2 = Terrain::alphaEdge;
  1893. }
  1894. if (vertices[0]->pVertex->elevation <= (Terrain::waterElevation - (MapData::alphaDepth * 3.0f)) )
  1895. {
  1896. alphaMode0 = Terrain::alphaDeep;
  1897. }
  1898. if (vertices[2]->pVertex->elevation <= (Terrain::waterElevation - (MapData::alphaDepth * 3.0f)) )
  1899. {
  1900. alphaMode1 = Terrain::alphaDeep;
  1901. }
  1902. if (vertices[3]->pVertex->elevation <= (Terrain::waterElevation - (MapData::alphaDepth * 3.0f)) )
  1903. {
  1904. alphaMode2 = Terrain::alphaDeep;
  1905. }
  1906. gVertex[0].argb = (vertices[0]->lightRGB & 0x00ffffff) + alphaMode0;
  1907. gVertex[1].argb = (vertices[2]->lightRGB & 0x00ffffff) + alphaMode1;
  1908. gVertex[2].argb = (vertices[3]->lightRGB & 0x00ffffff) + alphaMode2;
  1909. if ((gVertex[0].u > MaxMinUV) ||
  1910. (gVertex[0].v > MaxMinUV) ||
  1911. (gVertex[1].u > MaxMinUV) ||
  1912. (gVertex[1].v > MaxMinUV) ||
  1913. (gVertex[2].u > MaxMinUV) ||
  1914. (gVertex[2].v > MaxMinUV))
  1915. {
  1916. //If any are out range, move 'em back in range by adjustfactor.
  1917. float maxU = fmax(gVertex[0].u,fmax(gVertex[1].u,gVertex[2].u));
  1918. maxU = floor(maxU - (MaxMinUV-1.0f));
  1919. float maxV = fmax(gVertex[0].v,fmax(gVertex[1].v,gVertex[2].v));
  1920. maxV = floor(maxV - (MaxMinUV-1.0f));
  1921. gVertex[0].u -= maxU;
  1922. gVertex[1].u -= maxU;
  1923. gVertex[2].u -= maxU;
  1924. gVertex[0].v -= maxV;
  1925. gVertex[1].v -= maxV;
  1926. gVertex[2].v -= maxV;
  1927. }
  1928. if (alphaMode0 + alphaMode1 + alphaMode2)
  1929. {
  1930. mcTextureManager->addVertices(waterHandle,gVertex,MC2_ISTERRAIN | MC2_DRAWALPHA);
  1931. }
  1932. }
  1933. //----------------------------------------------------
  1934. // Draw the sky reflection on the water.
  1935. if (useWaterInterestTexture && (waterDetailHandle != 0xffffffff))
  1936. {
  1937. gos_VERTEX sVertex[3];
  1938. memcpy(sVertex,gVertex,sizeof(gos_VERTEX)*3);
  1939. sVertex[0].u = ((vertices[0]->vx - Terrain::mapTopLeft3d.x) * oneOverWaterTF) + sprayOffsetX;
  1940. sVertex[0].v = ((Terrain::mapTopLeft3d.y - vertices[0]->vy) * oneOverWaterTF) + sprayOffsetY;
  1941. sVertex[1].u = ((vertices[2]->vx - Terrain::mapTopLeft3d.x) * oneOverWaterTF) + sprayOffsetX;
  1942. sVertex[1].v = ((Terrain::mapTopLeft3d.y - vertices[2]->vy) * oneOverWaterTF) + sprayOffsetY;
  1943. sVertex[2].u = ((vertices[3]->vx - Terrain::mapTopLeft3d.x) * oneOverWaterTF) + sprayOffsetX;
  1944. sVertex[2].v = ((Terrain::mapTopLeft3d.y - vertices[3]->vy) * oneOverWaterTF) + sprayOffsetY;
  1945. sVertex[0].argb = (sVertex[0].argb & 0xff000000) + 0xffffff;
  1946. sVertex[1].argb = (sVertex[1].argb & 0xff000000) + 0xffffff;
  1947. sVertex[2].argb = (sVertex[2].argb & 0xff000000) + 0xffffff;
  1948. mcTextureManager->addVertices(waterDetailHandle,sVertex,MC2_ISTERRAIN | MC2_DRAWALPHA);
  1949. }
  1950. }
  1951. }
  1952. }
  1953. else if (uvMode == BOTTOMLEFT)
  1954. {
  1955. //------------------------------
  1956. // Top Triangle.
  1957. gVertex[0].x = vertices[0]->wx;
  1958. gVertex[0].y = vertices[0]->wy;
  1959. gVertex[0].z = vertices[0]->wz + TERRAIN_DEPTH_FUDGE;
  1960. gVertex[0].rhw = vertices[0]->ww;
  1961. gVertex[0].u = minU + cloudOffsetX;;
  1962. gVertex[0].v = minV + cloudOffsetY;;
  1963. gVertex[0].argb = vertices[0]->pVertex->selected ? SELECTION_COLOR : vertices[0]->lightRGB;
  1964. gVertex[0].frgb = vertices[0]->fogRGB;
  1965. gVertex[1].x = vertices[1]->wx;
  1966. gVertex[1].y = vertices[1]->wy;
  1967. gVertex[1].z = vertices[1]->wz + TERRAIN_DEPTH_FUDGE;
  1968. gVertex[1].rhw = vertices[1]->ww;
  1969. gVertex[1].u = maxU + cloudOffsetX;;
  1970. gVertex[1].v = minV + cloudOffsetY;;
  1971. gVertex[1].argb = vertices[1]->pVertex->selected ? SELECTION_COLOR : vertices[1]->lightRGB;
  1972. gVertex[1].frgb = vertices[1]->fogRGB;
  1973. gVertex[2].x = vertices[3]->wx;
  1974. gVertex[2].y = vertices[3]->wy;
  1975. gVertex[2].z = vertices[3]->wz + TERRAIN_DEPTH_FUDGE;
  1976. gVertex[2].rhw = vertices[3]->ww;
  1977. gVertex[2].u = minU + cloudOffsetX;;
  1978. gVertex[2].v = maxV + cloudOffsetY;;
  1979. gVertex[2].argb = vertices[3]->pVertex->selected ? SELECTION_COLOR : vertices[3]->lightRGB;
  1980. gVertex[2].frgb = vertices[3]->fogRGB;
  1981. gVertex[0].u = (vertices[0]->vx - Terrain::mapTopLeft3d.x) * oneOverTF + cloudOffsetX;
  1982. gVertex[0].v = (Terrain::mapTopLeft3d.y - vertices[0]->vy) * oneOverTF + cloudOffsetY;
  1983. gVertex[1].u = (vertices[1]->vx - Terrain::mapTopLeft3d.x) * oneOverTF + cloudOffsetX;
  1984. gVertex[1].v = (Terrain::mapTopLeft3d.y - vertices[1]->vy) * oneOverTF + cloudOffsetY;
  1985. gVertex[2].u = (vertices[3]->vx - Terrain::mapTopLeft3d.x) * oneOverTF + cloudOffsetX;
  1986. gVertex[2].v = (Terrain::mapTopLeft3d.y - vertices[3]->vy) * oneOverTF + cloudOffsetY;
  1987. if ((gVertex[0].z >= 0.0f) &&
  1988. (gVertex[0].z < 1.0f) &&
  1989. (gVertex[1].z >= 0.0f) &&
  1990. (gVertex[1].z < 1.0f) &&
  1991. (gVertex[2].z >= 0.0f) &&
  1992. (gVertex[2].z < 1.0f))
  1993. {
  1994. {
  1995. //-----------------------------------------------------------------------------
  1996. // Reject Any triangle which has vertices off screeen in software for now.
  1997. // Do real cliping in geometry layer for software and hardware that needs it!
  1998. if (waterHandle != 0xffffffff)
  1999. {
  2000. DWORD alphaMode0 = Terrain::alphaMiddle;
  2001. DWORD alphaMode1 = Terrain::alphaMiddle;
  2002. DWORD alphaMode2 = Terrain::alphaMiddle;
  2003. if (vertices[0]->pVertex->elevation >= (Terrain::waterElevation - MapData::alphaDepth) )
  2004. {
  2005. alphaMode0 = Terrain::alphaEdge;
  2006. }
  2007. if (vertices[1]->pVertex->elevation >= (Terrain::waterElevation - MapData::alphaDepth) )
  2008. {
  2009. alphaMode1 = Terrain::alphaEdge;
  2010. }
  2011. if (vertices[3]->pVertex->elevation >= (Terrain::waterElevation - MapData::alphaDepth) )
  2012. {
  2013. alphaMode2 = Terrain::alphaEdge;
  2014. }
  2015. if (vertices[0]->pVertex->elevation <= (Terrain::waterElevation - (MapData::alphaDepth * 3.0f)) )
  2016. {
  2017. alphaMode0 = Terrain::alphaDeep;
  2018. }
  2019. if (vertices[1]->pVertex->elevation <= (Terrain::waterElevation - (MapData::alphaDepth * 3.0f)) )
  2020. {
  2021. alphaMode1 = Terrain::alphaDeep;
  2022. }
  2023. if (vertices[3]->pVertex->elevation <= (Terrain::waterElevation - (MapData::alphaDepth * 3.0f)) )
  2024. {
  2025. alphaMode2 = Terrain::alphaDeep;
  2026. }
  2027. gVertex[0].argb = (vertices[0]->lightRGB & 0x00ffffff) + alphaMode0;
  2028. gVertex[1].argb = (vertices[1]->lightRGB & 0x00ffffff) + alphaMode1;
  2029. gVertex[2].argb = (vertices[3]->lightRGB & 0x00ffffff) + alphaMode2;
  2030. if ((gVertex[0].u > MaxMinUV) ||
  2031. (gVertex[0].v > MaxMinUV) ||
  2032. (gVertex[1].u > MaxMinUV) ||
  2033. (gVertex[1].v > MaxMinUV) ||
  2034. (gVertex[2].u > MaxMinUV) ||
  2035. (gVertex[2].v > MaxMinUV))
  2036. {
  2037. //If any are out range, move 'em back in range by adjustfactor.
  2038. float maxU = fmax(gVertex[0].u,fmax(gVertex[1].u,gVertex[2].u));
  2039. maxU = floor(maxU - (MaxMinUV-1.0f));
  2040. float maxV = fmax(gVertex[0].v,fmax(gVertex[1].v,gVertex[2].v));
  2041. maxV = floor(maxV - (MaxMinUV-1.0f));
  2042. gVertex[0].u -= maxU;
  2043. gVertex[1].u -= maxU;
  2044. gVertex[2].u -= maxU;
  2045. gVertex[0].v -= maxV;
  2046. gVertex[1].v -= maxV;
  2047. gVertex[2].v -= maxV;
  2048. }
  2049. if (alphaMode0 + alphaMode1 + alphaMode2)
  2050. {
  2051. mcTextureManager->addVertices(waterHandle,gVertex,MC2_ISTERRAIN | MC2_DRAWALPHA);
  2052. }
  2053. }
  2054. //----------------------------------------------------
  2055. // Draw the sky reflection on the water.
  2056. if (useWaterInterestTexture && (waterDetailHandle != 0xffffffff))
  2057. {
  2058. gos_VERTEX sVertex[3];
  2059. memcpy(sVertex,gVertex,sizeof(gos_VERTEX)*3);
  2060. sVertex[0].u = ((vertices[0]->vx - Terrain::mapTopLeft3d.x) * oneOverWaterTF) + sprayOffsetX;
  2061. sVertex[0].v = ((Terrain::mapTopLeft3d.y - vertices[0]->vy) * oneOverWaterTF) + sprayOffsetY;
  2062. sVertex[1].u = ((vertices[1]->vx - Terrain::mapTopLeft3d.x) * oneOverWaterTF) + sprayOffsetX;
  2063. sVertex[1].v = ((Terrain::mapTopLeft3d.y - vertices[1]->vy) * oneOverWaterTF) + sprayOffsetY;
  2064. sVertex[2].u = ((vertices[3]->vx - Terrain::mapTopLeft3d.x) * oneOverWaterTF) + sprayOffsetX;
  2065. sVertex[2].v = ((Terrain::mapTopLeft3d.y - vertices[3]->vy) * oneOverWaterTF) + sprayOffsetY;
  2066. sVertex[0].argb = (sVertex[0].argb & 0xff000000) + 0xffffff;
  2067. sVertex[1].argb = (sVertex[1].argb & 0xff000000) + 0xffffff;
  2068. sVertex[2].argb = (sVertex[2].argb & 0xff000000) + 0xffffff;
  2069. mcTextureManager->addVertices(waterDetailHandle,sVertex,MC2_ISTERRAIN | MC2_DRAWALPHA);
  2070. }
  2071. }
  2072. }
  2073. //---------------------------------------
  2074. // Bottom Triangle.
  2075. // gVertex[0] is same as above gVertex[1]
  2076. // gVertex[1] is new and calced from vertex[2].
  2077. // gVertex[2] is same as above.
  2078. gVertex[0].x = gVertex[1].x;
  2079. gVertex[0].y = gVertex[1].y;
  2080. gVertex[0].z = gVertex[1].z;
  2081. gVertex[0].rhw = gVertex[1].rhw;
  2082. gVertex[0].u = gVertex[1].u;
  2083. gVertex[0].v = gVertex[1].v;
  2084. gVertex[0].argb = gVertex[1].argb;
  2085. gVertex[0].frgb = gVertex[1].frgb;
  2086. gVertex[1].x = vertices[2]->wx;
  2087. gVertex[1].y = vertices[2]->wy;
  2088. gVertex[1].z = vertices[2]->wz + TERRAIN_DEPTH_FUDGE;
  2089. gVertex[1].rhw = vertices[2]->ww;
  2090. gVertex[1].u = maxU + cloudOffsetX;;
  2091. gVertex[1].v = maxV + cloudOffsetY;;
  2092. gVertex[1].argb = vertices[2]->pVertex->selected ? SELECTION_COLOR : vertices[2]->lightRGB;
  2093. gVertex[1].frgb = vertices[2]->fogRGB;
  2094. gVertex[0].u = (vertices[1]->vx - Terrain::mapTopLeft3d.x) * oneOverTF + cloudOffsetX;
  2095. gVertex[0].v = (Terrain::mapTopLeft3d.y - vertices[1]->vy) * oneOverTF + cloudOffsetY;
  2096. gVertex[1].u = (vertices[2]->vx - Terrain::mapTopLeft3d.x) * oneOverTF + cloudOffsetX;
  2097. gVertex[1].v = (Terrain::mapTopLeft3d.y - vertices[2]->vy) * oneOverTF + cloudOffsetY;
  2098. gVertex[2].u = (vertices[3]->vx - Terrain::mapTopLeft3d.x) * oneOverTF + cloudOffsetX;
  2099. gVertex[2].v = (Terrain::mapTopLeft3d.y - vertices[3]->vy) * oneOverTF + cloudOffsetY;
  2100. if ((gVertex[0].z >= 0.0f) &&
  2101. (gVertex[0].z < 1.0f) &&
  2102. (gVertex[1].z >= 0.0f) &&
  2103. (gVertex[1].z < 1.0f) &&
  2104. (gVertex[2].z >= 0.0f) &&
  2105. (gVertex[2].z < 1.0f))
  2106. {
  2107. {
  2108. //-----------------------------------------------------------------------------
  2109. // Reject Any triangle which has vertices off screeen in software for now.
  2110. // Do real cliping in geometry layer for software and hardware that needs it!
  2111. if (waterHandle != 0xffffffff)
  2112. {
  2113. DWORD alphaMode0 = Terrain::alphaMiddle;
  2114. DWORD alphaMode1 = Terrain::alphaMiddle;
  2115. DWORD alphaMode2 = Terrain::alphaMiddle;
  2116. if (vertices[1]->pVertex->elevation >= (Terrain::waterElevation - MapData::alphaDepth) )
  2117. {
  2118. alphaMode0 = Terrain::alphaEdge;
  2119. }
  2120. if (vertices[2]->pVertex->elevation >= (Terrain::waterElevation - MapData::alphaDepth) )
  2121. {
  2122. alphaMode1 = Terrain::alphaEdge;
  2123. }
  2124. if (vertices[3]->pVertex->elevation >= (Terrain::waterElevation - MapData::alphaDepth) )
  2125. {
  2126. alphaMode2 = Terrain::alphaEdge;
  2127. }
  2128. if (vertices[1]->pVertex->elevation <= (Terrain::waterElevation - (MapData::alphaDepth * 3.0f)) )
  2129. {
  2130. alphaMode0 = Terrain::alphaDeep;
  2131. }
  2132. if (vertices[2]->pVertex->elevation <= (Terrain::waterElevation - (MapData::alphaDepth * 3.0f)) )
  2133. {
  2134. alphaMode1 = Terrain::alphaDeep;
  2135. }
  2136. if (vertices[3]->pVertex->elevation <= (Terrain::waterElevation - (MapData::alphaDepth * 3.0f)) )
  2137. {
  2138. alphaMode2 = Terrain::alphaDeep;
  2139. }
  2140. gVertex[0].argb = (vertices[1]->lightRGB & 0x00ffffff) + alphaMode0;
  2141. gVertex[1].argb = (vertices[2]->lightRGB & 0x00ffffff) + alphaMode1;
  2142. gVertex[2].argb = (vertices[3]->lightRGB & 0x00ffffff) + alphaMode2;
  2143. if ((gVertex[0].u > MaxMinUV) ||
  2144. (gVertex[0].v > MaxMinUV) ||
  2145. (gVertex[1].u > MaxMinUV) ||
  2146. (gVertex[1].v > MaxMinUV) ||
  2147. (gVertex[2].u > MaxMinUV) ||
  2148. (gVertex[2].v > MaxMinUV))
  2149. {
  2150. //If any are out range, move 'em back in range by adjustfactor.
  2151. float maxU = fmax(gVertex[0].u,fmax(gVertex[1].u,gVertex[2].u));
  2152. maxU = floor(maxU - (MaxMinUV-1.0f));
  2153. float maxV = fmax(gVertex[0].v,fmax(gVertex[1].v,gVertex[2].v));
  2154. maxV = floor(maxV - (MaxMinUV-1.0f));
  2155. gVertex[0].u -= maxU;
  2156. gVertex[1].u -= maxU;
  2157. gVertex[2].u -= maxU;
  2158. gVertex[0].v -= maxV;
  2159. gVertex[1].v -= maxV;
  2160. gVertex[2].v -= maxV;
  2161. }
  2162. if (alphaMode0 + alphaMode1 + alphaMode2)
  2163. {
  2164. mcTextureManager->addVertices(waterHandle,gVertex,MC2_ISTERRAIN | MC2_DRAWALPHA);
  2165. }
  2166. }
  2167. //----------------------------------------------------
  2168. // Draw the sky reflection on the water.
  2169. if (useWaterInterestTexture && (waterDetailHandle != 0xffffffff))
  2170. {
  2171. gos_VERTEX sVertex[3];
  2172. memcpy(sVertex,gVertex,sizeof(gos_VERTEX)*3);
  2173. sVertex[0].u = ((vertices[1]->vx - Terrain::mapTopLeft3d.x) * oneOverWaterTF) + sprayOffsetX;
  2174. sVertex[0].v = ((Terrain::mapTopLeft3d.y - vertices[1]->vy) * oneOverWaterTF) + sprayOffsetY;
  2175. sVertex[1].u = ((vertices[2]->vx - Terrain::mapTopLeft3d.x) * oneOverWaterTF) + sprayOffsetX;
  2176. sVertex[1].v = ((Terrain::mapTopLeft3d.y - vertices[2]->vy) * oneOverWaterTF) + sprayOffsetY;
  2177. sVertex[2].u = ((vertices[3]->vx - Terrain::mapTopLeft3d.x) * oneOverWaterTF) + sprayOffsetX;
  2178. sVertex[2].v = ((Terrain::mapTopLeft3d.y - vertices[3]->vy) * oneOverWaterTF) + sprayOffsetY;
  2179. sVertex[0].argb = (sVertex[0].argb & 0xff000000) + 0xffffff;
  2180. sVertex[1].argb = (sVertex[1].argb & 0xff000000) + 0xffffff;
  2181. sVertex[2].argb = (sVertex[2].argb & 0xff000000) + 0xffffff;
  2182. mcTextureManager->addVertices(waterDetailHandle,sVertex,MC2_ISTERRAIN | MC2_DRAWALPHA);
  2183. }
  2184. }
  2185. }
  2186. }
  2187. }
  2188. }
  2189. //---------------------------------------------------------------------------
  2190. long DrawDebugCells = 0;
  2191. void TerrainQuad::drawLine (void)
  2192. {
  2193. long clipped1 = vertices[0]->clipInfo + vertices[1]->clipInfo + vertices[2]->clipInfo;
  2194. long clipped2 = vertices[0]->clipInfo + vertices[2]->clipInfo + vertices[3]->clipInfo;
  2195. if (uvMode == BOTTOMLEFT)
  2196. {
  2197. clipped1 = vertices[0]->clipInfo + vertices[1]->clipInfo + vertices[3]->clipInfo;
  2198. clipped2 = vertices[1]->clipInfo + vertices[2]->clipInfo + vertices[3]->clipInfo;
  2199. }
  2200. //------------------------------------------------------------
  2201. // Draw the Tile block lines at depth just above base tiles.
  2202. long color = XP_WHITE;
  2203. if (uvMode == BOTTOMRIGHT)
  2204. {
  2205. if (clipped1 != 0)
  2206. {
  2207. Stuff::Vector4D pos1(vertices[0]->px,vertices[0]->py,vertices[0]->pz-0.002f,1.0f / vertices[0]->pw);
  2208. Stuff::Vector4D pos2(vertices[1]->px,vertices[1]->py,vertices[1]->pz-0.002f,1.0f / vertices[1]->pw);
  2209. {
  2210. LineElement newElement(pos1,pos2,color,NULL);
  2211. newElement.draw();
  2212. }
  2213. pos1.x = vertices[1]->px;
  2214. pos1.y = vertices[1]->py;
  2215. pos2.x = vertices[2]->px;
  2216. pos2.y = vertices[2]->py;
  2217. {
  2218. LineElement newElement(pos1,pos2,color,NULL);
  2219. newElement.draw();
  2220. }
  2221. pos1.x = vertices[2]->px;
  2222. pos1.y = vertices[2]->py;
  2223. pos1.z = vertices[2]->pz - 0.002f;
  2224. pos2.x = vertices[0]->px;
  2225. pos2.y = vertices[0]->py;
  2226. pos2.z = vertices[0]->pz - 0.002f;
  2227. {
  2228. LineElement newElement(pos1,pos2,color,NULL);
  2229. newElement.draw();
  2230. }
  2231. }
  2232. if (clipped2 != 0)
  2233. {
  2234. Stuff::Vector4D pos1(vertices[0]->px,vertices[0]->py,vertices[0]->pz-0.002f,1.0f / vertices[0]->pw);
  2235. Stuff::Vector4D pos2(vertices[2]->px,vertices[2]->py,vertices[2]->pz-0.002f,1.0f / vertices[2]->pw);
  2236. {
  2237. LineElement newElement(pos1,pos2,color,NULL);
  2238. newElement.draw();
  2239. }
  2240. pos1.x = vertices[2]->px;
  2241. pos1.y = vertices[2]->py;
  2242. pos1.z = vertices[2]->pz - 0.002f;
  2243. pos2.x = vertices[3]->px;
  2244. pos2.y = vertices[3]->py;
  2245. pos2.z = vertices[3]->pz - 0.002f;
  2246. {
  2247. LineElement newElement(pos1,pos2,color,NULL);
  2248. newElement.draw();
  2249. }
  2250. pos1.x = vertices[3]->px;
  2251. pos1.y = vertices[3]->py;
  2252. pos1.z = vertices[3]->pz - 0.002f;
  2253. pos2.x = vertices[0]->px;
  2254. pos2.y = vertices[0]->py;
  2255. pos2.z = vertices[0]->pz - 0.002f;
  2256. {
  2257. LineElement newElement(pos1,pos2,color,NULL);
  2258. newElement.draw();
  2259. }
  2260. }
  2261. }
  2262. else
  2263. {
  2264. if (clipped1 != 0)
  2265. {
  2266. Stuff::Vector4D pos1(vertices[0]->px,vertices[0]->py,vertices[0]->pz-0.002f,1.0f / vertices[0]->pw);
  2267. Stuff::Vector4D pos2(vertices[1]->px,vertices[1]->py,vertices[1]->pz-0.002f,1.0f / vertices[1]->pw);
  2268. {
  2269. LineElement newElement(pos1,pos2,color,NULL);
  2270. newElement.draw();
  2271. }
  2272. pos1.x = vertices[1]->px;
  2273. pos1.y = vertices[1]->py;
  2274. pos1.z = vertices[1]->pz - 0.002f;
  2275. pos2.x = vertices[3]->px;
  2276. pos2.y = vertices[3]->py;
  2277. pos2.z = vertices[3]->pz - 0.002f;
  2278. {
  2279. LineElement newElement(pos1,pos2,color,NULL);
  2280. newElement.draw();
  2281. }
  2282. pos1.x = vertices[3]->px;
  2283. pos1.y = vertices[3]->py;
  2284. pos1.z = vertices[3]->pz - 0.002f;
  2285. pos2.x = vertices[0]->px;
  2286. pos2.y = vertices[0]->py;
  2287. pos2.z = vertices[0]->pz - 0.002f;
  2288. {
  2289. LineElement newElement(pos1,pos2,color,NULL);
  2290. newElement.draw();
  2291. }
  2292. }
  2293. if (clipped2 != 0)
  2294. {
  2295. Stuff::Vector4D pos1(vertices[1]->px,vertices[1]->py,vertices[1]->pz-0.002f,1.0f / vertices[1]->pw);
  2296. Stuff::Vector4D pos2(vertices[2]->px,vertices[2]->py,vertices[2]->pz-0.002f,1.0f / vertices[2]->pw);
  2297. {
  2298. LineElement newElement(pos1,pos2,color,NULL);
  2299. newElement.draw();
  2300. }
  2301. pos1.x = vertices[2]->px;
  2302. pos1.y = vertices[2]->py;
  2303. pos1.z = vertices[2]->pz - 0.002f;
  2304. pos2.x = vertices[3]->px;
  2305. pos2.y = vertices[3]->py;
  2306. pos2.z = vertices[3]->pz - 0.002f;
  2307. {
  2308. LineElement newElement(pos1,pos2,color,NULL);
  2309. newElement.draw();
  2310. }
  2311. pos1.x = vertices[3]->px;
  2312. pos1.y = vertices[3]->py;
  2313. pos1.z = vertices[3]->pz - 0.002f;
  2314. pos2.x = vertices[1]->px;
  2315. pos2.y = vertices[1]->py;
  2316. pos2.z = vertices[1]->pz - 0.002f;
  2317. {
  2318. LineElement newElement(pos1,pos2,color,NULL);
  2319. newElement.draw();
  2320. }
  2321. }
  2322. }
  2323. //------------------------------------------------------------
  2324. // Draw Movement Map Grid.
  2325. // Once movement is split up, turn this back on for editor -fs
  2326. // I need ALL cells drawn to check elevation Code
  2327. if (clipped1 != 0)
  2328. {
  2329. //--------------------------------------------------------------------
  2330. // Display the ScenarioMap cell grid, as well, displaying open\blocked
  2331. // states...
  2332. float cellWidth = Terrain::worldUnitsPerVertex / MAPCELL_DIM;
  2333. //cellWidth -= 5.0;
  2334. long rowCol = vertices[0]->posTile;
  2335. long tileR = rowCol>>16;
  2336. long tileC = rowCol & 0x0000ffff;
  2337. if (GameMap)
  2338. {
  2339. for (long cellR = 0; cellR < MAPCELL_DIM; cellR++)
  2340. {
  2341. for (long cellC = 0; cellC < MAPCELL_DIM; cellC++)
  2342. {
  2343. long actualCellRow = tileR * MAPCELL_DIM + cellR;
  2344. long actualCellCol = tileC * MAPCELL_DIM + cellC;
  2345. MapCellPtr curCell = NULL;
  2346. if (GameMap->inBounds(actualCellRow, actualCellCol))
  2347. curCell = GameMap->getCell(actualCellRow, actualCellCol);
  2348. if (!curCell ||
  2349. curCell->getDebug() ||
  2350. !curCell->getPassable() ||
  2351. curCell->getPathlock(0) ||
  2352. curCell->getDeepWater() ||
  2353. curCell->getShallowWater() ||
  2354. curCell->getForest())
  2355. {
  2356. Stuff::Vector4D pos1;
  2357. Stuff::Vector4D pos2;
  2358. Stuff::Vector4D pos3;
  2359. Stuff::Vector4D pos4;
  2360. Stuff::Vector3D thePoint(vertices[0]->vx,vertices[0]->vy,vertices[0]->pVertex->elevation);
  2361. thePoint.x += (cellC) * cellWidth;
  2362. thePoint.y -= (cellR) * cellWidth;
  2363. thePoint.z = land->getTerrainElevation(thePoint);
  2364. eye->projectZ(thePoint,pos4);
  2365. thePoint.x += cellWidth;
  2366. thePoint.z = land->getTerrainElevation(thePoint);
  2367. eye->projectZ(thePoint,pos1);
  2368. thePoint.y -= cellWidth;
  2369. thePoint.z = land->getTerrainElevation(thePoint);
  2370. eye->projectZ(thePoint,pos2);
  2371. thePoint.x -= cellWidth;
  2372. thePoint.z = land->getTerrainElevation(thePoint);
  2373. eye->projectZ(thePoint,pos3);
  2374. pos1.z -= 0.002f;
  2375. pos2.z -= 0.002f;
  2376. pos3.z -= 0.002f;
  2377. pos4.z -= 0.002f;
  2378. DWORD color = XP_RED;
  2379. if (!curCell)
  2380. {
  2381. color = XP_GREEN;
  2382. }
  2383. else if (curCell->getDebug() && DrawDebugCells)
  2384. {
  2385. color = XP_YELLOW;
  2386. }
  2387. else if (curCell->getPathlock(0))
  2388. {
  2389. color = XP_YELLOW;
  2390. }
  2391. else if (curCell->getForest())
  2392. {
  2393. color = SB_ORANGE;
  2394. }
  2395. else if (!curCell->getPassable())
  2396. {
  2397. color = SB_RED;
  2398. }
  2399. else if (curCell->getDeepWater())
  2400. {
  2401. color = SB_ORANGE;
  2402. }
  2403. else if (curCell->getShallowWater())
  2404. {
  2405. color = XP_BLUE;
  2406. }
  2407. {
  2408. LineElement newElement(pos1,pos2,color,NULL);
  2409. newElement.draw();
  2410. }
  2411. {
  2412. LineElement newElement(pos2,pos3,color,NULL);
  2413. newElement.draw();
  2414. }
  2415. {
  2416. LineElement newElement(pos3,pos4,color,NULL);
  2417. newElement.draw();
  2418. }
  2419. {
  2420. LineElement newElement(pos1,pos4,color,NULL);
  2421. newElement.draw();
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. if (GlobalMoveMap[0]->badLoad)
  2429. return;
  2430. if (clipped1 != 0)
  2431. {
  2432. float cellWidth = Terrain::worldUnitsPerVertex / MAPCELL_DIM;
  2433. cellWidth -= 5.0;
  2434. long rowCol = vertices[0]->posTile;
  2435. long tileR = rowCol>>16;
  2436. long tileC = rowCol & 0x0000ffff;
  2437. long cellR = tileR * MAPCELL_DIM;
  2438. long cellC = tileC * MAPCELL_DIM;
  2439. for (long currentDoor = 0;currentDoor < GlobalMoveMap[0]->numDoors;currentDoor++)
  2440. {
  2441. if ((GlobalMoveMap[0]->doors[currentDoor].row >= cellR) &&
  2442. (GlobalMoveMap[0]->doors[currentDoor].row < (cellR + MAPCELL_DIM)) &&
  2443. (GlobalMoveMap[0]->doors[currentDoor].col >= cellC) &&
  2444. (GlobalMoveMap[0]->doors[currentDoor].col < (cellC + MAPCELL_DIM)))
  2445. {
  2446. Stuff::Vector4D pos1;
  2447. Stuff::Vector4D pos2;
  2448. Stuff::Vector4D pos3;
  2449. Stuff::Vector4D pos4;
  2450. long xLength = 1;
  2451. long yLength = 1;
  2452. if (GlobalMoveMap[0]->doors[currentDoor].direction[0] == 1)
  2453. {
  2454. yLength = GlobalMoveMap[0]->doors[currentDoor].length;
  2455. }
  2456. if (GlobalMoveMap[0]->doors[currentDoor].direction[0] == 2)
  2457. {
  2458. xLength = GlobalMoveMap[0]->doors[currentDoor].length;
  2459. }
  2460. Stuff::Vector3D thePoint(vertices[0]->vx,vertices[0]->vy,vertices[0]->pVertex->elevation);
  2461. thePoint.x += (GlobalMoveMap[0]->doors[currentDoor].col - cellC) * cellWidth;
  2462. thePoint.y -= (GlobalMoveMap[0]->doors[currentDoor].row - cellR) * cellWidth;
  2463. thePoint.z = land->getTerrainElevation(thePoint);
  2464. eye->projectZ(thePoint,pos4);
  2465. thePoint.x += (xLength) * cellWidth;
  2466. thePoint.z = land->getTerrainElevation(thePoint);
  2467. eye->projectZ(thePoint,pos1);
  2468. thePoint.y -= (yLength) * cellWidth;
  2469. thePoint.z = land->getTerrainElevation(thePoint);
  2470. eye->projectZ(thePoint,pos2);
  2471. thePoint.x -= (xLength) * cellWidth;
  2472. thePoint.z = land->getTerrainElevation(thePoint);
  2473. eye->projectZ(thePoint,pos3);
  2474. pos1.z -= 0.002f;
  2475. pos2.z -= 0.002f;
  2476. pos3.z -= 0.002f;
  2477. pos4.z -= 0.002f;
  2478. {
  2479. LineElement newElement(pos1,pos2,XP_GREEN,NULL);
  2480. newElement.draw();
  2481. }
  2482. {
  2483. LineElement newElement(pos2,pos3,XP_GREEN,NULL);
  2484. newElement.draw();
  2485. }
  2486. {
  2487. LineElement newElement(pos3,pos4,XP_GREEN,NULL);
  2488. newElement.draw();
  2489. }
  2490. {
  2491. LineElement newElement(pos1,pos4,XP_GREEN,NULL);
  2492. newElement.draw();
  2493. }
  2494. }
  2495. }
  2496. }
  2497. }
  2498. //-----------------------------------------------------------------------------------------------
  2499. void TerrainQuad::drawLOSLine (void)
  2500. {
  2501. long clipped1 = vertices[0]->clipInfo + vertices[1]->clipInfo + vertices[2]->clipInfo;
  2502. long clipped2 = vertices[0]->clipInfo + vertices[2]->clipInfo + vertices[3]->clipInfo;
  2503. if (uvMode == BOTTOMLEFT)
  2504. {
  2505. clipped1 = vertices[0]->clipInfo + vertices[1]->clipInfo + vertices[3]->clipInfo;
  2506. clipped2 = vertices[1]->clipInfo + vertices[2]->clipInfo + vertices[3]->clipInfo;
  2507. }
  2508. //------------------------------------------------------------
  2509. // Draw the Tile block lines at depth just above base tiles.
  2510. //------------------------------------------------------------
  2511. // Draw LOS Map Grid.
  2512. // Draw a color for LOS cell height data based on height. Draw NOTHING if cell height is ZERO!!
  2513. if (clipped1 != 0)
  2514. {
  2515. //--------------------------------------------------------------------
  2516. float cellWidth = Terrain::worldUnitsPerVertex / MAPCELL_DIM;
  2517. long rowCol = vertices[0]->posTile;
  2518. long tileR = rowCol>>16;
  2519. long tileC = rowCol & 0x0000ffff;
  2520. if (GameMap)
  2521. {
  2522. for (long cellR = 0; cellR < MAPCELL_DIM; cellR++)
  2523. {
  2524. for (long cellC = 0; cellC < MAPCELL_DIM; cellC++)
  2525. {
  2526. long actualCellRow = tileR * MAPCELL_DIM + cellR;
  2527. long actualCellCol = tileC * MAPCELL_DIM + cellC;
  2528. MapCellPtr curCell = NULL;
  2529. if (GameMap->inBounds(actualCellRow, actualCellCol))
  2530. curCell = GameMap->getCell(actualCellRow, actualCellCol);
  2531. if (curCell && curCell->getLocalHeight())
  2532. {
  2533. Stuff::Vector4D pos1;
  2534. Stuff::Vector4D pos2;
  2535. Stuff::Vector4D pos3;
  2536. Stuff::Vector4D pos4;
  2537. Stuff::Vector3D thePoint(vertices[0]->vx,vertices[0]->vy,vertices[0]->pVertex->elevation);
  2538. thePoint.x += (cellC) * cellWidth;
  2539. thePoint.y -= (cellR) * cellWidth;
  2540. thePoint.z = land->getTerrainElevation(thePoint);
  2541. eye->projectZ(thePoint,pos4);
  2542. thePoint.x += cellWidth;
  2543. thePoint.z = land->getTerrainElevation(thePoint);
  2544. eye->projectZ(thePoint,pos1);
  2545. thePoint.y -= cellWidth;
  2546. thePoint.z = land->getTerrainElevation(thePoint);
  2547. eye->projectZ(thePoint,pos2);
  2548. thePoint.x -= cellWidth;
  2549. thePoint.z = land->getTerrainElevation(thePoint);
  2550. eye->projectZ(thePoint,pos3);
  2551. pos1.z -= 0.002f;
  2552. pos2.z -= 0.002f;
  2553. pos3.z -= 0.002f;
  2554. pos4.z -= 0.002f;
  2555. DWORD color = XP_BLACK;
  2556. if (curCell->getLocalHeight() < 2)
  2557. {
  2558. color = XP_BLACK;
  2559. }
  2560. else if (curCell->getLocalHeight() < 4)
  2561. {
  2562. color = XP_GRAY;
  2563. }
  2564. else if (curCell->getLocalHeight() < 6)
  2565. {
  2566. color = XP_RED;
  2567. }
  2568. else if (curCell->getLocalHeight() < 8)
  2569. {
  2570. color = XP_ORANGE;
  2571. }
  2572. else if (curCell->getLocalHeight() < 10)
  2573. {
  2574. color = XP_YELLOW;
  2575. }
  2576. else if (curCell->getLocalHeight() < 12)
  2577. {
  2578. color = XP_GREEN;
  2579. }
  2580. else if (curCell->getLocalHeight() < 14)
  2581. {
  2582. color = XP_BLUE;
  2583. }
  2584. else if (curCell->getLocalHeight() <= 16)
  2585. {
  2586. color = XP_WHITE;
  2587. }
  2588. {
  2589. LineElement newElement(pos1,pos2,color,NULL);
  2590. newElement.draw();
  2591. }
  2592. {
  2593. LineElement newElement(pos2,pos3,color,NULL);
  2594. newElement.draw();
  2595. }
  2596. {
  2597. LineElement newElement(pos3,pos4,color,NULL);
  2598. newElement.draw();
  2599. }
  2600. {
  2601. LineElement newElement(pos1,pos4,color,NULL);
  2602. newElement.draw();
  2603. }
  2604. }
  2605. }
  2606. }
  2607. }
  2608. }
  2609. }
  2610. //---------------------------------------------------------------------------
  2611. void TerrainQuad::drawDebugCellLine (void)
  2612. {
  2613. long clipped1 = vertices[0]->clipInfo + vertices[1]->clipInfo + vertices[2]->clipInfo;
  2614. long clipped2 = vertices[0]->clipInfo + vertices[2]->clipInfo + vertices[3]->clipInfo;
  2615. if (uvMode == BOTTOMLEFT)
  2616. {
  2617. clipped1 = vertices[0]->clipInfo + vertices[1]->clipInfo + vertices[3]->clipInfo;
  2618. clipped2 = vertices[1]->clipInfo + vertices[2]->clipInfo + vertices[3]->clipInfo;
  2619. }
  2620. //------------------------------------------------------------
  2621. // Draw the Tile block lines at depth just above base tiles.
  2622. if (uvMode == BOTTOMRIGHT)
  2623. {
  2624. if (clipped1 != 0)
  2625. {
  2626. Stuff::Vector4D pos1(vertices[0]->px,vertices[0]->py,HUD_DEPTH,1.0f / vertices[0]->pw);
  2627. Stuff::Vector4D pos2(vertices[1]->px,vertices[1]->py,HUD_DEPTH,1.0f / vertices[1]->pw);
  2628. {
  2629. //LineElement newElement(pos1,pos2,color,NULL);
  2630. //newElement.draw();
  2631. }
  2632. pos1.x = vertices[1]->px;
  2633. pos1.y = vertices[1]->py;
  2634. pos2.x = vertices[2]->px;
  2635. pos2.y = vertices[2]->py;
  2636. {
  2637. //LineElement newElement(pos1,pos2,color,NULL);
  2638. //newElement.draw();
  2639. }
  2640. pos1.x = vertices[2]->px;
  2641. pos1.y = vertices[2]->py;
  2642. pos2.x = vertices[0]->px;
  2643. pos2.y = vertices[0]->py;
  2644. {
  2645. //LineElement newElement(pos1,pos2,color,NULL);
  2646. //newElement.draw();
  2647. }
  2648. }
  2649. if (clipped2 != 0)
  2650. {
  2651. Stuff::Vector4D pos1(vertices[0]->px,vertices[0]->py,HUD_DEPTH,1.0f / vertices[0]->pw);
  2652. Stuff::Vector4D pos2(vertices[2]->px,vertices[2]->py,HUD_DEPTH,1.0f / vertices[2]->pw);
  2653. {
  2654. //LineElement newElement(pos1,pos2,color,NULL);
  2655. //newElement.draw();
  2656. }
  2657. pos1.x = vertices[2]->px;
  2658. pos1.y = vertices[2]->py;
  2659. pos2.x = vertices[3]->px;
  2660. pos2.y = vertices[3]->py;
  2661. {
  2662. //LineElement newElement(pos1,pos2,color,NULL);
  2663. //newElement.draw();
  2664. }
  2665. pos1.x = vertices[3]->px;
  2666. pos1.y = vertices[3]->py;
  2667. pos2.x = vertices[0]->px;
  2668. pos2.y = vertices[0]->py;
  2669. {
  2670. //LineElement newElement(pos1,pos2,color,NULL);
  2671. //newElement.draw();
  2672. }
  2673. }
  2674. }
  2675. else
  2676. {
  2677. if (clipped1 != 0)
  2678. {
  2679. Stuff::Vector4D pos1(vertices[0]->px,vertices[0]->py,HUD_DEPTH,1.0f / vertices[0]->pw);
  2680. Stuff::Vector4D pos2(vertices[1]->px,vertices[1]->py,HUD_DEPTH,1.0f / vertices[1]->pw);
  2681. {
  2682. //LineElement newElement(pos1,pos2,color,NULL);
  2683. //newElement.draw();
  2684. }
  2685. pos1.x = vertices[1]->px;
  2686. pos1.y = vertices[1]->py;
  2687. pos2.x = vertices[3]->px;
  2688. pos2.y = vertices[3]->py;
  2689. {
  2690. //LineElement newElement(pos1,pos2,color,NULL);
  2691. //newElement.draw();
  2692. }
  2693. pos1.x = vertices[3]->px;
  2694. pos1.y = vertices[3]->py;
  2695. pos2.x = vertices[0]->px;
  2696. pos2.y = vertices[0]->py;
  2697. {
  2698. //LineElement newElement(pos1,pos2,color,NULL);
  2699. //newElement.draw();
  2700. }
  2701. }
  2702. if (clipped2 != 0)
  2703. {
  2704. Stuff::Vector4D pos1(vertices[1]->px,vertices[1]->py,HUD_DEPTH,1.0f / vertices[1]->pw);
  2705. Stuff::Vector4D pos2(vertices[2]->px,vertices[2]->py,HUD_DEPTH,1.0f / vertices[2]->pw);
  2706. {
  2707. //LineElement newElement(pos1,pos2,color,NULL);
  2708. //newElement.draw();
  2709. }
  2710. pos1.x = vertices[2]->px;
  2711. pos1.y = vertices[2]->py;
  2712. pos2.x = vertices[3]->px;
  2713. pos2.y = vertices[3]->py;
  2714. {
  2715. //LineElement newElement(pos1,pos2,color,NULL);
  2716. //newElement.draw();
  2717. }
  2718. pos1.x = vertices[3]->px;
  2719. pos1.y = vertices[3]->py;
  2720. pos2.x = vertices[1]->px;
  2721. pos2.y = vertices[1]->py;
  2722. {
  2723. //LineElement newElement(pos1,pos2,color,NULL);
  2724. //newElement.draw();
  2725. }
  2726. }
  2727. }
  2728. //------------------------------------------------------------
  2729. // Draw Movement Map Grid.
  2730. // Once movement is split up, turn this back on for editor -fs
  2731. // I need ALL cells drawn to check elevation Code
  2732. if (clipped1 != 0)
  2733. {
  2734. //--------------------------------------------------------------------
  2735. // Display the ScenarioMap cell grid, as well, displaying open\blocked
  2736. // states...
  2737. float cellWidth = Terrain::worldUnitsPerVertex / MAPCELL_DIM;
  2738. //cellWidth -= 5.0;
  2739. long rowCol = vertices[0]->posTile;
  2740. long tileR = rowCol>>16;
  2741. long tileC = rowCol & 0x0000ffff;
  2742. if (GameMap)
  2743. {
  2744. for (long cellR = 0; cellR < MAPCELL_DIM; cellR++)
  2745. {
  2746. for (long cellC = 0; cellC < MAPCELL_DIM; cellC++)
  2747. {
  2748. long actualCellRow = tileR * MAPCELL_DIM + cellR;
  2749. long actualCellCol = tileC * MAPCELL_DIM + cellC;
  2750. MapCellPtr curCell = NULL;
  2751. if (GameMap->inBounds(actualCellRow, actualCellCol))
  2752. curCell = GameMap->getCell(actualCellRow, actualCellCol);
  2753. if (!curCell || curCell->getDebug())
  2754. {
  2755. Stuff::Vector4D pos1;
  2756. Stuff::Vector4D pos2;
  2757. Stuff::Vector4D pos3;
  2758. Stuff::Vector4D pos4;
  2759. Stuff::Vector3D thePoint(vertices[0]->vx,vertices[0]->vy,vertices[0]->pVertex->elevation);
  2760. thePoint.x += (cellC) * cellWidth;
  2761. thePoint.y -= (cellR) * cellWidth;
  2762. thePoint.z = land->getTerrainElevation(thePoint);
  2763. eye->projectZ(thePoint,pos4);
  2764. thePoint.x += cellWidth;
  2765. thePoint.z = land->getTerrainElevation(thePoint);
  2766. eye->projectZ(thePoint,pos1);
  2767. thePoint.y -= cellWidth;
  2768. thePoint.z = land->getTerrainElevation(thePoint);
  2769. eye->projectZ(thePoint,pos2);
  2770. thePoint.x -= cellWidth;
  2771. thePoint.z = land->getTerrainElevation(thePoint);
  2772. eye->projectZ(thePoint,pos3);
  2773. pos1.z = pos2.z = pos3.z = pos4.z = HUD_DEPTH;
  2774. DWORD color = XP_RED;
  2775. if (!curCell)
  2776. {
  2777. color = XP_GREEN;
  2778. }
  2779. else {
  2780. static DWORD debugColors[4] = {0, XP_RED, XP_WHITE, XP_BLUE};
  2781. DWORD cellDebugValue = curCell->getDebug();
  2782. if (cellDebugValue)
  2783. color = debugColors[cellDebugValue];
  2784. }
  2785. /* else if (curCell->getPathlock())
  2786. {
  2787. color = XP_YELLOW;
  2788. }
  2789. else if (!curCell->getLineOfSight())
  2790. {
  2791. color = XP_BLUE;
  2792. }
  2793. else if (!curCell->getPassable())
  2794. {
  2795. color = SB_RED;
  2796. }
  2797. */
  2798. {
  2799. LineElement newElement(pos1,pos2,color,NULL);
  2800. newElement.draw();
  2801. }
  2802. {
  2803. LineElement newElement(pos2,pos3,color,NULL);
  2804. newElement.draw();
  2805. }
  2806. {
  2807. LineElement newElement(pos3,pos4,color,NULL);
  2808. newElement.draw();
  2809. }
  2810. {
  2811. LineElement newElement(pos1,pos4,color,NULL);
  2812. newElement.draw();
  2813. }
  2814. }
  2815. }
  2816. }
  2817. }
  2818. }
  2819. }
  2820. //---------------------------------------------------------------------------
  2821. void TerrainQuad::drawMine (void)
  2822. {
  2823. long clipped1 = vertices[0]->clipInfo + vertices[1]->clipInfo + vertices[2]->clipInfo;
  2824. long clipped2 = vertices[0]->clipInfo + vertices[2]->clipInfo + vertices[3]->clipInfo;
  2825. if (uvMode == BOTTOMLEFT)
  2826. {
  2827. clipped1 = vertices[0]->clipInfo + vertices[1]->clipInfo + vertices[3]->clipInfo;
  2828. clipped2 = vertices[1]->clipInfo + vertices[2]->clipInfo + vertices[3]->clipInfo;
  2829. }
  2830. //------------------------------------------------------------
  2831. // Draw Mines.
  2832. // All mines are visible all the time!
  2833. if ((clipped1 != 0) || (clipped2 != 0))
  2834. {
  2835. long cellPos = 0;
  2836. float cellWidth = Terrain::worldUnitsPerCell;
  2837. for (long cellR = 0; cellR < MAPCELL_DIM; cellR++)
  2838. {
  2839. for (long cellC = 0; cellC < MAPCELL_DIM; cellC++,cellPos++)
  2840. {
  2841. //--------------------------------------------------------------------
  2842. bool drawMine = false;
  2843. bool drawBlownMine = false;
  2844. if (mineResult.getMine(cellPos) == 1)
  2845. drawMine = true;
  2846. if (mineResult.getMine(cellPos) == 2)
  2847. drawBlownMine = true;
  2848. if (drawMine || drawBlownMine)
  2849. {
  2850. Stuff::Vector4D pos1;
  2851. Stuff::Vector4D pos2;
  2852. Stuff::Vector4D pos3;
  2853. Stuff::Vector4D pos4;
  2854. //------------------------------------------------------------------------------------
  2855. // Dig the actual Vertex information out of the projected vertices already done.
  2856. // In this way, the draw requires only interpolation and not Giant Matrix multiplies.
  2857. Stuff::Vector3D thePoint(vertices[0]->vx,vertices[0]->vy,vertices[0]->pVertex->elevation);
  2858. thePoint.x += (cellC) * cellWidth;
  2859. thePoint.y -= (cellR) * cellWidth;
  2860. thePoint.z = land->getTerrainElevation(thePoint);
  2861. eye->projectZ(thePoint,pos4);
  2862. thePoint.x += cellWidth;
  2863. thePoint.z = land->getTerrainElevation(thePoint);
  2864. eye->projectZ(thePoint,pos1);
  2865. thePoint.y -= cellWidth;
  2866. thePoint.z = land->getTerrainElevation(thePoint);
  2867. eye->projectZ(thePoint,pos2);
  2868. thePoint.x -= cellWidth;
  2869. thePoint.z = land->getTerrainElevation(thePoint);
  2870. eye->projectZ(thePoint,pos3);
  2871. //------------------------------------
  2872. // Replace with New RIA code
  2873. gos_VERTEX gVertex[3];
  2874. gos_VERTEX sVertex[3];
  2875. gVertex[0].x = sVertex[0].x = pos1.x;
  2876. gVertex[0].y = sVertex[0].y = pos1.y;
  2877. gVertex[0].z = sVertex[0].z = pos1.z;
  2878. gVertex[0].rhw = sVertex[0].rhw = pos1.w;
  2879. gVertex[0].u = sVertex[0].u = 0.0f;
  2880. gVertex[0].v = sVertex[0].v = 0.0f;
  2881. gVertex[0].argb = sVertex[0].argb = vertices[0]->lightRGB;
  2882. gVertex[0].frgb = sVertex[0].frgb = vertices[0]->fogRGB;
  2883. gVertex[1].x = pos2.x;
  2884. gVertex[1].y = pos2.y;
  2885. gVertex[1].z = pos2.z;
  2886. gVertex[1].rhw = pos2.w;
  2887. gVertex[1].u = 0.999999999f;
  2888. gVertex[1].v = 0.0f;
  2889. gVertex[1].argb = vertices[1]->lightRGB;
  2890. gVertex[1].frgb = vertices[1]->fogRGB;
  2891. gVertex[2].x = sVertex[1].x = pos3.x;
  2892. gVertex[2].y = sVertex[1].y = pos3.y;
  2893. gVertex[2].z = sVertex[1].z = pos3.z;
  2894. gVertex[2].rhw = sVertex[1].rhw = pos3.w;
  2895. gVertex[2].u = sVertex[1].u = 0.999999999f;
  2896. gVertex[2].v = sVertex[1].v = 0.999999999f;
  2897. gVertex[2].argb = sVertex[1].argb = vertices[2]->lightRGB;
  2898. gVertex[2].frgb = sVertex[1].frgb = vertices[2]->fogRGB;
  2899. sVertex[2].x = pos4.x;
  2900. sVertex[2].y = pos4.y;
  2901. sVertex[2].z = pos4.z;
  2902. sVertex[2].rhw = pos4.w;
  2903. sVertex[2].u = 0.0f;
  2904. sVertex[2].v = 0.999999999f;
  2905. sVertex[2].argb = vertices[3]->lightRGB;
  2906. sVertex[2].frgb = vertices[3]->fogRGB;
  2907. if ((gVertex[0].z >= 0.0f) &&
  2908. (gVertex[0].z < 1.0f) &&
  2909. (gVertex[1].z >= 0.0f) &&
  2910. (gVertex[1].z < 1.0f) &&
  2911. (gVertex[2].z >= 0.0f) &&
  2912. (gVertex[2].z < 1.0f) &&
  2913. (sVertex[0].z >= 0.0f) &&
  2914. (sVertex[0].z < 1.0f) &&
  2915. (sVertex[1].z >= 0.0f) &&
  2916. (sVertex[1].z < 1.0f) &&
  2917. (sVertex[2].z >= 0.0f) &&
  2918. (sVertex[2].z < 1.0f))
  2919. {
  2920. if (drawBlownMine)
  2921. {
  2922. mcTextureManager->addVertices(blownTextureHandle,gVertex,MC2_DRAWALPHA);
  2923. mcTextureManager->addVertices(blownTextureHandle,sVertex,MC2_DRAWALPHA);
  2924. }
  2925. else
  2926. {
  2927. mcTextureManager->addVertices(mineTextureHandle,gVertex,MC2_DRAWALPHA);
  2928. mcTextureManager->addVertices(mineTextureHandle,sVertex,MC2_DRAWALPHA);
  2929. }
  2930. }
  2931. }
  2932. }
  2933. }
  2934. }
  2935. }
  2936. //---------------------------------------------------------------------------