tree.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 L3TREE_INCLUDED
00024 #define L3TREE_INCLUDED
00025 
00026 #include "../grinliz/gltypes.h"
00027 #include "meshresource.h"
00028 #include "mesh.h"
00029 #include "SDL_video.h"
00030 #include "worlddefine.h"
00031 
00032 namespace lilith3d
00033 {
00034 class TreeMesh;
00035 
00042 class TreeResource : public StaticResource
00043 {
00044   public:
00046         TreeResource( const std::string& name );
00047         ~TreeResource();
00048 
00049         virtual const TreeResource* ToTreeResource() const      { return this; }
00050 
00051         void StreamOutTree( bool enableState ) const;                                   // used by the TreeMesh
00052         void StreamOutShadow( ShadowVolumeCache* cache, const grinliz::Matrix4& mat ) const;
00053         virtual void ImportDone();                                                              // used to pre-render the tree billboards
00054 
00055         void SetShadow( const Texture* tex )    { shadow = tex; }
00056         const Texture* Shadow() const                   { return shadow; }
00057 
00058         /*
00059         const Texture* GetBillboardTex( int i ) const   { return billboard[i]; }
00060 
00061         enum {
00062                 NUM_ROTATIONS = 3
00063         };
00064          */
00065 
00066   private:
00067         void PreRender();
00068         //const Texture* billboard[4];  // each tree resource has 4 billboards: N,S,E,W
00069         const Texture* shadow;
00070 
00071   public:
00072         mutable std::vector< TreeMesh* > tree;
00073 
00074         /*
00075         // OPTIMIZATION: do not use
00076         struct TreeData 
00077         {
00078                 TreeMesh* mesh;
00079                 float alpha;
00080                 float d2;
00081         };
00082         struct BBData 
00083         {
00084                 TreeMesh* mesh;
00085                 float alpha;
00086                 float d2;
00087         };
00088 
00089         mutable TreeData treeCache[MAX_TREE_CACHE];
00090         mutable int nTreeCache;
00091         mutable BBData bbCache[4][MAX_BB_CACHE];
00092         mutable int nBBCache[4];
00093 
00094         mutable U16 triPos[ NUM_ROTATIONS ],  
00095                         triCount[ NUM_ROTATIONS ];
00096         
00097         void PushBBCache( int i, const BBData& data ) const {
00098                 GLASSERT( i>=0 && i<4 );
00099                 GLASSERT( nBBCache[i] < MAX_BB_CACHE );
00100                 if ( nBBCache[i] < MAX_BB_CACHE ) {
00101                         bbCache[i][nBBCache[i]] = data;
00102                         ++nBBCache[i];
00103                 }
00104         }
00105         void PushTreeCache( const TreeData& data ) const {
00106                 GLASSERT( nTreeCache < MAX_TREE_CACHE );
00107                 if ( nTreeCache < MAX_TREE_CACHE ) {
00108                         treeCache[nTreeCache] = data;
00109                         ++nTreeCache;
00110                 }
00111         }
00112         */
00113 };
00114 
00115 
00124 class TreeMesh : public StaticMesh
00125 {
00126   public:
00127         TreeMesh( const TreeResource* meshResource );
00128         virtual ~TreeMesh();
00129 
00130         // Streams out all the trees, and culls them from the render list
00131         // as it goes. Called by the engine directly. 
00132         static void StreamAllTrees( Lilith3D* lilith, Mesh* list );
00133         static void TreeMesh::StreamAllTreesVBO( Lilith3D* lilith, Mesh* list );
00134 
00135         //static void DeleteStatics();
00136 
00137         //virtual void StreamOutShadow( ShadowVolumeCache* cache );
00138 
00144         virtual void SetPosV( const grinliz::Vector3F& pos, const grinliz::Matrix4& rotation );
00145 
00146         // does nothing - use StreamAllTrees
00147         virtual void StreamOut()        {}
00148 
00149         const lilith3d::TreeResource* GetTreeResource() const   { return treeResource; }
00150         //int RotationIndex() { GLASSERT( rotationIndex >= 0 && rotationIndex < TreeResource::NUM_ROTATIONS );
00151         //                                              return rotationIndex; }
00152 
00153         float dSquared;
00154   private:
00155 
00156         //static bool init;
00157         //static grinliz::Vector2F frontUnit[TreeResource::NUM_ROTATIONS];
00158         //static grinliz::Vector2F leftUnit[TreeResource::NUM_ROTATIONS];
00159 
00160         //static TreeMesh* renderList[TREE_COUNT];
00161         //static int             nRenderList;
00162 
00163         //int rotationIndex;
00164         const TreeResource *treeResource;
00165         DecalMesh* decal;
00166 };
00167 };      // namespace lilith3d
00168 
00169 #endif

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