]> git.mxchange.org Git - flightgear.git/blob - Scenery/mesh.c
Added GNU copyright headers.
[flightgear.git] / Scenery / mesh.c
1 /**************************************************************************
2  * mesh.c -- data structures and routines for processing terrain meshes
3  *
4  * Written by Curtis Olson, started May 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 <malloc.h>
28 #include <stdio.h>
29 #include <stdlib.h>  /* atof(), atoi() */
30 #include <string.h>
31
32 #include "mesh.h"
33 #include "common.h"
34
35
36 /* return a pointer to a new mesh structure (no data array allocated yet) */
37 struct mesh *(new_mesh)() {
38     struct mesh *mesh_ptr;
39
40     mesh_ptr = (struct mesh *)malloc(sizeof(struct mesh));
41
42     if ( mesh_ptr == 0 ) {
43         printf("Virtual memory exceeded\n");
44         exit(-1);
45     }
46
47     mesh_ptr->cur_row = 0;
48     mesh_ptr->cur_col = 0;
49
50     return(mesh_ptr);
51 }
52
53
54 /* return a pointer to a dynamically allocated array */
55 float *(new_mesh_data)(int nrows, int ncols) {
56     float *mesh_data_ptr;
57
58     mesh_data_ptr = (float *)malloc(nrows * ncols * sizeof(float));
59
60     if ( mesh_data_ptr == 0 ) {
61         printf("Virtual memory exceeded\n");
62         exit(-1);
63     }
64
65     printf("Allocated float(%d, %d)\n", nrows, ncols);
66
67     return(mesh_data_ptr);
68 }
69
70
71 /* set the option name in the mesh data structure */
72 void mesh_set_option_name(struct mesh *m, char *name) {
73     if ( strlen(name) < MAX_IDENT_LEN ) {
74         strcpy(m->option_name, name);
75     } else {
76         strncpy(m->option_name, name, MAX_IDENT_LEN - 1);
77         m->option_name[MAX_IDENT_LEN - 1] = '\0';
78     }
79 }
80
81 /* set an option value in the mesh data structure */
82 void mesh_set_option_value(struct mesh *m, char *value) {
83     printf("Setting %s to %s\n", m->option_name, value);
84
85     if ( strcmp(m->option_name, "origin_lat") == 0 ) {
86         m->originx = atof(value);
87     } else if ( strcmp(m->option_name, "origin_lon") == 0 ) {
88         m->originy = atof(value);
89     } else if ( strcmp(m->option_name, "rows") == 0 ) {
90         m->rows = atoi(value);
91     } else if ( strcmp(m->option_name, "cols") == 0 ) {
92         m->cols = atoi(value);
93     } else if ( strcmp(m->option_name, "row_step") == 0 ) {
94         m->row_step = atof(value);
95     } else if ( strcmp(m->option_name, "col_step") == 0 ) {
96         m->col_step = atof(value);
97     } else {
98         printf("Unknown option %s with value %s, ignoring ...\n", 
99                m->option_name, value);
100     }
101 }
102
103
104 /* $Log$
105 /* Revision 1.3  1997/05/23 15:40:41  curt
106 /* Added GNU copyright headers.
107 /*
108  * Revision 1.2  1997/05/19 18:20:50  curt
109  * Slight change to origin key words.
110  *
111  * Revision 1.1  1997/05/16 16:07:04  curt
112  * Initial revision.
113  *
114  */