]> git.mxchange.org Git - flightgear.git/commitdiff
Playing around with texture coordinates.
authorcurt <curt>
Sat, 2 May 1998 01:52:14 +0000 (01:52 +0000)
committercurt <curt>
Sat, 2 May 1998 01:52:14 +0000 (01:52 +0000)
Scenery/obj.cxx
Scenery/obj.hxx
Scenery/scenery.cxx
Scenery/scenery.hxx
Scenery/tilecache.cxx
Scenery/tilecache.hxx
Scenery/tilemgr.cxx

index 1874603c6b16d278b65a3abd592ce34bd49f46ea..fcbd8e0cc76d1a1b284bae1ac11c6d42a351d4fe 100644 (file)
@@ -1,6 +1,5 @@
-/* -*- Mode: C++ -*-
- *
- * obj.c -- routines to handle WaveFront .obj format files.
+/*
+ * obj.cxx -- routines to handle "sorta" WaveFront .obj format files.
  *
  * Written by Curtis Olson, started October 1997.
  *
 #include <Main/options.hxx>
 #include <Math/mat3.h>
 #include <Math/fg_random.h>
-#include <Scenery/obj.hxx>
-#include <Scenery/scenery.hxx>
+#include <Math/polar3d.h>
+
+#include "obj.hxx"
+#include "scenery.hxx"
 
 
 #define MAXNODES 100000
@@ -73,33 +74,29 @@ void calc_normal(double p1[3], double p2[3], double p3[3], double normal[3])
 
 #define FG_TEX_CONSTANT 128.0
 
-float calc_lon(double x, double y, double z) {
-    float tmp;
-    tmp = fmod(
-              (RAD_TO_DEG*atan2(y, x)) * FG_TEX_CONSTANT, 
-              10.0);
 
-    // printf("lon = %.2f\n", (float)tmp);
-    return (float)tmp;
-}
+// Calculate texture coordinates for a given point.
+fgPolarPoint3d calc_tex_coords(double *node, fgCartesianPoint3d *ref) {
+    fgCartesianPoint3d cp;
+    fgPolarPoint3d pp;
 
+    cp.x = node[0] + ref->x; 
+    cp.y = node[1] + ref->y;
+    cp.z = node[2] + ref->z;
 
-float calc_lat(double x, double y, double z) {
-    float tmp;
+    pp = fgCartToPolar3d(cp);
 
-    tmp = fmod(
-              (90.0 - RAD_TO_DEG * 
-               atan2( sqrt(x*x + y*y), z )) * FG_TEX_CONSTANT,
-              10.0);
+    pp.lon = fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.lon, 15.0);
+    pp.lat = fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.lat, 15.0);
 
-    // printf("lat = %.2f\n", (float)tmp);
-    return (float)tmp;
+    return(pp);
 }
 
 
 /* Load a .obj file and generate the GL call list */
-GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
+GLint fgObjLoad(char *path, fgCartesianPoint3d *ref, double *radius) {
     fgOPTIONS *o;
+    fgPolarPoint3d pp;
     char fgpath[256], line[256], winding_str[256];
     double approx_normal[3], normal[3], scale;
     // double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
@@ -163,7 +160,8 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
            if ( ncount < MAXNODES ) {
                /* fgPrintf( FG_TERRAIN, FG_DEBUG, "vertex = %s", line); */
                sscanf(line, "v %lf %lf %lf\n", 
-                      &nodes[ncount][0], &nodes[ncount][1], &nodes[ncount][2]);
+                      &nodes[ncount][0], &nodes[ncount][1], 
+                      &nodes[ncount][2]);
 
                /* first time through set min's and max'es */
                /*
@@ -252,64 +250,44 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
                // (averaged) normals
                MAT3_SCALE_VEC(normal, normals[n1], scale);
                xglNormal3dv(normal);
-               xglTexCoord2f(calc_lon(nodes[n1][0] + ref->x, 
-                                      nodes[n1][1] + ref->y,
-                                      nodes[n1][2] + ref->z),
-                             calc_lat(nodes[n1][0] + ref->x,
-                                      nodes[n1][1] + ref->y,
-                                      nodes[n1][2] + ref->z));
+               pp = calc_tex_coords(nodes[n1], ref);
+               xglTexCoord2f(pp.lon, pp.lat);
                xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
 
                MAT3_SCALE_VEC(normal, normals[n2], scale);
                xglNormal3dv(normal);
-               xglTexCoord2f(calc_lon(nodes[n2][0] + ref->x,
-                                      nodes[n2][1] + ref->y,
-                                      nodes[n2][2] + ref->z),
-                             calc_lat(nodes[n2][0] + ref->x,
-                                      nodes[n2][1] + ref->y,
-                                      nodes[n2][2] + ref->z));
+                pp = calc_tex_coords(nodes[n2], ref);
+                xglTexCoord2f(pp.lon, pp.lat);
                xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
 
                MAT3_SCALE_VEC(normal, normals[n3], scale);
                xglNormal3dv(normal);
-               xglTexCoord2f(calc_lon(nodes[n3][0] + ref->x,
-                                      nodes[n3][1] + ref->y,
-                                      nodes[n3][2] + ref->z),
-                             calc_lat(nodes[n3][0] + ref->x,
-                                      nodes[n3][1] + ref->y,
-                                      nodes[n3][2] + ref->z));
+                pp = calc_tex_coords(nodes[n3], ref);
+                xglTexCoord2f(pp.lon, pp.lat);
                xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]);
            } else {
                // Shading model is "GL_FLAT" so calculate per face
                // normals on the fly.
                if ( odd ) {
-                   calc_normal(nodes[n1], nodes[n2], nodes[n3], approx_normal);
+                   calc_normal(nodes[n1], nodes[n2], 
+                               nodes[n3], approx_normal);
                } else {
-                   calc_normal(nodes[n2], nodes[n1], nodes[n3], approx_normal);
+                   calc_normal(nodes[n2], nodes[n1], 
+                               nodes[n3], approx_normal);
                }
                MAT3_SCALE_VEC(normal, approx_normal, scale);
                xglNormal3dv(normal);
 
-               xglTexCoord2f(calc_lon(nodes[n1][0] + ref->x,
-                                      nodes[n1][1] + ref->y,
-                                      nodes[n1][2] + ref->z),
-                             calc_lat(nodes[n1][0] + ref->x,
-                                      nodes[n1][1] + ref->y,
-                                      nodes[n1][2] + ref->z));
+                pp = calc_tex_coords(nodes[n1], ref);
+                xglTexCoord2f(pp.lon, pp.lat);
                xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
-               xglTexCoord2f(calc_lon(nodes[n2][0] + ref->x,
-                                      nodes[n2][1] + ref->y,
-                                      nodes[n2][2] + ref->z),
-                             calc_lat(nodes[n2][0] + ref->x,
-                                      nodes[n2][1] + ref->y,
-                                      nodes[n2][2] + ref->z));
+
+                pp = calc_tex_coords(nodes[n2], ref);
+                xglTexCoord2f(pp.lon, pp.lat);
                xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
-               xglTexCoord2f(calc_lon(nodes[n3][0] + ref->x,
-                                      nodes[n3][1] + ref->y,
-                                      nodes[n3][2] + ref->z),
-                             calc_lat(nodes[n3][0] + ref->x,
-                                      nodes[n3][1] + ref->y,
-                                      nodes[n3][2] + ref->z));
+
+                pp = calc_tex_coords(nodes[n3], ref);
+                xglTexCoord2f(pp.lon, pp.lat);
                xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]);
            }
 
@@ -327,12 +305,8 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
                    MAT3_SCALE_VEC(normal, approx_normal, scale);
                }
                xglNormal3dv(normal);
-               xglTexCoord2f(calc_lon(nodes[n4][0] + ref->x,
-                                      nodes[n4][1] + ref->y,
-                                      nodes[n4][2] + ref->z),
-                             calc_lat(nodes[n4][0] + ref->x,
-                                      nodes[n4][1] + ref->y,
-                                      nodes[n4][2] + ref->z));
+               pp = calc_tex_coords(nodes[n4], ref);
+                xglTexCoord2f(pp.lon, pp.lat);
                xglVertex3d(nodes[n4][0], nodes[n4][1], nodes[n4][2]);
 
                odd = 1 - odd;
@@ -355,30 +329,18 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
            sscanf(line, "f %d %d %d\n", &n1, &n2, &n3);
 
             xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
-           xglTexCoord2f(calc_lon(nodes[n1][0] + ref->x,
-                                  nodes[n1][1] + ref->y,
-                                  nodes[n1][2] + ref->z),
-                         calc_lat(nodes[n1][0] + ref->x,
-                                  nodes[n1][1] + ref->y,
-                                  nodes[n1][2] + ref->z));
-           xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
+           pp = calc_tex_coords(nodes[n1], ref);
+           xglTexCoord2f(pp.lon, pp.lat);
+           xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
 
             xglNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]);
-           xglTexCoord2f(calc_lon(nodes[n2][0] + ref->x,
-                                  nodes[n2][1] + ref->y,
-                                  nodes[n2][2] + ref->z),
-                         calc_lat(nodes[n2][0] + ref->x,
-                                  nodes[n2][1] + ref->y,
-                                  nodes[n2][2] + ref->z));
+            pp = calc_tex_coords(nodes[n2], ref);
+            xglTexCoord2f(pp.lon, pp.lat);
            xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
                
             xglNormal3d(normals[n3][0], normals[n3][1], normals[n3][2]);
-           xglTexCoord2f(calc_lon(nodes[n3][0] + ref->x,
-                                  nodes[n3][1] + ref->y,
-                                  nodes[n3][2] + ref->z),
-                         calc_lat(nodes[n3][0] + ref->x,
-                                  nodes[n3][1] + ref->y,
-                                  nodes[n3][2] + ref->z));
+            pp = calc_tex_coords(nodes[n3], ref);
+            xglTexCoord2f(pp.lon, pp.lat);
            xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]);
        } else if ( line[0] == 'q' ) {
            /* continue a triangle strip */
@@ -406,12 +368,8 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
                xglNormal3dv(normal);
            }
 
