AnyType dist_angle::run(AnyType& args) { return distAngle( args[0].getAs<MappedColumnVector>(), args[1].getAs<MappedColumnVector>() ); }
//------------------------------------------------------------------------------ // Esta función nos permite pintar los muros que forman parte del mapa definido. //------------------------------------------------------------------------------ void renderWalls(){ u32 loop; s16 curAngle; s32 gridX; // coordenada X en el mapa s32 gridY; // coordenada Y en el MAPA u16* destBuffer = videoBuffer; // apunta al buffer donde se pintan los muros. u8 x,y; double horzLength; // distancia al muro en horizontal (desde el pto de perpectiva del tio que anda.) double vertLength; // distancia al muro en vertical (desde el pto de perpectiva del tio que anda.) double* minLength; u32 lineLength; char darkgray = 0; // vertical --> darkgray, horzontal --> lightgray double fdistNextX; double fdistNextY; int ndistNextX; int ndistNextY; int horzY; double horzX; int vertX; double vertY; curAngle = nPlayerAngle + 30; // angulo de inicio. if (curAngle >= 360) curAngle -= 360; // 4 = SCREENWIDTH / 64 (TILEHEIGHT) for (loop = 0; loop < SCREENWIDTH; loop+=4) { // calcula la distancia horizontal. if (curAngle == 0 || curAngle == 180){ // no hay un muro en la dirección horizontal horzLength = 9999999.00; } else{ if (curAngle < 180){ horzY = (nPlayerY/64) * 64; ndistNextY = -64; double amountChange = ((s32) (horzY - nPlayerY) ) * tableINVTAN[curAngle]; if (curAngle < 90 || curAngle > 270){ if (amountChange < 0) amountChange *= -1; } else { if (amountChange > 0) amountChange *= -1; } horzX = nPlayerX + amountChange; horzY--; } else { horzY = (nPlayerY/64) * 64 + 64; ndistNextY = 64; double amountChange = ((s32)(horzY - nPlayerY)) * tableINVTAN[curAngle]; if (curAngle < 90 || curAngle > 270){ if (amountChange < 0) amountChange *= -1; // should be pos } else { if (amountChange > 0) amountChange *= -1; } horzX = nPlayerX + amountChange; } fdistNextX = (64.00 * tableINVTAN[curAngle]); if ( (curAngle < 90) || (curAngle>270) ){ if (fdistNextX < 0) fdistNextX *= -1; // distancia positiva al siguiente bloque } else{ if (fdistNextX > 0) fdistNextX *= -1; // distancia negativa al siguiente bloque } while (true){ gridX = (s32)(horzX / 64); gridY = (s32)(horzY / 64); if (gridX >= MAPWIDTH || gridY >= MAPHEIGHT || gridX < 0 || gridY < 0) { horzLength = 9999999.00; break; } else if (fMap[gridX+gridY*MAPHEIGHT]) { horzLength = (horzX - nPlayerX) * tableINVCOS[curAngle]; break; } horzX += fdistNextX; horzY += ndistNextY; } } // calcula la distancia vertical. if (curAngle == 90 || curAngle == 270){ vertLength = 9999999.00; } else{ if (curAngle < 90 || curAngle > 270){ vertX = (nPlayerX/64) * 64 + 64; ndistNextX = 64; double amountChange = tableTAN[curAngle]*((s32)(vertX-nPlayerX)); if (curAngle < 180){ if (amountChange > 0) amountChange *= -1; } else { if (amountChange < 0) amountChange *= -1; } vertY = nPlayerY + amountChange; } else{ vertX = (nPlayerX/64) * 64; ndistNextX = -64; double amountChange = tableTAN[curAngle]*((s32)(vertX-nPlayerX)); if (curAngle < 180){ if (amountChange > 0) amountChange *= -1; } else{ if (amountChange < 0) amountChange *= -1; } vertY = nPlayerY + amountChange; vertX--; } fdistNextY = 64.00 * tableTAN[curAngle]; if (curAngle < 180) { if (fdistNextY > 0) fdistNextY *= -1; } else{ if (fdistNextY < 0) fdistNextY *= -1; } while (true){ gridX = (s32)(vertX / 64); gridY = (s32)(vertY / 64); if (gridX >= MAPWIDTH || gridY >= MAPHEIGHT || gridX < 0 || gridY < 0) { vertLength = 9999999.00; break; } else if (fMap[gridX+gridY*MAPHEIGHT]) { vertLength = (vertY - nPlayerY) * tableINVSIN[curAngle]; break; } vertX += ndistNextX; vertY += fdistNextY; } } if (vertLength < 0) vertLength *= -1; if (horzLength < 0) horzLength *= -1; if (vertLength < horzLength){ minLength = &vertLength; darkgray = 1; } else{ darkgray = 0; minLength = &horzLength; } //arreglar la distorsión. (*minLength) = (*minLength) * tableCOS[distAngle(curAngle, nPlayerAngle)]; lineLength = absint((s32)((64.00 / *minLength) * PLAY_LENGTH) ); int end = (80 - lineLength/2); int start; if (end < 0){ end = 160; start = 0; } else{ start = end; end += lineLength; } u32 where = loop/2 + start*120; if (darkgray){ for(y = start; y<end; y++) { destBuffer[where] = 0x0f0f; destBuffer[where+1] = 0x0f0f; where += 120; } } else{ for(y = start; y<end; y++){ destBuffer[where] = 0x0e0e; destBuffer[where+1] = 0x0e0e; where += 120; } } curAngle -= 1; if (curAngle < 0) curAngle += 360; } }//fin de la función.