X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;ds=sidebyside;f=Source%2FTerrain.cpp;h=41a2181cacefe40556cec8b44fe5ca731f375733;hb=20e924d;hp=a50dd52b9ba02ad389a9aa6267f6584622d978ee;hpb=cd043e3f9e26c2b3406b40a354c2840941e9db7f;p=lugaru.git
diff --git a/Source/Terrain.cpp b/Source/Terrain.cpp
index a50dd52..41a2181 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.
@@ -20,6 +21,8 @@ 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;
@@ -34,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;
@@ -197,7 +199,6 @@ 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;
patch_size = size / subdivision;
@@ -404,15 +405,13 @@ 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);
+ 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) {
@@ -432,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 );
+ size = texture.sizeX;
- 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;
-
- 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();
@@ -536,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;
@@ -1327,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);
}
@@ -1486,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;