#include <stdio.h>
#include <string.h>
#include <GL/glut.h>
-#include "../XGL/xgl.h"
+#include <XGL/xgl.h>
-#include "obj.h"
-#include "scenery.h"
+#include <Scenery/obj.h>
+#include <Scenery/scenery.h>
-#include "../Math/mat3.h"
+#include <Math/mat3.h>
/* Load a .obj file and generate the GL call list */
-GLint fgObjLoad(char *path) {
+GLint fgObjLoad(char *path, struct fgCartesianPoint *ref) {
char line[256], winding_str[256];
- double v1[3], v2[3], approx_normal[3], dot_prod, temp;
- struct fgCartesianPoint ref;
+ double v1[3], v2[3], approx_normal[3], normal[3], dot_prod, scale, temp;
GLint area;
FILE *f;
int first, ncount, vncount, n1, n2, n3, n4;
if ( (f = fopen(path, "r")) == NULL ) {
printf("Cannot open file: %s\n", path);
- exit(-1);
+ /* exit(-1); */
+ return(0);
}
area = xglGenLists(1);
&nodes[ncount][0], &nodes[ncount][1], &nodes[ncount][2]);
if ( ncount == 1 ) {
/* first node becomes the reference point */
- ref.x = nodes[ncount][0];
- ref.y = nodes[ncount][1];
- ref.z = nodes[ncount][2];
- scenery.center = ref;
+ ref->x = nodes[ncount][0];
+ ref->y = nodes[ncount][1];
+ ref->z = nodes[ncount][2];
+ /* scenery.center = ref; */
}
ncount++;
} else {
xglFrontFace( GL_CW );
winding = 0;
} else {
- xglFrontFace ( GL_CCW );
+ glFrontFace ( GL_CCW );
winding = 1;
}
} else if ( line[0] == 't' ) {
if ( winding ) {
odd = 1;
+ scale = 1.0;
} else {
odd = 0;
+ scale = 1.0;
}
if ( use_vertex_norms ) {
- xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
- xglVertex3d(nodes[n1][0] - ref.x, nodes[n1][1] - ref.y,
- nodes[n1][2] - ref.z);
-
- xglNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]);
- xglVertex3d(nodes[n2][0] - ref.x, nodes[n2][1] - ref.y,
- nodes[n2][2] - ref.z);
-
- xglNormal3d(normals[n3][0], normals[n3][1], normals[n3][2]);
- xglVertex3d(nodes[n3][0] - ref.x, nodes[n3][1] - ref.y,
- nodes[n3][2] - ref.z);
+ MAT3_SCALE_VEC(normal, normals[n1], scale);
+ xglNormal3dv(normal);
+ xglVertex3d(nodes[n1][0] - ref->x, nodes[n1][1] - ref->y,
+ nodes[n1][2] - ref->z);
+
+ MAT3_SCALE_VEC(normal, normals[n2], scale);
+ xglNormal3dv(normal);
+ xglVertex3d(nodes[n2][0] - ref->x, nodes[n2][1] - ref->y,
+ nodes[n2][2] - ref->z);
+
+ MAT3_SCALE_VEC(normal, normals[n3], scale);
+ xglNormal3dv(normal);
+ xglVertex3d(nodes[n3][0] - ref->x, nodes[n3][1] - ref->y,
+ nodes[n3][2] - ref->z);
} else {
if ( odd ) {
calc_normal(nodes[n1], nodes[n2], nodes[n3], approx_normal);
} else {
calc_normal(nodes[n2], nodes[n1], nodes[n3], approx_normal);
}
- xglNormal3dv(approx_normal);
-
- xglVertex3d(nodes[n1][0] - ref.x, nodes[n1][1] - ref.y,
- nodes[n1][2] - ref.z);
- xglVertex3d(nodes[n2][0] - ref.x, nodes[n2][1] - ref.y,
- nodes[n2][2] - ref.z);
- xglVertex3d(nodes[n3][0] - ref.x, nodes[n3][1] - ref.y,
- nodes[n3][2] - ref.z);
+ MAT3_SCALE_VEC(normal, approx_normal, scale);
+ xglNormal3dv(normal);
+
+ xglVertex3d(nodes[n1][0] - ref->x, nodes[n1][1] - ref->y,
+ nodes[n1][2] - ref->z);
+ xglVertex3d(nodes[n2][0] - ref->x, nodes[n2][1] - ref->y,
+ nodes[n2][2] - ref->z);
+ xglVertex3d(nodes[n3][0] - ref->x, nodes[n3][1] - ref->y,
+ nodes[n3][2] - ref->z);
}
odd = 1 - odd;
if ( n4 > 0 ) {
if ( use_vertex_norms ) {
- xglNormal3d(normals[n4][0], normals[n4][1], normals[n4][2]);
+ MAT3_SCALE_VEC(normal, normals[n4], scale);
} else {
calc_normal(nodes[n3], nodes[n2], nodes[n4], approx_normal);
- xglNormal3dv(approx_normal);
+ MAT3_SCALE_VEC(normal, approx_normal, scale);
}
- xglVertex3d(nodes[n4][0] - ref.x, nodes[n4][1] - ref.y,
- nodes[n4][2] - ref.z);
+ xglNormal3dv(normal);
+ xglVertex3d(nodes[n4][0] - ref->x, nodes[n4][1] - ref->y,
+ nodes[n4][2] - ref->z);
odd = 1 - odd;
last1 = n3;
sscanf(line, "f %d %d %d\n", &n1, &n2, &n3);
xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
- xglVertex3d(nodes[n1][0] - ref.x, nodes[n1][1] - ref.y,
- nodes[n1][2] - ref.z);
+ xglVertex3d(nodes[n1][0] - ref->x, nodes[n1][1] - ref->y,
+ nodes[n1][2] - ref->z);
xglNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]);
- xglVertex3d(nodes[n2][0] - ref.x, nodes[n2][1] - ref.y,
- nodes[n2][2] - ref.z);
+ xglVertex3d(nodes[n2][0] - ref->x, nodes[n2][1] - ref->y,
+ nodes[n2][2] - ref->z);
xglNormal3d(normals[n3][0], normals[n3][1], normals[n3][2]);
- xglVertex3d(nodes[n3][0] - ref.x, nodes[n3][1] - ref.y,
- nodes[n3][2] - ref.z);
+ xglVertex3d(nodes[n3][0] - ref->x, nodes[n3][1] - ref->y,
+ nodes[n3][2] - ref->z);
} else if ( line[0] == 'q' ) {
/* continue a triangle strip */
n1 = n2 = 0;
/* printf("read %d %d\n", n1, n2); */
if ( use_vertex_norms ) {
- xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
+ MAT3_SCALE_VEC(normal, normals[n1], scale);
+ xglNormal3dv(normal);
} else {
if ( odd ) {
calc_normal(nodes[last1], nodes[last2], nodes[n1],
calc_normal(nodes[last2], nodes[last1], nodes[n1],
approx_normal);
}
- xglNormal3dv(approx_normal);
+ MAT3_SCALE_VEC(normal, approx_normal, scale);
+ xglNormal3dv(normal);
}
- xglVertex3d(nodes[n1][0] - ref.x, nodes[n1][1] - ref.y,
- nodes[n1][2] - ref.z);
+ xglVertex3d(nodes[n1][0] - ref->x, nodes[n1][1] - ref->y,
+ nodes[n1][2] - ref->z);
odd = 1 - odd;
last1 = last2;
/* printf(" (cont)\n"); */
if ( use_vertex_norms ) {
- xglNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]);
+ MAT3_SCALE_VEC(normal, normals[n2], scale);
+ xglNormal3dv(normal);
} else {
if ( odd ) {
calc_normal(nodes[last1], nodes[last2], nodes[n2],
calc_normal(nodes[last2], nodes[last1], nodes[n2],
approx_normal);
}
- xglNormal3dv(approx_normal);
+ MAT3_SCALE_VEC(normal, approx_normal, scale);
+ xglNormal3dv(normal);
}
- xglVertex3d(nodes[n2][0] - ref.x, nodes[n2][1] - ref.y,
- nodes[n2][2] - ref.z);
+ xglVertex3d(nodes[n2][0] - ref->x, nodes[n2][1] - ref->y,
+ nodes[n2][2] - ref->z);
odd = 1 -odd;
last1 = last2;
xglBegin(GL_LINES);
xglColor3f(0.0, 0.0, 0.0);
for ( i = 0; i < ncount; i++ ) {
- xglVertex3d(nodes[i][0] - ref.x,
- nodes[i][1] - ref.y,
- nodes[i][2] - ref.z);
- xglVertex3d(nodes[i][0] - ref.x + 500*normals[i][0],
- nodes[i][1] - ref.y + 500*normals[i][1],
- nodes[i][2] - ref.z + 500*normals[i][2]);
+ xglVertex3d(nodes[i][0] - ref->x,
+ nodes[i][1] - ref->y,
+ nodes[i][2] - ref->z);
+ xglVertex3d(nodes[i][0] - ref->x + 500*normals[i][0],
+ nodes[i][1] - ref->y + 500*normals[i][1],
+ nodes[i][2] - ref->z + 500*normals[i][2]);
}
xglEnd();
*/
/* $Log$
-/* Revision 1.15 1997/12/30 20:47:51 curt
-/* Integrated new event manager with subsystem initializations.
+/* Revision 1.18 1998/01/19 19:27:16 curt
+/* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
+/* This should simplify things tremendously.
/*
+ * Revision 1.17 1998/01/13 00:23:10 curt
+ * Initial changes to support loading and management of scenery tiles. Note,
+ * there's still a fair amount of work left to be done.
+ *
+ * Revision 1.16 1997/12/30 23:09:40 curt
+ * Worked on winding problem without luck, so back to calling glFrontFace()
+ * 3 times for each scenery area.
+ *
+ * Revision 1.15 1997/12/30 20:47:51 curt
+ * Integrated new event manager with subsystem initializations.
+ *
* Revision 1.14 1997/12/30 01:38:46 curt
* Switched back to per vertex normals and smooth shading for terrain.
*