-           xglTexCoord2f(calc_lon(nodes[n1][0] + ref->x,
-                                  nodes[n1][1] + ref->y,
-                                  nodes[n1][2] + ref->z),
-                         calc_lat(nodes[n1][0] + ref->x,
-                                  nodes[n1][1] + ref->y,
-                                  nodes[n1][2] + ref->z));
+            pp = calc_tex_coords(nodes[n1], ref);
+            xglTexCoord2f(pp.lon, pp.lat);
            xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
     
            odd = 1 - odd;
@@ -438,12 +396,8 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
                    xglNormal3dv(normal);
                }
 
-               xglTexCoord2f(calc_lon(nodes[n2][0] + ref->x,
-                                      nodes[n2][1] + ref->y,
-                                      nodes[n2][2] + ref->z),
-                             calc_lat(nodes[n2][0] + ref->x,
-                                      nodes[n2][1] + ref->y,
-                                      nodes[n2][2] + ref->z));
+               pp = calc_tex_coords(nodes[n2], ref);
+               xglTexCoord2f(pp.lon, pp.lat);
                xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
 
                odd = 1 -odd;
@@ -494,9 +448,12 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
 
 
 /* $Log$
-/* Revision 1.1  1998/04/30 12:35:28  curt
-/* Added a command line rendering option specify smooth/flat shading.
+/* Revision 1.2  1998/05/02 01:52:14  curt
+/* Playing around with texture coordinates.
 /*
+ * Revision 1.1  1998/04/30 12:35:28  curt
+ * Added a command line rendering option specify smooth/flat shading.
+ *
  * Revision 1.35  1998/04/28 21:43:26  curt
  * Wrapped zlib calls up so we can conditionally comment out zlib support.
  *
index 1539cfd6f20a6bc7dbbcac014ceeeb15e0c83580..28b7e297b148c2f7b1b07b47048a3db5c05a623a 100644 (file)
 
 
 /* Load a .obj file and generate the GL call list */
-GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius);
+GLint fgObjLoad(char *path, fgCartesianPoint3d *ref, double *radius);
 
 
 #endif /* _OBJ_HXX */
 
 
 /* $Log$
-/* Revision 1.1  1998/04/30 12:35:29  curt
-/* Added a command line rendering option specify smooth/flat shading.
+/* Revision 1.2  1998/05/02 01:52:15  curt
+/* Playing around with texture coordinates.
 /*
+ * Revision 1.1  1998/04/30 12:35:29  curt
+ * Added a command line rendering option specify smooth/flat shading.
+ *
  * Revision 1.11  1998/04/25 22:06:31  curt
  * Edited cvs log messages in source files ... bad bad bad!
  *
index e58d9921b40fb550637e8e70a80e988c2b524985..ff82ad45daf33ef78dc3c025e92c7c54f32cfaa8 100644 (file)
@@ -72,7 +72,7 @@ int fgSceneryInit( void ) {
     path[0] = '\0';
     strcat(path, g->root_dir);
     strcat(path, "/Textures/");
-    strcat(path, "forest.rgb");
+    strcat(path, "desert.rgb");
 
     // Try uncompressed
     if ( (texbuf = read_rgb_texture(path, &width, &height)) == NULL ) {
@@ -123,9 +123,12 @@ void fgSceneryRender( void ) {
 
 
 /* $Log$
-/* Revision 1.1  1998/04/30 12:35:30  curt
-/* Added a command line rendering option specify smooth/flat shading.
+/* Revision 1.2  1998/05/02 01:52:16  curt
+/* Playing around with texture coordinates.
 /*
+ * Revision 1.1  1998/04/30 12:35:30  curt
+ * Added a command line rendering option specify smooth/flat shading.
+ *
  * Revision 1.42  1998/04/28 21:43:27  curt
  * Wrapped zlib calls up so we can conditionally comment out zlib support.
  *
index 606912ec6408240c5a8349b8c04ad36a511ddf01..9ac5338188d6cb84725dad0f14c1663ce015debf 100644 (file)
@@ -42,10 +42,10 @@ struct fgSCENERY {
     int terrain_skip;
 
     /* center of current scenery chunk */
