WaterVisibilityPatch.cpp

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 #include <land/WaterVisibilityPatch.h>
00022 #include <land/VisibilityPatchGrid.h>
00023 #include <landscape/Landscape.h>
00024 #include <water/Water.h>
00025 #include <geomipmap/MipMapPatchIndexs.h>
00026 #include <graph/OptionsDisplay.h>
00027 
00028 WaterVisibilityPatch::WaterVisibilityPatch() : 
00029         visible_(false),
00030         leftPatch_(0), rightPatch_(0),
00031         topPatch_(0), bottomPatch_(0),
00032         visibilityIndex_(4)
00033 {
00034 }
00035 
00036 WaterVisibilityPatch::~WaterVisibilityPatch()
00037 {
00038 }
00039 
00040 void WaterVisibilityPatch::setLocation(int x, int y,
00041         int patchX, int patchY,
00042         WaterVisibilityPatch *leftPatch, 
00043         WaterVisibilityPatch *rightPatch, 
00044         WaterVisibilityPatch *topPatch, 
00045         WaterVisibilityPatch *bottomPatch)
00046 {
00047         x_ = x; y_ = y;
00048         leftPatch_ = leftPatch;
00049         rightPatch_ = rightPatch;
00050         topPatch_ = topPatch;
00051         bottomPatch_ = bottomPatch;
00052 
00053         patchX_ = patchX;
00054         patchY_ = patchY;
00055         patchIndex_ = patchX_ + patchY_ * 2;
00056 
00057         offset_ = Vector(x_, y_, 0);
00058         position_ = Vector(x_ + 64, y_ + 64, 5);
00059 }
00060 
00061 bool WaterVisibilityPatch::setVisible(Vector &cameraPos)
00062 { 
00063         float distance = (cameraPos - position_).Magnitude();
00064         visibilityIndex_ = 6;
00065         if (!OptionsDisplay::instance()->getNoWaterLOD())
00066         {
00067                 float *waterIndexErrors = Landscape::instance()->getWater().getIndexErrors();
00068                 int waterDetailLevelRamp = 
00069                         OptionsDisplay::instance()->getWaterDetailLevelRamp();
00070 
00071                 visibilityIndex_ = int(distance - 50.0f) / waterDetailLevelRamp;
00072                 if (waterIndexErrors[6] < 1.0f) visibilityIndex_ += 3;
00073                 else if (waterIndexErrors[6] < 2.0f) visibilityIndex_ += 2;
00074                 else if (waterIndexErrors[6] < 3.0f) visibilityIndex_ += 1;
00075 
00076                 if (OptionsDisplay::instance()->getNoWaterMovement())
00077                 {
00078                         visibilityIndex_ += 3;
00079                 }
00080                 visibilityIndex_ = MAX(0, MIN(visibilityIndex_, 6));
00081         }
00082 
00083         if (distance < 2000.0f) 
00084         {
00085                 visible_ = true;
00086                 return true;
00087         }
00088 
00089         visible_ = false;
00090         return false;
00091 }
00092 
00093 void WaterVisibilityPatch::setNotVisible()
00094 {
00095         visible_ = false;
00096 }

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