1 /*
2 
3 *************************************************************************
4 
5 ArmageTron -- Just another Tron Lightcycle Game in 3D.
6 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
7 
8 **************************************************************************
9 
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 
24 ***************************************************************************
25 
26 */
27 
28 #include "eFloor.h"
29 #include "rScreen.h"
30 #include "rTexture.h"
31 #include <stdlib.h>
32 
eFloor()33 eFloor::eFloor(){Floor = this;}
34 
~eFloor()35 eFloor::~eFloor(){
36     if (Floor == this)
37         Floor = NULL;
38 }
39 
se_GridSize()40 REAL se_GridSize(){
41     if (eFloor::Floor)
42         return eFloor::Floor->GridSize();
43     else
44         return 4;
45 }
46 
se_glFloorColor(REAL alpha,REAL intens)47 void se_glFloorColor(REAL alpha, REAL intens){
48     if (eFloor::Floor)
49         eFloor::Floor->glFloorColor(alpha, intens);
50 }
51 
se_glFloorTexture()52 void se_glFloorTexture(){
53     if (eFloor::Floor)
54         eFloor::Floor->glFloorTexture();
55 }
56 
se_glFloorTexture_a()57 void se_glFloorTexture_a(){
58     if (eFloor::Floor)
59         eFloor::Floor->glFloorTexture_a();
60 }
61 
se_glFloorTexture_b()62 void se_glFloorTexture_b(){
63     if (eFloor::Floor)
64         eFloor::Floor->glFloorTexture_b();
65 }
66 
se_BlackSky()67 bool se_BlackSky()
68 {
69     if (eFloor::Floor)
70         return eFloor::Floor->BlackSky();
71     else
72         return false;
73 }
74 
se_FloorColor(REAL & r,REAL & g,REAL & b)75 void se_FloorColor(REAL& r, REAL& g, REAL &b)
76 {
77     if (eFloor::Floor && sr_floorDetail > 1)
78         eFloor::Floor->FloorColor(r,g,b);
79     else
80     {
81         r = g = b = 0;
82     }
83 }
84 
se_MakeColorValid(REAL & r,REAL & g,REAL & b,REAL f)85 void se_MakeColorValid(REAL& r, REAL& g, REAL& b, REAL f)
86 {
87     REAL R, G, B; // the floor color
88     se_FloorColor(R, G, B);
89 
90     /*
91     	REAL wallInt = 2.0f;
92     	if ( TextureMode[rTEX_WALL] <= 0 )
93     	{
94     		wallInt = 1.0f;
95     	}
96 
97     	R *= wallInt;
98     	G *= wallInt;
99     	B *= wallInt;
100     */
101 
102     // if we are too close to the floor color, just change to white.
103     while ((r < .95 && g < .95 && b < .95) &&
104             (
105                 (fabs(R    - r*f) + fabs(G    - g*f) + fabs(B    - b*f) < .5 )  ||
106                 //			   (fabs(R*.5 - r*f) + fabs(G*.5 - g*f) + fabs(B*.5 - b*f) < .5) ||
107                 (fabs(r*f) + fabs(g*f) + fabs(b*f) < .5 )
108             )
109           )
110 
111     {
112         REAL step = 1/(15.0 * 3);
113         REAL step_r, step_g, step_b;
114         REAL rgb_sum = 0;
115         if ( r < .99 )
116             rgb_sum += r;
117         if ( g < .99 )
118             rgb_sum += g;
119         if ( b < .99 )
120             rgb_sum += b;
121 
122         if ( rgb_sum < .02 )
123         {
124             step_r = step;
125             step_g = step;
126             step_b = step;
127         }
128         else
129         {
130             step_r = step * r / rgb_sum;
131             step_g = step * g / rgb_sum;
132             step_b = step * b / rgb_sum;
133         }
134 
135         r += step_r;
136         g += step_g;
137         b += step_b;
138         if (r > 1)
139             r = 1;
140         if (g > 1)
141             g = 1;
142         if (b > 1)
143             b = 1;
144     }
145 }
146 
147 
148 
149 eFloor *eFloor::Floor;
150 
151