1998-08-25 16:51:22 +00:00
|
|
|
// fragment.hxx -- routines to handle "atomic" display objects
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started August 1998.
|
|
|
|
//
|
|
|
|
// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
|
|
|
|
//
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _FRAGMENT_HXX
|
|
|
|
#define _FRAGMENT_HXX
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
# error This library requires C++
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_WINDOWS_H
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <GL/glut.h>
|
|
|
|
#include <XGL/xgl.h>
|
|
|
|
|
|
|
|
#if defined ( __sun__ )
|
|
|
|
extern "C" void *memmove(void *, const void *, size_t);
|
|
|
|
extern "C" void *memset(void *, int, size_t);
|
|
|
|
#endif
|
|
|
|
|
1998-09-08 21:40:42 +00:00
|
|
|
#include <vector>
|
1998-08-25 16:51:22 +00:00
|
|
|
|
|
|
|
#include <Bucket/bucketutils.h>
|
1998-10-16 00:51:46 +00:00
|
|
|
// #include <Include/fg_types.h>
|
1998-09-01 19:02:53 +00:00
|
|
|
#include "Include/fg_constants.h"
|
1998-08-25 16:51:22 +00:00
|
|
|
#include <Math/mat3.h>
|
1998-10-16 00:51:46 +00:00
|
|
|
#include <Math/point3d.hxx>
|
1998-08-25 16:51:22 +00:00
|
|
|
|
|
|
|
#ifdef NEEDNAMESPACESTD
|
|
|
|
using namespace std;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Maximum nodes per tile
|
|
|
|
#define MAX_NODES 2000
|
|
|
|
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
class fgTILE;
|
|
|
|
class fgMATERIAL;
|
|
|
|
|
1998-09-10 19:07:09 +00:00
|
|
|
// Object fragment data class
|
|
|
|
class fgFRAGMENT {
|
1998-08-25 16:51:22 +00:00
|
|
|
|
1998-09-10 19:07:09 +00:00
|
|
|
private:
|
|
|
|
struct fgFACE {
|
|
|
|
int n1, n2, n3;
|
1998-09-01 19:02:53 +00:00
|
|
|
|
1998-09-10 19:07:09 +00:00
|
|
|
fgFACE( int a = 0, int b =0, int c =0 )
|
|
|
|
: n1(a), n2(b), n3(c) {}
|
1998-09-01 19:02:53 +00:00
|
|
|
|
1998-09-10 19:07:09 +00:00
|
|
|
fgFACE( const fgFACE & image )
|
|
|
|
: n1(image.n1), n2(image.n2), n3(image.n3) {}
|
1998-08-25 16:51:22 +00:00
|
|
|
|
1998-09-10 19:07:09 +00:00
|
|
|
~fgFACE() {}
|
|
|
|
};
|
1998-08-25 16:51:22 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// culling data for this object fragment (fine grain culling)
|
1998-10-16 00:51:46 +00:00
|
|
|
Point3D center;
|
1998-08-25 16:51:22 +00:00
|
|
|
double bounding_radius;
|
|
|
|
|
|
|
|
// variable offset data for this object fragment for this frame
|
|
|
|
// fgCartesianPoint3d tile_offset;
|
|
|
|
|
|
|
|
// saved transformation matrix for this fragment (used by renderer)
|
|
|
|
// GLfloat matrix[16];
|
|
|
|
|
|
|
|
// tile_ptr & material_ptr are set so that when we traverse the
|
|
|
|
// list of fragments we can quickly reference back the tile or
|
|
|
|
// material property this fragment is assigned to.
|
|
|
|
|
|
|
|
// material property pointer
|
|
|
|
fgMATERIAL *material_ptr;
|
|
|
|
|
|
|
|
// tile pointer
|
|
|
|
fgTILE *tile_ptr;
|
|
|
|
|
|
|
|
// OpenGL display list for fragment data
|
|
|
|
GLint display_list;
|
|
|
|
|
|
|
|
// face list (this indexes into the master tile vertex list)
|
1998-09-08 21:40:42 +00:00
|
|
|
typedef vector < fgFACE > container;
|
1998-09-01 19:02:53 +00:00
|
|
|
typedef container::iterator iterator;
|
|
|
|
typedef container::const_iterator const_iterator;
|
|
|
|
|
|
|
|
container faces;
|
1998-08-25 16:51:22 +00:00
|
|
|
|
|
|
|
// number of faces in this fragment
|
1998-09-15 01:35:03 +00:00
|
|
|
int num_faces() {
|
|
|
|
return faces.size();
|
|
|
|
}
|
1998-08-25 16:51:22 +00:00
|
|
|
|
|
|
|
// Add a face to the face list
|
1998-09-01 19:02:53 +00:00
|
|
|
void add_face(int n1, int n2, int n3) {
|
|
|
|
faces.push_back( fgFACE(n1,n2,n3) );
|
|
|
|
}
|
1998-08-25 16:51:22 +00:00
|
|
|
|
|
|
|
// 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
|
1998-10-16 00:51:46 +00:00
|
|
|
int intersect( const Point3D& end0,
|
|
|
|
const Point3D& end1,
|
1998-09-01 19:02:53 +00:00
|
|
|
int side_flag,
|
1998-10-16 00:51:46 +00:00
|
|
|
Point3D& result) const;
|
1998-08-25 16:51:22 +00:00
|
|
|
|
|
|
|
// Constructors
|
1998-09-15 01:35:03 +00:00
|
|
|
fgFRAGMENT () { /*faces.reserve(512);*/}
|
1998-08-25 16:51:22 +00:00
|
|
|
fgFRAGMENT ( const fgFRAGMENT &image );
|
|
|
|
|
|
|
|
// Destructor
|
1998-09-01 19:02:53 +00:00
|
|
|
~fgFRAGMENT() { faces.erase( faces.begin(), faces.end() ); }
|
1998-08-25 16:51:22 +00:00
|
|
|
|
|
|
|
// operators
|
|
|
|
fgFRAGMENT & operator = ( const fgFRAGMENT & rhs );
|
1998-09-01 19:02:53 +00:00
|
|
|
|
1998-09-10 19:07:09 +00:00
|
|
|
bool operator < ( const fgFRAGMENT & rhs ) const {
|
1998-09-01 19:02:53 +00:00
|
|
|
// This is completely arbitrary. It satisfies RW's STL implementation
|
|
|
|
return bounding_radius < rhs.bounding_radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
faces.erase( faces.begin(), faces.end() );
|
|
|
|
}
|
|
|
|
|
1998-09-08 21:40:42 +00:00
|
|
|
int deleteDisplayList() {
|
|
|
|
xglDeleteLists( display_list, 1 ); return 0;
|
1998-09-01 19:02:53 +00:00
|
|
|
}
|
1998-08-25 16:51:22 +00:00
|
|
|
};
|
|
|
|
|
1998-09-10 19:07:09 +00:00
|
|
|
inline bool
|
|
|
|
operator == ( const fgFRAGMENT::fgFACE& lhs,
|
|
|
|
const fgFRAGMENT::fgFACE& rhs )
|
|
|
|
{
|
|
|
|
return (lhs.n1 == rhs.n1) && (lhs.n2 == rhs.n2) && (lhs.n3 == rhs.n3);
|
|
|
|
}
|
|
|
|
|
1998-09-01 19:02:53 +00:00
|
|
|
inline bool
|
|
|
|
operator == ( const fgFRAGMENT & lhs, const fgFRAGMENT & rhs ) {
|
1998-10-16 00:51:46 +00:00
|
|
|
return lhs.center == rhs.center;
|
1998-09-01 19:02:53 +00:00
|
|
|
}
|
|
|
|
|
1998-08-25 16:51:22 +00:00
|
|
|
|
|
|
|
#endif // _FRAGMENT_HXX
|
|
|
|
|
|
|
|
|
|
|
|
// $Log$
|
1998-10-16 00:51:46 +00:00
|
|
|
// Revision 1.6 1998/10/16 00:54:38 curt
|
|
|
|
// Converted to Point3D class.
|
|
|
|
//
|
1998-09-15 01:35:03 +00:00
|
|
|
// Revision 1.5 1998/09/15 01:35:04 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()
|
|
|
|
//
|
1998-09-10 19:07:09 +00:00
|
|
|
// Revision 1.4 1998/09/10 19:07:09 curt
|
|
|
|
// /Simulator/Objects/fragment.hxx
|
|
|
|
// Nested fgFACE inside fgFRAGMENT since its not used anywhere else.
|
|
|
|
//
|
|
|
|
// ./Simulator/Objects/material.cxx
|
|
|
|
// ./Simulator/Objects/material.hxx
|
|
|
|
// Made fgMATERIAL and fgMATERIAL_MGR bona fide classes with private
|
|
|
|
// data members - that should keep the rabble happy :)
|
|
|
|
//
|
|
|
|
// ./Simulator/Scenery/tilemgr.cxx
|
|
|
|
// In viewable() delay evaluation of eye[0] and eye[1] in until they're
|
|
|
|
// actually needed.
|
|
|
|
// Change to fgTileMgrRender() to call fgMATERIAL_MGR::render_fragments()
|
|
|
|
// method.
|
|
|
|
//
|
|
|
|
// ./Include/fg_stl_config.h
|
|
|
|
// ./Include/auto_ptr.hxx
|
|
|
|
// Added support for g++ 2.7.
|
|
|
|
// Further changes to other files are forthcoming.
|
|
|
|
//
|
|
|
|
// Brief summary of changes required for g++ 2.7.
|
|
|
|
// operator->() not supported by iterators: use (*i).x instead of i->x
|
|
|
|
// default template arguments not supported,
|
|
|
|
// <functional> doesn't have mem_fun_ref() needed by callbacks.
|
|
|
|
// some std include files have different names.
|
|
|
|
// template member functions not supported.
|
|
|
|
//
|
1998-09-08 21:40:42 +00:00
|
|
|
// Revision 1.3 1998/09/08 21:40:44 curt
|
|
|
|
// Updates from Bernie Bright.
|
|
|
|
//
|
1998-09-01 19:02:53 +00:00
|
|
|
// Revision 1.2 1998/09/01 19:03:08 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!
|
|
|
|
//
|
1998-08-25 16:51:22 +00:00
|
|
|
// Revision 1.1 1998/08/25 16:51:23 curt
|
|
|
|
// Moved from ../Scenery
|
|
|
|
//
|
|
|
|
//
|