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 **************************************************************************/
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 = 10; /* Detail level 1 -- 1200 ... */
50 glNewList(mesh, GL_COMPILE);
51 glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color );
52 glShadeModel( GL_FLAT ); /* glShadeModel( GL_SMOOTH ); */
58 y2 = y1 + (m->col_step * istep);
60 for ( i = 0; i < iend; i += istep ) {
62 x2 = x1 + (m->row_step * jstep);
63 for ( j = 0; j < jend; j += jstep ) {
64 z11 = 0.03 * m->mesh_data[j * m->rows + i ];
65 z12 = 0.03 * m->mesh_data[j * m->rows + (i+istep)];
66 z21 = 0.03 * m->mesh_data[(j+jstep) * m->rows + i ];
67 z22 = 0.03 * m->mesh_data[(j+jstep) * m->rows + (i+istep)];
69 /* printf("x1 = %f y1 = %f\n", x1, y1);
70 printf("x2 = %f y2 = %f\n", x2, y2);
71 printf("z11 = %f z12 = %f z21 = %f z22 = %f\n",
72 z11, z12, z21, z22); */
74 v1[0] = x2 - x1; v1[1] = 0; v1[2] = z21 - z11;
75 v2[0] = x2 - x1; v2[1] = y2 - y1; v2[2] = z22 - z11;
76 mat3_cross_product(normal, v1, v2);
77 MAT3_NORMALIZE_VEC(normal,temp);
80 glVertex3f(x1, y1, z11);
81 glVertex3f(x2, y1, z21);
82 glVertex3f(x2, y2, z22);
83 /* printf("(%f, %f, %f)\n", x1, y1, z11);
84 printf("(%f, %f, %f)\n", x2, y1, z21);
85 printf("(%f, %f, %f)\n", x2, y2, z22); */
88 v1[0] = x2 - x1; v1[1] = y2 - y1; v1[2] = z22 - z11;
89 v2[0] = 0; v2[1] = y2 - y1; v2[2] = z12 - z11;
90 mat3_cross_product(normal, v1, v2);
91 MAT3_NORMALIZE_VEC(normal,temp);
94 glVertex3f(x1, y1, z11);
95 glVertex3f(x2, y2, z22);
96 glVertex3f(x1, y2, z12);
97 /* printf("(%f, %f, %f)\n", x1, y1, z11);
98 printf("(%f, %f, %f)\n", x2, y2, z22);
99 printf("(%f, %f, %f)\n", x1, y2, z12); */
103 x2 = x1 + (m->row_step * jstep);
106 y2 = y1 + (m->col_step * istep);
116 /* Revision 1.1 1997/05/21 15:57:52 curt
117 /* Renamed due to added GLUT support.
119 * Revision 1.3 1997/05/19 18:22:42 curt
120 * Parameter tweaking ... starting to stub in fog support.
122 * Revision 1.2 1997/05/17 00:17:35 curt
123 * Trying to stub in support for standard OpenGL.
125 * Revision 1.1 1997/05/16 16:05:52 curt