]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Terrain.cpp
cleanup, renamed rotations to yaw/pitch
[lugaru.git] / Source / Terrain.cpp
index e56f681f8190c9359c5741941855fd4ab1777ebb..74afa40af14551efc81a94686f266a3d58a4409c 100644 (file)
@@ -24,21 +24,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Objects.h"
 extern XYZ viewer;
 extern float viewdistance;
-extern float lightambient[3],lightbrightness[3];
 extern float fadestart;
 extern int environment;
 extern float texscale;
 extern Light light;
 extern float multiplier;
 extern FRUSTUM frustum;
-extern float texdetail,terraindetail;
+extern float texdetail;
 extern int detail;
 extern bool decals;
 extern float blurness;
 extern float targetblurness;
 extern Objects objects;
 extern TGAImageRec texture;
-extern Game * pgame;
 extern bool visibleloading;
 extern bool skyboxtexture;
 extern int tutoriallevel;
@@ -371,17 +369,20 @@ void Terrain::UpdateVertexArray(int whichx, int whichy){
 }
 
 
-bool Terrain::load(char *fileName)
+bool Terrain::load(const char *fileName)
 {
        static long                             i,j;
        static long x,y;
        static float patch_size;
 
        float temptexdetail=texdetail;
-       texdetail=terraindetail;
        //LoadTGA( fileName );
+
+       // Fixing filename so that it works with its own os
+       char * FixedFN = ConvertFileName(fileName);
+
        unsigned char fileNamep[256];
-       CopyCStringToPascal(fileName,fileNamep);
+       CopyCStringToPascal(FixedFN, fileNamep);
        //Load Image
        upload_image( fileNamep ,0); 
 
@@ -398,7 +399,7 @@ bool Terrain::load(char *fileName)
                }
        }
        texture.bpp=24;
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
        texdetail=temptexdetail;
 
@@ -425,12 +426,12 @@ bool Terrain::load(char *fileName)
 
                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/terraindetail;
+                               heightmap[size-1-i][j]=(float)((texture.data[(i+(j*size))*texture.bpp/8]))/5;
                        }
                }
 
        }
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
        float slopeness;
 
