]> git.mxchange.org Git - flightgear.git/blob - src/Objects/apt_signs.cxx
51b2dfc72f66d230c0f5e718f74c114e7222c82b
[flightgear.git] / src / Objects / 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/math/sg_types.hxx>
25
26 #include "apt_signs.hxx"
27 #include "obj.hxx"
28
29
30 ssgBranch *gen_taxi_sign( const string path, const string content ) {
31     // for demo purposes we assume each element (letter) is 1x1 meter.
32     // Sign is placed 0.25 meters above the ground
33
34     ssgBranch *object = new ssgBranch();
35     object->setName( (char *)content.c_str() );
36
37     double offset = content.length() / 2.0;
38
39     for ( unsigned int i = 0; i < content.length(); ++i ) {
40         string material;
41
42         char item = content[i];
43         if ( item == '<' ) {
44             material = "ArrowL.rgb";
45         } else if ( item == '>' ) {
46             material = "ArrowR.rgb";
47         } else if ( item >= 'A' && item <= 'Z' ) {
48             material = "Letter";
49             material += item;
50             material += ".rgb";
51         } else if ( item >= 'a' && item <= 'z' ) {
52             int tmp = item - 'a';
53             char c = 'A' + tmp;
54             material = "Black";
55             material += c;
56             material += ".rgb";
57         } else {
58             cout << "Unknown taxi sign code = '" << item << "' !!!!" << endl;
59             return NULL;
60         }
61
62         point_list nodes; nodes.clear();
63         point_list normals; normals.clear();
64         point_list texcoords; texcoords.clear();
65         int_list vertex_index; vertex_index.clear();
66         int_list tex_index; tex_index.clear();
67
68         nodes.push_back( Point3D( -offset + i, 0, 0.25 ) );
69         nodes.push_back( Point3D( -offset + i + 1, 0, 0.25 ) );
70         nodes.push_back( Point3D( -offset + i, 0, 1.25 ) );
71         nodes.push_back( Point3D( -offset + i + 1, 0, 1.25 ) );
72
73         normals.push_back( Point3D( 0, -1, 0 ) );
74         normals.push_back( Point3D( 0, -1, 0 ) );
75         normals.push_back( Point3D( 0, -1, 0 ) );
76         normals.push_back( Point3D( 0, -1, 0 ) );
77
78         texcoords.push_back( Point3D( 0, 0, 0 ) );
79         texcoords.push_back( Point3D( 1, 0, 0 ) );
80         texcoords.push_back( Point3D( 0, 1, 0 ) );
81         texcoords.push_back( Point3D( 1, 1, 0 ) );
82
83         vertex_index.push_back( 0 );
84         vertex_index.push_back( 1 );
85         vertex_index.push_back( 2 );
86         vertex_index.push_back( 3 );
87
88         tex_index.push_back( 0 );
89         tex_index.push_back( 1 );
90         tex_index.push_back( 2 );
91         tex_index.push_back( 3 );
92
93         ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material,
94                                   nodes, normals, texcoords,
95                                   vertex_index, tex_index,
96                                   false, NULL );
97
98         object->addKid( leaf );
99     }
100
101     return object;
102 }
103
104
105 ssgBranch *gen_runway_sign( const string path, const string name ) {
106     // for demo purposes we assume each element (letter) is 1x1 meter.
107     // Sign is placed 0.25 meters above the ground
108
109     ssgBranch *object = new ssgBranch();
110     object->setName( (char *)name.c_str() );
111
112     double width = name.length() / 3.0;
113
114     string material = name + ".rgb";
115
116     point_list nodes; nodes.clear();
117     point_list normals; normals.clear();
118     point_list texcoords; texcoords.clear();
119     int_list vertex_index; vertex_index.clear();
120     int_list tex_index; tex_index.clear();
121
122     nodes.push_back( Point3D( -width, 0, 0.25 ) );
123     nodes.push_back( Point3D( width + 1, 0, 0.25 ) );
124     nodes.push_back( Point3D( -width, 0, 1.25 ) );
125     nodes.push_back( Point3D( width + 1, 0, 1.25 ) );
126
127     normals.push_back( Point3D( 0, -1, 0 ) );
128     normals.push_back( Point3D( 0, -1, 0 ) );
129     normals.push_back( Point3D( 0, -1, 0 ) );
130     normals.push_back( Point3D( 0, -1, 0 ) );
131
132     texcoords.push_back( Point3D( 0, 0, 0 ) );
133     texcoords.push_back( Point3D( 1, 0, 0 ) );
134     texcoords.push_back( Point3D( 0, 1, 0 ) );
135     texcoords.push_back( Point3D( 1, 1, 0 ) );
136
137     vertex_index.push_back( 0 );
138     vertex_index.push_back( 1 );
139     vertex_index.push_back( 2 );
140     vertex_index.push_back( 3 );
141
142     tex_index.push_back( 0 );
143     tex_index.push_back( 1 );
144     tex_index.push_back( 2 );
145     tex_index.push_back( 3 );
146
147     ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material,
148                               nodes, normals, texcoords,
149                               vertex_index, tex_index,
150                               false, NULL );
151
152     object->addKid( leaf );
153
154     return object;
155 }