00001 // matmodel.hxx -- class to handle models tied to a material property 00002 // 00003 // Written by David Megginson, December 2001 00004 // 00005 // Copyright (C) 1998 - 2003 Curtis L. Olson - http://www.flightgear.org/~curt 00006 // 00007 // This program is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU General Public License as 00009 // published by the Free Software Foundation; either version 2 of the 00010 // License, or (at your option) any later version. 00011 // 00012 // This program is distributed in the hope that it will be useful, but 00013 // WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 // General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with this program; if not, write to the Free Software 00019 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00020 // 00021 // $Id: matmodel_8hxx_source.html,v 1.3 2010/02/23 22:10:15 curt Exp $ 00022 00023 00024 #ifndef _SG_MAT_MODEL_HXX 00025 #define _SG_MAT_MODEL_HXX 00026 00027 #ifndef __cplusplus 00028 # error This library requires C++ 00029 #endif 00030 00031 #include <simgear/compiler.h> 00032 00033 #include <string> // Standard C++ string library 00034 #include <vector> 00035 00036 #include <osg/ref_ptr> 00037 #include <osg/Node> 00038 #include <osg/NodeVisitor> 00039 #include <osg/Billboard> 00040 00041 #include <simgear/structure/SGReferenced.hxx> 00042 #include <simgear/structure/SGSharedPtr.hxx> 00043 #include <simgear/props/props.hxx> 00044 #include <simgear/math/sg_random.h> 00045 00046 00047 class SGMatModelGroup; 00048 00049 00059 class SGMatModel : public SGReferenced { 00060 00061 public: 00062 00066 enum HeadingType { 00067 HEADING_FIXED, 00068 HEADING_BILLBOARD, 00069 HEADING_RANDOM 00070 }; 00071 00077 int get_model_count( SGPropertyNode *prop_root ); 00078 00079 00085 osg::Node *get_random_model( SGPropertyNode *prop_root ); 00086 00087 00093 double get_coverage_m2 () const; 00094 00100 double get_range_m () const; 00101 00107 double get_randomized_range_m(mt* seed) const; 00108 00114 HeadingType get_heading_type () const; 00115 00116 virtual ~SGMatModel (); 00117 00118 00119 protected: 00120 00121 friend class SGMatModelGroup; 00122 00123 SGMatModel (const SGPropertyNode * node, double range_m); 00124 00125 private: 00126 00133 void load_models( SGPropertyNode *prop_root ); 00134 00135 std::vector<std::string> _paths; 00136 mutable std::vector<osg::ref_ptr<osg::Node> > _models; 00137 mutable bool _models_loaded; 00138 double _coverage_m2; 00139 double _range_m; 00140 HeadingType _heading_type; 00141 }; 00142 00143 00152 class SGMatModelGroup : public SGReferenced { 00153 00154 public: 00155 00156 virtual ~SGMatModelGroup (); 00157 00158 00164 double get_range_m () const; 00165 00166 00172 int get_object_count () const; 00173 00174 00181 SGMatModel * get_object (int index) const; 00182 00183 protected: 00184 00185 friend class SGMaterial; 00186 00187 SGMatModelGroup (SGPropertyNode * node); 00188 00189 private: 00190 00191 double _range_m; 00192 std::vector<SGSharedPtr<SGMatModel> > _objects; 00193 }; 00194 00195 #endif // _SG_MAT_MODEL_HXX