| 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 |
// bgl.cc : BGL base classes |
| 30 |
|
| 31 |
#include <stdio.h> |
| 32 |
#include <string.h> |
| 33 |
#include <math.h> |
| 34 |
|
| 35 |
#include "bgl.hpp" |
| 36 |
#include "bbox.hpp" |
| 37 |
|
| 38 |
////////////////////////////////////////////////////////////////// |
| 39 |
// DataChunk |
| 40 |
|
| 41 |
DataChunk::DataChunk() |
| 42 |
{ |
| 43 |
databuf = new DataBuf; |
| 44 |
} |
| 45 |
|
| 46 |
DataChunk::~DataChunk() |
| 47 |
{ |
| 48 |
delete databuf; |
| 49 |
} |
| 50 |
|
| 51 |
void DataChunk::WriteDataChunk(FILE *fp) |
| 52 |
{ |
| 53 |
fwrite(databuf->data(), databuf->size(), 1, fp); |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
///////////////////////////////////////////////////////////////// |
| 58 |
// Bgl |
| 59 |
|
| 60 |
Bgl::Bgl() |
| 61 |
{ |
| 62 |
fp = NULL; |
| 63 |
} |
| 64 |
|
| 65 |
Bgl::~Bgl() |
| 66 |
{ |
| 67 |
if (fp) { |
| 68 |
fclose(fp); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
void Bgl::OpenFile(const char *fname) |
| 73 |
{ |
| 74 |
fp = fopen(fname, "wb"); |
| 75 |
if (!fp) { |
| 76 |
fprintf(stderr, "Can't create file: %s\n", fname); |
| 77 |
exit(1); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
void Bgl::UpdateBoundingBox(BoundingBox &bb) |
| 82 |
{ |
| 83 |
bbox.extend(&bb); |
| 84 |
} |
| 85 |
|
| 86 |
void Bgl::WriteBGLHeader(const char *LWMHeaderLabel, const char *VTPHeaderLabel) |
| 87 |
{ |
| 88 |
fprintf(fp, ";-------------------------------------------------------------\n"); |
| 89 |
fprintf(fp, "; This file is created with AutoCoast automatically.\n"); |
| 90 |
fprintf(fp, "; Do not modify me.\n"); |
| 91 |
fprintf(fp, ";-------------------------------------------------------------\n"); |
| 92 |
fprintf(fp, "\n"); |
| 93 |
fprintf(fp, "include TDFMacros.inc\n"); |
| 94 |
fprintf(fp, "include TDFHeaders.inc\n"); |
| 95 |
fprintf(fp, "\n"); |
| 96 |
|
| 97 |
fprintf(fp, "BGLHeader %d, %d, %d, %d, %s, %s\n\n", |
| 98 |
int(ceil(bbox.ymax)), |
| 99 |
int(floor(bbox.ymin)), |
| 100 |
int(ceil(bbox.xmax)), |
| 101 |
int(floor(bbox.xmin)), |
| 102 |
(LWMHeaderLabel != NULL) ? LWMHeaderLabel : "TerrainHeaderStart", |
| 103 |
(VTPHeaderLabel != NULL) ? VTPHeaderLabel : "TerrainHeaderStart" |
| 104 |
); |
| 105 |
|
| 106 |
} |