src/engine/eFloor.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023   
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #include "eFloor.h"
00029 #include "rScreen.h"
00030 #include "rTexture.h"
00031 #include <stdlib.h>
00032 
00033 eFloor::eFloor(){Floor = this;}
00034 
00035 eFloor::~eFloor(){
00036     if (Floor == this)
00037         Floor = NULL;
00038 }
00039 
00040 REAL se_GridSize(){
00041     if (eFloor::Floor)
00042         return eFloor::Floor->GridSize();
00043     else
00044         return 4;
00045 }
00046 
00047 void se_glFloorColor(REAL alpha, REAL intens){
00048     if (eFloor::Floor)
00049         eFloor::Floor->glFloorColor(alpha, intens);
00050 }
00051 
00052 void se_glFloorTexture(){
00053     if (eFloor::Floor)
00054         eFloor::Floor->glFloorTexture();
00055 }
00056 
00057 void se_glFloorTexture_a(){
00058     if (eFloor::Floor)
00059         eFloor::Floor->glFloorTexture_a();
00060 }
00061 
00062 void se_glFloorTexture_b(){
00063     if (eFloor::Floor)
00064         eFloor::Floor->glFloorTexture_b();
00065 }
00066 
00067 bool se_BlackSky()
00068 {
00069     if (eFloor::Floor)
00070         return eFloor::Floor->BlackSky();
00071     else
00072         return false;
00073 }
00074 
00075 void se_FloorColor(REAL& r, REAL& g, REAL &b)
00076 {
00077     if (eFloor::Floor && sr_floorDetail > 1)
00078         eFloor::Floor->FloorColor(r,g,b);
00079     else
00080     {
00081         r = g = b = 0;
00082     }
00083 }
00084 
00085 void se_MakeColorValid(REAL& r, REAL& g, REAL& b, REAL f)
00086 {
00087     REAL R, G, B; // the floor color
00088     se_FloorColor(R, G, B);
00089 
00090     /*
00091         REAL wallInt = 2.0f;
00092         if ( TextureMode[rTEX_WALL] <= 0 )
00093         {
00094                 wallInt = 1.0f;
00095         }
00096 
00097         R *= wallInt;
00098         G *= wallInt;
00099         B *= wallInt;
00100     */  
00101 
00102     // if we are too close to the floor color, just change to white.
00103     while ((r < .95 && g < .95 && b < .95) &&
00104             (
00105                 (fabs(R    - r*f) + fabs(G    - g*f) + fabs(B    - b*f) < .5 )  ||
00106                 //                         (fabs(R*.5 - r*f) + fabs(G*.5 - g*f) + fabs(B*.5 - b*f) < .5) ||
00107                 (fabs(r*f) + fabs(g*f) + fabs(b*f) < .5 )
00108             )
00109           )
00110 
00111     {
00112         REAL step = 1/(15.0 * 3);
00113         REAL step_r, step_g, step_b;
00114         REAL rgb_sum = 0;
00115         if ( r < .99 )
00116             rgb_sum += r;
00117         if ( g < .99 )
00118             rgb_sum += g;
00119         if ( b < .99 )
00120             rgb_sum += b;
00121 
00122         if ( rgb_sum < .02 )
00123         {
00124             step_r = step;
00125             step_g = step;
00126             step_b = step;
00127         }
00128         else
00129         {
00130             step_r = step * r / rgb_sum;
00131             step_g = step * g / rgb_sum;
00132             step_b = step * b / rgb_sum;
00133         }
00134 
00135         r += step_r;
00136         g += step_g;
00137         b += step_b;
00138         if (r > 1)
00139             r = 1;
00140         if (g > 1)
00141             g = 1;
00142         if (b > 1)
00143             b = 1;
00144     }
00145 }
00146 
00147 
00148 
00149 eFloor *eFloor::Floor;
00150 

Generated on Sat Mar 15 22:55:44 2008 for Armagetron Advanced by  doxygen 1.5.4