X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FTerrain.cpp;h=34da00ea94b2fd1d3071e1f755dee31de2fc2b3c;hb=4f4771bb67958d2e9180ba24d422141b9069e363;hp=9441af070cf06d912c2350d92b9079dfc80fad13;hpb=25e3d5e35a7fd7efdffc420efe3c41a91cefe43f;p=lugaru.git diff --git a/Source/Terrain.cpp b/Source/Terrain.cpp index 9441af0..34da00e 100644 --- a/Source/Terrain.cpp +++ b/Source/Terrain.cpp @@ -1,27 +1,28 @@ /* Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) This file is part of Lugaru. -Lugaru is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. -This program is distributed in the hope that it will be useful, +Lugaru is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +along with Lugaru. If not, see . */ #include "Game.h" #include "Terrain.h" #include "Objects.h" +#include "Utils/Folders.h" + extern XYZ viewer; extern float viewdistance; extern float fadestart; @@ -36,7 +37,6 @@ extern bool decals; extern float blurness; extern float targetblurness; extern Objects objects; -extern TGAImageRec texture; extern bool visibleloading; extern bool skyboxtexture; extern int tutoriallevel; @@ -52,9 +52,7 @@ int Terrain::lineTerrain(XYZ p1, XYZ p2, XYZ *p) static int firstintersecting; static XYZ point; static int startx, starty; - static float slope; static int endx, endy; - static int numtris = (size - 1) * (size - 1) * 2; static float highest, lowest; firstintersecting = -1; @@ -201,9 +199,7 @@ void Terrain::UpdateTransparency(int whichx, int whichy) void Terrain::UpdateTransparencyother(int whichx, int whichy) { - static XYZ vertex; static int i, j, a, b, c, d, patch_size, stepsize; - static float distance; patch_size = size / subdivision; @@ -402,22 +398,20 @@ void Terrain::UpdateVertexArray(int whichx, int whichy) } -bool Terrain::load(const char *fileName) +bool Terrain::load(const std::string& fileName) { static long i, j; static long x, y; static float patch_size; float temptexdetail = texdetail; - //LoadTGA( fileName ); - // Fixing filename so that it works with its own os - char * FixedFN = ConvertFileName(fileName); + ImageRec texture; - unsigned char fileNamep[256]; - CopyCStringToPascal(FixedFN, fileNamep); //Load Image - upload_image( fileNamep , 0); + if (!load_image(Folders::getResourcePath(fileName).c_str(), texture)) { + return false; + } //Is it valid? if (texture.bpp > 24) { @@ -437,34 +431,14 @@ bool Terrain::load(const char *fileName) texdetail = temptexdetail; - size = 128; - if (1 == 1) { - /*if ( texture.bpp == 24 ) - type = GL_RGB; - else - type = GL_RGBA; - - glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); - - if(!terraintexture)glGenTextures( 1, &terraintexture ); - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - - glBindTexture( GL_TEXTURE_2D, terraintexture); - //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - - gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data ); - */ + size = texture.sizeX; - size = texture.sizeX; - - for (i = 0; i < size; i++) { - for (j = 0; j < size; j++) { - heightmap[size - 1 - i][j] = (float)((texture.data[(i + (j * size)) * texture.bpp / 8])) / 5; - } + for (i = 0; i < size; i++) { + for (j = 0; j < size; j++) { + heightmap[size - 1 - i][j] = (float)((texture.data[(i + (j * size)) * texture.bpp / 8])) / 5; } - } + if (visibleloading) Game::LoadingScreen(); @@ -541,28 +515,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; @@ -1131,11 +999,10 @@ void Terrain::draw(int layer) void Terrain::drawdecals() { if (decals) { - static int i, j; + static int i; static float distancemult; static int lasttype; - static float patch_size = size / subdivision * scale; static float viewdistsquared; static bool blend; @@ -1335,11 +1202,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); } @@ -1494,89 +1356,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;