RenderSoft.cpp 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537
  1. #ifdef _soft
  2. #include "Hunt.h"
  3. #include "stdio.h"
  4. /*
  5. typedef struct _tmpoint {
  6. int x, y, tx, ty;
  7. } tmpoint;
  8. */
  9. typedef struct _CharListItem {
  10. int CType, Index;
  11. } TCharListItem;
  12. typedef struct _CharListLine {
  13. int ICount;
  14. TCharListItem Items[256];
  15. } TCharListLine;
  16. TCharListLine ChRenderList[128];
  17. Vector2di ORList[2][2048];
  18. int ORLCount[2];
  19. int rmlistselector;
  20. void RenderBMPModel2 (TBMPModel*, float, float, float, int);
  21. //================================================================//
  22. int xa; int xb; int xa16; int xb16;
  23. int v1, v2, v3,
  24. l1, l2, l3,
  25. x1, Y1, tx1, ty1, lt1, zdepth1,
  26. x2, y2, tx2, ty2, lt2, zdepth2,
  27. x3, y3, tx3, ty3, lt3, zdepth3;
  28. int dx1, dx2, dx3,
  29. dtx1, dty1, dlt1,
  30. dtx2, dty2, dlt2,
  31. dtx3, dty3, dlt3,
  32. tyb, tya, txa, txb, lta, ltb,
  33. ddtx1, ddty1, ddtx2, ddty2, ddtx3, ddty3;
  34. int ctdy, ctdx, cdlt;
  35. int _sp;
  36. float k;
  37. BOOL LockWater;
  38. int OpacityMode;
  39. void STTextOut(int x, int y, LPSTR t, int color)
  40. {
  41. SetTextColor(hdcCMain, 0x00000000);
  42. TextOut(hdcCMain, x+1, y+1, t, strlen(t));
  43. SetTextColor(hdcCMain, color);
  44. TextOut(hdcCMain, x, y, t, strlen(t));
  45. }
  46. void ShowControlElements()
  47. {
  48. HBITMAP hbmpOld = SelectObject(hdcCMain, hbmpVideoBuf);
  49. char buf[128];
  50. SetBkMode(hdcCMain, TRANSPARENT);
  51. if (TIMER) {
  52. wsprintf(buf,"msc: %d", TimeDt);
  53. STTextOut(WinEX-70, 10, buf, 0x0020A0A0);
  54. wsprintf(buf,"polys: %d", dFacesCount);
  55. STTextOut(WinEX-90, 24, buf, 0x0020A0A0);
  56. }
  57. if (MessageList.timeleft) {
  58. if (RealTime>MessageList.timeleft) MessageList.timeleft = 0;
  59. STTextOut(10, 10, MessageList.mtext, 0x0020A0A0);
  60. }
  61. if (ExitTime) {
  62. int y = WinH / 3;
  63. wsprintf(buf,"Preparing for evacuation...");
  64. STTextOut(VideoCX - GetTextW(hdcMain, buf)/2, y, buf, 0x0060C0D0);
  65. wsprintf(buf,"%d seconds left.", 1 + ExitTime / 1000);
  66. STTextOut(VideoCX - GetTextW(hdcMain, buf)/2, y + 18, buf, 0x0060C0D0);
  67. }
  68. SelectObject(hdcCMain, hbmpOld);
  69. }
  70. void _RenderObject(int x, int y)
  71. {
  72. int ob = OMap[y][x];
  73. if (!MObjects[ob].model) {
  74. //return;
  75. wsprintf(logt,"Incorrect model at [%d][%d]!", x, y);
  76. DoHalt(logt);
  77. }
  78. int FI = (FMap[y][x] >> 2) & 3;
  79. float fi = CameraAlpha + (float)(FI * 2.f*pi / 4.f);
  80. int mlight;
  81. if (MObjects[ob].info.flags & (ofDEFLIGHT+ofGRNDLIGHT) )
  82. mlight = MObjects[ob].info.DefLight; else /*
  83. if (MObjects[ob].info.flags & ofGRNDLIGHT)
  84. {
  85. mlight = 128;
  86. CalcModelGroundLight(MObjects[ob].model, x*256+128, y*256+128, FI);
  87. FI = 0;
  88. }
  89. else */
  90. mlight = -(RandomMap[y & 31][x & 31] >> 5) + (LMap[y][x]>>1) + 96;
  91. if (mlight >192) mlight =192;
  92. if (mlight < 64) mlight = 64;
  93. v[0].x = x*256+128 - CameraX;
  94. v[0].z = y*256+128 - CameraZ;
  95. v[0].y = (float)(HMapO[y][x]) * ctHScale - CameraY;
  96. waterclip = FALSE;
  97. if (!UNDERWATER)
  98. if (FMap[y][x] & fmWaterA)
  99. if (HMapO[y][x] < WaterList[ WMap[y][x] ].wlevel) {
  100. if (WaterList[ WMap[y][x] ].wlevel * ctHScale >
  101. HMapO[y][x] * ctHScale + MObjects[ob].info.YHi) return;
  102. waterclipbase = v[0];
  103. waterclipbase.y = WaterList[ WMap[y][x] ].wlevel * ctHScale - CameraY;
  104. waterclipbase = RotateVector(waterclipbase);
  105. waterclip = TRUE;
  106. }
  107. float zs = VectorLength(v[0]);
  108. if (v[0].y + MObjects[ob].info.YHi < (int)(HMap[y][x]+HMap[y+1][x+1]) / 2 * ctHScale - CameraY) return;
  109. v[0] = RotateVector(v[0]);
  110. GlassL = 0;
  111. if (zs > 256 * (ctViewR-4))
  112. GlassL = min(255, (zs/4 - 64*(ctViewR-4)));
  113. if (GlassL==255) return;
  114. if (MObjects[ob].info.flags & ofANIMATED)
  115. if (MObjects[ob].info.LastAniTime!=RealTime) {
  116. MObjects[ob].info.LastAniTime=RealTime;
  117. CreateMorphedObject(MObjects[ob].model,
  118. MObjects[ob].vtl,
  119. RealTime % MObjects[ob].vtl.AniTime);
  120. }
  121. if (MObjects[ob].info.flags & ofNOBMP) zs = 0;
  122. if (zs>ctViewRM*256)
  123. RenderBMPModel(&MObjects[ob].bmpmodel, v[0].x, v[0].y, v[0].z, mlight-16);
  124. else
  125. if (v[0].z<-256*12 && !waterclip)
  126. RenderModel(MObjects[ob].model, v[0].x, v[0].y, v[0].z, mlight, FI, fi, CameraBeta);
  127. else
  128. RenderModelClip(MObjects[ob].model, v[0].x, v[0].y, v[0].z, mlight, FI, fi, CameraBeta);
  129. }
  130. void RenderMList()
  131. {
  132. rmlistselector=1-rmlistselector;
  133. for (int o=0; o<ORLCount[rmlistselector]; o++)
  134. _RenderObject(ORList[rmlistselector][o].x,
  135. ORList[rmlistselector][o].y);
  136. ORLCount[rmlistselector] = 0;
  137. }
  138. void CreateChRenderList()
  139. {
  140. //=========== ship ================//
  141. Ship.rpos.x = Ship.pos.x - CameraX;
  142. Ship.rpos.y = Ship.pos.y - CameraY;
  143. Ship.rpos.z = Ship.pos.z - CameraZ;
  144. float r = (float)max( fabs(Ship.rpos.x), fabs(Ship.rpos.z) );
  145. int ri = -1 + (int)(r / 256.f + 1.6f);
  146. if (Ship.State!=-1)
  147. if (ri < ctViewR-6) {
  148. int h = (int)((Ship.pos.y - GetLandUpH(Ship.pos.x, Ship.pos.z)) / 1.8);
  149. // AddShadowCircle((int)Ship.pos.x+h, (int)Ship.pos.z+h, 1200, 24);
  150. }
  151. if (HARD3D) return;
  152. for (int c=0; c<=ctViewR; c++)
  153. ChRenderList[c].ICount = 0;
  154. //=========== ship ================//
  155. if (Ship.State==-1) goto NOSHIP;
  156. if (ri < 0) ri = 0;
  157. if (ri < ctViewR) {
  158. Ship.rpos = RotateVector(Ship.rpos);
  159. if (Ship.rpos.z > BackViewR) goto NOSHIP;
  160. if ( fabs(Ship.rpos.x) > -Ship.rpos.z + BackViewR ) goto NOSHIP;
  161. int i = ChRenderList[ri].ICount++;
  162. ChRenderList[ri].Items[i].CType = 3;
  163. }
  164. NOSHIP: ;
  165. //============= Dinosaurs ====================//
  166. TCharacter *cptr;
  167. for (c=0; c<ChCount; c++) {
  168. cptr = &Characters[c];
  169. cptr->rpos.x = cptr->pos.x - CameraX;
  170. cptr->rpos.y = cptr->pos.y - CameraY;
  171. cptr->rpos.z = cptr->pos.z - CameraZ;
  172. float r = (float)max( fabs(cptr->rpos.x), fabs(cptr->rpos.z) );
  173. int ri = -1 + (int)(r / 256.f + 0.5f);
  174. if (ri < 0) ri = 0;
  175. if (ri > ctViewR) continue;
  176. cptr->rpos = RotateVector(cptr->rpos);
  177. float br = BackViewR + DinoInfo[cptr->CType].Radius;
  178. if (cptr->rpos.z > br) continue;
  179. if ( fabs(cptr->rpos.x) > -cptr->rpos.z + br ) continue;
  180. if ( fabs(cptr->rpos.y) > -cptr->rpos.z + br ) continue;
  181. /*
  182. if (cptr->rpos.z > BackViewR + ) continue;
  183. if ( fabs(cptr->rpos.x) > -cptr->rpos.z + BackViewR ) continue;
  184. */
  185. // AddShadowCircle((int)cptr->pos.x+100, (int)cptr->pos.z+100, 360, 16);
  186. int i = ChRenderList[ri].ICount++;
  187. ChRenderList[ri].Items[i].CType = 0;
  188. ChRenderList[ri].Items[i].Index = c;
  189. }
  190. }
  191. void RenderChList(int r)
  192. {
  193. if (HARD3D) return;
  194. for (int c=0; c<ChRenderList[r].ICount; c++) {
  195. if (ChRenderList[r].Items[c].CType ==0) RenderCharacter(ChRenderList[r].Items[c].Index); else
  196. if (ChRenderList[r].Items[c].CType ==3) RenderShip();
  197. }
  198. }
  199. void ProcessWaterMap(int x, int y, int r)
  200. {
  201. //WATERREVERSE = TRUE;
  202. ReverseOn = (FMap[y][x] & fmReverse);
  203. TDirection = (FMap[y][x] & 3);
  204. int t1 = TMap1[y][x];
  205. int t2 = TMap2[y][x];
  206. x = x - CCX + 64;
  207. y = y - CCY + 64;
  208. if ((VMap2[y][x].DFlags & VMap2[y][x+1].DFlags & VMap2[y+1][x+1].DFlags & VMap2[y+1][x].DFlags) == 0xFFFF) return;
  209. if (VMap2[y][x].DFlags!=0xFFFF) ev[0] = VMap2[y][x]; else ev[0] = VMap[y][x];
  210. if (VMap2[y][x+1].DFlags!=0xFFFF) ev[1] = VMap2[y][x+1]; else ev[1] = VMap[y][x+1];
  211. if (ReverseOn)
  212. if (VMap2[y+1][x].DFlags!=0xFFFF) ev[2] = VMap2[y+1][x]; else ev[2] = VMap[y+1][x];
  213. else
  214. if (VMap2[y+1][x+1].DFlags!=0xFFFF) ev[2] = VMap2[y+1][x+1]; else ev[2] = VMap[y+1][x+1];
  215. lpTextureAddr = &(Textures[0]->DataB[0]);
  216. HLineT = (void*) HLineTBGlass25;
  217. if (!t1)
  218. if (r>4) DrawTPlane(FALSE);
  219. else DrawTPlaneClip(FALSE);
  220. if (ReverseOn) {
  221. ev[0] = ev[2];
  222. if (VMap2[y+1][x+1].DFlags!=0xFFFF) ev[2] = VMap2[y+1][x+1]; else ev[2] = VMap[y+1][x+1];
  223. } else {
  224. ev[1] = ev[2];
  225. if (VMap2[y+1][x].DFlags!=0xFFFF) ev[2] = VMap2[y+1][x]; else ev[2] = VMap[y+1][x];
  226. }
  227. if (!t2)
  228. if (r>4) DrawTPlane(TRUE);
  229. else DrawTPlaneClip(TRUE);
  230. }
  231. void RenderElements()
  232. {
  233. }
  234. void RenderModelsList()
  235. {
  236. }
  237. void RenderWater()
  238. {
  239. }
  240. void RenderGround()
  241. {
  242. rmlistselector = 0;
  243. ORLCount[0] = 0;
  244. ORLCount[1] = 0;
  245. for (r=ctViewR; r>=ctViewR1-2; r-=2) {
  246. if (r<ctViewR1) LockWater = TRUE;
  247. for (int x=r; x>0; x-=2) {
  248. ProcessMap2(CCX-x, CCY+r, r);
  249. ProcessMap2(CCX+x, CCY+r, r);
  250. ProcessMap2(CCX-x, CCY-r, r);
  251. ProcessMap2(CCX+x, CCY-r, r);
  252. }
  253. ProcessMap2(CCX, CCY-r, r);
  254. ProcessMap2(CCX, CCY+r, r);
  255. for (int y=r-2; y>0; y-=2) {
  256. ProcessMap2(CCX+r, CCY-y, r);
  257. ProcessMap2(CCX+r, CCY+y, r);
  258. ProcessMap2(CCX-r, CCY+y, r);
  259. ProcessMap2(CCX-r, CCY-y, r);
  260. }
  261. ProcessMap2(CCX-r, CCY, r);
  262. ProcessMap2(CCX+r, CCY, r);
  263. RenderMList();
  264. RenderMList();
  265. RenderChList(r);
  266. RenderChList(r-1);
  267. }
  268. LockWater = FALSE;
  269. r = ctViewR1-1;
  270. for (int x=r; x>-r; x--) {
  271. ProcessMap(CCX+r, CCY+x, r);
  272. ProcessMap(CCX+x, CCY+r, r);
  273. }
  274. for (r=ctViewR1-2; r>0; r--) {
  275. for (int x=r; x>0; x--) {
  276. ProcessMap(CCX-x, CCY+r, r);
  277. ProcessMap(CCX+x, CCY+r, r);
  278. ProcessMap(CCX-x, CCY-r, r);
  279. ProcessMap(CCX+x, CCY-r, r);
  280. }
  281. ProcessMap(CCX, CCY-r, r);
  282. ProcessMap(CCX, CCY+r, r);
  283. for (int y=r-1; y>0; y--) {
  284. ProcessMap(CCX+r, CCY-y, r);
  285. ProcessMap(CCX+r, CCY+y, r);
  286. ProcessMap(CCX-r, CCY+y, r);
  287. ProcessMap(CCX-r, CCY-y, r);
  288. }
  289. ProcessMap(CCX-r, CCY, r);
  290. ProcessMap(CCX+r, CCY, r);
  291. RenderMList();
  292. RenderChList(r);
  293. }
  294. ProcessMap(CCX, CCY, 0);
  295. RenderMList();
  296. RenderMList();
  297. RenderChList(0);
  298. }
  299. void RenderObject(int x, int y)
  300. {
  301. if (OMap[y][x]==255) return;
  302. if (!MODELS) return;
  303. int o = ORLCount[rmlistselector];
  304. if (o>2000) return;
  305. ORList[rmlistselector][o].x = x;
  306. ORList[rmlistselector][o].y = y;
  307. ORLCount[rmlistselector]++;
  308. }
  309. void ProcessMap2(int x, int y, int r)
  310. {
  311. //WATERREVERSE = FALSE;
  312. if (x>=ctMapSize-1 || y>=ctMapSize-1 ||
  313. x<0 || y<0) return;
  314. float BackR = BackViewR;
  315. if (OMap[y][x]!=255) BackR+=MObjects[OMap[y][x]].info.BoundR;
  316. ev[0] = VMap[y-CCY+128][x-CCX+128]; if (ev[0].v.z>BackR) return;
  317. int t1 = TMap2[y][x];
  318. int hw = WaterList[ WMap[y][x] ].wlevel-1;
  319. ReverseOn = FALSE;
  320. TDirection = ((FMap[y][x]>>8) & 3);
  321. int _x = x;
  322. int _y = y;
  323. x = x - CCX + 128;
  324. y = y - CCY + 128;
  325. ev[1] = VMap[y][x+2];
  326. if (ReverseOn) ev[2] = VMap[y+2][x];
  327. else ev[2] = VMap[y+2][x+2];
  328. float xx = (ev[0].v.x + VMap[y+2][x+2].v.x) / 2;
  329. float yy = (ev[0].v.y + VMap[y+2][x+2].v.y) / 2;
  330. float zz = (ev[0].v.z + VMap[y+2][x+2].v.z) / 2;
  331. int zs;
  332. if ( fabs(xx) > -zz + BackR) return;
  333. zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
  334. if (zs > ctViewR*256) return;
  335. GlassL = 0;
  336. if (MIPMAP) ts = (int)CameraW * 4 * 128 / zs;
  337. else ts = 128;
  338. if (ts>=128) {
  339. lpTextureAddr = &(Textures[t1]->DataA[0]);
  340. HLineT = (void*) HLineTxGOURAUD; } else
  341. if (ts>=64) {
  342. lpTextureAddr = &(Textures[t1]->DataB[0]);
  343. HLineT = (void*) HLineTxB; }
  344. else {
  345. lpTextureAddr = &(Textures[t1]->DataC[0]);
  346. HLineT = (void*) HLineTxC;
  347. }
  348. if (zs > 256 * (ctViewR-4)) {
  349. GlassL = min(255, (zs/4 - 64*(ctViewR-4)));
  350. if (GlassL) lpTextureAddr = &(Textures[t1]->SDataC[1]);
  351. if (GlassL)
  352. if (GlassL>160) HLineT = (void*) HLineTDGlass25; else
  353. if (GlassL>80 ) HLineT = (void*) HLineTDGlass50; else
  354. HLineT = (void*) HLineTDGlass75;
  355. }
  356. if (!UNDERWATER)
  357. if (ReverseOn) {
  358. if ( (HMap[_y][_x]<hw) && (HMap[_y][_x+2]<hw) && (HMap[_y+2][_x]<hw) ) goto S1;
  359. } else {
  360. if ( (HMap[_y][_x]<hw) && (HMap[_y][_x+2]<hw) && (HMap[_y+2][_x+1]<hw) ) goto S1;
  361. }
  362. DrawTPlane(FALSE);
  363. S1:
  364. if (!UNDERWATER)
  365. if (ReverseOn) {
  366. if ( (HMap[_y][_x+2]<hw) && (HMap[_y+2][_x+2]<hw) && (HMap[_y+2][_x]<hw) ) goto S2;
  367. } else {
  368. if ( (HMap[_y][_x]<hw) && (HMap[_y+2][_x+2]<hw) && (HMap[_y+2][_x]<hw) ) goto S2;
  369. }
  370. if (ReverseOn) { ev[0] = ev[2]; ev[2] = VMap[y+2][x+2]; }
  371. else { ev[1] = ev[2]; ev[2] = VMap[y+2][x]; }
  372. DrawTPlane(TRUE);
  373. S2:
  374. x = x + CCX - 128;
  375. y = y + CCY - 128;
  376. if (!LockWater) {
  377. RenderObject(x , y);
  378. RenderObject(x+1, y);
  379. RenderObject(x , y+1);
  380. RenderObject(x+1, y+1);
  381. if (FMap[y][x] & fmWaterA) ProcessMapW2(x,y,r);
  382. }
  383. }
  384. void ProcessMap(int x, int y, int r)
  385. {
  386. if (x>=ctMapSize-1 || y>=ctMapSize-1 ||
  387. x<0 || y<0) return;
  388. float BackR = BackViewR;
  389. if (OMap[y][x]!=255) BackR+=MObjects[OMap[y][x]].info.BoundR;
  390. int zs;
  391. float xx,yy,zz;
  392. int hw = WaterList[ WMap[y][x] ].wlevel;
  393. ev[0] = VMap[y-CCY+128][x-CCX+128]; if (ev[0].v.z>BackR) return;
  394. BOOL
  395. wpr = ((FMap[y ][x ] & fmWaterA) &&
  396. (FMap[y ][x+1] & fmWaterA) &&
  397. (FMap[y+1][x ] & fmWaterA) &&
  398. (FMap[y+1][x+1] & fmWaterA) );
  399. int ob = OMap[y][x];
  400. if (!MODELS) ob=255;
  401. int t1 = TMap1[y][x];
  402. ReverseOn = (FMap[y][x] & fmReverse);
  403. TDirection = (FMap[y][x] & 3);
  404. int _x = x;
  405. int _y = y;
  406. x = x - CCX + 128;
  407. y = y - CCY + 128;
  408. ev[1] = VMap[y][x+1];
  409. if (ReverseOn) ev[2] = VMap[y+1][x];
  410. else ev[2] = VMap[y+1][x+1];
  411. xx = (ev[0].v.x + VMap[y+1][x+1].v.x) / 2;
  412. yy = (ev[0].v.y + VMap[y+1][x+1].v.y) / 2;
  413. zz = (ev[0].v.z + VMap[y+1][x+1].v.z) / 2;
  414. if ( fabs(xx) > -zz + BackR) return;
  415. zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
  416. if (zs > ctViewR*256) return;
  417. GlassL = 0;
  418. if (MIPMAP) ts = (int)CameraW * 4 * 128 / zs;
  419. else ts = 128;
  420. if (ts>=128) {
  421. lpTextureAddr = &(Textures[t1]->DataA[0]);
  422. HLineT = (void*) HLineTxGOURAUD; } else
  423. if (ts>=64) {
  424. lpTextureAddr = &(Textures[t1]->DataB[0]);
  425. HLineT = (void*) HLineTxB; }
  426. else {
  427. lpTextureAddr = &(Textures[t1]->DataC[0]);
  428. HLineT = (void*) HLineTxC;
  429. }
  430. if (!UNDERWATER)
  431. if (wpr)
  432. if (ReverseOn) {
  433. if ( (HMap[_y][_x]<hw) || (HMap[_y][_x+1]<hw) || (HMap[_y+1][_x]<hw) ) goto S1;
  434. } else {
  435. if ( (HMap[_y][_x]<hw) || (HMap[_y][_x+1]<hw) || (HMap[_y+1][_x+1]<hw) ) goto S1;
  436. }
  437. if (r>6) DrawTPlane(FALSE);
  438. else DrawTPlaneClip(FALSE);
  439. S1:
  440. if (ReverseOn) { ev[0] = ev[2]; ev[2] = VMap[y+1][x+1]; }
  441. else { ev[1] = ev[2]; ev[2] = VMap[y+1][x]; }
  442. if (!UNDERWATER)
  443. if (wpr)
  444. if (ReverseOn) {
  445. if ( (HMap[_y][_x+1]<hw) || (HMap[_y+1][_x+1]<hw) || (HMap[_y+1][_x]<hw) ) goto S2;
  446. } else {
  447. if ( (HMap[_y][_x]<hw) || (HMap[_y+1][_x+1]<hw) || (HMap[_y+1][_x]<hw) ) goto S2;
  448. }
  449. if (r>6) DrawTPlane(TRUE);
  450. else DrawTPlaneClip(TRUE);
  451. S2:
  452. x = x + CCX - 128;
  453. y = y + CCY - 128;
  454. SKIP:
  455. RenderObject(x, y);
  456. if (wpr) ProcessMapW(x,y,r);
  457. }
  458. void ProcessMapW(int x, int y, int r)
  459. {
  460. if (RunMode) return;
  461. if (x>=ctMapSize-1 || y>=ctMapSize-1 || x<0 || y<0) return;
  462. int t1 = WaterList[ WMap[y][x] ].tindex;
  463. int hw = WaterList[ WMap[y][x] ].wlevel;
  464. ev[0] = VMap2[y-CCY+128][x-CCX+128];
  465. if (ev[0].v.z>BackViewR) return;
  466. ReverseOn = (FMap[y][x] & fmReverse);
  467. TDirection = 0;
  468. // if ( (HMap[y][x]>hw) || (HMap[y+1][x+1]>hw) ) ReverseOn = TRUE;
  469. int _x = x;
  470. int _y = y;
  471. x = x - CCX + 128;
  472. y = y - CCY + 128;
  473. ev[1] = VMap2[y][x+1];
  474. if (ReverseOn) ev[2] = VMap2[y+1][x];
  475. else ev[2] = VMap2[y+1][x+1];
  476. float xx = (ev[0].v.x + VMap2[y+1][x+1].v.x) / 2;
  477. float yy = (ev[0].v.y + VMap2[y+1][x+1].v.y) / 2;
  478. float zz = (ev[0].v.z + VMap2[y+1][x+1].v.z) / 2;
  479. int zs;
  480. if ( fabs(xx*FOVK) > -zz + BackViewR) return;
  481. zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
  482. if (zs > ctViewR*256) return;
  483. GlassL = 0;
  484. if (MIPMAP) ts = (int)CameraW * 4 * 128 / zs;
  485. else ts = 128;
  486. ts = 128;
  487. if (ts>=128) {
  488. lpTextureAddr = &(Textures[t1]->DataA[0]);
  489. HLineT = (void*) HLineTxGOURAUD; } else
  490. if (ts>=64) {
  491. lpTextureAddr = &(Textures[t1]->DataB[0]);
  492. HLineT = (void*) HLineTxB;
  493. }
  494. else {
  495. lpTextureAddr = &(Textures[t1]->DataC[0]);
  496. HLineT = (void*) HLineTxC;
  497. }
  498. if (UNDERWATER) {
  499. lpTextureAddr = &(Textures[t1]->DataB[0]);
  500. HLineT = (void*) HLineTBGlass25;
  501. }
  502. WATERREVERSE = UNDERWATER;
  503. if (ReverseOn) {
  504. if ( (HMap[_y][_x]>hw) || (HMap[_y][_x+1]>hw) || (HMap[_y+1][_x]>hw) ) goto S1;
  505. } else {
  506. if ( (HMap[_y][_x]>hw) || (HMap[_y][_x+1]>hw) || (HMap[_y+1][_x+1]>hw) ) goto S1;
  507. }
  508. if (r>6) DrawTPlane(FALSE);
  509. else DrawTPlaneClip(FALSE);
  510. S1:
  511. if (ReverseOn) { ev[0] = ev[2]; ev[2] = VMap2[y+1][x+1]; }
  512. else { ev[1] = ev[2]; ev[2] = VMap2[y+1][x]; }
  513. if (ReverseOn) {
  514. if ( (HMap[_y][_x+1]>hw) || (HMap[_y+1][_x+1]>hw) || (HMap[_y+1][_x]>hw) ) goto S2;
  515. } else {
  516. if ( (HMap[_y][_x]>hw) || (HMap[_y+1][_x+1]>hw) || (HMap[_y+1][_x]>hw) ) goto S2;
  517. }
  518. if (r>6) DrawTPlane(TRUE);
  519. else DrawTPlaneClip(TRUE);
  520. S2:
  521. WATERREVERSE = FALSE;
  522. }
  523. void ProcessMapW2(int x, int y, int r)
  524. {
  525. if (RunMode) return;
  526. if (!( (FMap[y ][x ] & fmWaterA) &&
  527. (FMap[y ][x+2] & fmWaterA) &&
  528. (FMap[y+2][x ] & fmWaterA) &&
  529. (FMap[y+2][x+2] & fmWaterA) )) return;
  530. if (x>=ctMapSize-1 || y>=ctMapSize-1 || x<0 || y<0) return;
  531. int t1 = WaterList[ WMap[y][x] ].tindex;
  532. int hw = WaterList[ WMap[y][x] ].wlevel;
  533. ev[0] = VMap2[y-CCY+128][x-CCX+128];
  534. if (ev[0].v.z>BackViewR) return;
  535. // ReverseOn = (FMap[y][x] & fmReverse);
  536. TDirection = 0;
  537. if ( (HMap[y][x]>hw) || (HMap[y+2][x+2]>hw) ) ReverseOn = TRUE;
  538. int _x = x;
  539. int _y = y;
  540. x = x - CCX + 128;
  541. y = y - CCY + 128;
  542. ev[1] = VMap2[y][x+2];
  543. if (ReverseOn) ev[2] = VMap2[y+2][x];
  544. else ev[2] = VMap2[y+2][x+2];
  545. float xx = (ev[0].v.x + VMap2[y+1][x+2].v.x) / 2;
  546. float yy = (ev[0].v.y + VMap2[y+1][x+2].v.y) / 2;
  547. float zz = (ev[0].v.z + VMap2[y+1][x+2].v.z) / 2;
  548. int zs;
  549. if ( fabs(xx*FOVK) > -zz + BackViewR) return;
  550. zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
  551. if (zs > ctViewR*256) return;
  552. GlassL = 0;
  553. if (MIPMAP) ts = (int)CameraW * 4 * 128 / zs;
  554. else ts = 128;
  555. if (UNDERWATER) {
  556. lpTextureAddr = &(Textures[t1]->DataB[0]);
  557. HLineT = (void*) HLineTBGlass25;
  558. } else {
  559. lpTextureAddr = &(Textures[t1]->DataC[0]);
  560. HLineT = (void*) HLineTxC;
  561. }
  562. WATERREVERSE = UNDERWATER;
  563. if (ReverseOn) {
  564. if ( (HMap[_y][_x]>hw) && (HMap[_y][_x+2]>hw) && (HMap[_y+2][_x]>hw) ) goto S1;
  565. } else {
  566. if ( (HMap[_y][_x]>hw) && (HMap[_y][_x+2]>hw) && (HMap[_y+2][_x+2]>hw) ) goto S1;
  567. }
  568. if (r>6) DrawTPlane(FALSE);
  569. else DrawTPlaneClip(FALSE);
  570. S1:
  571. if (ReverseOn) { ev[0] = ev[2]; ev[2] = VMap2[y+2][x+2]; }
  572. else { ev[1] = ev[2]; ev[2] = VMap2[y+2][x]; }
  573. if (ReverseOn) {
  574. if ( (HMap[_y][_x+2]>hw) && (HMap[_y+2][_x+2]>hw) && (HMap[_y+2][_x]>hw) ) goto S2;
  575. } else {
  576. if ( (HMap[_y][_x]>hw) && (HMap[_y+2][_x+2]>hw) && (HMap[_y+2][_x]>hw) ) goto S2;
  577. }
  578. if (r>6) DrawTPlane(TRUE);
  579. else DrawTPlaneClip(TRUE);
  580. S2:
  581. WATERREVERSE = FALSE;
  582. }
  583. #include "RenderASM.cpp"
  584. void ClipVector(CLIPPLANE& C, int vn)
  585. {
  586. int ClipRes = 0;
  587. float s,s1,s2;
  588. int vleft = (vn-1); if (vleft <0) vleft=vused-1;
  589. int vright = (vn+1); if (vright>=vused) vright=0;
  590. MulVectorsScal(cp[vn].ev.v, C.nv, s); /*s=SGN(s-0.01f);*/
  591. if (s>=0) return;
  592. MulVectorsScal(cp[vleft ].ev.v, C.nv, s1); /* s1=SGN(s1+0.01f); */ //s1+=0.001f;
  593. MulVectorsScal(cp[vright].ev.v, C.nv, s2); /* s2=SGN(s2+0.01f); */ //s2+=0.001f;
  594. if (s1>0) {
  595. ClipRes+=1;
  596. /*
  597. CalcHitPoint(C,cp[vn].ev.v,
  598. cp[vleft].ev.v, hleft.ev.v);
  599. float ll = VectorLength(SubVectors(cp[vleft].ev.v, cp[vn].ev.v));
  600. float lc = VectorLength(SubVectors(hleft.ev.v, cp[vn].ev.v));
  601. lc = lc / ll;
  602. */
  603. float lc = -s / (s1-s);
  604. hleft.ev.v.x = cp[vn].ev.v.x + ((cp[vleft].ev.v.x - cp[vn].ev.v.x) * lc);
  605. hleft.ev.v.y = cp[vn].ev.v.y + ((cp[vleft].ev.v.y - cp[vn].ev.v.y) * lc);
  606. hleft.ev.v.z = cp[vn].ev.v.z + ((cp[vleft].ev.v.z - cp[vn].ev.v.z) * lc);
  607. hleft.tx = cp[vn].tx + (int)((cp[vleft].tx - cp[vn].tx) * lc);
  608. hleft.ty = cp[vn].ty + (int)((cp[vleft].ty - cp[vn].ty) * lc);
  609. hleft.ev.Light = cp[vn].ev.Light + (int)((cp[vleft].ev.Light - cp[vn].ev.Light) * lc);
  610. }
  611. if (s2>0) {
  612. ClipRes+=2;
  613. /*
  614. CalcHitPoint(C,cp[vn].ev.v,
  615. cp[vright].ev.v, hright.ev.v);
  616. float ll = VectorLength(SubVectors(cp[vright].ev.v, cp[vn].ev.v));
  617. float lc = VectorLength(SubVectors(hright.ev.v, cp[vn].ev.v));
  618. lc = lc / ll;
  619. */
  620. float lc = -s / (s2-s);
  621. hright.ev.v.x = cp[vn].ev.v.x + ((cp[vright].ev.v.x - cp[vn].ev.v.x) * lc);
  622. hright.ev.v.y = cp[vn].ev.v.y + ((cp[vright].ev.v.y - cp[vn].ev.v.y) * lc);
  623. hright.ev.v.z = cp[vn].ev.v.z + ((cp[vright].ev.v.z - cp[vn].ev.v.z) * lc);
  624. hright.tx = cp[vn].tx + (int)((cp[vright].tx - cp[vn].tx) * lc);
  625. hright.ty = cp[vn].ty + (int)((cp[vright].ty - cp[vn].ty) * lc);
  626. hright.ev.Light = cp[vn].ev.Light + (int)((cp[vright].ev.Light - cp[vn].ev.Light) * lc);
  627. }
  628. if (ClipRes == 0) {
  629. u--; vused--;
  630. cp[vn] = cp[vn+1];
  631. cp[vn+1] = cp[vn+2];
  632. cp[vn+2] = cp[vn+3];
  633. cp[vn+3] = cp[vn+4];
  634. cp[vn+4] = cp[vn+5];
  635. cp[vn+5] = cp[vn+6];
  636. //memcpy(&cp[vn], &cp[vn+1], (15-vn)*sizeof(ClipPoint));
  637. }
  638. if (ClipRes == 1) {cp[vn] = hleft; }
  639. if (ClipRes == 2) {cp[vn] = hright;}
  640. if (ClipRes == 3) {
  641. u++; vused++;
  642. //memcpy(&cp[vn+1], &cp[vn], (15-vn)*sizeof(ClipPoint));
  643. cp[vn+6] = cp[vn+5];
  644. cp[vn+5] = cp[vn+4];
  645. cp[vn+4] = cp[vn+3];
  646. cp[vn+3] = cp[vn+2];
  647. cp[vn+2] = cp[vn+1];
  648. cp[vn+1] = cp[vn];
  649. cp[vn] = hleft;
  650. cp[vn+1] = hright;
  651. }
  652. }
  653. int SGNi(int f)
  654. {
  655. if (f<0) return -1;
  656. else return 1;
  657. }
  658. void DrawTPlaneClip(BOOL SECONT)
  659. {
  660. int n;
  661. if (!WATERREVERSE) {
  662. MulVectorsVect(SubVectors(ev[1].v, ev[0].v), SubVectors(ev[2].v, ev[0].v), nv);
  663. if (nv.x*ev[0].v.x + nv.y*ev[0].v.y + nv.z*ev[0].v.z<0) return;
  664. }
  665. cp[0].ev = ev[0]; cp[1].ev = ev[1]; cp[2].ev = ev[2];
  666. if (ReverseOn)
  667. if (SECONT) {
  668. switch (TDirection) {
  669. case 0:
  670. cp[0].tx = TCMIN; cp[0].ty = TCMAX;
  671. cp[1].tx = TCMAX; cp[1].ty = TCMIN;
  672. cp[2].tx = TCMAX; cp[2].ty = TCMAX;
  673. break;
  674. case 1:
  675. cp[0].tx = TCMAX; cp[0].ty = TCMAX;
  676. cp[1].tx = TCMIN; cp[1].ty = TCMIN;
  677. cp[2].tx = TCMAX; cp[2].ty = TCMIN;
  678. break;
  679. case 2:
  680. cp[0].tx = TCMAX; cp[0].ty = TCMIN;
  681. cp[1].tx = TCMIN; cp[1].ty = TCMAX;
  682. cp[2].tx = TCMIN; cp[2].ty = TCMIN;
  683. break;
  684. case 3:
  685. cp[0].tx = TCMIN; cp[0].ty = TCMIN;
  686. cp[1].tx = TCMAX; cp[1].ty = TCMAX;
  687. cp[2].tx = TCMIN; cp[2].ty = TCMAX;
  688. break;
  689. }
  690. } else {
  691. switch (TDirection) {
  692. case 0:
  693. cp[0].tx = TCMIN; cp[0].ty = TCMIN;
  694. cp[1].tx = TCMAX; cp[1].ty = TCMIN;
  695. cp[2].tx = TCMIN; cp[2].ty = TCMAX;
  696. break;
  697. case 1:
  698. cp[0].tx = TCMIN; cp[0].ty = TCMAX;
  699. cp[1].tx = TCMIN; cp[1].ty = TCMIN;
  700. cp[2].tx = TCMAX; cp[2].ty = TCMAX;
  701. break;
  702. case 2:
  703. cp[0].tx = TCMAX; cp[0].ty = TCMAX;
  704. cp[1].tx = TCMIN; cp[1].ty = TCMAX;
  705. cp[2].tx = TCMAX; cp[2].ty = TCMIN;
  706. break;
  707. case 3:
  708. cp[0].tx = TCMAX; cp[0].ty = TCMIN;
  709. cp[1].tx = TCMAX; cp[1].ty = TCMAX;
  710. cp[2].tx = TCMIN; cp[2].ty = TCMIN;
  711. break;
  712. }
  713. }
  714. else
  715. if (SECONT) {
  716. switch (TDirection) {
  717. case 0:
  718. cp[0].tx = TCMIN; cp[0].ty = TCMIN;
  719. cp[1].tx = TCMAX; cp[1].ty = TCMAX;
  720. cp[2].tx = TCMIN; cp[2].ty = TCMAX;
  721. break;
  722. case 1:
  723. cp[0].tx = TCMIN; cp[0].ty = TCMAX;
  724. cp[1].tx = TCMAX; cp[1].ty = TCMIN;
  725. cp[2].tx = TCMAX; cp[2].ty = TCMAX;
  726. break;
  727. case 2:
  728. cp[0].tx = TCMAX; cp[0].ty = TCMAX;
  729. cp[1].tx = TCMIN; cp[1].ty = TCMIN;
  730. cp[2].tx = TCMAX; cp[2].ty = TCMIN;
  731. break;
  732. case 3:
  733. cp[0].tx = TCMAX; cp[0].ty = TCMIN;
  734. cp[1].tx = TCMIN; cp[1].ty = TCMAX;
  735. cp[2].tx = TCMIN; cp[2].ty = TCMIN;
  736. break;
  737. }
  738. } else {
  739. switch (TDirection) {
  740. case 0:
  741. cp[0].tx = TCMIN; cp[0].ty = TCMIN;
  742. cp[1].tx = TCMAX; cp[1].ty = TCMIN;
  743. cp[2].tx = TCMAX; cp[2].ty = TCMAX;
  744. break;
  745. case 1:
  746. cp[0].tx = TCMIN; cp[0].ty = TCMAX;
  747. cp[1].tx = TCMIN; cp[1].ty = TCMIN;
  748. cp[2].tx = TCMAX; cp[2].ty = TCMIN;
  749. break;
  750. case 2:
  751. cp[0].tx = TCMAX; cp[0].ty = TCMAX;
  752. cp[1].tx = TCMIN; cp[1].ty = TCMAX;
  753. cp[2].tx = TCMIN; cp[2].ty = TCMIN;
  754. break;
  755. case 3:
  756. cp[0].tx = TCMAX; cp[0].ty = TCMIN;
  757. cp[1].tx = TCMAX; cp[1].ty = TCMAX;
  758. cp[2].tx = TCMIN; cp[2].ty = TCMAX;
  759. break;
  760. }
  761. }
  762. /*
  763. cp[0].tx = TCMIN; cp[0].ty = TCMIN;
  764. if (SECONT) {
  765. cp[1].tx = TCMAX; cp[1].ty = TCMAX;
  766. cp[2].tx = TCMIN; cp[2].ty = TCMAX;
  767. } else {
  768. cp[1].tx = TCMAX; cp[1].ty = TCMIN;
  769. cp[2].tx = TCMAX; cp[2].ty = TCMAX;
  770. }*/
  771. vused = 3;
  772. for (u=0; u<vused; u++) cp[u].ev.v.z+=12.0f;
  773. for (u=0; u<vused; u++) ClipVector(ClipZ,u);
  774. for (u=0; u<vused; u++) cp[u].ev.v.z-=12.0f;
  775. if (vused<3) return;
  776. for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) return;
  777. for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) return;
  778. for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) return;
  779. for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) return;
  780. //float dy = -1.1f;
  781. //if (WATERREVERSE) dy = 0;
  782. for (u=0; u<vused; u++) {
  783. cp[u].ev.scrx = VideoCX - (int)(cp[u].ev.v.x / cp[u].ev.v.z * CameraW);
  784. cp[u].ev.scry = VideoCY + (int)(cp[u].ev.v.y / cp[u].ev.v.z * CameraH);
  785. }
  786. scrp[0].x = cp[0].ev.scrx;
  787. scrp[0].y = cp[0].ev.scry;
  788. scrp[0].Light = cp[0].ev.Light/4;
  789. scrp[0].tx = cp[0].tx;
  790. scrp[0].ty = cp[0].ty;
  791. scrp[0].z = (int)cp[0].ev.v.z;
  792. for (u=0; u<vused-2; u++) {
  793. for (n=1; n<3; n++) {
  794. scrp[n].x = cp[n+u].ev.scrx;
  795. scrp[n].y = cp[n+u].ev.scry;
  796. scrp[n].Light = cp[n+u].ev.Light/4;
  797. scrp[n].tx = cp[n+u].tx;
  798. scrp[n].ty = cp[n+u].ty;
  799. scrp[n].z = (int)cp[n+u].ev.v.z;
  800. }
  801. if (CORRECTION) DrawCorrectedTexturedFace();
  802. else DrawTexturedFace();
  803. }
  804. }
  805. void DrawTPlane(BOOL SECONT)
  806. {
  807. int n;
  808. if (!WATERREVERSE)
  809. if ((ev[1].scrx-ev[0].scrx)*(ev[2].scry-ev[0].scry) -
  810. (ev[1].scry-ev[0].scry)*(ev[2].scrx-ev[0].scrx) < 0) return;
  811. Mask1=0x007F;
  812. for (n=0; n<3; n++) {
  813. if (ev[n].DFlags & 128) return;
  814. Mask1=Mask1 & ev[n].DFlags; }
  815. if (Mask1>0) return;
  816. for (n=0; n<3; n++) {
  817. scrp[n].x = ev[n].scrx;
  818. scrp[n].y = ev[n].scry;
  819. scrp[n].Light = ev[n].Light / 4;
  820. }
  821. if (ReverseOn)
  822. if (SECONT) {
  823. switch (TDirection) {
  824. case 0:
  825. scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
  826. scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
  827. scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
  828. break;
  829. case 1:
  830. scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
  831. scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
  832. scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
  833. break;
  834. case 2:
  835. scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
  836. scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
  837. scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
  838. break;
  839. case 3:
  840. scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
  841. scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
  842. scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
  843. break;
  844. }
  845. } else {
  846. switch (TDirection) {
  847. case 0:
  848. scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
  849. scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
  850. scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
  851. break;
  852. case 1:
  853. scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
  854. scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
  855. scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
  856. break;
  857. case 2:
  858. scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
  859. scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
  860. scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
  861. break;
  862. case 3:
  863. scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
  864. scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
  865. scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
  866. break;
  867. }
  868. }
  869. else
  870. if (SECONT) {
  871. switch (TDirection) {
  872. case 0:
  873. scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
  874. scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
  875. scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
  876. break;
  877. case 1:
  878. scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
  879. scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
  880. scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
  881. break;
  882. case 2:
  883. scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
  884. scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
  885. scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
  886. break;
  887. case 3:
  888. scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
  889. scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
  890. scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
  891. break;
  892. }
  893. } else {
  894. switch (TDirection) {
  895. case 0:
  896. scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
  897. scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
  898. scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
  899. break;
  900. case 1:
  901. scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
  902. scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
  903. scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
  904. break;
  905. case 2:
  906. scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
  907. scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
  908. scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
  909. break;
  910. case 3:
  911. scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
  912. scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
  913. scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
  914. break;
  915. }
  916. }
  917. DrawTexturedFace();
  918. }
  919. void BuildTree()
  920. {
  921. Vector2di v[3];
  922. Current = -1;
  923. TFace* fptr;
  924. int sg;
  925. for (int f=0; f<mptr->FCount; f++)
  926. {
  927. fptr = &mptr->gFace[f];
  928. v[0] = gScrp[fptr->v1];
  929. v[1] = gScrp[fptr->v2];
  930. v[2] = gScrp[fptr->v3];
  931. if (v[0].x == 0xFFFFFF) continue;
  932. if (v[1].x == 0xFFFFFF) continue;
  933. if (v[2].x == 0xFFFFFF) continue;
  934. //fptr->Flags &= 0x00FF;
  935. if (fptr->Flags & (sfDarkBack + sfNeedVC) ) {
  936. sg = (v[1].x-v[0].x)*(v[2].y-v[1].y) - (v[1].y-v[0].y)*(v[2].x-v[1].x);
  937. if (sg<0) continue;
  938. /*
  939. if (fptr->Flags & sfNeedVC) { if (sg<0) continue; }
  940. else if (sg<0) fptr->Flags |= sfDark; */
  941. }
  942. //if (NODARKBACK) fptr->Flags &= 0x00FF;
  943. fptr->Distant = (int)(-(rVertex[fptr->v1].z + rVertex[fptr->v2].z + rVertex[fptr->v3].z));
  944. fptr->Next=-1;
  945. if (Current==-1) Current=f; else
  946. if (mptr->gFace[Current].Distant < fptr->Distant)
  947. { fptr->Next=Current; Current=f; } else {
  948. int n=Current;
  949. while (mptr->gFace[n].Next!=-1 && mptr->gFace[mptr->gFace[n].Next].Distant > fptr->Distant)
  950. n=mptr->gFace[n].Next;
  951. fptr->Next = mptr->gFace[n].Next;
  952. mptr->gFace[n].Next = f; }
  953. }
  954. }
  955. void BuildTreeNoSort()
  956. {
  957. Vector2di v[3];
  958. Current = -1;
  959. int LastFace = -1;
  960. TFace* fptr;
  961. int sg;
  962. for (int f=0; f<mptr->FCount; f++)
  963. {
  964. fptr = &mptr->gFace[f];
  965. v[0] = gScrp[fptr->v1];
  966. v[1] = gScrp[fptr->v2];
  967. v[2] = gScrp[fptr->v3];
  968. if (v[0].x == 0xFFFFFF) continue;
  969. if (v[1].x == 0xFFFFFF) continue;
  970. if (v[2].x == 0xFFFFFF) continue;
  971. if (fptr->Flags & (sfDarkBack+sfNeedVC)) {
  972. sg = (v[1].x-v[0].x)*(v[2].y-v[1].y) - (v[1].y-v[0].y)*(v[2].x-v[1].x);
  973. if (sg<0) continue;
  974. }
  975. fptr->Next=-1;
  976. if (Current==-1) { Current=f; LastFace = f; } else
  977. { mptr->gFace[LastFace].Next=f; LastFace=f; }
  978. }
  979. }
  980. void BuildTreeClip()
  981. {
  982. Current = -1;
  983. TFace* fptr;
  984. for (int f=0; f<mptr->FCount; f++)
  985. {
  986. fptr = &mptr->gFace[f];
  987. if (fptr->Flags & (sfDarkBack + sfNeedVC) ) {
  988. MulVectorsVect(SubVectors(rVertex[fptr->v2], rVertex[fptr->v1]), SubVectors(rVertex[fptr->v3], rVertex[fptr->v1]), nv);
  989. if (nv.x*rVertex[fptr->v1].x + nv.y*rVertex[fptr->v1].y + nv.z*rVertex[fptr->v1].z<0) continue;
  990. }
  991. fptr->Distant = (int)(-(rVertex[fptr->v1].z + rVertex[fptr->v2].z + rVertex[fptr->v3].z));
  992. fptr->Next=-1;
  993. if (Current==-1) Current=f; else
  994. if (mptr->gFace[Current].Distant < fptr->Distant)
  995. { fptr->Next=Current; Current=f; } else {
  996. int n=Current;
  997. while (mptr->gFace[n].Next!=-1 && mptr->gFace[mptr->gFace[n].Next].Distant > fptr->Distant)
  998. n=mptr->gFace[n].Next;
  999. fptr->Next = mptr->gFace[n].Next;
  1000. mptr->gFace[n].Next = f; }
  1001. }
  1002. }
  1003. void BuildTreeClipNoSort()
  1004. {
  1005. Current = -1;
  1006. int LastFace = -1;
  1007. TFace* fptr;
  1008. for (int f=0; f<mptr->FCount; f++)
  1009. {
  1010. fptr = &mptr->gFace[f];
  1011. if (fptr->Flags & (sfDarkBack + sfNeedVC) ) {
  1012. MulVectorsVect(SubVectors(rVertex[fptr->v2], rVertex[fptr->v1]), SubVectors(rVertex[fptr->v3], rVertex[fptr->v1]), nv);
  1013. if (nv.x*rVertex[fptr->v1].x + nv.y*rVertex[fptr->v1].y + nv.z*rVertex[fptr->v1].z<0) continue;
  1014. }
  1015. fptr->Next=-1;
  1016. if (Current==-1) { Current=f; LastFace = f; } else
  1017. { mptr->gFace[LastFace].Next=f; LastFace=f; }
  1018. }
  1019. }
  1020. void RenderModelClip(TModel* _mptr, float x0, float y0, float z0, int light, int VT, float al, float bt)
  1021. {
  1022. int f,CMASK;
  1023. mptr = _mptr;
  1024. float ca = (float)cos(al);
  1025. float sa = (float)sin(al);
  1026. float cb = (float)cos(bt);
  1027. float sb = (float)sin(bt);
  1028. __asm {
  1029. mov eax,light
  1030. shr eax,2
  1031. shl eax,16
  1032. add eax, offset FadeTab
  1033. mov iModelFade,eax
  1034. mov iModelBaseFade,eax
  1035. }
  1036. HLineT = (void*) HLineTxModel;
  1037. lpTextureAddr = (void*) mptr->lpTexture;
  1038. BOOL BL = FALSE;
  1039. for (int s=0; s<mptr->VCount; s++) {
  1040. rVertex[s].x = (mptr->gVertex[s].x * ca + mptr->gVertex[s].z * sa) + x0;
  1041. float vz = mptr->gVertex[s].z * ca - mptr->gVertex[s].x * sa;
  1042. rVertex[s].y = (mptr->gVertex[s].y * cb - vz * sb) + y0;
  1043. rVertex[s].z = (vz * cb + mptr->gVertex[s].y * sb) + z0;
  1044. if (rVertex[s].z<0) BL=TRUE;
  1045. if (rVertex[s].z>-64) { gScrp[s].x = 0xFFFFFF; gScrp[s].y = 0xFF; }
  1046. else {
  1047. int f = 0;
  1048. int sx = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
  1049. int sy = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
  1050. if (sx<=0 ) f+=2;
  1051. if (sx>=WinEX) f+=1;
  1052. if (sy>=WinEY) f+=4;
  1053. if (sy<=0 ) f+=8;
  1054. if (f) { gScrp[s].x = 0xFFFFFF; gScrp[s].y = f; }
  1055. else { gScrp[s].x = sx; gScrp[s].y = sy; }
  1056. }
  1057. }
  1058. if (!BL) return;
  1059. BuildTreeClip();
  1060. f = Current;
  1061. while( f!=-1 ) {
  1062. vused = 3;
  1063. TFace *fptr = &mptr->gFace[f];
  1064. //======== if face fully on screen NO 3D CLIPPING ====================/
  1065. if (!waterclip)
  1066. if (gScrp[fptr->v1].x != 0xFFFFFF && gScrp[fptr->v2].x != 0xFFFFFF && gScrp[fptr->v3].x != 0xFFFFFF )
  1067. {
  1068. mscrp[0].x = gScrp[fptr->v1].x; mscrp[0].y = gScrp[fptr->v1].y;
  1069. mscrp[0].tx = fptr->tax; mscrp[0].ty = fptr->tay;
  1070. mscrp[1].x = gScrp[fptr->v2].x; mscrp[1].y = gScrp[fptr->v2].y;
  1071. mscrp[1].tx = fptr->tbx; mscrp[1].ty = fptr->tby;
  1072. mscrp[2].x = gScrp[fptr->v3].x; mscrp[2].y = gScrp[fptr->v3].y;
  1073. mscrp[2].tx = fptr->tcx; mscrp[2].ty = fptr->tcy;
  1074. OpacityMode = (fptr->Flags & (sfOpacity + sfTransparent));
  1075. if (fptr->Flags & sfDark)
  1076. iModelFade = iModelBaseFade + 12*256*256;
  1077. else iModelFade = iModelBaseFade;
  1078. DrawModelFace();
  1079. goto LNEXT;
  1080. }
  1081. CMASK = 0;
  1082. if (gScrp[fptr->v1].x == 0xFFFFFF) CMASK|=gScrp[fptr->v1].y;
  1083. if (gScrp[fptr->v2].x == 0xFFFFFF) CMASK|=gScrp[fptr->v2].y;
  1084. if (gScrp[fptr->v3].x == 0xFFFFFF) CMASK|=gScrp[fptr->v3].y;
  1085. // CMASK = 0xFF;
  1086. cp[0].ev.v = rVertex[fptr->v1]; cp[0].tx = fptr->tax; cp[0].ty = fptr->tay;
  1087. cp[1].ev.v = rVertex[fptr->v2]; cp[1].tx = fptr->tbx; cp[1].ty = fptr->tby;
  1088. cp[2].ev.v = rVertex[fptr->v3]; cp[2].tx = fptr->tcx; cp[2].ty = fptr->tcy;
  1089. if (CMASK == 0xFF) {
  1090. for (u=0; u<vused; u++) cp[u].ev.v.z+=12.0f;
  1091. for (u=0; u<vused; u++) ClipVector(ClipZ,u);
  1092. for (u=0; u<vused; u++) cp[u].ev.v.z-=12.0f;
  1093. if (vused<3) goto LNEXT;
  1094. }
  1095. if (waterclip) {
  1096. for (u=0; u<vused; u++) { cp[u].ev.v.x-=waterclipbase.x; cp[u].ev.v.y-=waterclipbase.y; cp[u].ev.v.z-=waterclipbase.z; }
  1097. for (u=0; u<vused; u++) ClipVector(ClipW,u);
  1098. for (u=0; u<vused; u++) { cp[u].ev.v.x+=waterclipbase.x; cp[u].ev.v.y+=waterclipbase.y; cp[u].ev.v.z+=waterclipbase.z; }
  1099. if (vused<3) goto LNEXT;
  1100. }
  1101. if (CMASK & 1) for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) goto LNEXT;
  1102. if (CMASK & 2) for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) goto LNEXT;
  1103. if (CMASK & 4) for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) goto LNEXT;
  1104. if (CMASK & 8) for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) goto LNEXT;
  1105. for (u=0; u<vused; u++) {
  1106. cp[u].ev.scrx = VideoCX - (int)(cp[u].ev.v.x / cp[u].ev.v.z * CameraW);
  1107. cp[u].ev.scry = VideoCY + (int)(cp[u].ev.v.y / cp[u].ev.v.z * CameraH);
  1108. }
  1109. mscrp[0].x = cp[0].ev.scrx;
  1110. mscrp[0].y = cp[0].ev.scry;
  1111. mscrp[0].tx = cp[0].tx;
  1112. mscrp[0].ty = cp[0].ty;
  1113. OpacityMode = (fptr->Flags & (sfOpacity + sfTransparent));
  1114. for (u=0; u<vused-2; u++) {
  1115. for (int n=1; n<3; n++) {
  1116. mscrp[n].x = cp[n+u].ev.scrx;
  1117. mscrp[n].y = cp[n+u].ev.scry;
  1118. mscrp[n].tx = cp[n+u].tx;
  1119. mscrp[n].ty = cp[n+u].ty; }
  1120. DrawModelFace();
  1121. }
  1122. LNEXT:
  1123. f = mptr->gFace[f].Next;
  1124. }
  1125. }
  1126. void RenderModelClipWater(TModel* _mptr, float x0, float y0, float z0, int light, int VT, float al, float bt)
  1127. {
  1128. int f;
  1129. mptr = _mptr;
  1130. float ca = (float)cos(al);
  1131. float sa = (float)sin(al);
  1132. float cb = (float)cos(bt);
  1133. float sb = (float)sin(bt);
  1134. __asm {
  1135. mov eax,light
  1136. shr eax,2
  1137. shl eax,16
  1138. add eax, offset FadeTab
  1139. mov iModelFade,eax
  1140. mov iModelBaseFade,eax
  1141. }
  1142. //=================== select mipmap & glass =============================//
  1143. if (!GlassL) HLineT = (void*) HLineTxModel; else
  1144. if (GlassL>160) HLineT = (void*) HLineTxModel25; else
  1145. if (GlassL>80 ) HLineT = (void*) HLineTxModel50; else
  1146. HLineT = (void*) HLineTxModel75;
  1147. lpTextureAddr = (void*) mptr->lpTexture;
  1148. if (GlassL) lpTextureAddr = (void*) mptr->lpTexture3;
  1149. else
  1150. if (ts <=64)
  1151. if (ts > 32) {
  1152. lpTextureAddr = (void*) mptr->lpTexture2;
  1153. HLineT = (void*) HLineTxModel2;
  1154. } else {
  1155. lpTextureAddr = (void*) mptr->lpTexture3;
  1156. HLineT = (void*) HLineTxModel3;
  1157. }
  1158. BOOL BL = FALSE;
  1159. float sg;
  1160. for (int s=0; s<mptr->VCount; s++) {
  1161. rVertex[s].x = (mptr->gVertex[s].x * ca + mptr->gVertex[s].z * sa) + x0;
  1162. float vz = mptr->gVertex[s].z * ca - mptr->gVertex[s].x * sa;
  1163. rVertex[s].y = (mptr->gVertex[s].y * cb - vz * sb) + y0;
  1164. rVertex[s].z = (vz * cb + mptr->gVertex[s].y * sb) + z0;
  1165. v[0] = SubVectors(rVertex[s], waterclipbase);
  1166. MulVectorsScal(v[0], ClipW.nv, sg);
  1167. if (sg>=0) gScrp[s].x = 0; else gScrp[s].x=1;
  1168. if (rVertex[s].z<0) BL=TRUE;
  1169. }
  1170. if (!BL) return;
  1171. if (fabs(z0) + fabs(x0)>256*10)
  1172. BuildTreeClipNoSort(); else BuildTreeClip();
  1173. f = Current;
  1174. while( f!=-1 ) {
  1175. vused = 3;
  1176. TFace *fptr = &mptr->gFace[f];
  1177. if (rVertex[fptr->v1].z > -128) goto LNEXT;
  1178. if (rVertex[fptr->v2].z > -128) goto LNEXT;
  1179. if (rVertex[fptr->v3].z > -128) goto LNEXT;
  1180. if (gScrp[fptr->v1].x & gScrp[fptr->v2].x & gScrp[fptr->v3].x) goto LNEXT;
  1181. cp[0].ev.v = rVertex[fptr->v1]; cp[0].tx = fptr->tax; cp[0].ty = fptr->tay;
  1182. cp[1].ev.v = rVertex[fptr->v2]; cp[1].tx = fptr->tbx; cp[1].ty = fptr->tby;
  1183. cp[2].ev.v = rVertex[fptr->v3]; cp[2].tx = fptr->tcx; cp[2].ty = fptr->tcy;
  1184. if (!(gScrp[fptr->v1].x | gScrp[fptr->v2].x | gScrp[fptr->v3].x)) goto LNOCLIP;
  1185. for (u=0; u<vused; u++) { cp[u].ev.v.x-=waterclipbase.x; cp[u].ev.v.y-=waterclipbase.y; cp[u].ev.v.z-=waterclipbase.z; }
  1186. for (u=0; u<vused; u++) ClipVector(ClipW,u);
  1187. for (u=0; u<vused; u++) { cp[u].ev.v.x+=waterclipbase.x; cp[u].ev.v.y+=waterclipbase.y; cp[u].ev.v.z+=waterclipbase.z; }
  1188. if (vused<3) goto LNEXT;
  1189. LNOCLIP:
  1190. for (u=0; u<vused; u++) {
  1191. cp[u].ev.scrx = VideoCX - (int)(cp[u].ev.v.x / cp[u].ev.v.z * CameraW);
  1192. cp[u].ev.scry = VideoCY + (int)(cp[u].ev.v.y / cp[u].ev.v.z * CameraH);
  1193. }
  1194. mscrp[0].x = cp[0].ev.scrx;
  1195. mscrp[0].y = cp[0].ev.scry;
  1196. mscrp[0].tx = cp[0].tx;
  1197. mscrp[0].ty = cp[0].ty;
  1198. OpacityMode = (fptr->Flags & (sfOpacity + sfTransparent));
  1199. for (u=0; u<vused-2; u++) {
  1200. for (int n=1; n<3; n++) {
  1201. mscrp[n].x = cp[n+u].ev.scrx;
  1202. mscrp[n].y = cp[n+u].ev.scry;
  1203. mscrp[n].tx = cp[n+u].tx;
  1204. mscrp[n].ty = cp[n+u].ty; }
  1205. DrawModelFace();
  1206. }
  1207. LNEXT:
  1208. f = mptr->gFace[f].Next;
  1209. }
  1210. }
  1211. void RenderModel(TModel* _mptr, float x0, float y0, float z0, int light, int VT, float al, float bt)
  1212. {
  1213. int f;
  1214. mptr = _mptr;
  1215. float ca = (float)cos(al);
  1216. float sa = (float)sin(al);
  1217. float cb = (float)cos(bt);
  1218. float sb = (float)sin(bt);
  1219. int minx = 10241024;
  1220. int maxx =-10241024;
  1221. int miny = 10241024;
  1222. int maxy =-10241024;
  1223. __asm {
  1224. mov eax,light
  1225. shr eax,2
  1226. shl eax,16
  1227. add eax, offset FadeTab
  1228. mov iModelFade,eax
  1229. mov iModelBaseFade,eax
  1230. }
  1231. if (!GlassL) HLineT = (void*) HLineTxModel; else
  1232. if (GlassL>160) HLineT = (void*) HLineTxModel25; else
  1233. if (GlassL>80 ) HLineT = (void*) HLineTxModel50; else
  1234. HLineT = (void*) HLineTxModel75;
  1235. lpTextureAddr = (void*) mptr->lpTexture;
  1236. if (GlassL) lpTextureAddr = (void*) mptr->lpTexture3;
  1237. else
  1238. if (ts <=64)
  1239. if (ts > 32) {
  1240. lpTextureAddr = (void*) mptr->lpTexture2;
  1241. HLineT = (void*) HLineTxModel2;
  1242. } else {
  1243. lpTextureAddr = (void*) mptr->lpTexture3;
  1244. HLineT = (void*) HLineTxModel3;
  1245. }
  1246. for (int s=0; s<mptr->VCount; s++) {
  1247. rVertex[s].x = (mptr->gVertex[s].x * ca + mptr->gVertex[s].z * sa) + x0;
  1248. float vz = mptr->gVertex[s].z * ca - mptr->gVertex[s].x * sa;
  1249. rVertex[s].y = (mptr->gVertex[s].y * cb - vz * sb) + y0;
  1250. rVertex[s].z = (vz * cb + mptr->gVertex[s].y * sb) + z0;
  1251. if (rVertex[s].z>-64) gScrp[s].x = 0xFFFFFF; else {
  1252. gScrp[s].x = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
  1253. gScrp[s].y = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH); }
  1254. if (gScrp[s].x > maxx) maxx = gScrp[s].x;
  1255. if (gScrp[s].x < minx) minx = gScrp[s].x;
  1256. if (gScrp[s].y > maxy) maxy = gScrp[s].y;
  1257. if (gScrp[s].y < miny) miny = gScrp[s].y;
  1258. }
  1259. if (minx == 10241024) return;
  1260. if (minx>WinW || maxx<0 || miny>WinH || maxy<0) return;
  1261. if (fabs(z0) + fabs(x0)>256*10)
  1262. BuildTreeNoSort(); else BuildTree();
  1263. if (Current != -1) DrawModelFaces();
  1264. return;
  1265. f = Current;
  1266. while( f!=-1 ) {
  1267. mscrp[0].x = gScrp[mptr->gFace[f].v1].x;
  1268. mscrp[0].y = gScrp[mptr->gFace[f].v1].y;
  1269. mscrp[0].tx = mptr->gFace[f].tax;
  1270. mscrp[0].ty = mptr->gFace[f].tay;
  1271. mscrp[1].x = gScrp[mptr->gFace[f].v2].x;
  1272. mscrp[1].y = gScrp[mptr->gFace[f].v2].y;
  1273. mscrp[1].tx = mptr->gFace[f].tbx;
  1274. mscrp[1].ty = mptr->gFace[f].tby;
  1275. mscrp[2].x = gScrp[mptr->gFace[f].v3].x;
  1276. mscrp[2].y = gScrp[mptr->gFace[f].v3].y;
  1277. mscrp[2].tx = mptr->gFace[f].tcx;
  1278. mscrp[2].ty = mptr->gFace[f].tcy;
  1279. OpacityMode = (mptr->gFace[f].Flags & (sfOpacity + sfTransparent));
  1280. if (mptr->gFace[f].Flags & sfDark)
  1281. iModelFade = iModelBaseFade + 12*256*256;
  1282. else iModelFade = iModelBaseFade;
  1283. DrawModelFace();
  1284. f = mptr->gFace[f].Next;
  1285. }
  1286. }
  1287. void RenderBMPModel(TBMPModel* _mptr, float x0, float y0, float z0, int light)
  1288. {
  1289. int f;
  1290. TBMPModel *mptr = _mptr;
  1291. int minx = 10241024;
  1292. int maxx =-10241024;
  1293. int miny = 10241024;
  1294. int maxy =-10241024;
  1295. __asm {
  1296. mov eax,light
  1297. shr eax,2
  1298. shl eax,16
  1299. add eax, offset FadeTab
  1300. mov iModelFade,eax
  1301. mov iModelBaseFade,eax
  1302. }
  1303. lpTextureAddr = (void*) mptr->lpTexture;
  1304. HLineT = (void*) HLineTxModel2;
  1305. for (int s=0; s<4; s++) {
  1306. rVertex[s].x = mptr->gVertex[s].x + x0;
  1307. rVertex[s].y = mptr->gVertex[s].y + y0;
  1308. rVertex[s].z = z0;
  1309. if (rVertex[s].z<-256) {
  1310. gScrp[s].x = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
  1311. gScrp[s].y = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
  1312. } else return;
  1313. if (gScrp[s].x > maxx) maxx = gScrp[s].x;
  1314. if (gScrp[s].x < minx) minx = gScrp[s].x;
  1315. if (gScrp[s].y > maxy) maxy = gScrp[s].y;
  1316. if (gScrp[s].y < miny) miny = gScrp[s].y;
  1317. }
  1318. if (minx == 10241024) return;
  1319. if (minx>WinW || maxx<0 || miny>WinH || maxy<0) return;
  1320. //int w = gScrp[1].x - gScrp[0].x;
  1321. int h = gScrp[2].y - gScrp[1].y;
  1322. //int xo = (gScrp[1].x + gScrp[0].x) / 2;
  1323. int yo = gScrp[0].y;
  1324. if (!h) return;
  1325. xa = gScrp[0].x<<16;
  1326. xb = gScrp[1].x<<16;
  1327. Y1 = yo;
  1328. int DTY = 128*256*256 / h;
  1329. int TY = -DTY;
  1330. for (int y=0; y<h; y++) {
  1331. Y1++;
  1332. TY+=DTY;
  1333. if (Y1< 0 ) continue;
  1334. if (Y1>=WinH) continue;
  1335. lpTextureAddr = (void*) (mptr->lpTexture + (TY>>16)*128);
  1336. HLineTxModelBMP();
  1337. }
  1338. }
  1339. void RenderNearModel(TModel* _mptr, float x0, float y0, float z0, int light, float al, float bt)
  1340. {
  1341. int f;
  1342. mptr = _mptr;
  1343. float ca = (float)cos(al);
  1344. float sa = (float)sin(al);
  1345. float cb = (float)cos(bt);
  1346. float sb = (float)sin(bt);
  1347. //light = 0;
  1348. __asm {
  1349. mov eax,light
  1350. shr eax,2
  1351. shl eax,16
  1352. add eax, offset FadeTab
  1353. mov iModelFade,eax
  1354. mov iModelBaseFade,eax
  1355. }
  1356. HLineT = (void*) HLineTxModel;
  1357. lpTextureAddr = (void*) mptr->lpTexture;
  1358. BOOL BL = FALSE;
  1359. for (int s=0; s<mptr->VCount; s++) {
  1360. rVertex[s].x = (mptr->gVertex[s].x * ca + mptr->gVertex[s].z * sa) + x0;
  1361. float vz = mptr->gVertex[s].z * ca - mptr->gVertex[s].x * sa;
  1362. rVertex[s].y = (mptr->gVertex[s].y * cb - vz * sb) + y0;
  1363. rVertex[s].z = (vz * cb + mptr->gVertex[s].y * sb) + z0;
  1364. if (rVertex[s].z<0) BL=TRUE;
  1365. }
  1366. if (!BL) return;
  1367. BuildTreeClip();
  1368. f = Current;
  1369. while( f!=-1 ) {
  1370. vused = 3;
  1371. TFace *fptr = &mptr->gFace[f];
  1372. cp[0].ev.v = rVertex[fptr->v1]; cp[0].tx = fptr->tax; cp[0].ty = fptr->tay;
  1373. cp[1].ev.v = rVertex[fptr->v2]; cp[1].tx = fptr->tbx; cp[1].ty = fptr->tby;
  1374. cp[2].ev.v = rVertex[fptr->v3]; cp[2].tx = fptr->tcx; cp[2].ty = fptr->tcy;
  1375. for (u=0; u<vused; u++) cp[u].ev.v.z+=12.0f;
  1376. for (u=0; u<vused; u++) ClipVector(ClipZ,u);
  1377. for (u=0; u<vused; u++) cp[u].ev.v.z-=12.0f;
  1378. if (vused<3) goto LNEXT;
  1379. for (u=0; u<vused; u++) ClipVector(ClipA,u);
  1380. for (u=0; u<vused; u++) ClipVector(ClipC,u);
  1381. for (u=0; u<vused; u++) ClipVector(ClipB,u);
  1382. for (u=0; u<vused; u++) ClipVector(ClipD,u);
  1383. if (vused<3) goto LNEXT;
  1384. for (u=0; u<vused; u++) {
  1385. cp[u].ev.scrx = VideoCX - (int)(cp[u].ev.v.x / cp[u].ev.v.z * CameraW);
  1386. cp[u].ev.scry = VideoCY + (int)(cp[u].ev.v.y / cp[u].ev.v.z * CameraH);
  1387. }
  1388. scrp[0].x = cp[0].ev.scrx;
  1389. scrp[0].y = cp[0].ev.scry;
  1390. scrp[0].z = (int)cp[0].ev.v.z;
  1391. scrp[0].tx = cp[0].tx;
  1392. scrp[0].ty = cp[0].ty;
  1393. OpacityMode = (fptr->Flags & (sfOpacity + sfTransparent));
  1394. if (CORRECTION) Soft_Persp_K = 2.0f;
  1395. else Soft_Persp_K = 0.0f;
  1396. for (u=0; u<vused-2; u++) {
  1397. for (int n=1; n<3; n++) {
  1398. scrp[n].x = cp[n+u].ev.scrx;
  1399. scrp[n].y = cp[n+u].ev.scry;
  1400. scrp[n].z = (int)cp[n+u].ev.v.z;
  1401. scrp[n].tx = cp[n+u].tx;
  1402. scrp[n].ty = cp[n+u].ty; }
  1403. DrawCorrectedTexturedFace();
  1404. }
  1405. Soft_Persp_K = 1.5f;
  1406. LNEXT:
  1407. f = mptr->gFace[f].Next;
  1408. }
  1409. }
  1410. void RenderCharacter(int index)
  1411. {
  1412. TCharacter *cptr = &Characters[index];
  1413. float zs = (float)VectorLength( cptr->rpos );
  1414. if (zs > ctViewR*256) return;
  1415. GlassL = 0;
  1416. if (zs > 256 * (ctViewR-4))
  1417. GlassL = min(255, (zs/4 - 64*(ctViewR-4)));
  1418. CreateChMorphedModel(cptr);
  1419. float wh = GetLandUpH(cptr->pos.x, cptr->pos.z);
  1420. waterclip = FALSE;
  1421. if (!UNDERWATER)
  1422. if (wh > cptr->pos.y + 32*2) {
  1423. waterclipbase.x = cptr->pos.x - CameraX;
  1424. waterclipbase.y = wh - CameraY;
  1425. waterclipbase.z = cptr->pos.z - CameraZ;
  1426. waterclipbase = RotateVector(waterclipbase);
  1427. waterclip = TRUE;
  1428. }
  1429. if ( fabs(cptr->rpos.z) + fabs(cptr->rpos.x) <2560)
  1430. RenderModelClip(cptr->pinfo->mptr,
  1431. cptr->rpos.x, cptr->rpos.y, cptr->rpos.z, 240, 0,
  1432. -cptr->alpha + pi / 2 + CameraAlpha,
  1433. CameraBeta );
  1434. else
  1435. if (waterclip)
  1436. RenderModelClipWater(cptr->pinfo->mptr,
  1437. cptr->rpos.x, cptr->rpos.y, cptr->rpos.z, 240, 0,
  1438. -cptr->alpha + pi / 2 + CameraAlpha,
  1439. CameraBeta );
  1440. else
  1441. RenderModel(cptr->pinfo->mptr,
  1442. cptr->rpos.x, cptr->rpos.y, cptr->rpos.z, 240, 0,
  1443. -cptr->alpha + pi / 2 + CameraAlpha,
  1444. CameraBeta );
  1445. }
  1446. void RenderShip()
  1447. {
  1448. float zs = (float)VectorLength( Ship.rpos );
  1449. if (zs > ctViewR*256) return;
  1450. GlassL = 0;
  1451. if (zs > 256 * (ctViewR-4))
  1452. GlassL = min(255, (zs/4 - 64*(ctViewR-4)));
  1453. CreateMorphedModel(ShipModel.mptr, &ShipModel.Animation[0], Ship.FTime, 1.0);
  1454. if ( fabs(Ship.rpos.z) < 4000)
  1455. RenderModelClip(ShipModel.mptr,
  1456. Ship.rpos.x, Ship.rpos.y, Ship.rpos.z, 240, 0, -Ship.alpha -pi/2 + CameraAlpha, CameraBeta);
  1457. else
  1458. RenderModel(ShipModel.mptr,
  1459. Ship.rpos.x, Ship.rpos.y, Ship.rpos.z, 240, 0, -Ship.alpha -pi/2 + CameraAlpha, CameraBeta);
  1460. }
  1461. void _FillMemoryWord(int maddr, int count, WORD w)
  1462. {
  1463. __asm {
  1464. mov edi,maddr
  1465. mov ecx,count
  1466. shr ecx,2
  1467. mov ax,w
  1468. shl eax,16
  1469. mov ax,w
  1470. rep stosd
  1471. }
  1472. }
  1473. void FillMemoryWord(int maddr, int count, WORD w)
  1474. {
  1475. WORD ww[4];
  1476. ww[0] = w; ww[1] = w; ww[2] = w; ww[3] = w;
  1477. __asm {
  1478. EMMS
  1479. mov edi,maddr
  1480. mov ecx,count
  1481. shr ecx,3
  1482. MOVQ MM0,ww
  1483. } L1: __asm {
  1484. MOVQ [edi],MM0
  1485. add edi,8
  1486. dec cx
  1487. jnz L1
  1488. EMMS
  1489. }
  1490. }
  1491. void _memcpy(void* daddr, void* saddr, int count)
  1492. {
  1493. __asm {
  1494. EMMS
  1495. mov edi,daddr
  1496. mov esi,saddr
  1497. mov ecx,count
  1498. shr ecx,3
  1499. } L1: __asm {
  1500. MOVQ MM0,[esi]
  1501. MOVQ [edi],MM0
  1502. add edi,8
  1503. add esi,8
  1504. dec cx
  1505. jnz L1
  1506. EMMS
  1507. }
  1508. }
  1509. void DrawPicture(int x, int y, TPicture &pic)
  1510. {
  1511. for (int yy=0; yy<pic.H; yy++)
  1512. if ( (yy+y>=0) && (yy+y < WinH) )
  1513. memcpy( (WORD*)lpVideoBuf + ((yy+y)<<10) + x,
  1514. pic.lpImage + yy*pic.W,
  1515. pic.W<<1);
  1516. }
  1517. void ClearVideoBuf()
  1518. {
  1519. WORD w = HiColor(SkyR/8, SkyG/8, SkyB/8);
  1520. for(int y=0; y<WinH; y++) {
  1521. _FillMemoryWord( (int)lpVideoBuf + y*2048, WinW*2, w);
  1522. }
  1523. }
  1524. int CircleCX, CircleCY;
  1525. void PutPixel(int x, int y)
  1526. {
  1527. if (y<0 || y>=WinH) return;
  1528. *((WORD*)lpVideoBuf + (y<<10) + x) = 18<<5;
  1529. }
  1530. void Put8pix(int X,int Y)
  1531. {
  1532. PutPixel(CircleCX + X, CircleCY + Y);
  1533. PutPixel(CircleCX + X, CircleCY - Y);
  1534. PutPixel(CircleCX - X, CircleCY + Y);
  1535. PutPixel(CircleCX - X, CircleCY - Y);
  1536. PutPixel(CircleCX + Y, CircleCY + X);
  1537. PutPixel(CircleCX + Y, CircleCY - X);
  1538. PutPixel(CircleCX - Y, CircleCY + X);
  1539. PutPixel(CircleCX - Y, CircleCY - X);
  1540. }
  1541. void DrawCircle(int cx, int cy, int R)
  1542. {
  1543. int d = 3 - (2 * R);
  1544. int x = 0;
  1545. int y = R;
  1546. CircleCX=cx;
  1547. CircleCY=cy;
  1548. do {
  1549. Put8pix(x,y); x++;
  1550. if (d < 0) d = d + (x<<2) + 6; else
  1551. { d = d + (x - y) * 4 + 10; y--; }
  1552. } while (x<y);
  1553. Put8pix(x,y);
  1554. }
  1555. void DrawHMap()
  1556. {
  1557. //if (WinH < 280) return;
  1558. DrawPicture(VideoCX-MapPic.W/2, VideoCY - MapPic.H/2, MapPic);
  1559. int xx = VideoCX - 128 + (CCX>>2);
  1560. int yy = VideoCY - 128 + (CCY>>2)+6;
  1561. if (yy>0 || yy<WinH) {
  1562. DrawCircle(xx, yy, 17);
  1563. *((WORD*)lpVideoBuf + yy*1024 + xx) = 31<<10;
  1564. *((WORD*)lpVideoBuf + yy*1024 + xx+1) = 31<<10;
  1565. yy++;
  1566. *((WORD*)lpVideoBuf + yy*1024 + xx) = 31<<10;
  1567. *((WORD*)lpVideoBuf + yy*1024 + xx+1) = 31<<10;
  1568. }
  1569. if (RadarMode)
  1570. for (int c=0; c<ChCount; c++) {
  1571. if (! (TargetDino & (1<<Characters[c].AI)) ) continue;
  1572. if (!Characters[c].Health) continue;
  1573. xx = VideoCX - 128 + (int)Characters[c].pos.x / 1024;
  1574. yy = VideoCY - 128 + (int)Characters[c].pos.z / 1024;
  1575. if (yy<=0 || yy>=WinH) continue;
  1576. if (xx<=0 || xx>=WinW) continue;
  1577. *((WORD*)lpVideoBuf + yy*1024 + xx) = 30<<5;
  1578. *((WORD*)lpVideoBuf + yy*1024 + xx+1) = 30<<5;
  1579. yy++;
  1580. *((WORD*)lpVideoBuf + yy*1024 + xx) = 30<<5;
  1581. *((WORD*)lpVideoBuf + yy*1024 + xx+1) = 30<<5;
  1582. }
  1583. }
  1584. void DrawTrophyText(int x0, int y0)
  1585. {
  1586. int x;
  1587. HBITMAP hbmpOld = SelectObject(hdcCMain, hbmpVideoBuf);
  1588. HFONT oldfont = SelectObject(hdcCMain, fnt_Small);
  1589. /*
  1590. int dtype = Characters[TrophyBody].CType;
  1591. int tc = Characters[TrophyBody].State;
  1592. int time = TrophyRoom.Body[tc].time;
  1593. int date = TrophyRoom.Body[tc].date;
  1594. int wep = TrophyRoom.Body[tc].weapon;
  1595. int score = TrophyRoom.Body[tc].score;
  1596. float scale = Characters[TrophyBody].scale;*/
  1597. int tc = TrophyBody;
  1598. int dtype = TrophyRoom.Body[tc].ctype;
  1599. int time = TrophyRoom.Body[tc].time;
  1600. int date = TrophyRoom.Body[tc].date;
  1601. int wep = TrophyRoom.Body[tc].weapon;
  1602. int score = TrophyRoom.Body[tc].score;
  1603. float scale = TrophyRoom.Body[tc].scale;
  1604. float range = TrophyRoom.Body[tc].range;
  1605. char t[32];
  1606. x0+=16; y0+=18;
  1607. x = x0;
  1608. STTextOut(x, y0 , "Name: ", 0x00BFBFBF); x+=GetTextW(hdcCMain,"Name: ");
  1609. STTextOut(x, y0 , DinoInfo[dtype].Name, 0x0000BFBF);
  1610. x = x0;
  1611. STTextOut(x, y0+16, "Weight: ", 0x00BFBFBF); x+=GetTextW(hdcCMain,"Weight: ");
  1612. if (OptSys)
  1613. sprintf(t,"%3.2ft ", DinoInfo[dtype].Mass * scale * scale / 0.907);
  1614. else
  1615. sprintf(t,"%3.2fT ", DinoInfo[dtype].Mass * scale * scale);
  1616. STTextOut(x, y0+16, t, 0x0000BFBF); x+=GetTextW(hdcCMain,t);
  1617. STTextOut(x, y0+16, "Length: ", 0x00BFBFBF); x+=GetTextW(hdcCMain,"Length: ");
  1618. if (OptSys)
  1619. sprintf(t,"%3.2fft", DinoInfo[dtype].Length * scale / 0.3);
  1620. else
  1621. sprintf(t,"%3.2fm", DinoInfo[dtype].Length * scale);
  1622. STTextOut(x, y0+16, t, 0x0000BFBF);
  1623. x = x0;
  1624. STTextOut(x, y0+32, "Weapon: ", 0x00BFBFBF); x+=GetTextW(hdcCMain,"Weapon: ");
  1625. wsprintf(t,"%s ", WeapInfo[wep].Name);
  1626. STTextOut(x, y0+32, t, 0x0000BFBF); x+=GetTextW(hdcCMain,t);
  1627. STTextOut(x, y0+32, "Score: ", 0x00BFBFBF); x+=GetTextW(hdcCMain,"Score: ");
  1628. wsprintf(t,"%d", score);
  1629. STTextOut(x, y0+32, t, 0x0000BFBF);
  1630. x = x0;
  1631. STTextOut(x, y0+48, "Range of kill: ", 0x00BFBFBF); x+=GetTextW(hdcCMain,"Range of kill: ");
  1632. if (OptSys) sprintf(t,"%3.1fft", range / 0.3);
  1633. else sprintf(t,"%3.1fm", range);
  1634. STTextOut(x, y0+48, t, 0x0000BFBF);
  1635. x = x0;
  1636. STTextOut(x, y0+64, "Date: ", 0x00BFBFBF); x+=GetTextW(hdcCMain,"Date: ");
  1637. if (OptSys)
  1638. wsprintf(t,"%d.%d.%d ", ((date>>10) & 255), (date & 255), date>>20);
  1639. else
  1640. wsprintf(t,"%d.%d.%d ", (date & 255), ((date>>10) & 255), date>>20);
  1641. STTextOut(x, y0+64, t, 0x0000BFBF); x+=GetTextW(hdcCMain,t);
  1642. STTextOut(x, y0+64, "Time: ", 0x00BFBFBF); x+=GetTextW(hdcCMain,"Time: ");
  1643. wsprintf(t,"%d:%02d", ((time>>10) & 255), (time & 255));
  1644. STTextOut(x, y0+64, t, 0x0000BFBF);
  1645. SelectObject(hdcCMain, oldfont);
  1646. SelectObject(hdcCMain, hbmpOld);
  1647. }
  1648. void Render_LifeInfo(int li)
  1649. {
  1650. int x,y;
  1651. HBITMAP hbmpOld = SelectObject(hdcCMain, hbmpVideoBuf);
  1652. HFONT oldfont = SelectObject(hdcCMain, fnt_Small);
  1653. int ctype = Characters[li].CType;
  1654. float scale = Characters[li].scale;
  1655. char t[32];
  1656. x = VideoCX + WinW / 64;
  1657. y = VideoCY + (int)(WinH / 6.8);
  1658. STTextOut(x, y, DinoInfo[ctype].Name, 0x0000b000);
  1659. if (OptSys) sprintf(t,"Weight: %3.2ft ", DinoInfo[ctype].Mass * scale * scale / 0.907);
  1660. else sprintf(t,"Weight: %3.2fT ", DinoInfo[ctype].Mass * scale * scale);
  1661. STTextOut(x, y+16, t, 0x0000b000);
  1662. int R = (int)(VectorLength( SubVectors(Characters[li].pos, PlayerPos) )*3 / 64.f);
  1663. if (OptSys) sprintf(t,"Distance: %dft ", R);
  1664. else sprintf(t,"Distance: %dm ", R/3);
  1665. STTextOut(x, y+32, t, 0x0000b000);
  1666. SelectObject(hdcMain, oldfont);
  1667. SelectObject(hdcCMain, oldfont);
  1668. SelectObject(hdcCMain, hbmpOld);
  1669. }
  1670. void RotateVVector(Vector3d& v)
  1671. {
  1672. float x = v.x * ca - v.z * sa;
  1673. float y = v.y;
  1674. float z = v.z * ca + v.x * sa;
  1675. float xx = x;
  1676. float xy = y * cb + z * sb;
  1677. float xz = z * cb - y * sb;
  1678. v.x = xx; v.y = xy; v.z = xz;
  1679. }
  1680. void RenderSkyPlane()
  1681. {
  1682. ClearVideoBuf();
  1683. Vector3d v,vbase;
  1684. Vector3d tx,ty,nv;
  1685. float p,q, qx, qy, qz, px, py, pz, rx, ry, rz, ddx, ddy;
  1686. int lastdt = 0;
  1687. cb = (float)cos(CameraBeta);
  1688. sb = (float)sin(CameraBeta);
  1689. SKYDTime = (RealTime*256) & ((256<<16) - 1);
  1690. float sh = - CameraY;
  1691. if (MapMinY==10241024) MapMinY=0;
  1692. sh = (float)((int)MapMinY)*ctHScale - CameraY;
  1693. v.x = 0;
  1694. v.z = (ctViewR*4.f)/5.f*256.f;
  1695. v.y = sh;
  1696. vbase.x = v.x;
  1697. vbase.y = v.y * cb + v.z * sb;
  1698. vbase.z = v.z * cb - v.y * sb;
  1699. if (vbase.z < 128) vbase.z = 128;
  1700. int scry = VideoCY - (int)(vbase.y / vbase.z * CameraH);
  1701. if (scry<0) return;
  1702. if (scry>WinEY) scry = WinEY;
  1703. cb = (float)cos(CameraBeta-0.15);
  1704. sb = (float)sin(CameraBeta-0.15);
  1705. tx.x=0.004f; tx.y=0; tx.z=0;
  1706. ty.x=0.0f; ty.y=0; ty.z=0.004f;
  1707. nv.x=0; nv.y=-1.f; nv.z=0;
  1708. tx.x*=0x10000;
  1709. ty.z*=0x10000;
  1710. RotateVVector(tx);
  1711. RotateVVector(ty);
  1712. RotateVVector(nv);
  1713. sh = 4*512*16;
  1714. vbase.x = -CameraX;
  1715. vbase.y = sh;
  1716. vbase.z = +CameraZ;
  1717. RotateVVector(vbase);
  1718. //============= calc render params =================//
  1719. p = nv.x * vbase.x + nv.y * vbase.y + nv.z * vbase.z;
  1720. ddx = vbase.x * tx.x + vbase.y * tx.y + vbase.z * tx.z;
  1721. ddy = vbase.x * ty.x + vbase.y * ty.y + vbase.z * ty.z;
  1722. qx = CameraH * nv.x; qy = CameraW * nv.y; qz = CameraW*CameraH * nv.z;
  1723. px = p*CameraH*tx.x; py = p*CameraW*tx.y; pz = p*CameraW*CameraH* tx.z;
  1724. rx = p*CameraH*ty.x; ry = p*CameraW*ty.y; rz = p*CameraW*CameraH* ty.z;
  1725. px=px - ddx*qx; py=py - ddx*qy; pz=pz - ddx*qz;
  1726. rx=rx - ddy*qx; ry=ry - ddy*qy; rz=rz - ddy*qz;
  1727. int sx1 = - VideoCX;
  1728. int sx2 = + VideoCX;
  1729. float qx1 = qx * sx1 + qz;
  1730. float qx2 = qx * sx2 + qz;
  1731. float qyy;
  1732. for (int sky=0; sky<=scry; sky++) {
  1733. int sy = VideoCY - sky;
  1734. qyy = qy * sy;
  1735. q = qx1 + qyy;
  1736. float fxa = (px * sx1 + py * sy + pz) / q;
  1737. float fya = (rx * sx1 + ry * sy + rz) / q;
  1738. q = qx2 + qyy;
  1739. float fxb = (px * sx2 + py * sy + pz) / q;
  1740. float fyb = (rx * sx2 + ry * sy + rz) / q;
  1741. txa = ((int)fxa + SKYDTime) & ((256<<16) - 1);
  1742. tya = ((int)fya - SKYDTime) & ((256<<16) - 1);
  1743. ctdx = (int)(fxb-fxa);
  1744. ctdy = (int)(fyb-fya);
  1745. int dt = (int)(sqrt( (fxb-fxa)*(fxb-fxa) + (fyb-fya)*(fyb-fya) ) / 0x600000 ) - 7;
  1746. if (dt>8) dt = 8;
  1747. if (dt<lastdt) dt = lastdt;
  1748. lastdt = dt;
  1749. ctdx/=WinW; ctdy/=WinW;
  1750. if (LoDetailSky)
  1751. if (dt) RenderSkyLineFadeLo(sky, dt); else RenderSkyLineLo(sky); else
  1752. if (dt) RenderSkyLineFade(sky,dt); else RenderSkyLine(sky);
  1753. }
  1754. }
  1755. void ShowVideo()
  1756. {
  1757. HDC _hdc = hdcCMain;
  1758. HBITMAP hbmpOld = SelectObject(_hdc,hbmpVideoBuf);
  1759. if (UNDERWATER & CORRECTION)
  1760. for (int y=0; y<WinH; y++)
  1761. for (int x=0; x<WinW; x++)
  1762. *((WORD*)lpVideoBuf + y*1024 + x) = FadeTab[64][*((WORD*)lpVideoBuf + y*1024 + x) & 0x7FFF];
  1763. RenderHealthBar();
  1764. BitBlt(hdcMain,0,0,WinW,WinH, _hdc,0,0, SRCCOPY);
  1765. SelectObject(_hdc,hbmpOld);
  1766. //DeleteDC(_hdc);
  1767. }
  1768. void RenderHealthBar()
  1769. {
  1770. if (MyHealth >= 100000) return;
  1771. if (MyHealth == 000000) return;
  1772. int L = WinW / 4;
  1773. int x0 = WinW - (WinW / 20) - L;
  1774. int y0 = WinH / 40;
  1775. int G = min( (MyHealth * 30 / 100000), 20);
  1776. int R = min( ( (100000 - MyHealth) * 30 / 100000), 20);
  1777. int HCOLOR = (G<<5) + (R<<10);
  1778. int L0 = (L * MyHealth) / 100000;
  1779. int H = WinH / 200;
  1780. FillMemory((WORD*)lpVideoBuf + ((y0-1)<<10) + x0-1, L*2+4, 0);
  1781. FillMemory((WORD*)lpVideoBuf + ((y0+H+1)<<10) + x0-1, L*2+4, 0);
  1782. for (int y=0; y<=H; y++) {
  1783. *((WORD*)lpVideoBuf + ((y0+y)<<10) + x0 - 1) = 0;
  1784. *((WORD*)lpVideoBuf + ((y0+y)<<10) + x0 + L) = 0;
  1785. for (int x=0; x<L0; x++)
  1786. *((WORD*)lpVideoBuf + ((y0+y)<<10) + x0 + x) = HCOLOR;
  1787. }
  1788. }
  1789. void Render_Cross(int sx, int sy)
  1790. {
  1791. int w = WinW / 12;
  1792. for (int x=-w+1; x<w; x++) {
  1793. int offset = (sy<<10) + (sx+x);
  1794. WORD C = *((WORD*)lpVideoBuf + offset);
  1795. *((WORD*)lpVideoBuf + offset) = (C & 0x7BDE) >> 1;
  1796. }
  1797. for (int y=-w+1; y<w; y++) {
  1798. int offset = ((sy+y)<<10) + sx;
  1799. WORD C = *((WORD*)lpVideoBuf + offset);
  1800. *((WORD*)lpVideoBuf + offset) = (C & 0x7BDE) >> 1;
  1801. }
  1802. }
  1803. //======== software has no implementation for 3DHard ===========/
  1804. void Init3DHardware()
  1805. {
  1806. PrintLog("\n");
  1807. PrintLog("==Init Direct Draw==\n");
  1808. HRESULT hres;
  1809. hres = DirectDrawCreate( NULL, &lpDD, NULL );
  1810. if( hres != DD_OK ) {
  1811. wsprintf(logt, "DirectDrawCreate Error: %Xh\n", hres);
  1812. PrintLog(logt);
  1813. DoHalt("");
  1814. }
  1815. PrintLog("DirectDrawCreate: Ok\n");
  1816. PrintLog("Direct Draw activated.\n");
  1817. PrintLog("\n");
  1818. DirectActive = TRUE;
  1819. }
  1820. void Activate3DHardware()
  1821. {
  1822. SetVideoMode(WinW, WinH);
  1823. DWORD cl = DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN;
  1824. #ifdef _DEBUG
  1825. cl = DDSCL_NORMAL;
  1826. #endif
  1827. HRESULT hres = lpDD->SetCooperativeLevel( hwndMain, cl);
  1828. if( hres != DD_OK ) {
  1829. wsprintf(logt, "SetCooperativeLevel Error: %Xh\n", hres);
  1830. PrintLog(logt);
  1831. DoHalt("");
  1832. }
  1833. PrintLog("SetCooperativeLevel: Ok\n");
  1834. hres = lpDD->SetDisplayMode( WinW, WinH, 16);
  1835. if (hres != DD_OK) {
  1836. wsprintf(logt, "DDRAW: Error set video mode %dx%d\n", WinW, WinH);
  1837. PrintLog(logt);
  1838. }
  1839. }
  1840. void ShutDown3DHardware()
  1841. {
  1842. lpDD->RestoreDisplayMode();
  1843. lpDD->SetCooperativeLevel( hwndMain, DDSCL_NORMAL);
  1844. }
  1845. void Render3DHardwarePosts()
  1846. {
  1847. }
  1848. void CopyHARDToDIB()
  1849. {
  1850. }
  1851. void Hardware_ZBuffer(BOOL bl)
  1852. {
  1853. }
  1854. #endif