]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/matmodel.hxx
Random buildings - initial commit.
[simgear.git] / simgear / scene / material / matmodel.hxx
index 33d769e8b476baa46315d245577ddd80fe87236b..1687302e26bbe3c150c863ebf86855537f6abe94 100644 (file)
@@ -2,7 +2,7 @@
 //
 // Written by David Megginson, December 2001
 //
-// Copyright (C) 1998 - 2003  Curtis L. Olson  - curt@flightgear.org
+// Copyright (C) 1998 - 2003  Curtis L. Olson  - http://www.flightgear.org/~curt
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
@@ -16,7 +16,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 #ifndef _SG_MAT_MODEL_HXX
 #define _SG_MAT_MODEL_HXX
 
-#ifndef __cplusplus                                                          
+#ifndef __cplusplus
 # error This library requires C++
-#endif                                   
+#endif
 
 #include <simgear/compiler.h>
 
-#include STL_STRING      // Standard C++ string library
+#include <string>      // Standard C++ string library
+#include <vector>
 
-#include <plib/sg.h>
-#include <plib/ssg.h>
+#include <osg/ref_ptr>
+#include <osg/Node>
+#include <osg/NodeVisitor>
+#include <osg/Billboard>
 
+#include <simgear/structure/SGReferenced.hxx>
+#include <simgear/structure/SGSharedPtr.hxx>
 #include <simgear/props/props.hxx>
-#include <simgear/scene/model/loader.hxx>
-
-SG_USING_STD(string);
+#include <simgear/math/sg_random.h>
 
 
 class SGMatModelGroup;
@@ -53,7 +56,7 @@ class SGMatModelGroup;
  * different shapes of trees), but they are considered equivalent
  * and interchangeable.
  */
-class SGMatModel {
+class SGMatModel : public SGReferenced {
 
 public:
 
@@ -63,7 +66,8 @@ public:
     enum HeadingType {
         HEADING_FIXED,
         HEADING_BILLBOARD,
-        HEADING_RANDOM
+        HEADING_RANDOM,
+        HEADING_MASK
     };
 
     /**
@@ -71,23 +75,7 @@ public:
      *
      * @return The number of variant models.
      */
-    int get_model_count( SGModelLoader *loader,
-                         const string &fg_root,
-                         SGPropertyNode *prop_root,
-                         double sim_time_sec );
-
-
-    /**
-     * Get a specific variant model for the object.
-     *
-     * @param index The index of the model.
-     * @return The model.
-     */
-    ssgEntity *get_model( int index,
-                          SGModelLoader *loader,
-                          const string &fg_root,
-                          SGPropertyNode *prop_root,
-                          double sim_time_sec );
+    int get_model_count( SGPropertyNode *prop_root );
 
 
     /**
@@ -95,10 +83,7 @@ public:
      *
      * @return A randomly select model from the variants.
      */
-    ssgEntity *get_random_model( SGModelLoader *loader,
-                                 const string &fg_root,
-                                 SGPropertyNode *prop_root,
-                                 double sim_time_sec );
+    osg::Node *get_random_model( SGPropertyNode *prop_root, mt *seed );
 
 
     /**
@@ -108,6 +93,28 @@ public:
      */
     double get_coverage_m2 () const;
 
+    /**
+     * Get the visual range of the object in meters.
+     *
+     * @return The visual range.
+     */
+    double get_range_m () const;
+
+    /**
+     * Get the minimum spacing between this and any
+     * other objects in m
+     *
+     * @return The spacing in m.
+     */
+    double get_spacing_m () const;
+    
+    
+    /**
+     * Get a randomized visual range
+     *
+     * @return a randomized visual range
+     */    
+    double get_randomized_range_m(mt* seed) const;    
 
     /**
      * Get the heading type for the object.
@@ -116,14 +123,15 @@ public:
      */
     HeadingType get_heading_type () const;
 
+    virtual ~SGMatModel ();
+    
+
 protected:
 
     friend class SGMatModelGroup;
 
     SGMatModel (const SGPropertyNode * node, double range_m);
 
-    virtual ~SGMatModel ();
-
 private:
 
     /**
@@ -132,15 +140,13 @@ private:
      * This class uses lazy loading so that models won't be held
      * in memory for materials that are never referenced.
      */
-    void load_models( SGModelLoader *loader,
-                      const string &fg_root,
-                      SGPropertyNode *prop_root,
-                      double sim_time_sec );
+    void load_models( SGPropertyNode *prop_root );
 
-    vector<string> _paths;
-    mutable vector<ssgEntity *> _models;
+    std::vector<std::string> _paths;
+    mutable std::vector<osg::ref_ptr<osg::Node> > _models;
     mutable bool _models_loaded;
     double _coverage_m2;
+    double _spacing_m;
     double _range_m;
     HeadingType _heading_type;
 };
@@ -154,7 +160,7 @@ private:
  * Each SGMaterial instance keeps a (possibly-empty) list of
  * object groups for placing randomly on the scenery.
  */
-class SGMatModelGroup {
+class SGMatModelGroup : public SGReferenced {
 
 public:
 
@@ -194,9 +200,7 @@ protected:
 private:
 
     double _range_m;
-    vector<SGMatModel *> _objects;
-
+    std::vector<SGSharedPtr<SGMatModel> > _objects;
 };
 
-
 #endif // _SG_MAT_MODEL_HXX