shadowvolumecache.h

00001 /*--License:
00002         Lilith 3D Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2002-2007
00004         www.grinninglizard.com/lilith
00005 
00006         This program is free software; you can redistribute it and/or
00007         modify it under the terms of the GNU General Public License
00008         as published by the Free Software Foundation; either version 2
00009         of the License, or (at your option) any later version.
00010 
00011         This program 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 this program; if not, write to the Free Software
00018         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020         The full text of the license can be found in license.txt
00021 */
00022 
00023 #ifndef SHADOW_VOLUME_CACHE_INCLUDED
00024 #define SHADOW_VOLUME_CACHE_INCLUDED
00025 
00026 #include "../grinliz/glvector.h"
00027 #include "../grinliz/glmatrix.h"
00028 #include "worlddefine.h"
00029 #include <vector>
00030 
00031 namespace lilith3d 
00032 {
00033 class Tri;
00034 
00035 
00036 class ShadowVolumeCache
00037 {
00038 public:
00039         ShadowVolumeCache();
00040         ~ShadowVolumeCache();
00041 
00042         void SetSun( const grinliz::Vector3F& normal );
00043         const grinliz::Vector3F& Sun()          { return toSun; }
00044 
00045         void AddTri( const grinliz::Vector3F* vertex,   // input, required
00046                                  unsigned vertexStride,                         // input, required, byte count between vertices
00047                                  unsigned vertexCount,                          
00048                                  const Tri* triArray,                           // input, can be 0
00049                                  unsigned triCount,
00050                                  const U16* index,                                      // input, required
00051                                  unsigned indexCount,
00052                                  const grinliz::Matrix4& mat );
00053 
00054 
00055         const grinliz::Vector3F* GetVertex()            { return &vertex[0]; }
00056         U32                                              NumVertex()            { return vertex.size();; }
00057         const U16*                               GetIndex()                     { return &index[0]; }
00058         U32                                              NumIndex()                     { GLASSERT( index.size()%3 == 0 );
00059                                                                                                   return index.size();
00060                                                                                                 }
00061 
00062         void StreamToStencil();
00063 
00064 private:
00065 
00066         U32 OFFSET( U32 idx ) { return (base + idx*2 ); }
00067         U32 SHADOW( U32 idx ) { return (base + idx*2+1 ); }
00068 
00069         inline void AddSideToTri( U32 i0, U32 i1, U32 i2, U32 side )
00070         {
00071                 const U32 arr[4] = { i0, i1, i2, i0 };
00072                 U32 off0 = OFFSET( arr[side+0] );
00073                 U32 off1 = OFFSET( arr[side+1] );
00074                 U32 shadow0 = SHADOW( arr[side+0] );
00075                 U32 shadow1 = SHADOW( arr[side+1] );
00076 
00077                 unsigned ib = index.size();
00078                 index.resize( ib+6 );
00079 
00080                 index[ib+0] = off1;
00081                 index[ib+1] = off0;
00082                 index[ib+2] = shadow0;
00083 
00084                 index[ib+3] = off1;
00085                 index[ib+4] = shadow0;
00086                 index[ib+5] = shadow1;
00087         }
00088 
00089         grinliz::Vector3F toSun;
00090         grinliz::Vector3F shadow;
00091         grinliz::Vector3F offset;
00092 
00093         std::vector< U16 > index;
00094         std::vector< grinliz::Vector3F > vertex;
00095         std::vector< Tri > tri;
00096         U32 base;
00097 };
00098 };
00099 #endif

Generated on Fri Mar 23 19:36:22 2007 for Lilith3D by  doxygen 1.5.1-p1