]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/apt_signs.cxx
Moved some low level scene graph construction code over to simgear/scene/tgdb/
[simgear.git] / simgear / scene / tgdb / apt_signs.cxx
1 // apt_signs.cxx -- build airport signs on the fly
2 //
3 // Written by Curtis Olson, started July 2001.
4 //
5 // Copyright (C) 2001  Curtis L. Olson  - curt@flightgear.org
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #include <simgear/debug/logstream.hxx>
25 #include <simgear/math/sg_types.hxx>
26 #include <simgear/scene/tgdb/leaf.hxx>
27
28 #include "apt_signs.hxx"
29
30
31 ssgBranch *gen_taxi_sign( SGMaterialLib *matlib,
32                           const string path, const string content )
33 {
34     // for demo purposes we assume each element (letter) is 1x1 meter.
35     // Sign is placed 0.25 meters above the ground
36
37     ssgBranch *object = new ssgBranch();
38     object->setName( (char *)content.c_str() );
39
40     double offset = content.length() / 2.0;
41
42     for ( unsigned int i = 0; i < content.length(); ++i ) {
43         string material;
44
45         char item = content[i];
46         if ( item == '<' ) {
47             material = "ArrowL.rgb";
48         } else if ( item == '>' ) {
49             material = "ArrowR.rgb";
50         } else if ( item >= 'A' && item <= 'Z' ) {
51             material = "Letter";
52             material += item;
53             material += ".rgb";
54         } else if ( item >= 'a' && item <= 'z' ) {
55             int tmp = item - 'a';
56             char c = 'A' + tmp;
57             material = "Black";
58             material += c;
59             material += ".rgb";
60         } else {
61             SG_LOG( SG_TERRAIN, SG_ALERT,
62                     "Unknown taxi sign code = '" << item << "' !!!!" );
63             return NULL;
64         }
65
66         point_list nodes; nodes.clear();
67         point_list normals; normals.clear();
68         point_list texcoords; texcoords.clear();
69         int_list vertex_index; vertex_index.clear();
70         int_list normal_index; normal_index.clear();
71         int_list tex_index; tex_index.clear();
72
73         nodes.push_back( Point3D( -offset + i, 0, 0.25 ) );
74         nodes.push_back( Point3D( -offset + i + 1, 0, 0.25 ) );
75         nodes.push_back( Point3D( -offset + i, 0, 1.25 ) );
76         nodes.push_back( Point3D( -offset + i + 1, 0, 1.25 ) );
77
78         normals.push_back( Point3D( 0, -1, 0 ) );
79
80         texcoords.push_back( Point3D( 0, 0, 0 ) );
81         texcoords.push_back( Point3D( 1, 0, 0 ) );
82         texcoords.push_back( Point3D( 0, 1, 0 ) );
83         texcoords.push_back( Point3D( 1, 1, 0 ) );
84
85         vertex_index.push_back( 0 );
86         vertex_index.push_back( 1 );
87         vertex_index.push_back( 2 );
88         vertex_index.push_back( 3 );
89
90         normal_index.push_back( 0 );
91         normal_index.push_back( 0 );
92         normal_index.push_back( 0 );
93         normal_index.push_back( 0 );
94
95         tex_index.push_back( 0 );
96         tex_index.push_back( 1 );
97         tex_index.push_back( 2 );
98         tex_index.push_back( 3 );
99
100         ssgLeaf *leaf = sgMakeLeaf( path, GL_TRIANGLE_STRIP, matlib, material,
101                                     nodes, normals, texcoords,
102                                     vertex_index, normal_index, tex_index,
103                                     false, NULL );
104
105         object->addKid( leaf );
106     }
107
108     return object;
109 }
110
111
112 ssgBranch *gen_runway_sign( SGMaterialLib *matlib,
113                             const string path, const string name )
114 {
115     // for demo purposes we assume each element (letter) is 1x1 meter.
116     // Sign is placed 0.25 meters above the ground
117
118     ssgBranch *object = new ssgBranch();
119     object->setName( (char *)name.c_str() );
120
121     double width = name.length() / 3.0;
122
123     string material = name + ".rgb";
124
125     point_list nodes; nodes.clear();
126     point_list normals; normals.clear();
127     point_list texcoords; texcoords.clear();
128     int_list vertex_index; vertex_index.clear();
129     int_list normal_index; normal_index.clear();
130     int_list tex_index; tex_index.clear();
131
132     nodes.push_back( Point3D( -width, 0, 0.25 ) );
133     nodes.push_back( Point3D( width + 1, 0, 0.25 ) );
134     nodes.push_back( Point3D( -width, 0, 1.25 ) );
135     nodes.push_back( Point3D( width + 1, 0, 1.25 ) );
136
137     normals.push_back( Point3D( 0, -1, 0 ) );
138
139     texcoords.push_back( Point3D( 0, 0, 0 ) );
140     texcoords.push_back( Point3D( 1, 0, 0 ) );
141     texcoords.push_back( Point3D( 0, 1, 0 ) );
142     texcoords.push_back( Point3D( 1, 1, 0 ) );
143
144     vertex_index.push_back( 0 );
145     vertex_index.push_back( 1 );
146     vertex_index.push_back( 2 );
147     vertex_index.push_back( 3 );
148
149     normal_index.push_back( 0 );
150     normal_index.push_back( 0 );
151     normal_index.push_back( 0 );
152     normal_index.push_back( 0 );
153
154     tex_index.push_back( 0 );
155     tex_index.push_back( 1 );
156     tex_index.push_back( 2 );
157     tex_index.push_back( 3 );
158
159     ssgLeaf *leaf = sgMakeLeaf( path, GL_TRIANGLE_STRIP, matlib, material,
160                                 nodes, normals, texcoords,
161                                 vertex_index, normal_index, tex_index,
162                                 false, NULL );
163
164     object->addKid( leaf );
165
166     return object;
167 }