Develop and Download Open Source Software

Browse CVS Repository

Contents of /autocoast/src/lib/bgllwm.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Fri Nov 26 09:22:38 2004 UTC (19 years, 4 months ago) by tmurakam
Branch: MAIN
CVS Tags: v0_3, v0_2, HEAD
Changes since 1.3: +0 -2 lines
File MIME type: text/x-c++src
support split bgl

1 //
2 // AutoCoast: Automatic Coastline scenery generator for Flight Simulator
3 //
4 // Copyright (c) 2004, Takuya Murakami. All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
8 // are met:
9 //
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // 2. Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
21 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 // bgllwm.cc : LWM BGL process
30
31 #include <stdio.h>
32 #include <string.h>
33 #include <math.h>
34
35 #include "bgllwm.hpp"
36 #include "bbox.hpp"
37
38 //////////////////////////////////////////////////////////////////
39 // LwmDataChunk
40
41 void LwmDataChunk::DataAreaFill(int blocksz, int attr, int u, int v)
42 {
43 if (attr == 1) {
44 return; // land polygon ::: ad hoc... ###
45 }
46
47 switch (blocksz) {
48 case 1:
49 databuf->sprintf("\tLWMDataAreaFill1x1 0, %d, 1, %d, %d\n", attr, u, v);
50 break;
51
52 case 2:
53 case 4:
54 case 8:
55 case 16:
56 databuf->sprintf("\tLWMDataAreaFill%dx%d 0, %d, 0, 1, %d, 0, %d\n",
57 blocksz, blocksz,
58 attr, u/blocksz, v/blocksz);
59 break;
60
61 default:
62 /* oops!!! */
63 break;
64 }
65 if (attr == 0 || attr == 2 || true) {//###
66 databuf->sprintf("\tLWMDataAreaHeight -9999, 0\n");
67 }
68 }
69
70 void LwmDataChunk::DataAreaDrawPolygons(int PolyCount, int u, int v)
71 {
72 if (PolyCount <= 6) {
73 databuf->sprintf(
74 "\tLWMDataAreaDrawPolygons %d, %d, %d, %d, %d\n",
75 PolyCount, // poly count
76 3, // attr (must be 3)
77 1, // flag (must be 1)
78 u, // col
79 v // row
80 );
81 } else {
82 databuf->sprintf(
83 "\tLWMDataAreaDrawPolygonsEx %d, %d, %d, %d, %d, %d\n",
84 7, // poly ex flag (must be 7)
85 3, // attr (must be 3)
86 1, // flag (must be 1)
87 u, // col
88 v, // row
89 PolyCount - 7 // ExPolyCount
90 );
91 }
92 }
93
94 void LwmDataChunk::Polygon(int NumVertices, int type)
95 {
96 if (NumVertices <= 62) {
97 databuf->sprintf(
98 "\tLWMPoly2 %d, %d, %d, %d, %d\n",
99 NumVertices, // PointCount
100 0, // reserved
101 type, // attr (0 = water, 1 = land)
102 -9999, // Height
103 0 // Fraction
104 );
105 } else {
106 databuf->sprintf(
107 "\tLWMPoly2Ex %d, %d, %d, %d, %d, %d\n",
108 63, // PointCount (must be 63)
109 0, // reserved
110 type, // attr (0 = water, 1 = land)
111 -9999, // Height
112 0, // Fraction
113 NumVertices-63 // ExPointCount
114 );
115 }
116 }
117
118 void LwmDataChunk::Point(int x, int y)
119 {
120 databuf->sprintf("\t\tLWMPoint %d, %d\n", x, y);
121 }
122
123 /////////////////////////////////////////////////////////////////
124 // LwmBgl
125
126 LwmBgl::LwmBgl()
127 {
128 // nothing to do
129 }
130
131 LwmBgl::~LwmBgl()
132 {
133 // nothing to do
134 }
135
136 DataChunk *LwmBgl::NewDataChunk(int u, int v, BoundingBox &bb)
137 {
138 LwmDataChunk *data = new LwmDataChunk();
139 data->setuv(u, v);
140
141 datachunk.push_back(data);
142
143 UpdateBoundingBox(bb);
144
145 return data;
146 }
147
148 void LwmBgl::WriteBGL(const char *fname)
149 {
150 OpenFile(fname);
151
152 int count = datachunk.size();
153 int i;
154
155 // Write BGL + TerrainHeader
156 WriteBGLHeader("LWMHeader", NULL);
157
158 // Write LWM Header
159 fprintf(fp,"LWMHeader label word\n");
160 fprintf(fp,"\tLWMFileHeader 201h, LWMIndexStart, LWMDataStart, LWMEnd\n\n");
161
162 fprintf(fp,"LWMStart label word\n");
163 fprintf(fp,"DataStart label word\n\n");
164 fprintf(fp,";--------------------------------------------------------\n");
165
166 // Data
167 fprintf(fp, "LWMDataStart label word\n");
168 for (i = 0; i < count; i++) {
169 fprintf(fp, "LWMDataStart_%d label word\n", i);
170 datachunk[i]->WriteDataChunk(fp);
171 fprintf(fp, "LWMDataEnd_%d label word\n", i);
172 }
173 fprintf(fp, "LWMDataEnd label word\n");
174
175 // Index Header
176 fprintf(fp, ";--------------------------------------------------------\n");
177
178 fprintf(fp, "\n");
179
180 fprintf(fp, "LWMIndexStart label word\n");
181 fprintf(fp, "\tLWMIndexHeader %d, LWMIndexData\n", count);
182 fprintf(fp, "\n");
183
184 // Index Entry
185 fprintf(fp, "LWMIndexData label word\n");
186 for (i = 0; i < count; i++) {
187 int u, v;
188 datachunk[i]->getuv(u, v);
189
190 fprintf(fp, "\tCell_id_%d_%d EQU LWMCellID 0, 0, %d, %d, %d\n", u, v,
191 1/*fill with land!*/, u, v);
192 fprintf(fp, "\tLWMIndexEntry Cell_id_%d_%d, LWMStart"
193 ", LWMDataStart_%d, LWMDataEnd_%d\n\n",
194 u, v, i, i);
195 }
196
197 // End
198 fprintf(fp, "LWMEnd label word\n");
199 fprintf(fp, ";EOF\n");
200 }
201

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26