-    struct fgCartesianPoint center;
+    fgCartesianPoint3d center;
 
     /* next center of current scenery chunk */
-    struct fgCartesianPoint next_center;
+    fgCartesianPoint3d next_center;
 
     /* angle of sun relative to current local horizontal */
     double sun_angle;
@@ -71,9 +71,12 @@ void fgSceneryRender( void );
 
 
 /* $Log$
-/* Revision 1.1  1998/04/30 12:35:31  curt
-/* Added a command line rendering option specify smooth/flat shading.
+/* Revision 1.2  1998/05/02 01:52:16  curt
+/* Playing around with texture coordinates.
 /*
+ * Revision 1.1  1998/04/30 12:35:31  curt
+ * Added a command line rendering option specify smooth/flat shading.
+ *
  * Revision 1.21  1998/04/25 22:06:31  curt
  * Edited cvs log messages in source files ... bad bad bad!
  *
index 08303ab9435dcbd389659c9fcaf4203e7460858b..98f6e0d46720f819e9ad7569a0a7421259fb64a1 100644 (file)
@@ -132,7 +132,7 @@ void fgTileCacheEntryFree( int index ) {
 
 /* Return info for a tile cache entry */
 void fgTileCacheEntryInfo( int index, GLint *display_list, 
-                          struct fgCartesianPoint *local_ref ) {
+                          fgCartesianPoint3d *local_ref ) {
     *display_list = tile_cache[index].display_list;
     /* fgPrintf(FG_TERRAIN, FG_DEBUG, "Display list = %d\n", *display_list); */
 
@@ -200,9 +200,12 @@ int fgTileCacheNextAvail( void ) {
 
 
 /* $Log$
-/* Revision 1.5  1998/04/30 12:35:31  curt
-/* Added a command line rendering option specify smooth/flat shading.
+/* Revision 1.6  1998/05/02 01:52:17  curt
+/* Playing around with texture coordinates.
 /*
+ * Revision 1.5  1998/04/30 12:35:31  curt
+ * Added a command line rendering option specify smooth/flat shading.
+ *
  * Revision 1.4  1998/04/28 01:21:43  curt
  * Tweaked texture parameter calculations to keep the number smaller.  This
  * avoids the "swimming" problem.
index 705c2e6a2b3e1b7df63355eebb67be4e20711c6d..13ab34f27db50800471a9f4edbb4034b812677f0 100644 (file)
@@ -57,7 +57,7 @@
 struct fgTILE {
     struct fgBUCKET tile_bucket;
     GLint display_list;
-    struct fgCartesianPoint local_ref;
+    fgCartesianPoint3d local_ref;
     double bounding_radius;
     int used;
     int priority;
@@ -81,16 +81,19 @@ void fgTileCacheEntryFillIn( int index, struct fgBUCKET *p );
 
 /* Return info for a tile cache entry */
 void fgTileCacheEntryInfo( int index, GLint *display_list, 
-                          struct fgCartesianPoint *local_ref );
+                          fgCartesianPoint3d *local_ref );
 
 
 #endif /* _TILECACHE_HXX */
 
 
 /* $Log$
-/* Revision 1.4  1998/04/30 12:35:31  curt
-/* Added a command line rendering option specify smooth/flat shading.
+/* Revision 1.5  1998/05/02 01:52:17  curt
+/* Playing around with texture coordinates.
 /*
+ * Revision 1.4  1998/04/30 12:35:31  curt
+ * Added a command line rendering option specify smooth/flat shading.
+ *
  * Revision 1.3  1998/04/25 22:06:32  curt
  * Edited cvs log messages in source files ... bad bad bad!
  *
index 0fd38eaabcb7c3a9fcb5e04695cc8e685ff13970..a67952c524ae0c39fc5d098027e2e51dc143d03d 100644 (file)
@@ -185,7 +185,7 @@ int fgTileMgrUpdate( void ) {
 void fgTileMgrRender( void ) {
     fgFLIGHT *f;
     struct fgBUCKET p;
-    struct fgCartesianPoint local_ref;
+    fgCartesianPoint3d local_ref;
     GLint display_list;
     int i;
     int index;
@@ -221,9 +221,12 @@ void fgTileMgrRender( void ) {
 
 
 /* $Log$
-/* Revision 1.5  1998/04/30 12:35:32  curt
-/* Added a command line rendering option specify smooth/flat shading.
+/* Revision 1.6  1998/05/02 01:52:18  curt
+/* Playing around with texture coordinates.
 /*
+ * Revision 1.5  1998/04/30 12:35:32  curt
+ * Added a command line rendering option specify smooth/flat shading.
+ *
  * Revision 1.4  1998/04/27 03:30:14  curt
  * Minor transformation adjustments to try to keep scenery tiles closer to
  * (0, 0, 0)  GLfloats run out of precision at the distances we need to model