| 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 |
// bglvtp.cc : VTP bgl |
| 30 |
|
| 31 |
#include <stdio.h> |
| 32 |
#include <string.h> |
| 33 |
#include <math.h> |
| 34 |
|
| 35 |
#include "bglvtp.hpp" |
| 36 |
#include "bbox.hpp" |
| 37 |
#include "opt.hpp" |
| 38 |
|
| 39 |
////////////////////////////////////////////////////////////////// |
| 40 |
// VtpDataChunk |
| 41 |
|
| 42 |
void VtpDataChunk::DataArea(int u, int v, int numTexture, int autocalc) |
| 43 |
{ |
| 44 |
databuf->sprintf( |
| 45 |
"\tVTPDataArea %d, %d, %d, %d\n", |
| 46 |
1, // layer count |
| 47 |
autocalc, // autocalc |
| 48 |
u, // row |
| 49 |
v); // column |
| 50 |
databuf->sprintf( |
| 51 |
"\t\tVTPLayer %d, %d\n", |
| 52 |
8, // layer (8 : shoreline) |
| 53 |
1); // replace (1 : replace all previous data in the same layer) |
| 54 |
databuf->sprintf( |
| 55 |
"\t\tVTPNumTexturesInLayer %d, 0\n", |
| 56 |
numTexture); |
| 57 |
} |
| 58 |
|
| 59 |
void VtpDataChunk::TextureStart(int PolyCount) |
| 60 |
{ |
| 61 |
databuf->sprintf( |
| 62 |
"\t\tVTPTextureId 0, 0\n" |
| 63 |
"\t\tVTPPolyCount %d, 0\n", PolyCount); |
| 64 |
} |
| 65 |
|
| 66 |
void VtpDataChunk::PolyStart(int PointCount) |
| 67 |
{ |
| 68 |
if (PointCount <= 30) { |
| 69 |
databuf->sprintf( |
| 70 |
"\t\tVTPPolyMethod2 %d, %d, 0\n", |
| 71 |
PointCount, |
| 72 |
1); // IsLine (0:fan 1:line) |
| 73 |
} else { |
| 74 |
databuf->sprintf( |
| 75 |
"\t\tVTPPolyMethod2 %d, %d, 0\n", |
| 76 |
31, // must be 31 |
| 77 |
1); // IsLine (0:fan 1:line) |
| 78 |
databuf->sprintf( |
| 79 |
"\t\tVTPPolyMethod2Ex %d\n", |
| 80 |
PointCount - 31); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
void VtpDataChunk::WidePoint(int x, int y, int usewidth) |
| 85 |
{ |
| 86 |
databuf->sprintf("\t\t\tVTPWidePoint %d, %d, %d, %d\n", |
| 87 |
x, // X |
| 88 |
usewidth, // use width? |
| 89 |
y, // Y |
| 90 |
0); // reserved |
| 91 |
} |
| 92 |
|
| 93 |
void VtpDataChunk::WidePointWidth(int w) |
| 94 |
{ |
| 95 |
databuf->sprintf("\t\t\tVTPWidePointWidth %d\n", w); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
///////////////////////////////////////////////////////////////// |
| 100 |
// VtpBgl |
| 101 |
|
| 102 |
VtpBgl::VtpBgl() |
| 103 |
{ |
| 104 |
// nothing to do |
| 105 |
} |
| 106 |
|
| 107 |
VtpBgl::~VtpBgl() |
| 108 |
{ |
| 109 |
// nothing to do |
| 110 |
} |
| 111 |
|
| 112 |
DataChunk *VtpBgl::NewDataChunk(int u, int v, BoundingBox &bb) |
| 113 |
{ |
| 114 |
VtpDataChunk *data = new VtpDataChunk(); |
| 115 |
data->setuv(u, v); |
| 116 |
|
| 117 |
datachunk.push_back(data); |
| 118 |
|
| 119 |
UpdateBoundingBox(bb); |
| 120 |
|
| 121 |
return data; |
| 122 |
} |
| 123 |
|
| 124 |
void VtpBgl::WriteBGL(const char *fname) |
| 125 |
{ |
| 126 |
OpenFile(fname); |
| 127 |
|
| 128 |
int count = datachunk.size(); |
| 129 |
int i; |
| 130 |
|
| 131 |
// Write BGL + TerrainHeader |
| 132 |
WriteBGLHeader(NULL, "VTPHeader"); |
| 133 |
|
| 134 |
// Write VTPFileHeader |
| 135 |
fprintf(fp,"VTPHeader label word\n"); |
| 136 |
fprintf(fp, "\tVTPFileHeader 256, VTPIndexStart, TextureStart, VTPEnd\n\n"); |
| 137 |
fprintf(fp,";--------------------------------------------------------\n"); |
| 138 |
|
| 139 |
// Data |
| 140 |
fprintf(fp, "VTPDataStart label word\n"); |
| 141 |
for (i = 0; i < count; i++) { |
| 142 |
fprintf(fp, "VTPDataStart_%d label word\n", i); |
| 143 |
datachunk[i]->WriteDataChunk(fp); |
| 144 |
fprintf(fp, "VTPDataEnd_%d label word\n", i); |
| 145 |
} |
| 146 |
fprintf(fp, "VTPDataEnd label word\n"); |
| 147 |
|
| 148 |
// Index Header |
| 149 |
fprintf(fp, ";--------------------------------------------------------\n\n"); |
| 150 |
|
| 151 |
fprintf(fp, "VTPIndexStart label word\n"); |
| 152 |
fprintf(fp, "\tVTPIndexHeader %d, VTPIndexData, VTPDataStart\n", count); |
| 153 |
fprintf(fp, "\n"); |
| 154 |
|
| 155 |
// Index Entry |
| 156 |
fprintf(fp, "VTPIndexData label word\n"); |
| 157 |
for (i = 0; i < count; i++) { |
| 158 |
int u, v; |
| 159 |
datachunk[i]->getuv(u, v); |
| 160 |
|
| 161 |
fprintf(fp, "\tCell_id_%d_%d EQU VTPCellID 0, %d, %d\n", u, v, u, v); |
| 162 |
fprintf(fp, "\tVTPIndexEntry Cell_id_%d_%d, VTPDataStart" |
| 163 |
", VTPDataStart_%d, VTPDataEnd_%d\n\n", |
| 164 |
u, v, i, i); |
| 165 |
} |
| 166 |
|
| 167 |
// Texture names |
| 168 |
fprintf(fp, ";--------------------------------------------------------\n\n"); |
| 169 |
|
| 170 |
fprintf(fp, |
| 171 |
"TextureStart label word\n" |
| 172 |
"\tVTPTextureListHeader 1, TextureIndexStart, TextureDataStart, TextureDataEnd\n"); |
| 173 |
fprintf(fp, |
| 174 |
"TextureIndexStart label word\n" |
| 175 |
"\tVTPTextureListEntry TextureDataStart, TextureDataStart_0, TextureDataEnd_0\n"); |
| 176 |
|
| 177 |
fprintf(fp, |
| 178 |
"TextureDataStart label word\n" |
| 179 |
"TextureDataStart_0 label word\n" |
| 180 |
"\tVTPTextureName \"%s\"\n" |
| 181 |
"\tVTPTextureType 2, 0, 0, 4\n" |
| 182 |
"TextureDataEnd_0 label word\n" |
| 183 |
"TextureDataEnd label word\n", |
| 184 |
AcOpts.textureName); |
| 185 |
|
| 186 |
// end |
| 187 |
fprintf(fp, "VTPEnd label word\n"); |
| 188 |
fprintf(fp, ";EOF\n"); |
| 189 |
} |