Water2Constants.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #if !defined(__INCLUDE_Water2Constantsh_INCLUDE__)
00022 #define __INCLUDE_Water2Constantsh_INCLUDE__
00023 
00024 #include <common/Vector.h>
00025 
00026 static inline float myfmod(float a, float b) { return a-floorf(a/b)*b; }//fmod is different for negative a/b
00027 
00028 static const float wave_tidecycle_time = 10.24f;
00029 static const unsigned int wave_phases = 256;
00030 static const unsigned int wave_patch_width = 64;
00031 static const unsigned int wave_resolution = 128;
00032 
00033 static const float grid_size = 512.0f / (256.0f / float(wave_patch_width));
00034 static const float half_grid_size = grid_size / 2.0f;
00035 
00036 static const float wavetile_length = 256.0f;
00037 static const float wave_waterwidth = wavetile_length;
00038 static const float wavetile_length_rcp = 1.0f / wavetile_length;
00039 
00040 static const float VIRTUAL_PLANE_HEIGHT = 25.0f;
00041 
00042 #define REFRAC_COLOR_RES 32
00043 #define FRESNEL_FCT_RES 256
00044 
00045 class Water2Points
00046 {
00047 public:
00048         Vector &getPoint(int x, int y)
00049         {
00050                 DIALOG_ASSERT(x>=0 && y>=0 && x<wave_resolution && y<wave_resolution);
00051                 return points[x][y];
00052         };
00053 
00054 private:
00055         Vector points[wave_resolution][wave_resolution];
00056 };
00057 
00058 static inline float exact_fresnel(float x)
00059 {
00060         // the real formula (recheck it!)
00061 /*
00062         float g = 1.333f + x*x - 1;
00063         float z1 = g-x;
00064         float z2 = g+x;
00065         return (z1*z1)*(1+((x*z2-1)*(x*z2-1))/((x*z1+1)*(x*z1+1)))/(2*z2*z2);
00066 */
00067 
00068 /*
00069         // a very crude guess
00070         float tmp = 1-4*x;
00071         if (tmp < 0.0f) tmp = 0.0f;
00072         return tmp;
00073 */
00074         // a good approximation (1/(x+1)^8)
00075         float x1 = x + 1.0f;
00076         float x2 = x1*x1;
00077         float x4 = x2*x2;
00078         return 1.0f/(x4*x4);
00079 }
00080 
00081 
00082 #endif // __INCLUDE_Water2Constantsh_INCLUDE__

Generated on Mon Feb 16 15:14:48 2009 for Scorched3D by  doxygen 1.5.3