# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

heat_haze.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #include "std3d.h"
00027 
00028 
00029 #include "3d/heat_haze.h"
00030 #include "3d/scene.h"
00031 #include "3d/deform_2d.h"
00032 #include "nel/misc/vector_2f.h"
00033 
00034 namespace NL3D
00035 {
00036         
00037 
00038         struct CSinWave : public CDeform2d::IPerturbUV
00039         {
00040                 float Phase;
00041                 virtual void perturbUV(float x, float y, float &du, float &dv) const
00042                 {
00043                         du = 0.01f * sinf(25.f * y + Phase);
00044                         dv = 0.05f * cosf(19.3f * x + Phase);
00045                 }
00046         } _SinWave;
00047 
00048         
00049 
00050 
00051         void CHeatHaze::performHeatHaze(uint width, uint height, CScene &s, IDriver *drv)       
00052         {
00053                 NLMISC::CMatrix m  = s.getCam()->getMatrix();
00054                 NLMISC::CMatrix im = m.inverted();
00055 
00056                 // compute the shape of the horizon
00057 
00058                 // first we compute the direction of the world up vector in the viewer basis.   
00059                 NLMISC::CVector up = im * NLMISC::CVector::K;
00060                 // project onto the I and K vectors
00061                 float upNorm = (up.x * up.x + up.z * up.z);
00062 
00063                 const float threshold = 10E-4f;
00064 
00065                 if (upNorm < threshold) return; // the viewer is looking above or below  himlself
00066 
00067                 // Compute the right vector. This is done by intersecting the horizon plane with a near plane. 
00068                 // to do this, we transform the horizon plane into the view basis.This may be optimized, but is not critical.
00069                 //
00070                 NLMISC::CPlane h;
00071                 h.make(NLMISC::CVector::K, NLMISC::CVector::Null);
00072 
00073                 h = h * m; // note : this multiply by the transposition of m
00074 
00075                 // intersect with near plane : we got y = 0, which gives us, as a right vector :
00076                 // if c is not 0, we got : x = 1 and z = (-a - d) / c as a working solution.
00077                 // Else we got x = (- d - c )/ a and z = 1
00078 
00079 
00080                 NLMISC::CVector right;
00081 
00082                 if (fabsf(h.c) > threshold)
00083                 {
00084                         right.set(1, 0, (h.a + h.d) / - h.c );
00085                 }
00086                 else
00087                 {
00088                         right.set( (h.d + h.c) / h.a, 0,  1);
00089                 }
00090 
00091                 right.normalize();
00092 
00093                 // now, find a point on screen that lay on the horizon line
00094                 static std::vector<NLMISC::CVector2f> poly(4);          
00095 
00096                 
00097 
00098                 const sint xCenter = width >> 1;
00099                 const sint yCenter = height >> 1;
00100 
00101                 const float horizonHeight = (float) (height >> 2);
00102                 const float horizonWidth  = (float) (width  >> 2);
00103 
00104                 NLMISC::CVector tmp ;
00105 
00106                 tmp = horizonWidth * right + horizonHeight * up;
00107                 poly[0] = NLMISC::CVector2f(xCenter + tmp.x, yCenter + tmp.z) ;
00108                 tmp = horizonWidth   * right - horizonHeight  * up;
00109                 poly[1] = NLMISC::CVector2f(xCenter + tmp.x, yCenter + tmp.z) ;
00110                 tmp = - horizonWidth   * right - horizonHeight  * up;
00111                 poly[2] = NLMISC::CVector2f(xCenter + tmp.x, yCenter + tmp.z);
00112                 tmp = - horizonWidth   * right + horizonHeight  * up;
00113                 poly[3] = NLMISC::CVector2f(xCenter + tmp.x, yCenter + tmp.z);
00114 
00115 
00116                 CDeform2d::doDeform(poly, drv, &_SinWave);
00117 
00118 
00119 
00120 
00121         }
00122 
00123 } // NL3D