]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/SGBuildingBin.hxx
Fix degenerate random building placement case which resulted in buildings
[simgear.git] / simgear / scene / tgdb / SGBuildingBin.hxx
1 /* -*-c++-*-
2  *
3  * Copyright (C) 2011 Stuart Buchanan
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  * MA 02110-1301, USA.
19  *
20  */
21
22 #ifndef SG_BUILDING_BIN_HXX
23 #define SG_BUILDING_BIN_HXX
24
25 #include <math.h>
26
27 #include <vector>
28 #include <string>
29
30 #include <osg/Geometry>
31 #include <osg/Group>
32 #include <osg/Matrix>
33
34 #include <simgear/scene/util/OsgMath.hxx>
35
36 namespace simgear
37 {
38 class SGBuildingBin {
39 public:
40
41   enum BuildingType {
42     SMALL = 0,
43     MEDIUM,
44     LARGE };      
45
46   struct Building {
47     Building(BuildingType t, const SGVec3f& p, float w, float d, float h, int f, float rot, bool pitch) :
48       type(t), 
49       position(p), 
50       width(w), 
51       depth(d), 
52       height(h), 
53       floors(f),
54       rotation(rot), 
55       pitched(pitch), 
56       radius(std::max(d, 0.5f*w))
57     { }
58     Building(const SGVec3f& p, Building b) :
59       type(b.type), 
60       position(p), 
61       width(b.width), 
62       depth(b.depth), 
63       height(b.height),
64       floors(b.floors),
65       rotation(b.rotation), 
66       pitched(b.pitched),
67       radius(std::max(b.depth, 0.5f*b.width))
68     { }  
69     
70     BuildingType type;
71     SGVec3f position;
72     float width;
73     float depth;
74     float height;
75     int floors;
76     float rotation;
77     bool pitched;
78     float radius;
79     
80     float getFootprint() {
81       return radius;
82     }
83   };
84   
85   typedef std::vector<Building> BuildingList;
86   BuildingList buildings;
87   
88   std::string texture;
89   std::string lightMap;
90
91   void insert(const Building& model)
92   { 
93     buildings.push_back(model);   
94   }
95   
96   void insert(BuildingType t, const SGVec3f& p, float w, float d, float h, int f, float rot, bool pitch)
97   { insert(Building(t, p, w, d, h, f, rot, pitch)); }
98
99   unsigned getNumBuildings() const
100   { return buildings.size(); }
101   const Building& getBuilding(unsigned i) const
102   { return buildings[i]; }  
103   
104   ~SGBuildingBin() {
105     buildings.clear();    
106   }
107 };
108
109 // List of buildings
110 typedef std::list<SGBuildingBin*> SGBuildingBinList;
111
112 osg::Group* createRandomBuildings(SGBuildingBinList buildinglist, const osg::Matrix& transform,
113                          const SGReaderWriterOptions* options);
114 }
115 #endif