]> git.mxchange.org Git - flightgear.git/blob - Scenery/geometry.c
More twiddling with the Scenery Management system.
[flightgear.git] / Scenery / geometry.c
1 /**************************************************************************
2  * geometry.c -- data structures and routines for processing vrml geometry
3  *
4  * Written by Curtis Olson, started June 1997.
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 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "geometry.h"
32 #include "mesh.h"
33
34
35 static vrmlGeometryType;
36 static struct mesh eg;
37
38
39 /* Begin a new vrml geometry statement */
40 int vrmlInitGeometry(char *type) {
41     printf("Beginning geometry item = %s\n", type);
42
43     if ( strcmp(type, "ElevationGrid") == 0 ) {
44         vrmlGeometryType = VRML_ELEV_GRID;
45         mesh_init(&eg);
46     } else {
47         vrmlGeometryType = -1;
48         printf("Unimplemented geometry type = %s\n", type);
49     }
50
51     return(vrmlGeometryType);
52 }
53
54
55 /* Set current vrml geometry option name */
56 void vrmlGeomOptionName(char *name) {
57     /* printf("Found vrml geometry option = %s\n", name); */
58
59     switch(vrmlGeometryType) {
60     case VRML_ELEV_GRID:
61         if ( strcmp(name, "xDimension") == 0 ) {
62             mesh_set_option_name(&eg, "rows");
63         } else if ( strcmp(name, "zDimension") == 0 ) {
64             mesh_set_option_name(&eg, "cols");
65         } else if ( strcmp(name, "xSpacing") == 0 ) {
66             mesh_set_option_name(&eg, "row_step");
67         } else if ( strcmp(name, "zSpacing") == 0 ) {
68             mesh_set_option_name(&eg, "col_step");
69         } else if ( strcmp(name, "height") == 0 ) {
70             eg.mesh_data = new_mesh_data(eg.rows, eg.cols);
71             mesh_set_option_name(&eg, "do_data");
72         } else {
73             printf("Unknown ElevationGrid option = %s\n", name);
74         }
75         break;
76     }
77 }
78
79
80 /* Set current vrml geometry value */
81 void vrmlGeomOptionsValue(char *value) {
82     /* printf("Found vrml geometry value = %s\n", value); */
83
84     switch(vrmlGeometryType) {
85     case VRML_ELEV_GRID:
86         mesh_set_option_value(&eg, value);
87     }
88 }
89
90
91 /* We've finished parsing the current geometry.  Now do whatever needs
92  * to be done with it (like generating the OpenGL call list for
93  * instance */
94 void vrmlHandleGeometry() {
95     switch(vrmlGeometryType) {
96     case VRML_ELEV_GRID:
97         mesh_do_it(&eg);
98     }
99 }
100
101
102 /* Finish up the current vrml geometry statement */
103 int vrmlFreeGeometry() {
104     printf("Freeing geometry type = %d\n", vrmlGeometryType);
105
106     switch(vrmlGeometryType) {
107     case VRML_ELEV_GRID:
108         free(eg.mesh_data);
109     }
110     return(vrmlGeometryType);
111 }
112
113
114 /* $Log$
115 /* Revision 1.1  1997/06/29 21:16:48  curt
116 /* More twiddling with the Scenery Management system.
117 /*
118  * Revision 1.1  1997/06/22 21:42:35  curt
119  * Initial revision of VRML (subset) parser.
120  *
121  */