1 /**************************************************************************
2 * mesh2ogl.c -- walk through a mesh data structure and make ogl calls
4 * Written by Curtis Olson, started May 1997.
7 * (Log is kept at end of this file)
8 **************************************************************************/
11 /* assumes -I/usr/include/mesa in compile command */
14 #include "../scenery/mesh.h"
18 /* Sets the first vector to be the cross-product of the last two
20 static void mat3_cross_product(float result_vec[3], register float vec1[3],
21 register float vec2[3]) {
23 register float *temp = tempvec;
25 temp[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
26 temp[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
27 temp[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
29 MAT3_COPY_VEC(result_vec, temp);
33 /* walk through mesh and make ogl calls */
34 GLint mesh_to_ogl(struct mesh *m) {
36 static GLfloat color[4] = { 0.3, 0.7, 0.2, 1.0 };
38 float x1, y1, x2, y2, z11, z12, z21, z22;
39 float v1[3], v2[3], normal[3];
40 int i, j, istep, jstep, iend, jend;
43 istep = jstep = 50; /* Detail level 1 -- 1200 ... */
46 glNewList(mesh, GL_COMPILE);
47 glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color );
48 glShadeModel( GL_FLAT ); /* glShadeModel( GL_SMOOTH ); */
54 y2 = y1 + (m->col_step * istep);
56 for ( i = 0; i < iend; i += istep ) {
58 x2 = x1 + (m->row_step * jstep);
59 for ( j = 0; j < jend; j += jstep ) {
60 z11 = 0.12 * m->mesh_data[j * m->rows + i ];
61 z12 = 0.12 * m->mesh_data[j * m->rows + (i+istep)];
62 z21 = 0.12 * m->mesh_data[(j+jstep) * m->rows + i ];
63 z22 = 0.12 * m->mesh_data[(j+jstep) * m->rows + (i+istep)];
65 /* printf("x1 = %f y1 = %f\n", x1, y1);
66 printf("x2 = %f y2 = %f\n", x2, y2);
67 printf("z11 = %f z12 = %f z21 = %f z22 = %f\n",
68 z11, z12, z21, z22); */
70 v1[0] = x2 - x1; v1[1] = 0; v1[2] = z21 - z11;
71 v2[0] = x2 - x1; v2[1] = y2 - y1; v2[2] = z22 - z11;
72 mat3_cross_product(normal, v1, v2);
73 MAT3_NORMALIZE_VEC(normal,temp);
76 glVertex3f(x1, y1, z11);
77 glVertex3f(x2, y1, z21);
78 glVertex3f(x2, y2, z22);
79 /* printf("(%f, %f, %f)\n", x1, y1, z11);
80 printf("(%f, %f, %f)\n", x2, y1, z21);
81 printf("(%f, %f, %f)\n", x2, y2, z22); */
84 v1[0] = x2 - x1; v1[1] = y2 - y1; v1[2] = z22 - z11;
85 v2[0] = 0; v2[1] = y2 - y1; v2[2] = z12 - z11;
86 mat3_cross_product(normal, v1, v2);
87 MAT3_NORMALIZE_VEC(normal,temp);
90 glVertex3f(x1, y1, z11);
91 glVertex3f(x2, y2, z22);
92 glVertex3f(x1, y2, z12);
93 /* printf("(%f, %f, %f)\n", x1, y1, z11);
94 printf("(%f, %f, %f)\n", x2, y2, z22);
95 printf("(%f, %f, %f)\n", x1, y2, z12); */
99 x2 = x1 + (m->row_step * jstep);
102 y2 = y1 + (m->col_step * istep);
112 /* Revision 1.1 1997/05/16 16:05:52 curt