@@ -439,7 +440,7 @@ bool Terrain::load(char *fileName)
                        textureness[i][j]=-1;
                }
        }
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
 
        for(i=0;i<size;i++){
@@ -473,7 +474,7 @@ bool Terrain::load(char *fileName)
                        }
                }
        }
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
        for(i=0;i<size;i++){
                for(j=0;j<size;j++){
@@ -485,7 +486,7 @@ bool Terrain::load(char *fileName)
                        }
                }
        }
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
        /*float total;
        int todivide;
@@ -595,7 +596,7 @@ bool Terrain::load(char *fileName)
                        }
                }
        }
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
        patch_size=size/subdivision;
        patch_elements=(patch_size)*(patch_size)*54;
@@ -975,7 +976,7 @@ void Terrain::draw(int layer)
        endz=(viewer.z+viewdistance)/(patch_size)+1;
        if(endz>subdivision)endz=subdivision;
 
-       if(!layer)
+       if(!layer) {
                for(i=beginx;i<endx;i++){       
                        for(j=beginz;j<endz;j++){       
                                terrainpoint.x=i*patch_size+(patch_size)/2;
@@ -984,35 +985,48 @@ void Terrain::draw(int layer)
                                distance[i][j]=findDistancefast(&viewer,&terrainpoint);
                        }
                }
-
-               for(i=beginx;i<endx;i++){       
-                       for(j=beginz;j<endz;j++){       
-                               if(distance[i][j]<(viewdistance+patch_size)*(viewdistance+patch_size)){
-                                       opacity=1;
-                                       if(distance[i][j]>viewdistsquared*fadestart-viewdistsquared)opacity=0;
-                                       if(opacity==1&&i!=subdivision)if(distance[i+1][j]>viewdistsquared*fadestart-viewdistsquared)opacity=0;
-                                       if(opacity==1&&j!=subdivision)if(distance[i][j+1]>viewdistsquared*fadestart-viewdistsquared)opacity=0;
-                                       if(opacity==1&&j!=subdivision&&i!=subdivision)if(distance[i+1][j+1]>viewdistsquared*fadestart-viewdistsquared)opacity=0;
-                                       glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
-                                       glPushMatrix();
-                                               if(frustum.CubeInFrustum(i*patch_size+patch_size*.5,avgypatch[i][j],j*patch_size+patch_size*.5,heightypatch[i][j]/2))
-                                               {   
-                                                       if(environment==desertenvironment&&distance[i][j]>viewdistsquared/4)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness);
-                                                       else if(environment==desertenvironment)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
-                                                       if(!layer&&textureness[i][j]!=allsecond)drawpatch(i,j,opacity);
-                                                       if(layer==1&&textureness[i][j]!=allfirst)drawpatchother(i,j,opacity);
-                                                       if(layer==2&&textureness[i][j]!=allfirst)drawpatchotherother(i,j,opacity);
-                                               }
-                                       glPopMatrix();
-                               }
+       }
+       for(i=beginx;i<endx;i++){
+               for(j=beginz;j<endz;j++){       
+                       if(distance[i][j]<(viewdistance+patch_size)*(viewdistance+patch_size)){
+                               opacity=1;
+                               if(distance[i][j]>viewdistsquared*fadestart-viewdistsquared)
+                                       opacity=0;
+                               if(opacity==1&&i!=subdivision)
+                                       if(distance[i+1][j]>viewdistsquared*fadestart-viewdistsquared)
+                                               opacity=0;
+                               if(opacity==1&&j!=subdivision)
+                                       if(distance[i][j+1]>viewdistsquared*fadestart-viewdistsquared)
+                                               opacity=0;
+                               if(opacity==1&&j!=subdivision&&i!=subdivision)
+                                       if(distance[i+1][j+1]>viewdistsquared*fadestart-viewdistsquared)
+                                               opacity=0;
+                               glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
+                               glPushMatrix();
+                                       if(frustum.CubeInFrustum(i*patch_size+patch_size*.5,avgypatch[i][j],j*patch_size+patch_size*.5,heightypatch[i][j]/2))
+                                       {   
+                                               if(environment==desertenvironment&&distance[i][j]>viewdistsquared/4)
+                                                       glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness);
+                                               else if(environment==desertenvironment)
+                                                       glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
+                                               if(!layer&&textureness[i][j]!=allsecond)
+                                                       drawpatch(i,j,opacity);
+                                               if(layer==1&&textureness[i][j]!=allfirst)
+                                                       drawpatchother(i,j,opacity);
+                                               if(layer==2&&textureness[i][j]!=allfirst)
+                                                       drawpatchotherother(i,j,opacity);
+                                       }
+                               glPopMatrix();
                        }
                }
-               if(environment==desertenvironment)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
+       }
+       if(environment==desertenvironment)
+               glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
 }
 
 void Terrain::drawdecals()
 {
-       if(decals){
+       if(decals) {
                static int i,j;
                static float distancemult;
                static int lasttype;
@@ -1150,10 +1164,10 @@ void Terrain::AddObject(XYZ where, float radius, int id)
                                        points[3].x=(size/subdivision)*i;
                                        points[3].z=(size/subdivision)*(j+1);
                                        points[3].y=heightmap[(int)points[3].x][(int)points[3].z];
-                                       points[0]*=scale*terraindetail;
-                                       points[1]*=scale*terraindetail;
-                                       points[2]*=scale*terraindetail;
-                                       points[3]*=scale*terraindetail;
+                                       points[0]*=scale;
+                                       points[1]*=scale;
+                                       points[2]*=scale;
+                                       points[3]*=scale;
                                        if(!done&&where.x+radius>points[0].x&&where.x-radius<points[2].x&&where.z+radius>points[0].z&&where.z-radius<points[2].z){
                                                patchobjects[i][j][patchobjectnum[i][j]]=id;
                                                patchobjectnum[i][j]++;
@@ -1183,8 +1197,8 @@ void Terrain::DeleteDecal(int which)
 }
 
 void Terrain::MakeDecal(int type, XYZ where, float size, float opacity, float rotation){
-       if(decals){
-               if(opacity>0&&size>0){
+       if(decals) {
+               if(opacity>0&&size>0) {
                        static int patchx[4];
                        static int patchy[4];
 
@@ -1234,11 +1248,9 @@ void Terrain::MakeDecalLock(int type, XYZ where,int whichx, int whichy, float si
                decalbrightness[numdecals]=(rot.x+rot.y+rot.z)/3;
                if(decalbrightness[numdecals]<.4)decalbrightness[numdecals]=.4;
 
-               //if(type==blooddecal||type==blooddecalfast||type==blooddecalslow){
                if(environment==grassyenvironment){
                        decalbrightness[numdecals]*=.6;
                }
-               //}
 
                if(decalbrightness[numdecals]>1)decalbrightness[numdecals]=1;
                decalbright=decalbrightness[numdecals];
@@ -1446,12 +1458,12 @@ void Terrain::DoShadows()
                                        if(objects.type[l]!=treetrunktype){
                                                testpoint=terrainpoint;
                                                testpoint2=terrainpoint+lightloc*50*(1-shadowed);
-                                               if(objects.model[l].LineCheck(&testpoint,&testpoint2,&col,&objects.position[l],&objects.rotation[l])!=-1){
+                                               if(objects.model[l].LineCheck(&testpoint,&testpoint2,&col,&objects.position[l],&objects.yaw[l])!=-1){
                                                        shadowed=1-(findDistance(&terrainpoint,&col)/50);       
                                                }
                                        }
                                }
-                               if(visibleloading)pgame->LoadingScreen();
+                               if(visibleloading) Game::LoadingScreen();
                        }
                        brightness=dotproduct(&lightloc,&normals[i][j]);
                        if(shadowed)brightness*=1-shadowed;
@@ -1472,7 +1484,7 @@ void Terrain::DoShadows()
                }
        }
 
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
        //Smooth shadows
        for(i=0;i<size;i++){