1 /*
2  * CRRCsim - the Charles River Radio Control Club Flight Simulator Project
3  *
4  *   Copyright (C) 2000, 2001 Jan Kansky (original author)
5  *   Copyright (C) 2004-2010 Jan Reucker
6  *   Copyright (C) 2005, 2008 Jens Wilhelm Wulf
7  *   Copyright (C) 2009 Joel Lienard
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2
11  * as published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
25 #ifndef MODEL_BASED_SCENERY_H
26 #define MODEL_BASED_SCENERY_H
27 
28 #include <crrc_config.h>
29 
30 #include "crrc_scenery.h"
31 #include "../mod_math/vector3.h"
32 #include "../mod_misc/SimpleXMLTransfer.h"
33 #include <plib/ssg.h>
34 #include "winddata3D.h"
35 #include "heightdata.h"
36 
37 #define DEFAULT_HEIGHT_MODE   2
38 
39 
40 /**
41  *  \brief Class for 3D-model-based sceneries
42  *
43  */
44 class ModelBasedScenery : public Scenery
45 {
46   public:
47     /**
48      *  The constructor
49      *
50      *  \param xml SimpleXMLTransfer from which the base classes will be initialized
51      */
52     ModelBasedScenery(SimpleXMLTransfer *xml, int sky_variant);
53 
54     /**
55      *  The destructor
56      */
57     ~ModelBasedScenery();
58 
59     /**
60      *  Draw the scenery
61      */
62     void draw(double current_time);
63 
64     /**
65      *  Draw the shadows casted by scenery's objects
66      */
67     void draw_shadows(double current_time);
68 
69     /**
70      *  Get the height at a distinct point.
71      *  \param x x coordinate
72      *  \param z z coordinate
73      *  \return terrain height at this point in ft
74      */
75     float getHeight(float x, float z);
76 
77     /**
78      *  get height and plane equation at x|z
79      *  \param x x coordinate
80      *  \param z z coordinate
81      *  \param tplane this is where the plane equation will be stored
82      *  \return terrain height at this point in ft
83      */
84     float getHeightAndPlane(float x, float z, float tplane[4]);
85 
86     /**
87      *  Get an ID code for this location or scenery type
88      */
getID()89     int getID() {return location;};
90 
91     /**
92      *  Get wind components at position X_cg, Y_cg, Z_cg
93      */
94     int getWindComponents(double X_cg, double Y_cg, double Z_cg,
95                           float *x_wind_velocity,
96                           float *y_wind_velocity,
97                           float *z_wind_velocity);
98 
99   private:
100     ssgRoot        *SceneGraph;
101     int location;   ///< location id
102     int getHeight_mode;
103       //0 : use ssgLOS (slow if many triangle)
104       //1 : ssgLOS()s en table (not god)
105       //2 : tiling of surface
106 
107     HeightData *heightdata;
108 
109     void evaluateNodeAttributes(ssgEntity* ent, bool def_t, bool def_v, bool def_a);
110     void addInstance(SimpleXMLTransfer *xml, bool c, bool s, ssgEntity *model, ssgBranch *parent);
111     void addPopulation(SimpleXMLTransfer *xml, bool c, bool s, ssgEntity *model, ssgBranch *parent);
112     void addObject(bool c, bool s, ssgEntity *model, ssgBranch *parent, sgMat4 xform);
113     void activateSceneTree(ssgEntity *ent, bool fObject);
114     void updateSceneShadows(ssgEntity *ent);
115 
116 #if WINDDATA3D == 1
117     int init_wind_data(const char* filename);
118     int find_wind_data(float n, float e, float u, float *vx, float *vy, float * vz);
119     WindData *wind_data;
120     float wind_position_coef;
121 #endif
122 };
123 
124 #endif  // MODEL_BASED_SCENERY_H
125