]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/apt_signs.cxx
5674d7a64ddff6d06aedc05d77f7d3a06f1a51db
[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  - http://www.flightgear.org/~curt
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23 #ifdef HAVE_CONFIG_H
24 #  include <simgear_config.h>
25 #endif
26
27 #include <simgear/debug/logstream.hxx>
28 #include <simgear/math/sg_types.hxx>
29 #include <simgear/scene/tgdb/leaf.hxx>
30
31 #include "apt_signs.hxx"
32
33
34 ssgBranch *sgMakeTaxiSign( SGMaterialLib *matlib,
35                            const string path, const string content )
36 {
37     // for demo purposes we assume each element (letter) is 1x1 meter.
38     // Sign is placed 0.25 meters above the ground
39
40     ssgBranch *object = new ssgBranch();
41     object->setName( (char *)content.c_str() );
42
43     double offset = content.length() / 2.0;
44
45     for ( unsigned int i = 0; i < content.length(); ++i ) {
46         string material;
47
48         char item = content[i];
49         if ( item == '<' ) {
50             material = "ArrowL.rgb";
51         } else if ( item == '>' ) {
52             material = "ArrowR.rgb";
53         } else if ( item >= 'A' && item <= 'Z' ) {
54             material = "Letter";
55             material += item;
56             material += ".rgb";
57         } else if ( item >= 'a' && item <= 'z' ) {
58             int tmp = item - 'a';
59             char c = 'A' + tmp;
60             material = "Black";
61             material += c;
62             material += ".rgb";
63         } else {
64             SG_LOG( SG_TERRAIN, SG_ALERT,
65                     "Unknown taxi sign code = '" << item << "' !!!!" );
66             return NULL;
67         }
68
69         point_list nodes; nodes.clear();
70         point_list normals; normals.clear();
71         point_list texcoords; texcoords.clear();
72         int_list vertex_index; vertex_index.clear();
73         int_list normal_index; normal_index.clear();
74         int_list tex_index; tex_index.clear();
75
76         nodes.push_back( Point3D( -offset + i, 0, 0.25 ) );
77         nodes.push_back( Point3D( -offset + i + 1, 0, 0.25 ) );
78         nodes.push_back( Point3D( -offset + i, 0, 1.25 ) );
79         nodes.push_back( Point3D( -offset + i + 1, 0, 1.25 ) );
80
81         normals.push_back( Point3D( 0, -1, 0 ) );
82
83         texcoords.push_back( Point3D( 0, 0, 0 ) );
84         texcoords.push_back( Point3D( 1, 0, 0 ) );
85         texcoords.push_back( Point3D( 0, 1, 0 ) );
86         texcoords.push_back( Point3D( 1, 1, 0 ) );
87
88         vertex_index.push_back( 0 );
89         vertex_index.push_back( 1 );
90         vertex_index.push_back( 2 );
91         vertex_index.push_back( 3 );
92
93         normal_index.push_back( 0 );
94         normal_index.push_back( 0 );
95         normal_index.push_back( 0 );
96         normal_index.push_back( 0 );
97
98         tex_index.push_back( 0 );
99         tex_index.push_back( 1 );
100         tex_index.push_back( 2 );
101         tex_index.push_back( 3 );
102
103         ssgLeaf *leaf = sgMakeLeaf( path, GL_TRIANGLE_STRIP, matlib, material,
104                                     nodes, normals, texcoords,
105                                     vertex_index, normal_index, tex_index,
106                                     false, NULL );
107
108         object->addKid( leaf );
109     }
110
111     return object;
112 }
113
114
115 ssgBranch *sgMakeRunwaySign( SGMaterialLib *matlib,
116                              const string path, const string name )
117 {
118     // for demo purposes we assume each element (letter) is 1x1 meter.
119     // Sign is placed 0.25 meters above the ground
120
121     ssgBranch *object = new ssgBranch();
122     object->setName( (char *)name.c_str() );
123
124     double width = name.length() / 3.0;
125
126     string material = name + ".rgb";
127
128     point_list nodes; nodes.clear();
129     point_list normals; normals.clear();
130     point_list texcoords; texcoords.clear();
131     int_list vertex_index; vertex_index.clear();
132     int_list normal_index; normal_index.clear();
133     int_list tex_index; tex_index.clear();
134
135     nodes.push_back( Point3D( -width, 0, 0.25 ) );
136     nodes.push_back( Point3D( width + 1, 0, 0.25 ) );
137     nodes.push_back( Point3D( -width, 0, 1.25 ) );
138     nodes.push_back( Point3D( width + 1, 0, 1.25 ) );
139
140     normals.push_back( Point3D( 0, -1, 0 ) );
141
142     texcoords.push_back( Point3D( 0, 0, 0 ) );
143     texcoords.push_back( Point3D( 1, 0, 0 ) );
144     texcoords.push_back( Point3D( 0, 1, 0 ) );
145     texcoords.push_back( Point3D( 1, 1, 0 ) );
146
147     vertex_index.push_back( 0 );
148     vertex_index.push_back( 1 );
149     vertex_index.push_back( 2 );
150     vertex_index.push_back( 3 );
151
152     normal_index.push_back( 0 );
153     normal_index.push_back( 0 );
154     normal_index.push_back( 0 );
155     normal_index.push_back( 0 );
156
157     tex_index.push_back( 0 );
158     tex_index.push_back( 1 );
159     tex_index.push_back( 2 );
160     tex_index.push_back( 3 );
161
162     ssgLeaf *leaf = sgMakeLeaf( path, GL_TRIANGLE_STRIP, matlib, material,
163                                 nodes, normals, texcoords,
164                                 vertex_index, normal_index, tex_index,
165                                 false, NULL );
166
167     object->addKid( leaf );
168
169     return object;
170 }