]> git.mxchange.org Git - flightgear.git/blob - Scenery/tilemgr.c
Initial changes to support loading and management of scenery tiles. Note,
[flightgear.git] / Scenery / tilemgr.c
1 /**************************************************************************
2  * tilemgr.c -- routines to handle dynamic management of scenery tiles
3  *
4  * Written by Curtis Olson, started January 1998.
5  *
6  * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * $Id$
23  * (Log is kept at end of this file)
24  **************************************************************************/
25
26
27 #ifdef WIN32
28 #  include <windows.h>
29 #endif
30
31 #include <GL/glut.h>
32 #include "../XGL/xgl.h"
33
34 #include "scenery.h"
35 #include "tileutils.h"
36 #include "obj.h"
37
38 #include "../Aircraft/aircraft.h"
39 #include "../Include/constants.h"
40 #include "../Include/general.h"
41 #include "../Include/types.h"
42
43
44 /* here's where we keep the array of closest (potentially viewable) tiles */
45 struct bucket local_tiles[49];
46 GLint local_display_lists[49];
47 struct fgCartesianPoint local_refs[49];
48
49
50 /* Initialize the Tile Manager subsystem */
51 void fgTileMgrInit() {
52     printf("Initializing Tile Manager subsystem.\n");
53     /* fgTileCacheInit(); */
54 }
55
56
57 /* given the current lon/lat, fill in the array of local chunks.  If
58  * the chunk isn't already in the cache, then read it from disk. */
59 void fgTileMgrUpdate() {
60     struct fgFLIGHT *f;
61     struct fgGENERAL *g;
62     struct bucket p;
63     char base_path[256];
64     char file_name[256];
65     int i, j;
66
67     f = &current_aircraft.flight;
68     g = &general;
69
70     find_bucket(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p);
71     printf("Updating Tile list for %d,%d %d,%d\n", p.lon, p.lat, p.x, p.y);
72
73     gen_idx_array(&p, local_tiles, 7, 7);
74
75     /* scenery.center = ref; */
76
77     for ( i = 0; i < 49; i++ ) {
78         gen_base_path(&local_tiles[i], base_path);
79         sprintf(file_name, "%s/Scenery/%s/%ld.obj", 
80                 g->root_dir, base_path, gen_index(&local_tiles[i]));
81         local_display_lists[i] = 
82             fgObjLoad(file_name, &local_refs[i]);
83
84         if ( (local_tiles[i].lon == p.lon) &&
85              (local_tiles[i].lat == p.lat) &&
86              (local_tiles[i].x == p.x) &&
87              (local_tiles[i].y == p.y) ) {
88             scenery.center = local_refs[i];
89         }
90     }
91 }
92
93
94 /* Render the local tiles --- hack, hack, hack */
95 void fgTileMgrRender() {
96     static GLfloat terrain_color[4] = { 0.6, 0.8, 0.4, 1.0 };
97     static GLfloat terrain_ambient[4];
98     static GLfloat terrain_diffuse[4];
99     int i, j;
100
101     for ( i = 0; i < 4; i++ ) {
102         terrain_ambient[i] = terrain_color[i] * 0.5;
103         terrain_diffuse[i] = terrain_color[i];
104     }
105
106     xglMaterialfv(GL_FRONT, GL_AMBIENT, terrain_ambient);
107     xglMaterialfv(GL_FRONT, GL_DIFFUSE, terrain_diffuse);
108
109     for ( i = 0; i < 49; i++ ) {
110         xglPushMatrix();
111         xglTranslatef(local_refs[i].x - scenery.center.x,
112                       local_refs[i].y - scenery.center.y,
113                       local_refs[i].z - scenery.center.z);
114         xglCallList(local_display_lists[i]);
115         xglPopMatrix();
116     }
117 }
118
119
120 /* $Log$
121 /* Revision 1.3  1998/01/13 00:23:11  curt
122 /* Initial changes to support loading and management of scenery tiles.  Note,
123 /* there's still a fair amount of work left to be done.
124 /*
125  * Revision 1.2  1998/01/08 02:22:27  curt
126  * Continue working on basic features.
127  *
128  * Revision 1.1  1998/01/07 23:50:51  curt
129  * "area" renamed to "tile"
130  *
131  * Revision 1.2  1998/01/07 03:29:29  curt
132  * Given an arbitrary lat/lon, we can now:
133  *   generate a unique index for the chunk containing the lat/lon
134  *   generate a path name to the chunk file
135  *   build a list of the indexes of all the nearby areas.
136  *
137  * Revision 1.1  1998/01/07 02:05:48  curt
138  * Initial revision.
139  * */
140
141