]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/SGModelBin.hxx
Random object support from Stuart Buchanan
[simgear.git] / simgear / scene / tgdb / SGModelBin.hxx
1 /* -*-c++-*-
2  *
3  * Copyright (C) 2007 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_MAT_MODEL_BIN_HXX
23 #define SG_MAT_MODEL_BIN_HXX
24
25 #include <math.h>
26
27 class SGMatModelBin {
28 public:
29   struct MatModel {
30     MatModel(const SGVec3f& p, SGMatModel *m) :
31       position(p), model(m)
32     { }
33     SGVec3f position;
34     SGMatModel *model;
35   };
36   typedef std::vector<MatModel> MatModelList;
37
38   void insert(const MatModel& model)
39   { 
40     float x = model.position.x();
41     float y = model.position.y();
42     float z = model.position.z();
43   
44     if (_models.size() == 0) 
45     {
46       min_x = x;
47       max_x = x;
48       
49       min_y = y;
50       max_y = y;
51       
52       min_z = z;
53       max_z = z;
54     }
55     else
56     {      
57       min_x = SGMisc<float>::min(min_x, x);
58       max_x = SGMisc<float>::max(max_x, x);
59
60       min_y = SGMisc<float>::min(min_y, y);
61       max_y = SGMisc<float>::max(max_y, y);
62
63       min_z = SGMisc<float>::min(min_z, z);
64       max_z = SGMisc<float>::max(max_z, z);
65     }
66     
67     _models.push_back(model);   
68   }
69   
70   void insert(const SGVec3f& p, SGMatModel *m)
71   { insert(MatModel(p, m)); }
72
73   unsigned getNumModels() const
74   { return _models.size(); }
75   const MatModel& getMatModel(unsigned i) const
76   { return _models[i]; }
77   
78 private:
79   MatModelList _models;
80   float min_x;
81   float max_x;
82   float min_y;
83   float max_y;
84   float min_z;
85   float max_z;
86 };
87
88 #endif