Develop and Download Open Source Software

Browse CVS Repository

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

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


Revision 1.2 - (show annotations) (download) (as text)
Wed Nov 17 09:56:44 2004 UTC (19 years, 4 months ago) by tmurakam
Branch: MAIN
CVS Tags: v0_3, v0_2, HEAD
Changes since 1.1: +13 -0 lines
File MIME type: text/x-c++src
Fill land only area

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 // cellarea.cc : Cell/Area process
30
31 #include <math.h>
32 #include "area.hpp"
33 #include "bgl.hpp"
34
35 ///////////////////////////////////////////////////////////////////////
36 // Area
37
38 Area::Area()
39 {
40 polygon = NULL;
41 }
42
43 void Area::setid(int uu, int vv, BoundingBox & cellbox)
44 {
45 u = uu;
46 v = vv;
47
48 bbox.xmin = cellbox.xmin + (cellbox.xmax - cellbox.xmin) * u / 32.0;
49 bbox.xmax = cellbox.xmin + (cellbox.xmax - cellbox.xmin) * (u+1) / 32.0;
50
51 bbox.ymax = cellbox.ymax - (cellbox.ymax - cellbox.ymin) * v / 32.0;
52 bbox.ymin = cellbox.ymax - (cellbox.ymax - cellbox.ymin) * (v+1) / 32.0;
53 }
54
55 void Area::Clipping(DataSet *source)
56 {
57 polygon = source->Clipping(bbox);
58 }
59
60 //
61 // decide Area type
62 //
63 void Area::setType(void)
64 {
65 areaType = T_WATER; // default: water
66
67 for (int i = 1; i <= NUM_LEVEL; i++) {
68 // If there are no polygons, go to next level.
69 if (polygon->get(i)->isEmpty()) continue;
70
71 if (polygon->get(i)->isFull(bbox)) {
72 // Whole the area is covered with one polygon.
73 // Change area type.
74 if (i == LV_LAND || i == LV_LAKE_ISLAND) {
75 areaType = T_LAND;
76 } else {
77 areaType = T_WATER;
78 }
79 }
80 else {
81 // The area is partially covered with some polygons.
82 areaType = (areaType == T_LAND) ? T_MIX_LAND : T_MIX_WATER;
83 break;
84 }
85 }
86 //printf("%d %d %d\n", u, v, areaType); //DEBUG
87 }
88
89 /////////////////////////////////////////////////////////////////////////
90 // LWM Process
91
92 void Area::DrawLwmPolygon(LwmDataChunk *chunk)
93 {
94 if (areaType != T_MIX_LAND && areaType != T_MIX_WATER) return;
95
96 for (int level = 1; level <= 4; level++) {
97 GpcPolygon *p = polygon->get(level);
98
99 // Is drawing needed?
100 if (p->isEmpty() || p->isFull(bbox)) continue;
101
102 chunk->DataAreaDrawPolygons(p->numVList(), u, v);
103
104 for (int i = 0; i < p->numVList(); i++) {
105 GpcVertexList *vlist = p->getVList(i);
106
107 chunk->Polygon(vlist->numVertices(),
108 (level == LV_LAND || level == LV_LAKE_ISLAND) ? 1 : 0);
109
110 for (int j = 0; j < vlist->numVertices(); j++) {
111 int x = (int)((vlist->vx(j) - bbox.xmin) / (bbox.xmax - bbox.xmin) * 255.0);
112 int y = (int)((bbox.ymax - vlist->vy(j)) / (bbox.ymax - bbox.ymin) * 255.0);
113
114 chunk->Point(x, y);
115 }
116 }
117 }
118 }
119
120 void Area::FillLand(LwmDataChunk *chunk)
121 {
122 ASSERT(areaType == T_LAND);
123
124 chunk->DataAreaDrawPolygons(1, u, v);
125 chunk->Polygon(4, 1);
126
127 chunk->Point(0, 0);
128 chunk->Point(255, 0);
129 chunk->Point(255, 255);
130 chunk->Point(0, 255);
131 }
132

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