1 /**************************************************************************
2 * mesh2GL.c -- walk through a mesh data structure and make GL calls
4 * Written by Curtis Olson, started May 1997.
6 * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
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.
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.
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.
23 * (Log is kept at end of this file)
24 **************************************************************************/
30 /* assumes -I/usr/include/mesa in compile command */
34 #include "../scenery/mesh.h"
35 #include "../mat3/mat3.h"
38 /* walk through mesh and make ogl calls */
39 GLint mesh2GL(struct mesh *m) {
42 float x1, y1, x2, y2, z11, z12, z21, z22;
43 MAT3vec v1, v2, normal;
44 int i, j, istep, jstep, iend, jend;
47 istep = jstep = 30; /* Detail level 1 -- 1200 ... */
50 glNewList(mesh, GL_COMPILE);
56 y2 = y1 + (m->col_step * istep);
58 for ( i = 0; i < iend; i += istep ) {
60 x2 = x1 + (m->row_step * jstep);
62 glBegin(GL_TRIANGLE_STRIP);
64 for ( j = 0; j < jend; j += jstep ) {
65 z11 = 0.03 * m->mesh_data[j * m->rows + i ];
66 z12 = 0.03 * m->mesh_data[j * m->rows + (i+istep)];
67 z21 = 0.03 * m->mesh_data[(j+jstep) * m->rows + i ];
68 z22 = 0.03 * m->mesh_data[(j+jstep) * m->rows + (i+istep)];
70 v1[0] = x2 - x1; v1[1] = 0; v1[2] = z21 - z11;
71 v2[0] = 0; v2[1] = y2 - y1; v2[2] = z12 - z11;
72 MAT3cross_product(normal, v1, v2);
73 MAT3_NORMALIZE_VEC(normal,temp);
74 glNormal3d(normal[0], normal[1], normal[2]);
77 /* first time through */
78 glVertex3f(x1, y1, z11);
79 glVertex3f(x1, y2, z12);
82 glVertex3f(x2, y1, z21);
84 v1[0] = x2 - x1; v1[1] = y1 - y2; v1[2] = z21 - z12;
85 v2[0] = x2 - x1; v2[1] = 0; v2[2] = z22 - z12;
86 MAT3cross_product(normal, v1, v2);
87 MAT3_NORMALIZE_VEC(normal,temp);
88 glNormal3d(normal[0], normal[1], normal[2]);
89 glVertex3f(x2, y2, z22);
92 x2 = x1 + (m->row_step * jstep);
97 y2 = y1 + (m->col_step * istep);
107 /* Revision 1.15 1997/06/02 03:01:38 curt
108 /* Working on views (side, front, back, transitions, etc.)
110 * Revision 1.14 1997/05/31 19:16:26 curt
111 * Elevator trim added.
113 * Revision 1.13 1997/05/31 04:13:53 curt
116 * Continuing work on the LaRCsim flight model integration.
117 * Added some MSFS-like keyboard input handling.
119 * Revision 1.12 1997/05/30 23:26:20 curt
120 * Added elevator/aileron controls.
122 * Revision 1.11 1997/05/30 19:27:02 curt
123 * The LaRCsim flight model is starting to look like it is working.
125 * Revision 1.10 1997/05/30 03:54:11 curt
126 * Made a bit more progress towards integrating the LaRCsim flight model.
128 * Revision 1.9 1997/05/29 22:39:51 curt
129 * Working on incorporating the LaRCsim flight model.
131 * Revision 1.8 1997/05/29 12:31:40 curt
132 * Minor tweaks, moving towards general flight model integration.
134 * Revision 1.7 1997/05/29 02:33:24 curt
135 * Updated to reflect changing interfaces in other "modules."
137 * Revision 1.6 1997/05/27 17:44:32 curt
138 * Renamed & rearranged variables and routines. Added some initial simple
139 * timer/alarm routines so the flight model can be updated on a regular
142 * Revision 1.5 1997/05/24 01:45:32 curt
143 * Fixed surface normals for triangle mesh.
145 * Revision 1.4 1997/05/23 20:05:24 curt
146 * First stab at using GL_TRIANGLE_STRIP's instead of GL_POLYGONS (to conserve
149 * Revision 1.3 1997/05/23 15:40:26 curt
150 * Added GNU copyright headers.
153 * Revision 1.2 1997/05/23 00:35:13 curt
154 * Trying to get fog to work ...
156 * Revision 1.1 1997/05/21 15:57:52 curt
157 * Renamed due to added GLUT support.
159 * Revision 1.3 1997/05/19 18:22:42 curt
160 * Parameter tweaking ... starting to stub in fog support.
162 * Revision 1.2 1997/05/17 00:17:35 curt
163 * Trying to stub in support for standard OpenGL.
165 * Revision 1.1 1997/05/16 16:05:52 curt