]> git.mxchange.org Git - flightgear.git/blob - Scenery/mesh.c
803a24d9eb9574f4c199d2c96ea0c21d89e786d4
[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  * $Id$
7  * (Log is kept at end of this file)
8  **************************************************************************/
9
10
11 #include <malloc.h>
12 #include <stdio.h>
13 #include <stdlib.h>  /* atof(), atoi() */
14 #include <string.h>
15
16 #include "mesh.h"
17 #include "common.h"
18
19
20 /* return a pointer to a new mesh structure (no data array allocated yet) */
21 struct mesh *(new_mesh)() {
22     struct mesh *mesh_ptr;
23
24     mesh_ptr = (struct mesh *)malloc(sizeof(struct mesh));
25
26     if ( mesh_ptr == 0 ) {
27         printf("Virtual memory exceeded\n");
28         exit(-1);
29     }
30
31     mesh_ptr->cur_row = 0;
32     mesh_ptr->cur_col = 0;
33
34     return(mesh_ptr);
35 }
36
37
38 /* return a pointer to a dynamically allocated array */
39 float *(new_mesh_data)(int nrows, int ncols) {
40     float *mesh_data_ptr;
41
42     mesh_data_ptr = (float *)malloc(nrows * ncols * sizeof(float));
43
44     if ( mesh_data_ptr == 0 ) {
45         printf("Virtual memory exceeded\n");
46         exit(-1);
47     }
48
49     printf("Allocated float(%d, %d)\n", nrows, ncols);
50
51     return(mesh_data_ptr);
52 }
53
54
55 /* set the option name in the mesh data structure */
56 void mesh_set_option_name(struct mesh *m, char *name) {
57     if ( strlen(name) < MAX_IDENT_LEN ) {
58         strcpy(m->option_name, name);
59     } else {
60         strncpy(m->option_name, name, MAX_IDENT_LEN - 1);
61         m->option_name[MAX_IDENT_LEN - 1] = '\0';
62     }
63 }
64
65 /* set an option value in the mesh data structure */
66 void mesh_set_option_value(struct mesh *m, char *value) {
67     printf("Setting %s to %s\n", m->option_name, value);
68
69     if ( strcmp(m->option_name, "origin_lat") == 0 ) {
70         m->originx = atof(value);
71     } else if ( strcmp(m->option_name, "origin_lon") == 0 ) {
72         m->originy = atof(value);
73     } else if ( strcmp(m->option_name, "rows") == 0 ) {
74         m->rows = atoi(value);
75     } else if ( strcmp(m->option_name, "cols") == 0 ) {
76         m->cols = atoi(value);
77     } else if ( strcmp(m->option_name, "row_step") == 0 ) {
78         m->row_step = atof(value);
79     } else if ( strcmp(m->option_name, "col_step") == 0 ) {
80         m->col_step = atof(value);
81     } else {
82         printf("Unknown option %s with value %s, ignoring ...\n", 
83                m->option_name, value);
84     }
85 }
86
87
88 /* $Log$
89 /* Revision 1.2  1997/05/19 18:20:50  curt
90 /* Slight change to origin key words.
91 /*
92  * Revision 1.1  1997/05/16 16:07:04  curt
93  * Initial revision.
94  *
95  */