1998-03-14 00:30:50 +00:00
|
|
|
/* -*- Mode: C++ -*-
|
|
|
|
*
|
1997-10-28 21:14:54 +00:00
|
|
|
* obj.c -- routines to handle WaveFront .obj format files.
|
|
|
|
*
|
|
|
|
* Written by Curtis Olson, started October 1997.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
* (Log is kept at end of this file)
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
1997-11-14 00:26:49 +00:00
|
|
|
#include <string.h>
|
1997-10-28 21:14:54 +00:00
|
|
|
#include <GL/glut.h>
|
1998-01-19 19:26:51 +00:00
|
|
|
#include <XGL/xgl.h>
|
1997-10-28 21:14:54 +00:00
|
|
|
|
1998-03-14 00:30:50 +00:00
|
|
|
#include <Include/fg_constants.h>
|
1998-01-27 03:26:41 +00:00
|
|
|
#include <Main/fg_debug.h>
|
|
|
|
#include <Math/mat3.h>
|
1998-03-14 00:30:50 +00:00
|
|
|
#include <Math/fg_random.h>
|
1998-01-19 19:26:51 +00:00
|
|
|
#include <Scenery/obj.h>
|
|
|
|
#include <Scenery/scenery.h>
|
1997-10-28 21:14:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MAXNODES 100000
|
|
|
|
|
1998-02-09 15:07:47 +00:00
|
|
|
static double nodes[MAXNODES][3];
|
|
|
|
static double normals[MAXNODES][3];
|
1997-10-31 04:49:12 +00:00
|
|
|
|
|
|
|
|
1997-12-15 23:54:25 +00:00
|
|
|
/* given three points defining a triangle, calculate the normal */
|
1998-01-31 00:42:57 +00:00
|
|
|
void calc_normal(double p1[3], double p2[3], double p3[3], double normal[3])
|
1997-12-15 23:54:25 +00:00
|
|
|
{
|
|
|
|
double v1[3], v2[3];
|
1998-01-31 00:42:57 +00:00
|
|
|
double temp;
|
1997-12-15 23:54:25 +00:00
|
|
|
|
|
|
|
v1[0] = p2[0] - p1[0]; v1[1] = p2[1] - p1[1]; v1[2] = p2[2] - p1[2];
|
|
|
|
v2[0] = p3[0] - p1[0]; v2[1] = p3[1] - p1[1]; v2[2] = p3[2] - p1[2];
|
|
|
|
|
|
|
|
MAT3cross_product(normal, v1, v2);
|
|
|
|
MAT3_NORMALIZE_VEC(normal,temp);
|
|
|
|
|
1998-01-27 03:26:41 +00:00
|
|
|
/* fgPrintf( FG_TERRAIN, FG_DEBUG, " Normal = %.2f %.2f %.2f\n",
|
|
|
|
normal[0], normal[1], normal[2]);*/
|
1997-12-15 23:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-03-14 00:30:50 +00:00
|
|
|
#define FG_TEX_CONSTANT 64.0
|
|
|
|
|
|
|
|
float calc_lon(double x, double y, double z) {
|
|
|
|
float tmp;
|
|
|
|
tmp = (RAD_TO_DEG*atan2(y, x)) * FG_TEX_CONSTANT;
|
|
|
|
|
|
|
|
// printf("lon = %.2f\n", (float)tmp);
|
|
|
|
return (float)tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float calc_lat(double x, double y, double z) {
|
|
|
|
float tmp;
|
|
|
|
|
|
|
|
tmp = (90.0 - RAD_TO_DEG*atan2( sqrt(x*x + y*y), z )) * FG_TEX_CONSTANT;
|
|
|
|
|
|
|
|
// printf("lat = %.2f\n", (float)tmp);
|
|
|
|
return (float)tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-10-28 21:14:54 +00:00
|
|
|
/* Load a .obj file and generate the GL call list */
|
1998-01-31 00:42:57 +00:00
|
|
|
GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
|
1997-12-15 23:54:25 +00:00
|
|
|
char line[256], winding_str[256];
|
1998-01-27 03:26:41 +00:00
|
|
|
double approx_normal[3], normal[3], scale;
|
1998-01-31 00:42:57 +00:00
|
|
|
double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
|
1998-03-14 00:30:50 +00:00
|
|
|
GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 };
|
1998-01-29 00:51:38 +00:00
|
|
|
GLint tile;
|
1997-10-28 21:14:54 +00:00
|
|
|
FILE *f;
|
1997-11-14 00:26:49 +00:00
|
|
|
int first, ncount, vncount, n1, n2, n3, n4;
|
1998-02-09 21:30:18 +00:00
|
|
|
static int use_per_vertex_norms = 1;
|
1998-01-27 03:26:41 +00:00
|
|
|
int winding;
|
1997-12-15 23:54:25 +00:00
|
|
|
int last1, last2, odd;
|
1997-10-28 21:14:54 +00:00
|
|
|
|
|
|
|
if ( (f = fopen(path, "r")) == NULL ) {
|
1998-01-27 03:26:41 +00:00
|
|
|
fgPrintf(FG_TERRAIN, FG_ALERT, "Cannot open file: %s\n", path);
|
1998-02-01 03:39:53 +00:00
|
|
|
return(-1);
|
1997-10-28 21:14:54 +00:00
|
|
|
}
|
|
|
|
|
1998-01-29 00:51:38 +00:00
|
|
|
tile = xglGenLists(1);
|
|
|
|
xglNewList(tile, GL_COMPILE);
|
1997-10-28 21:14:54 +00:00
|
|
|
|
1998-03-14 00:30:50 +00:00
|
|
|
/*
|
|
|
|
xglTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
|
|
|
xglTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
|
|
|
xglTexGenfv(GL_S, GL_OBJECT_PLANE, sgenparams);
|
|
|
|
xglTexGenfv(GL_T, GL_OBJECT_PLANE, sgenparams);
|
|
|
|
// xglTexGenfv(GL_S, GL_SPHERE_MAP, 0);
|
|
|
|
// xglTexGenfv(GL_T, GL_SPHERE_MAP, 0);
|
|
|
|
xglEnable(GL_TEXTURE_GEN_S);
|
|
|
|
xglEnable(GL_TEXTURE_GEN_T);
|
|
|
|
*/
|
|
|
|
|
1997-10-28 21:14:54 +00:00
|
|
|
first = 1;
|
|
|
|
ncount = 1;
|
1997-11-14 00:26:49 +00:00
|
|
|
vncount = 1;
|
1997-10-28 21:14:54 +00:00
|
|
|
|
|
|
|
while ( fgets(line, 250, f) != NULL ) {
|
|
|
|
if ( line[0] == '#' ) {
|
|
|
|
/* comment -- ignore */
|
1997-12-30 20:47:34 +00:00
|
|
|
} else if ( line[0] == '\n' ) {
|
|
|
|
/* empty line -- ignore */
|
1997-11-14 00:26:49 +00:00
|
|
|
} else if ( strncmp(line, "v ", 2) == 0 ) {
|
1997-10-28 21:14:54 +00:00
|
|
|
/* node (vertex) */
|
|
|
|
if ( ncount < MAXNODES ) {
|
1998-01-27 03:26:41 +00:00
|
|
|
/* fgPrintf( FG_TERRAIN, FG_DEBUG, "vertex = %s", line); */
|
1998-01-31 00:42:57 +00:00
|
|
|
sscanf(line, "v %lf %lf %lf\n", &x, &y, &z);
|
1998-01-29 00:51:38 +00:00
|
|
|
nodes[ncount][0] = x;
|
|
|
|
nodes[ncount][1] = y;
|
|
|
|
nodes[ncount][2] = z;
|
|
|
|
|
|
|
|
/* first time through set min's and max'es */
|
1997-10-30 12:38:35 +00:00
|
|
|
if ( ncount == 1 ) {
|
1998-01-29 00:51:38 +00:00
|
|
|
xmin = x;
|
|
|
|
xmax = x;
|
|
|
|
ymin = y;
|
|
|
|
ymax = y;
|
|
|
|
zmin = z;
|
|
|
|
zmax = z;
|
1997-10-30 12:38:35 +00:00
|
|
|
}
|
1998-01-29 00:51:38 +00:00
|
|
|
|
|
|
|
/* keep track of min/max vertex values */
|
|
|
|
if ( x < xmin ) xmin = x;
|
|
|
|
if ( x > xmax ) xmax = x;
|
|
|
|
if ( y < ymin ) ymin = y;
|
|
|
|
if ( y > ymax ) ymax = y;
|
|
|
|
if ( z < zmin ) zmin = z;
|
|
|
|
if ( z > zmax ) zmax = z;
|
|
|
|
|
1997-10-28 21:14:54 +00:00
|
|
|
ncount++;
|
|
|
|
} else {
|
1998-01-27 03:26:41 +00:00
|
|
|
fgPrintf( FG_TERRAIN, FG_EXIT,
|
|
|
|
"Read too many nodes ... dying :-(\n");
|
1997-10-28 21:14:54 +00:00
|
|
|
}
|
1997-11-14 00:26:49 +00:00
|
|
|
} else if ( strncmp(line, "vn ", 3) == 0 ) {
|
|
|
|
/* vertex normal */
|
|
|
|
if ( vncount < MAXNODES ) {
|
1998-01-27 03:26:41 +00:00
|
|
|
/* fgPrintf( FG_TERRAIN, FG_DEBUG, "vertex normal = %s", line); */
|
1998-01-31 00:42:57 +00:00
|
|
|
sscanf(line, "vn %lf %lf %lf\n",
|
1997-11-14 00:26:49 +00:00
|
|
|
&normals[vncount][0], &normals[vncount][1],
|
|
|
|
&normals[vncount][2]);
|
|
|
|
vncount++;
|
|
|
|
} else {
|
1998-01-27 03:26:41 +00:00
|
|
|
fgPrintf( FG_TERRAIN, FG_EXIT,
|
|
|
|
"Read too many vertex normals ... dying :-(\n");
|
1997-11-14 00:26:49 +00:00
|
|
|
}
|
1997-12-08 22:51:17 +00:00
|
|
|
} else if ( strncmp(line, "winding ", 8) == 0 ) {
|
1997-12-15 23:54:25 +00:00
|
|
|
sscanf(line+8, "%s", winding_str);
|
1998-01-27 03:26:41 +00:00
|
|
|
fgPrintf( FG_TERRAIN, FG_DEBUG, " WINDING = %s\n", winding_str);
|
1997-12-08 22:51:17 +00:00
|
|
|
|
1997-12-15 23:54:25 +00:00
|
|
|
/* can't call xglFrontFace() between xglBegin() & xglEnd() */
|
|
|
|
xglEnd();
|
1997-12-08 22:51:17 +00:00
|
|
|
first = 1;
|
|
|
|
|
1997-12-15 23:54:25 +00:00
|
|
|
if ( strcmp(winding_str, "cw") == 0 ) {
|
|
|
|
xglFrontFace( GL_CW );
|
|
|
|
winding = 0;
|
1997-12-08 22:51:17 +00:00
|
|
|
} else {
|
1997-12-30 23:09:40 +00:00
|
|
|
glFrontFace ( GL_CCW );
|
1997-12-15 23:54:25 +00:00
|
|
|
winding = 1;
|
1997-12-08 22:51:17 +00:00
|
|
|
}
|
1997-10-28 21:14:54 +00:00
|
|
|
} else if ( line[0] == 't' ) {
|
|
|
|
/* start a new triangle strip */
|
|
|
|
|
1997-10-30 12:38:35 +00:00
|
|
|
n1 = n2 = n3 = n4 = 0;
|
|
|
|
|
1997-10-28 21:14:54 +00:00
|
|
|
if ( !first ) {
|
|
|
|
/* close out the previous structure and start the next */
|
1997-12-15 23:54:25 +00:00
|
|
|
xglEnd();
|
1997-10-30 12:38:35 +00:00
|
|
|
} else {
|
|
|
|
first = 0;
|
1997-10-28 21:14:54 +00:00
|
|
|
}
|
|
|
|
|
1998-01-27 03:26:41 +00:00
|
|
|
/* fgPrintf( FG_TERRAIN, FG_DEBUG, " new tri strip = %s",
|
|
|
|
line); */
|
1997-10-31 04:49:12 +00:00
|
|
|
sscanf(line, "t %d %d %d %d\n", &n1, &n2, &n3, &n4);
|
1997-10-28 21:14:54 +00:00
|
|
|
|
1998-01-27 03:26:41 +00:00
|
|
|
/* fgPrintf( FG_TERRAIN, FG_DEBUG, "(t) = "); */
|
1997-10-30 12:38:35 +00:00
|
|
|
|
1997-12-15 23:54:25 +00:00
|
|
|
xglBegin(GL_TRIANGLE_STRIP);
|
|
|
|
|
|
|
|
if ( winding ) {
|
|
|
|
odd = 1;
|
1997-12-30 23:09:40 +00:00
|
|
|
scale = 1.0;
|
1997-12-15 23:54:25 +00:00
|
|
|
} else {
|
|
|
|
odd = 0;
|
1997-12-30 23:09:40 +00:00
|
|
|
scale = 1.0;
|
1997-12-15 23:54:25 +00:00
|
|
|
}
|
|
|
|
|
1998-02-09 21:30:18 +00:00
|
|
|
if ( use_per_vertex_norms ) {
|
1997-12-30 23:09:40 +00:00
|
|
|
MAT3_SCALE_VEC(normal, normals[n1], scale);
|
|
|
|
xglNormal3dv(normal);
|
1998-03-14 00:30:50 +00:00
|
|
|
xglTexCoord2f(calc_lon(nodes[n1][0], nodes[n1][1], nodes[n1][2]), calc_lat(nodes[n1][0], nodes[n1][1], nodes[n1][2]));
|
1998-02-09 21:30:18 +00:00
|
|
|
xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
|
1997-12-08 22:51:17 +00:00
|
|
|
|
1997-12-30 23:09:40 +00:00
|
|
|
MAT3_SCALE_VEC(normal, normals[n2], scale);
|
|
|
|
xglNormal3dv(normal);
|
1998-03-14 00:30:50 +00:00
|
|
|
xglTexCoord2f(calc_lon(nodes[n2][0], nodes[n2][1], nodes[n2][2]), calc_lat(nodes[n2][0], nodes[n2][1], nodes[n2][2]));
|
1998-02-09 21:30:18 +00:00
|
|
|
xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
|
1997-11-14 00:26:49 +00:00
|
|
|
|
1997-12-30 23:09:40 +00:00
|
|
|
MAT3_SCALE_VEC(normal, normals[n3], scale);
|
|
|
|
xglNormal3dv(normal);
|
1998-03-14 00:30:50 +00:00
|
|
|
xglTexCoord2f(calc_lon(nodes[n3][0], nodes[n3][1], nodes[n3][2]), calc_lat(nodes[n3][0], nodes[n3][1], nodes[n3][2]));
|
1998-02-09 21:30:18 +00:00
|
|
|
xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]);
|
1997-12-30 01:38:37 +00:00
|
|
|
} else {
|
|
|
|
if ( odd ) {
|
|
|
|
calc_normal(nodes[n1], nodes[n2], nodes[n3], approx_normal);
|
|
|
|
} else {
|
|
|
|
calc_normal(nodes[n2], nodes[n1], nodes[n3], approx_normal);
|
|
|
|
}
|
1997-12-30 23:09:40 +00:00
|
|
|
MAT3_SCALE_VEC(normal, approx_normal, scale);
|
|
|
|
xglNormal3dv(normal);
|
1997-11-14 00:26:49 +00:00
|
|
|
|
1998-03-14 00:30:50 +00:00
|
|
|
xglTexCoord2f(calc_lon(nodes[n1][0], nodes[n1][1], nodes[n1][2]), calc_lat(nodes[n1][0], nodes[n1][1], nodes[n1][2]));
|
1998-02-09 21:30:18 +00:00
|
|
|
xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
|
1998-03-14 00:30:50 +00:00
|
|
|
xglTexCoord2f(calc_lon(nodes[n2][0], nodes[n2][1], nodes[n2][2]), calc_lat(nodes[n2][0], nodes[n2][1], nodes[n2][2]));
|
1998-02-09 21:30:18 +00:00
|
|
|
xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
|
1998-03-14 00:30:50 +00:00
|
|
|
xglTexCoord2f(calc_lon(nodes[n3][0], nodes[n3][1], nodes[n3][2]), calc_lat(nodes[n3][0], nodes[n3][1], nodes[n3][2]));
|
1998-02-09 21:30:18 +00:00
|
|
|
xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]);
|
1997-12-30 01:38:37 +00:00
|
|
|
}
|
1997-12-15 23:54:25 +00:00
|
|
|
|
|
|
|
odd = 1 - odd;
|
|
|
|
last1 = n2;
|
|
|
|
last2 = n3;
|
1997-10-31 04:49:12 +00:00
|
|
|
|
1997-10-30 12:38:35 +00:00
|
|
|
if ( n4 > 0 ) {
|
1998-02-09 21:30:18 +00:00
|
|
|
if ( use_per_vertex_norms ) {
|
1997-12-30 23:09:40 +00:00
|
|
|
MAT3_SCALE_VEC(normal, normals[n4], scale);
|
1997-12-15 23:54:25 +00:00
|
|
|
} else {
|
1997-12-30 01:38:37 +00:00
|
|
|
calc_normal(nodes[n3], nodes[n2], nodes[n4], approx_normal);
|
1997-12-30 23:09:40 +00:00
|
|
|
MAT3_SCALE_VEC(normal, approx_normal, scale);
|
1997-12-15 23:54:25 +00:00
|
|
|
}
|
1997-12-30 23:09:40 +00:00
|
|
|
xglNormal3dv(normal);
|
1998-03-14 00:30:50 +00:00
|
|
|
xglTexCoord2f(calc_lon(nodes[n4][0], nodes[n4][1], nodes[n4][2]), calc_lat(nodes[n4][0], nodes[n4][1], nodes[n4][2]));
|
1998-02-09 21:30:18 +00:00
|
|
|
xglVertex3d(nodes[n4][0], nodes[n4][1], nodes[n4][2]);
|
1997-12-15 23:54:25 +00:00
|
|
|
|
|
|
|
odd = 1 - odd;
|
|
|
|
last1 = n3;
|
|
|
|
last2 = n4;
|
1997-10-30 12:38:35 +00:00
|
|
|
}
|
1997-11-14 00:26:49 +00:00
|
|
|
} else if ( line[0] == 'f' ) {
|
|
|
|
/* unoptimized face */
|
|
|
|
|
|
|
|
if ( !first ) {
|
|
|
|
/* close out the previous structure and start the next */
|
1997-12-15 23:54:25 +00:00
|
|
|
xglEnd();
|
1997-11-14 00:26:49 +00:00
|
|
|
} else {
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
|
1997-12-15 23:54:25 +00:00
|
|
|
xglBegin(GL_TRIANGLES);
|
1997-11-14 00:26:49 +00:00
|
|
|
|
1998-01-27 03:26:41 +00:00
|
|
|
/* fgPrintf( FG_TERRAIN, FG_DEBUG, "new triangle = %s", line);*/
|
1997-11-14 00:26:49 +00:00
|
|
|
sscanf(line, "f %d %d %d\n", &n1, &n2, &n3);
|
|
|
|
|
1997-12-15 23:54:25 +00:00
|
|
|
xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
|
1998-03-14 00:30:50 +00:00
|
|
|
xglTexCoord2f(calc_lon(nodes[n1][0], nodes[n1][1], nodes[n1][2]), calc_lat(nodes[n1][0], nodes[n1][1], nodes[n1][2]));
|
1998-02-09 21:30:18 +00:00
|
|
|
xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
|
1997-11-14 00:26:49 +00:00
|
|
|
|
1997-12-15 23:54:25 +00:00
|
|
|
xglNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]);
|
1998-03-14 00:30:50 +00:00
|
|
|
xglTexCoord2f(calc_lon(nodes[n2][0], nodes[n2][1], nodes[n2][2]), calc_lat(nodes[n2][0], nodes[n2][1], nodes[n2][2]));
|
1998-02-09 21:30:18 +00:00
|
|
|
xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
|
1998-03-14 00:30:50 +00:00
|
|
|
|
1997-12-15 23:54:25 +00:00
|
|
|
xglNormal3d(normals[n3][0], normals[n3][1], normals[n3][2]);
|
1998-03-14 00:30:50 +00:00
|
|
|
xglTexCoord2f(calc_lon(nodes[n3][0], nodes[n3][1], nodes[n3][2]), calc_lat(nodes[n3][0], nodes[n3][1], nodes[n3][2]));
|
1998-02-09 21:30:18 +00:00
|
|
|
xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]);
|
1997-10-28 21:14:54 +00:00
|
|
|
} else if ( line[0] == 'q' ) {
|
|
|
|
/* continue a triangle strip */
|
|
|
|
n1 = n2 = 0;
|
|
|
|
|
1998-01-27 03:26:41 +00:00
|
|
|
/* fgPrintf( FG_TERRAIN, FG_DEBUG, "continued tri strip = %s ",
|
|
|
|
line); */
|
1997-10-28 21:14:54 +00:00
|
|
|
sscanf(line, "q %d %d\n", &n1, &n2);
|
1998-01-27 03:26:41 +00:00
|
|
|
/* fgPrintf( FG_TERRAIN, FG_DEBUG, "read %d %d\n", n1, n2); */
|
1997-10-30 12:38:35 +00:00
|
|
|
|
1998-02-09 21:30:18 +00:00
|
|
|
if ( use_per_vertex_norms ) {
|
1997-12-30 23:09:40 +00:00
|
|
|
MAT3_SCALE_VEC(normal, normals[n1], scale);
|
|
|
|
xglNormal3dv(normal);
|
1997-12-15 23:54:25 +00:00
|
|
|
} else {
|
1997-12-30 01:38:37 +00:00
|
|
|
if ( odd ) {
|
|
|
|
calc_normal(nodes[last1], nodes[last2], nodes[n1],
|
|
|
|
approx_normal);
|
|
|
|
} else {
|
|
|
|
calc_normal(nodes[last2], nodes[last1], nodes[n1],
|
|
|
|
approx_normal);
|
|
|
|
}
|
1997-12-30 23:09:40 +00:00
|
|
|
MAT3_SCALE_VEC(normal, approx_normal, scale);
|
|
|
|
xglNormal3dv(normal);
|
1997-12-15 23:54:25 +00:00
|
|
|
}
|
|
|
|
|
1998-03-14 00:30:50 +00:00
|
|
|
xglTexCoord2f(calc_lon(nodes[n1][0], nodes[n1][1], nodes[n1][2]), calc_lat(nodes[n1][0], nodes[n1][1], nodes[n1][2]));
|
1998-02-09 21:30:18 +00:00
|
|
|
xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
|
1998-03-14 00:30:50 +00:00
|
|
|
|
1997-12-15 23:54:25 +00:00
|
|
|
odd = 1 - odd;
|
|
|
|
last1 = last2;
|
|
|
|
last2 = n1;
|
1997-10-31 04:49:12 +00:00
|
|
|
|
1997-10-30 12:38:35 +00:00
|
|
|
if ( n2 > 0 ) {
|
1998-01-27 03:26:41 +00:00
|
|
|
/* fgPrintf( FG_TERRAIN, FG_DEBUG, " (cont)\n"); */
|
1997-12-30 01:38:37 +00:00
|
|
|
|
1998-02-09 21:30:18 +00:00
|
|
|
if ( use_per_vertex_norms ) {
|
1997-12-30 23:09:40 +00:00
|
|
|
MAT3_SCALE_VEC(normal, normals[n2], scale);
|
|
|
|
xglNormal3dv(normal);
|
1997-12-15 23:54:25 +00:00
|
|
|
} else {
|
1997-12-30 01:38:37 +00:00
|
|
|
if ( odd ) {
|
|
|
|
calc_normal(nodes[last1], nodes[last2], nodes[n2],
|
|
|
|
approx_normal);
|
|
|
|
} else {
|
|
|
|
calc_normal(nodes[last2], nodes[last1], nodes[n2],
|
|
|
|
approx_normal);
|
|
|
|
}
|
1997-12-30 23:09:40 +00:00
|
|
|
MAT3_SCALE_VEC(normal, approx_normal, scale);
|
|
|
|
xglNormal3dv(normal);
|
1997-12-15 23:54:25 +00:00
|
|
|
}
|
|
|
|
|
1998-03-14 00:30:50 +00:00
|
|
|
xglTexCoord2f(calc_lon(nodes[n2][0], nodes[n2][1], nodes[n2][2]), calc_lat(nodes[n2][0], nodes[n2][1], nodes[n2][2]));
|
1998-02-09 21:30:18 +00:00
|
|
|
xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
|
1997-12-15 23:54:25 +00:00
|
|
|
|
|
|
|
odd = 1 -odd;
|
|
|
|
last1 = last2;
|
|
|
|
last2 = n2;
|
1997-10-30 12:38:35 +00:00
|
|
|
}
|
1997-10-28 21:14:54 +00:00
|
|
|
} else {
|
1998-01-27 03:26:41 +00:00
|
|
|
fgPrintf( FG_TERRAIN, FG_WARN, "Unknown line in %s = %s\n",
|
|
|
|
path, line);
|
1997-10-28 21:14:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-12-15 23:54:25 +00:00
|
|
|
xglEnd();
|
1997-12-08 22:51:17 +00:00
|
|
|
|
|
|
|
/* Draw normal vectors (for visually verifying normals)*/
|
1997-12-10 01:19:42 +00:00
|
|
|
/*
|
1997-12-15 23:54:25 +00:00
|
|
|
xglBegin(GL_LINES);
|
|
|
|
xglColor3f(0.0, 0.0, 0.0);
|
1997-12-10 01:19:42 +00:00
|
|
|
for ( i = 0; i < ncount; i++ ) {
|
1998-02-09 21:30:18 +00:00
|
|
|
xglVertex3d(nodes[i][0],
|
|
|
|
nodes[i][1] ,
|
|
|
|
nodes[i][2]);
|
|
|
|
xglVertex3d(nodes[i][0] + 500*normals[i][0],
|
|
|
|
nodes[i][1] + 500*normals[i][1],
|
|
|
|
nodes[i][2] + 500*normals[i][2]);
|
1997-12-10 01:19:42 +00:00
|
|
|
}
|
1997-12-15 23:54:25 +00:00
|
|
|
xglEnd();
|
1997-12-10 01:19:42 +00:00
|
|
|
*/
|
1997-12-08 22:51:17 +00:00
|
|
|
|
1998-03-14 00:30:50 +00:00
|
|
|
// xglDisable(GL_TEXTURE_GEN_S);
|
|
|
|
// xglDisable(GL_TEXTURE_GEN_T);
|
|
|
|
|
1997-12-18 23:32:28 +00:00
|
|
|
xglFrontFace ( GL_CCW );
|
|
|
|
|
1997-12-15 23:54:25 +00:00
|
|
|
xglEndList();
|
1997-10-28 21:14:54 +00:00
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
|
1998-02-09 21:30:18 +00:00
|
|
|
/* reference point is the "center" */
|
|
|
|
ref->x = (xmin + xmax) / 2.0;
|
|
|
|
ref->y = (ymin + ymax) / 2.0;
|
|
|
|
ref->z = (zmin + zmax) / 2.0;
|
|
|
|
|
1998-01-29 00:51:38 +00:00
|
|
|
return(tile);
|
1997-10-28 21:14:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* $Log$
|
1998-03-14 00:30:50 +00:00
|
|
|
/* Revision 1.25 1998/03/14 00:30:50 curt
|
|
|
|
/* Beginning initial terrain texturing experiments.
|
1997-10-28 21:14:54 +00:00
|
|
|
/*
|
1998-03-14 00:30:50 +00:00
|
|
|
* Revision 1.24 1998/02/09 21:30:18 curt
|
|
|
|
* Fixed a nagging problem with terrain tiles not "quite" matching up perfectly.
|
|
|
|
*
|
1998-02-09 21:30:18 +00:00
|
|
|
* Revision 1.23 1998/02/09 15:07:52 curt
|
|
|
|
* Minor tweaks.
|
|
|
|
*
|
1998-02-09 15:07:47 +00:00
|
|
|
* Revision 1.22 1998/02/01 03:39:54 curt
|
|
|
|
* Minor tweaks.
|
|
|
|
*
|
1998-02-01 03:39:53 +00:00
|
|
|
* Revision 1.21 1998/01/31 00:43:25 curt
|
|
|
|
* Added MetroWorks patches from Carmen Volpe.
|
|
|
|
*
|
1998-01-31 00:42:57 +00:00
|
|
|
* Revision 1.20 1998/01/29 00:51:39 curt
|
|
|
|
* First pass at tile cache, dynamic tile loading and tile unloading now works.
|
|
|
|
*
|
1998-01-29 00:51:38 +00:00
|
|
|
* Revision 1.19 1998/01/27 03:26:42 curt
|
|
|
|
* Playing with new fgPrintf command.
|
|
|
|
*
|
1998-01-27 03:26:41 +00:00
|
|
|
* 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.
|
|
|
|
*
|
1998-01-19 19:26:51 +00:00
|
|
|
* 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.
|
|
|
|
*
|
1998-01-13 00:23:08 +00:00
|
|
|
* 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.
|
|
|
|
*
|
1997-12-30 23:09:40 +00:00
|
|
|
* Revision 1.15 1997/12/30 20:47:51 curt
|
|
|
|
* Integrated new event manager with subsystem initializations.
|
|
|
|
*
|
1997-12-30 20:47:34 +00:00
|
|
|
* Revision 1.14 1997/12/30 01:38:46 curt
|
|
|
|
* Switched back to per vertex normals and smooth shading for terrain.
|
|
|
|
*
|
1997-12-30 01:38:37 +00:00
|
|
|
* Revision 1.13 1997/12/18 23:32:36 curt
|
|
|
|
* First stab at sky dome actually starting to look reasonable. :-)
|
|
|
|
*
|
1997-12-18 23:32:28 +00:00
|
|
|
* Revision 1.12 1997/12/17 23:13:47 curt
|
|
|
|
* Began working on rendering the sky.
|
|
|
|
*
|
1997-12-17 23:13:45 +00:00
|
|
|
* Revision 1.11 1997/12/15 23:55:01 curt
|
|
|
|
* Add xgl wrappers for debugging.
|
|
|
|
* Generate terrain normals on the fly.
|
|
|
|
*
|
1997-12-15 23:54:25 +00:00
|
|
|
* Revision 1.10 1997/12/12 21:41:28 curt
|
|
|
|
* More light/material property tweaking ... still a ways off.
|
|
|
|
*
|
1997-12-12 21:41:24 +00:00
|
|
|
* Revision 1.9 1997/12/12 19:52:57 curt
|
|
|
|
* Working on lightling and material properties.
|
|
|
|
*
|
1997-12-12 19:52:47 +00:00
|
|
|
* Revision 1.8 1997/12/10 01:19:51 curt
|
|
|
|
* Tweaks for verion 0.15 release.
|
|
|
|
*
|
1997-12-10 01:19:42 +00:00
|
|
|
* Revision 1.7 1997/12/08 22:51:17 curt
|
|
|
|
* Enhanced to handle ccw and cw tri-stripe winding. This is a temporary
|
|
|
|
* admission of defeat. I will eventually go back and get all the stripes
|
|
|
|
* wound the same way (ccw).
|
|
|
|
*
|
1997-12-08 22:51:17 +00:00
|
|
|
* Revision 1.6 1997/11/25 19:25:35 curt
|
|
|
|
* Changes to integrate Durk's moon/sun code updates + clean up.
|
|
|
|
*
|
1997-11-25 19:25:27 +00:00
|
|
|
* Revision 1.5 1997/11/15 18:16:39 curt
|
|
|
|
* minor tweaks.
|
|
|
|
*
|
1997-11-15 18:16:34 +00:00
|
|
|
* Revision 1.4 1997/11/14 00:26:49 curt
|
|
|
|
* Transform scenery coordinates earlier in pipeline when scenery is being
|
|
|
|
* created, not when it is being loaded. Precalculate normals for each node
|
|
|
|
* as average of the normals of each containing polygon so Garoude shading is
|
|
|
|
* now supportable.
|
|
|
|
*
|
1997-11-14 00:26:49 +00:00
|
|
|
* Revision 1.3 1997/10/31 04:49:12 curt
|
|
|
|
* Tweaking vertex orders.
|
|
|
|
*
|
1997-10-31 04:49:12 +00:00
|
|
|
* Revision 1.2 1997/10/30 12:38:45 curt
|
|
|
|
* Working on new scenery subsystem.
|
|
|
|
*
|
1997-10-30 12:38:35 +00:00
|
|
|
* Revision 1.1 1997/10/28 21:14:54 curt
|
|
|
|
* Initial revision.
|
|
|
|
*
|
1997-10-28 21:14:54 +00:00
|
|
|
*/
|