1 /**************************************************************************
2 * mesh2GL.c -- walk through a mesh data structure and make GL calls
4 * Written by Curtis Olson, started May 1997.
7 * (Log is kept at end of this file)
8 **************************************************************************/
14 /* assumes -I/usr/include/mesa in compile command */
18 #include "../scenery/mesh.h"
22 /* Sets the first vector to be the cross-product of the last two
24 static void mat3_cross_product(float result_vec[3], register float vec1[3],
25 register float vec2[3]) {
27 register float *temp = tempvec;
29 temp[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
30 temp[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
31 temp[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
33 MAT3_COPY_VEC(result_vec, temp);
37 /* walk through mesh and make ogl calls */
38 GLint mesh_to_ogl(struct mesh *m) {
40 /* static GLfloat color[4] = { 0.3, 0.7, 0.2, 1.0 }; */
42 float x1, y1, x2, y2, z11, z12, z21, z22;
43 float v1[3], v2[3], normal[3];
44 int i, j, istep, jstep, iend, jend;
47 istep = jstep = 25; /* Detail level 1 -- 1200 ... */
50 glNewList(mesh, GL_COMPILE);
51 /* glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color ); */
56 y1 = 0.0; /* y1 = m->originy; */
57 y2 = y1 + (m->col_step * istep);
59 for ( i = 0; i < iend; i += istep ) {
60 x1 = 0.0; /* x1 = m->originx; */
61 x2 = x1 + (m->row_step * jstep);
62 for ( j = 0; j < jend; j += jstep ) {
63 z11 = 0.03 * m->mesh_data[j * m->rows + i ];
64 z12 = 0.03 * m->mesh_data[j * m->rows + (i+istep)];
65 z21 = 0.03 * m->mesh_data[(j+jstep) * m->rows + i ];
66 z22 = 0.03 * m->mesh_data[(j+jstep) * m->rows + (i+istep)];
68 /* printf("x1 = %f y1 = %f\n", x1, y1);
69 printf("x2 = %f y2 = %f\n", x2, y2);
70 printf("z11 = %f z12 = %f z21 = %f z22 = %f\n",
71 z11, z12, z21, z22); */
73 v1[0] = x2 - x1; v1[1] = 0; v1[2] = z21 - z11;
74 v2[0] = x2 - x1; v2[1] = y2 - y1; v2[2] = z22 - z11;
75 mat3_cross_product(normal, v1, v2);
76 MAT3_NORMALIZE_VEC(normal,temp);
79 glVertex3f(x1, y1, z11);
80 glVertex3f(x2, y1, z21);
81 glVertex3f(x2, y2, z22);
82 /* printf("(%f, %f, %f)\n", x1, y1, z11);
83 printf("(%f, %f, %f)\n", x2, y1, z21);
84 printf("(%f, %f, %f)\n", x2, y2, z22); */
87 v1[0] = x2 - x1; v1[1] = y2 - y1; v1[2] = z22 - z11;
88 v2[0] = 0; v2[1] = y2 - y1; v2[2] = z12 - z11;
89 mat3_cross_product(normal, v1, v2);
90 MAT3_NORMALIZE_VEC(normal,temp);
93 glVertex3f(x1, y1, z11);
94 glVertex3f(x2, y2, z22);
95 glVertex3f(x1, y2, z12);
96 /* printf("(%f, %f, %f)\n", x1, y1, z11);
97 printf("(%f, %f, %f)\n", x2, y2, z22);
98 printf("(%f, %f, %f)\n", x1, y2, z12); */
102 x2 = x1 + (m->row_step * jstep);
105 y2 = y1 + (m->col_step * istep);
115 /* Revision 1.2 1997/05/23 00:35:13 curt
116 /* Trying to get fog to work ...
118 * Revision 1.1 1997/05/21 15:57:52 curt
119 * Renamed due to added GLUT support.
121 * Revision 1.3 1997/05/19 18:22:42 curt
122 * Parameter tweaking ... starting to stub in fog support.
124 * Revision 1.2 1997/05/17 00:17:35 curt
125 * Trying to stub in support for standard OpenGL.
127 * Revision 1.1 1997/05/16 16:05:52 curt