X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FTerrain.cpp;h=8c0335c8a8872b8f2dd4250be708c56a8c9c0e9d;hb=250a16d5fa14b462b44b1e698372164ac33aa721;hp=ea3b8028eb55b369648a2cbe9f2c6d54afa82ba2;hpb=7de3125ca72d91329f0d4d0980635cf7355c3082;p=lugaru.git diff --git a/Source/Terrain.cpp b/Source/Terrain.cpp index ea3b802..8c0335c 100644 --- a/Source/Terrain.cpp +++ b/Source/Terrain.cpp @@ -1,5 +1,6 @@ /* Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) This file is part of Lugaru. @@ -34,7 +35,7 @@ extern bool decals; extern float blurness; extern float targetblurness; extern Objects objects; -extern TGAImageRec texture; +extern ImageRec texture; extern bool visibleloading; extern bool skyboxtexture; extern int tutoriallevel; @@ -404,15 +405,9 @@ bool Terrain::load(const char *fileName) static float patch_size; float temptexdetail = texdetail; - //LoadTGA( fileName ); - // Fixing filename so that it works with its own os - char * FixedFN = ConvertFileName(fileName); - - unsigned char fileNamep[256]; - CopyCStringToPascal(FixedFN, fileNamep); //Load Image - upload_image( fileNamep , 0); + upload_image(ConvertFileName(fileName)); //Is it valid? if (texture.bpp > 24) { @@ -516,28 +511,6 @@ bool Terrain::load(const char *fileName) if (visibleloading) Game::LoadingScreen(); - /*float total; - int todivide; - //Smooth opacityother - for(i=0;i= size - 1 || pointz >= size - 1 || pointx <= 0 || pointz <= 0) - return 0; - if (point2x >= size - 1 || point2z >= size - 1 || point2x <= 0 || point2z <= 0) - return 0; - - startpoint.x = point2x; - startpoint.y = -1000; - startpoint.z = point2z; - - endpoint = startpoint; - endpoint.y = 1000; - - tilex = pointx; - tiley = pointz; - - triangle[0].x = tilex; - triangle[0].z = tiley; - triangle[0].y = heightmap[tilex][tiley]; - - triangle[1].x = tilex + 1; - triangle[1].z = tiley; - triangle[1].y = heightmap[tilex + 1][tiley]; - - triangle[2].x = tilex; - triangle[2].z = tiley + 1; - triangle[2].y = heightmap[tilex][tiley + 1]; - - XYZ mid; - - mid = (triangle[0] + triangle[1] + triangle[2]) / 2; - - triangle[0] = mid + (triangle[0] - mid) * 10; - triangle[1] = mid + (triangle[0] - mid) * 10; - triangle[2] = mid + (triangle[0] - mid) * 10; - - /* - if(!LineFacetd(&startpoint,&endpoint,&triangle[0],&triangle[1],&triangle[2],&intersect)){ - triangle[0].x=tilex+1; - triangle[0].z=tiley; - triangle[0].y=heightmap[tilex+1][tiley]; - - triangle[1].x=tilex+1; - triangle[1].z=tiley+1; - triangle[1].y=heightmap[tilex+1][tiley+1]; - - triangle[2].x=tilex; - triangle[2].z=tiley+1; - triangle[2].y=heightmap[tilex][tiley+1]; - LineFacetd(&startpoint,&endpoint,&triangle[0],&triangle[1],&triangle[2],&intersect); - }*/ - return intersect.y * scale + getOpacity(pointx * scale, pointz * scale) / 8; - - //height1=heightmap[tilex][tiley]*(1-(pointx-tilex))+heightmap[tilex+1][tiley]*(pointx-tilex); - //height2=heightmap[tilex][tiley+1]*(1-(pointx-tilex))+heightmap[tilex+1][tiley+1]*(pointx-tilex); - - //return height1*(1-(pointz-tiley))*scale+height2*(pointz-tiley)*scale; } - float Terrain::getOpacity(float pointx, float pointz) { static float height1, height2; @@ -1306,11 +1198,6 @@ void Terrain::MakeDecal(int type, XYZ where, float size, float opacity, float ro patchy[2] = (where.z + size) / scale; patchy[3] = (where.z + size) / scale; - /*if(patchx[1]0&&patchy[1]>0) - if(patchx[2]0&&patchy[2]>0) - if(patchx[3]0&&patchy[3]>0) - if(patchx[0]0&&patchy[0]>0){ - */ if ((patchx[0] != patchx[1] || patchy[0] != patchy[1]) && (patchx[0] != patchx[2] || patchy[0] != patchy[2]) && (patchx[0] != patchx[3] || patchy[0] != patchy[3])) { MakeDecalLock(type, where, patchx[0], patchy[0], size, opacity, rotation); } @@ -1465,89 +1352,6 @@ void Terrain::MakeDecalLock(int type, XYZ where, int whichx, int whichy, float s } } -void Terrain::DoLighting() -{ - static int i, j, k, todivide; - static float brightness, total; - static XYZ blank, terrainpoint, lightloc; - lightloc = light.location; - Normalise(&lightloc); - //Calculate shadows - for (i = 0; i < size; i++) { - for (j = 0; j < size; j++) { - terrainpoint.x = (float)i * scale; - terrainpoint.z = (float)j * scale; - terrainpoint.y = heightmap[i][j] * scale + .1; - /*brightness=0; - if(lineTerrain(lightlocation*10+terrainpoint,terrainpoint,&blank)==-1) - */ - brightness = dotproduct(&lightloc, &normals[i][j]); - - if (brightness > 1) - brightness = 1; - if (brightness < 0) - brightness = 0; - - colors[i][j][0] = light.color[0] * brightness + light.ambient[0]; - colors[i][j][1] = light.color[1] * brightness + light.ambient[1]; - colors[i][j][2] = light.color[2] * brightness + light.ambient[2]; - - if (colors[i][j][0] > 1) colors[i][j][0] = 1; - if (colors[i][j][1] > 1) colors[i][j][1] = 1; - if (colors[i][j][2] > 1) colors[i][j][2] = 1; - if (colors[i][j][0] < 0) colors[i][j][0] = 0; - if (colors[i][j][1] < 0) colors[i][j][1] = 0; - if (colors[i][j][2] < 0) colors[i][j][2] = 0; - } - } - - //Smooth shadows - for (i = 0; i < size; i++) { - for (j = 0; j < size; j++) { - for (k = 0; k < 3; k++) { - total = 0; - todivide = 0; - if (i != 0) { - total += colors[j][i - 1][k]; - todivide++; - } - if (i != size - 1) { - total += colors[j][i + 1][k]; - todivide++; - } - if (j != 0) { - total += colors[j - 1][i][k]; - todivide++; - } - if (j != size - 1) { - total += colors[j + 1][i][k]; - todivide++; - } - if (i != 0 && j != 0) { - total += colors[j - 1][i - 1][k]; - todivide++; - } - if (i != size - 1 && j != 0) { - total += colors[j - 1][i + 1][k]; - todivide++; - } - if (j != size - 1 && i != size - 1) { - total += colors[j + 1][i + 1][k]; - todivide++; - } - if (j != size - 1 && i != 0) { - total += colors[j + 1][i - 1][k]; - todivide++; - } - total += colors[j][i][k]; - todivide++; - - colors[j][i][k] = total / todivide; - } - } - } -} - void Terrain::DoShadows() { static int i, j, k, l, todivide;