]> git.mxchange.org Git - flightgear.git/blobdiff - Objects/fragment.cxx
Removed an extraneous output message.
[flightgear.git] / Objects / fragment.cxx
index 089ac15bc2bd764b2f42dfce36abaebe52802bf7..2466dfd7690264775f6be7944f764b2f7174f2db 100644 (file)
 
 
 #include <Include/fg_constants.h>
-#include <Include/fg_types.h>
+// #include <Include/fg_types.h>
 #include <Math/mat3.h>
+#include <Math/point3d.hxx>
 #include <Scenery/tile.hxx>
 
 #include "fragment.hxx"
 
 
-// return the sign of a value
-#define FG_SIGN( x )  ((x) < 0 ? -1 : 1)
-
-// return min or max of two values
-#define FG_MIN(A,B)    ((A) < (B) ? (A) :  (B))
-#define FG_MAX(A,B)    ((A) > (B) ? (A) :  (B))
-
-
-fgFACE :: fgFACE () : 
-    n1(0), n2(0), n3(0)
-{
+template <class T>
+inline const int FG_SIGN(const T& x) {
+    return x < T(0) ? -1 : 1;
 }
 
-fgFACE :: ~fgFACE()
-{
+template <class T>
+inline const T& FG_MIN(const T& a, const T& b) {
+    return b < a ? b : a;
 }
 
-fgFACE :: fgFACE( const fgFACE & image ) :
-    n1( image.n1), n2( image.n2), n3( image.n3)
-{
-}
-
-bool fgFACE :: operator < (const fgFACE & rhs )
-{
-    return ( n1 < rhs.n1 ? true : false);
+template <class T>
+inline const T& FG_MAX(const T& a, const T& b) {
+    return  a < b ? b : a;
 }
 
-bool fgFACE :: operator == (const fgFACE & rhs )
+// return the minimum of the three values
+template <class T>
+inline const T& fg_min3( const T& a, const T& b, const T& c)
 {
-    return ((n1 == rhs.n1) && (n2 == rhs.n2) && ( n3 == rhs.n3));
+    return (a > b ? FG_MIN (b, c) : FG_MIN (a, c));
 }
 
 
-// Constructor
-fgFRAGMENT::fgFRAGMENT ( void ) {
+// return the maximum of the three values
+template <class T>
+inline const T& fg_max3 (const T& a, const T& b, const T& c)
+{
+    return (a < b ? FG_MAX (b, c) : FG_MAX (a, c));
 }
 
-
+// Add a face to the face list
 // Copy constructor
-fgFRAGMENT ::   fgFRAGMENT ( const fgFRAGMENT & rhs ) :
+fgFRAGMENT::fgFRAGMENT ( const fgFRAGMENT & rhs ) :
     center         ( rhs.center          ),
     bounding_radius( rhs.bounding_radius ),
     material_ptr   ( rhs.material_ptr    ),
     tile_ptr       ( rhs.tile_ptr        ),
     display_list   ( rhs.display_list    ),
-    faces          ( rhs.faces           ),
-    num_faces      ( rhs.num_faces       )
+    faces          ( rhs.faces           )
 {
 }
 
-fgFRAGMENT & fgFRAGMENT :: operator = ( const fgFRAGMENT & rhs )
+fgFRAGMENT & fgFRAGMENT::operator = ( const fgFRAGMENT & rhs )
 {
     if(!(this == &rhs )) {
        center          = rhs.center;
@@ -94,44 +87,18 @@ fgFRAGMENT & fgFRAGMENT :: operator = ( const fgFRAGMENT & rhs )
 }
 
 
-// Add a face to the face list
-void fgFRAGMENT::add_face(int n1, int n2, int n3) {
-    fgFACE face;
-
-    face.n1 = n1;
-    face.n2 = n2;
-    face.n3 = n3;
-
-    faces.push_back(face);
-    num_faces++;
-}
-
-
-// return the minimum of the three values
-static double fg_min3 (double a, double b, double c)
-{
-    return (a > b ? FG_MIN (b, c) : FG_MIN (a, c));
-}
-
-
-// return the maximum of the three values
-static double fg_max3 (double a, double b, double c)
-{
-  return (a < b ? FG_MAX (b, c) : FG_MAX (a, c));
-}
-
-
 // test if line intesects with this fragment.  p0 and p1 are the two
 // line end points of the line.  If side_flag is true, check to see
 // that end points are on opposite sides of face.  Returns 1 if it
 // intersection found, 0 otherwise.  If it intesects, result is the
 // point of intersection
 
-int fgFRAGMENT::intersect( fgPoint3d *end0, fgPoint3d *end1, int side_flag,
-                          fgPoint3d *result)
+int fgFRAGMENT::intersect( const Point3D& end0,
+                          const Point3D& end1,
+                          int side_flag,
+                          Point3D& result) const
 {
     fgTILE *t;
-    fgFACE face;
     MAT3vec v1, v2, n, center;
     double p1[3], p2[3], p3[3];
     double x, y, z;  // temporary holding spot for result
@@ -141,8 +108,6 @@ int fgFRAGMENT::intersect( fgPoint3d *end0, fgPoint3d *end1, int side_flag,
     double xmin, xmax, ymin, ymax, zmin, zmax;
     double dx, dy, dz, min_dim, x2, y2, x3, y3, rx, ry;
     int side1, side2;
-    list < fgFACE > :: iterator current;
-    list < fgFACE > :: iterator last;
 
     // find the associated tile
     t = tile_ptr;
@@ -150,22 +115,19 @@ int fgFRAGMENT::intersect( fgPoint3d *end0, fgPoint3d *end1, int side_flag,
     // printf("Intersecting\n");
 
     // traverse the face list for this fragment
-    current = faces.begin();
-    last = faces.end();
-    while ( current != last ) {
-       face = *current;
-       current++;
-
+    const_iterator last = faces.end();
+    for ( const_iterator current = faces.begin(); current != last; ++current )
+    {
        // printf(".");
 
        // get face vertex coordinates
-       center[0] = t->center.x;
-       center[1] = t->center.y;
-       center[2] = t->center.z;
+       center[0] = t->center.x();
+       center[1] = t->center.y();
+       center[2] = t->center.z();
 
-       MAT3_ADD_VEC(p1, t->nodes[face.n1], center);
-       MAT3_ADD_VEC(p2, t->nodes[face.n2], center);
-       MAT3_ADD_VEC(p3, t->nodes[face.n3], center);
+       MAT3_ADD_VEC(p1, t->nodes[(*current).n1], center);
+       MAT3_ADD_VEC(p2, t->nodes[(*current).n2], center);
+       MAT3_ADD_VEC(p3, t->nodes[(*current).n3], center);
 
        // printf("point 1 = %.2f %.2f %.2f\n", p1[0], p1[1], p1[2]);
        // printf("point 2 = %.2f %.2f %.2f\n", p2[0], p2[1], p2[2]);
@@ -191,9 +153,9 @@ int fgFRAGMENT::intersect( fgPoint3d *end0, fgPoint3d *end1, int side_flag,
        // printf("p3(d) = %.2f\n", a * p3[0] + b * p3[1] + c * p3[2]);
 
        // calculate the line coefficients for the specified line
-       x0 = end0->x;  x1 = end1->x;
-       y0 = end0->y;  y1 = end1->y;
-       z0 = end0->z;  z1 = end1->z;
+       x0 = end0.x();  x1 = end1.x();
+       y0 = end0.y();  y1 = end1.y();
+       z0 = end0.z();  z1 = end1.z();
 
        if ( fabs(x1 - x0) > FG_EPSILON ) {
            a1 = 1.0 / (x1 - x0);
@@ -240,9 +202,7 @@ int fgFRAGMENT::intersect( fgPoint3d *end0, fgPoint3d *end1, int side_flag,
                // everything is too close together to tell the difference
                // so the current intersection point should work as good
                // as any
-               result->x = x;
-               result->y = y;
-               result->z = z;
+               result = Point3D(x, y, z);
                return(1);
            }
            side1 = FG_SIGN (t1 - t2);
@@ -322,9 +282,7 @@ int fgFRAGMENT::intersect( fgPoint3d *end0, fgPoint3d *end1, int side_flag,
        } else {
            // all dimensions are really small so lets call it close
            // enough and return a successful match
-           result->x = x;
-           result->y = y;
-           result->z = z;
+           result = Point3D(x, y, z);
            return(1);
        }
 
@@ -356,9 +314,7 @@ int fgFRAGMENT::intersect( fgPoint3d *end0, fgPoint3d *end1, int side_flag,
        }
 
        // printf( "intersection point = %.2f %.2f %.2f\n", x, y, z);
-       result->x = x;
-       result->y = y;
-       result->z = z;
+       result = Point3D(x, y, z);
        return(1);
     }
 
@@ -367,44 +323,80 @@ int fgFRAGMENT::intersect( fgPoint3d *end0, fgPoint3d *end1, int side_flag,
     return(0);
 }
 
-
-// Destructor
-fgFRAGMENT::~fgFRAGMENT ( void ) {
-    // Step through the face list deleting the items until the list is
-    // empty
-
-    // printf("destructing a fragment with %d faces\n", faces.size());
-
-    while ( faces.size() ) {
-       //  printf("emptying face list\n");
-       faces.pop_front();
-    }
-}
-
-
-// equality operator
-bool  fgFRAGMENT :: operator == ( const fgFRAGMENT & rhs)
-{
-    if(( center.x - rhs.center.x ) < FG_EPSILON) {
-       if(( center.y - rhs.center.y) < FG_EPSILON) {
-           if(( center.z - rhs.center.z) < FG_EPSILON) {
-               return true;
-           }
-       }
-    }
-    return false;
-}
-
-// comparison operator
-bool  fgFRAGMENT :: operator < ( const fgFRAGMENT &rhs)
-{
-    // This is completely arbitrary. It satisfies RW's STL implementation
-
-    return bounding_radius < rhs.bounding_radius;
-}
-
-
 // $Log$
+// Revision 1.6  1998/10/18 01:17:20  curt
+// Point3D tweaks.
+//
+// Revision 1.5  1998/10/16 00:54:37  curt
+// Converted to Point3D class.
+//
+// Revision 1.4  1998/09/15 01:35:03  curt
+// cleaned up my fragment.num_faces hack :-) to use the STL (no need in
+// duplicating work.)
+// Tweaked fgTileMgrRender() do not calc tile matrix unless necessary.
+// removed some unneeded stuff from fgTileMgrCurElev()
+//
+// Revision 1.3  1998/09/08 21:40:42  curt
+// Updates from Bernie Bright.
+//
+// Revision 1.2  1998/09/01 19:03:07  curt
+// Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
+//  - The new classes in libmisc.tgz define a stream interface into zlib.
+//    I've put these in a new directory, Lib/Misc.  Feel free to rename it
+//    to something more appropriate.  However you'll have to change the
+//    include directives in all the other files.  Additionally you'll have
+//    add the library to Lib/Makefile.am and Simulator/Main/Makefile.am.
+//
+//    The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf
+//    test so I've included the required changes in config.tgz.
+//
+//    There are a fair few changes to Simulator/Objects as I've moved
+//    things around.  Loading tiles is quicker but thats not where the delay
+//    is.  Tile loading takes a few tenths of a second per file on a P200
+//    but it seems to be the post-processing that leads to a noticeable
+//    blip in framerate.  I suppose its time to start profiling to see where
+//    the delays are.
+//
+//    I've included a brief description of each archives contents.
+//
+// Lib/Misc/
+//   zfstream.cxx
+//   zfstream.hxx
+//     C++ stream interface into zlib.
+//     Taken from zlib-1.1.3/contrib/iostream/.
+//     Minor mods for STL compatibility.
+//     There's no copyright associated with these so I assume they're
+//     covered by zlib's.
+//
+//   fgstream.cxx
+//   fgstream.hxx
+//     FlightGear input stream using gz_ifstream.  Tries to open the
+//     given filename.  If that fails then filename is examined and a
+//     ".gz" suffix is removed or appended and that file is opened.
+//
+//   stopwatch.hxx
+//     A simple timer for benchmarking.  Not used in production code.
+//     Taken from the Blitz++ project.  Covered by GPL.
+//
+//   strutils.cxx
+//   strutils.hxx
+//     Some simple string manipulation routines.
+//
+// Simulator/Airports/
+//   Load airports database using fgstream.
+//   Changed fgAIRPORTS to use set<> instead of map<>.
+//   Added bool fgAIRPORTS::search() as a neater way doing the lookup.
+//   Returns true if found.
+//
+// Simulator/Astro/
+//   Modified fgStarsInit() to load stars database using fgstream.
+//
+// Simulator/Objects/
+//   Modified fgObjLoad() to use fgstream.
+//   Modified fgMATERIAL_MGR::load_lib() to use fgstream.
+//   Many changes to fgMATERIAL.
+//   Some changes to fgFRAGMENT but I forget what!
+//
 // Revision 1.1  1998/08/25 16:51:23  curt
 // Moved from ../Scenery
 //