]> git.mxchange.org Git - flightgear.git/blobdiff - Scenery/mesh.c
Merged in make system changes from Bob Kuehne <rpk@sgi.com>
[flightgear.git] / Scenery / mesh.c
index 45de26ad73875a7d5df9266ef8324c37cc46cb70..77cae1e24b36374f134f8a2c8b0e6f4c2234e272 100644 (file)
 
 #include <GL/glut.h>
 
-#include "../constants.h"
-#include "../types.h"
-#include "../Math/fg_geodesy.h"
-#include "../Math/fg_random.h"
-#include "../Math/mat3.h"
-#include "../Math/polar.h"
+#include <Include/constants.h>
+#include <Include/types.h>
+#include <Math/fg_geodesy.h>
+#include <Math/fg_random.h>
+#include <Math/mat3.h>
+#include <Math/polar.h>
 
-#include "mesh.h"
-#include "common.h"
-#include "scenery.h"
+#include <Scenery/mesh.h>
+#include <Scenery/common.h>
+#include <Scenery/scenery.h>
 
 
 /* Temporary hack until we get the scenery management system running */
-extern GLint mesh_hack;
-extern struct mesh eg;
+extern GLint area_terrain;
+extern struct MESH eg;
 
 /* initialize the non-array mesh values */
-void mesh_init(struct mesh *m) {
+void mesh_init(struct MESH *m) {
     m->originx = 0.0;
     m->originy = 0.0;
 
@@ -72,10 +72,10 @@ void mesh_init(struct mesh *m) {
 
 
 /* return a pointer to a new mesh structure (no data array allocated yet) */
-struct mesh *(new_mesh)() {
-    struct mesh *mesh_ptr;
+struct MESH *(new_mesh)( void ) {
+    struct MESH *mesh_ptr;
 
-    mesh_ptr = (struct mesh *)malloc(sizeof(struct mesh));
+    mesh_ptr = (struct MESH *)malloc(sizeof(struct MESH));
 
     if ( mesh_ptr == 0 ) {
        printf("Virtual memory exceeded\n");
@@ -107,7 +107,7 @@ float *(new_mesh_data)(int nrows, int ncols) {
 
 
 /* set the option name in the mesh data structure */
-void mesh_set_option_name(struct mesh *m, char *name) {
+void mesh_set_option_name(struct MESH *m, char *name) {
     if ( strlen(name) < MAX_IDENT_LEN ) {
        strcpy(m->option_name, name);
     } else {
@@ -123,7 +123,7 @@ void mesh_set_option_name(struct mesh *m, char *name) {
 
 
 /* set an option value in the mesh data structure */
-void mesh_set_option_value(struct mesh *m, char *value) {
+void mesh_set_option_value(struct MESH *m, char *value) {
     /* printf("Setting %s to %s\n", m->option_name, value); */
 
     if ( m->do_data ) {
@@ -160,8 +160,8 @@ void mesh_set_option_value(struct mesh *m, char *value) {
 
 /* do whatever needs to be done with the mesh now that it's been
    loaded, such as generating the OpenGL call list. */
-void mesh_do_it(struct mesh *m) {
-    mesh_hack = mesh_to_OpenGL(m);
+void mesh_do_it(struct MESH *m) {
+    area_terrain = mesh_to_OpenGL(m);
 }
 
 
@@ -175,7 +175,7 @@ double mesh_altitude(double lon, double lat) {
     int xindex, yindex;
     int skip;
 
-    skip = cur_scenery_params.terrain_skip;
+    skip = scenery.terrain_skip;
     /* determine if we are in the lower triangle or the upper triangle 
        ______
        |   /|
@@ -227,7 +227,7 @@ double mesh_altitude(double lon, double lat) {
        
        /* printf("  zA = %.2f  zB = %.2f\n", zA, zB); */
 
-       if ( dx > EPSILON ) {
+       if ( dx > FG_EPSILON ) {
            elev = dy * (zB - zA) / dx + zA;
        } else {
            elev = zA;
@@ -259,7 +259,7 @@ double mesh_altitude(double lon, double lat) {
        /* printf("  zA = %.2f  zB = %.2f\n", zA, zB );
        printf("  xB - xA = %.2f\n", eg.col_step * dy / eg.row_step); */
 
-       if ( dy > EPSILON ) {
+       if ( dy > FG_EPSILON ) {
            elev = dx * (zB - zA) / dy    + zA;
        } else {
            elev = zA;
@@ -271,14 +271,16 @@ double mesh_altitude(double lon, double lat) {
 
 
 /* walk through mesh and make opengl calls */
-GLint mesh_to_OpenGL(struct mesh *m) {
+GLint mesh_to_OpenGL(struct MESH *m) {
     GLint mesh;
     /* static GLfloat color[4] = { 0.5, 0.4, 0.25, 1.0 }; */ /* dark desert */
-    static GLfloat color[4] = { 0.5, 0.5, 0.25, 1.0 };
+    /* static GLfloat color[4] = { 0.5, 0.5, 0.25, 1.0 }; */
+    static GLfloat color[4] = { 1.0, 0.0, 0.0, 1.0 };
+    double centerx, centery;
     double randx, randy;
 
     float x1, y1, x2, y2, z11, z12, z21, z22;
-    struct fgCartesianPoint p11, p12, p21, p22;
+    struct fgCartesianPoint p11, p12, p21, p22, c;
     double gc_lon, gc_lat, sl_radius;
 
     MAT3vec v1, v2, normal; 
@@ -290,12 +292,19 @@ GLint mesh_to_OpenGL(struct mesh *m) {
     /* Detail level.  This is how big a step we take as we walk
      * through the DEM data set.  This value is initialized in
      * .../Scenery/scenery.c:fgSceneryInit() */
-    istep = jstep = cur_scenery_params.terrain_skip ;
+    istep = jstep = scenery.terrain_skip ;
+
+    centerx = m->originx + (m->rows * m->row_step) / 2.0;
+    centery = m->originy + (m->cols * m->col_step) / 2.0;
+    fgGeodToGeoc(centery*ARCSEC_TO_RAD, 0, &sl_radius, &gc_lat);
+    c = fgPolarToCart(centerx*ARCSEC_TO_RAD, gc_lat, sl_radius);
+    scenery.center = c;
 
     mesh = glGenLists(1);
     glNewList(mesh, GL_COMPILE);
 
-    glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color );
+    /* glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color ); */
+    glColor3fv(color);
 
     iend = m->cols - 1;
     jend = m->rows - 1;
@@ -347,11 +356,11 @@ GLint mesh_to_OpenGL(struct mesh *m) {
             
             if ( j == 0 ) {
                 /* first time through */
-                glVertex3d(p12.x, p12.y, p12.z);
-                glVertex3d(p11.x, p11.y, p11.z);
+                glVertex3d(p12.x - c.x, p12.y - c.y, p12.z - c.z);
+                glVertex3d(p11.x - c.x, p11.y - c.y, p11.z - c.z);
             }
             
-            glVertex3d(p22.x, p22.y, p22.z);
+            glVertex3d(p22.x - c.x, p22.y - c.y, p22.z - c.z);
     
             v2[0] = p21.y - p11.y; v2[1] = p21.z - p11.z; v2[2] = z21 - z11;
             MAT3cross_product(normal, v2, v1);
@@ -360,7 +369,7 @@ GLint mesh_to_OpenGL(struct mesh *m) {
             /* printf("normal 2 = (%.2f %.2f %.2f\n", normal[0], normal[1], 
                    normal[2]); */
 
-            glVertex3d(p21.x, p21.y, p21.z);
+            glVertex3d(p21.x - c.x, p21.y - c.y, p21.z - c.z);
 
             x1 += m->row_step * jstep;
             x2 += m->row_step * jstep;
@@ -387,9 +396,39 @@ GLint mesh_to_OpenGL(struct mesh *m) {
 
 
 /* $Log$
-/* Revision 1.18  1997/08/02 19:10:14  curt
-/* Incorporated mesh2GL.c into mesh.c
+/* Revision 1.27  1998/01/19 19:27:15  curt
+/* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
+/* This should simplify things tremendously.
 /*
+ * Revision 1.26  1998/01/19 18:40:36  curt
+ * Tons of little changes to clean up the code and to remove fatal errors
+ * when building with the c++ compiler.
+ *
+ * Revision 1.25  1998/01/07 03:31:27  curt
+ * Miscellaneous tweaks.
+ *
+ * Revision 1.24  1997/12/15 23:54:59  curt
+ * Add xgl wrappers for debugging.
+ * Generate terrain normals on the fly.
+ *
+ * Revision 1.23  1997/10/30 12:38:44  curt
+ * Working on new scenery subsystem.
+ *
+ * Revision 1.22  1997/10/28 21:00:21  curt
+ * Changing to new terrain format.
+ *
+ * Revision 1.21  1997/08/27 03:30:27  curt
+ * Changed naming scheme of basic shared structures.
+ *
+ * Revision 1.20  1997/08/19 23:55:08  curt
+ * Worked on better simulating real lighting.
+ *
+ * Revision 1.19  1997/08/06 00:24:28  curt
+ * Working on correct real time sun lighting.
+ *
+ * Revision 1.18  1997/08/02 19:10:14  curt
+ * Incorporated mesh2GL.c into mesh.c
+ *
  * Revision 1.17  1997/07/18 23:41:26  curt
  * Tweaks for building with Cygnus Win32 compiler.
  *