1998-05-23 14:09:20 +00:00
|
|
|
// tile.hxx -- routines to handle a scenery tile
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started May 1998.
|
|
|
|
//
|
|
|
|
// Copyright (C) 1998 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$
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _TILE_HXX
|
|
|
|
#define _TILE_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>
|
|
|
|
|
1999-02-26 22:08:34 +00:00
|
|
|
#include <Include/compiler.h>
|
1998-06-12 00:55:58 +00:00
|
|
|
|
1999-02-26 22:08:34 +00:00
|
|
|
#include <vector>
|
|
|
|
#include STL_STRING
|
1998-05-23 14:09:20 +00:00
|
|
|
|
1999-03-25 19:03:24 +00:00
|
|
|
#include <Bucket/newbucket.hxx>
|
1998-07-12 03:18:27 +00:00
|
|
|
#include <Math/mat3.h>
|
1998-10-16 00:51:46 +00:00
|
|
|
#include <Math/point3d.hxx>
|
1998-08-25 16:52:38 +00:00
|
|
|
#include <Objects/fragment.hxx>
|
1998-07-12 03:18:27 +00:00
|
|
|
|
1999-02-26 22:08:34 +00:00
|
|
|
#ifdef FG_HAVE_NATIVE_SGI_COMPILERS
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
1998-07-12 03:18:27 +00:00
|
|
|
|
1999-03-25 19:03:24 +00:00
|
|
|
FG_USING_STD(string);
|
|
|
|
FG_USING_STD(vector);
|
|
|
|
|
|
|
|
|
1998-05-23 14:09:20 +00:00
|
|
|
// Scenery tile class
|
|
|
|
class fgTILE {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
1998-11-09 23:40:46 +00:00
|
|
|
typedef vector < fgFRAGMENT > container;
|
|
|
|
typedef container::iterator FragmentIterator;
|
|
|
|
typedef container::const_iterator FragmentConstIterator;
|
|
|
|
|
|
|
|
public:
|
1998-07-12 03:18:27 +00:00
|
|
|
// node list (the per fragment face lists reference this node list)
|
|
|
|
double (*nodes)[3];
|
|
|
|
int ncount;
|
|
|
|
|
1998-05-23 14:09:20 +00:00
|
|
|
// culling data for whole tile (course grain culling)
|
1998-10-16 00:51:46 +00:00
|
|
|
Point3D center;
|
1998-05-23 14:09:20 +00:00
|
|
|
double bounding_radius;
|
1998-10-16 00:51:46 +00:00
|
|
|
Point3D offset;
|
1998-07-04 00:54:28 +00:00
|
|
|
GLdouble model_view[16];
|
1998-05-23 14:09:20 +00:00
|
|
|
|
|
|
|
// this tile's official location in the world
|
1999-03-25 19:03:24 +00:00
|
|
|
FGBucket tile_bucket;
|
1998-05-23 14:09:20 +00:00
|
|
|
|
|
|
|
// the tile cache will mark here if the tile is being used
|
1998-11-09 23:40:46 +00:00
|
|
|
bool used;
|
|
|
|
|
|
|
|
container fragment_list;
|
1998-05-23 14:09:20 +00:00
|
|
|
|
1998-11-09 23:40:46 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
FragmentIterator begin() { return fragment_list.begin(); }
|
|
|
|
FragmentConstIterator begin() const { return fragment_list.begin(); }
|
|
|
|
|
|
|
|
FragmentIterator end() { return fragment_list.end(); }
|
|
|
|
FragmentConstIterator end() const { return fragment_list.end(); }
|
|
|
|
|
|
|
|
void add_fragment( fgFRAGMENT& frag ) {
|
|
|
|
frag.tile_ptr = this;
|
|
|
|
fragment_list.push_back( frag );
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
size_t num_fragments() const {
|
|
|
|
return fragment_list.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step through the fragment list, deleting the display list, then
|
|
|
|
// the fragment, until the list is empty.
|
|
|
|
void release_fragments();
|
|
|
|
|
|
|
|
// int ObjLoad( const string& path, const fgBUCKET& p );
|
1998-05-23 14:09:20 +00:00
|
|
|
|
|
|
|
// Constructor
|
|
|
|
fgTILE ( void );
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
~fgTILE ( void );
|
1998-09-17 18:35:52 +00:00
|
|
|
|
|
|
|
// Calculate this tile's offset
|
1998-11-09 23:40:46 +00:00
|
|
|
void SetOffset( const Point3D& off)
|
1998-09-17 18:35:52 +00:00
|
|
|
{
|
1998-10-16 00:51:46 +00:00
|
|
|
offset = center - off;
|
1998-09-17 18:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate the model_view transformation matrix for this tile
|
|
|
|
inline void
|
1998-11-09 23:40:46 +00:00
|
|
|
UpdateViewMatrix(GLdouble *MODEL_VIEW)
|
1998-09-17 18:35:52 +00:00
|
|
|
{
|
|
|
|
|
1998-12-03 01:18:16 +00:00
|
|
|
#if defined( USE_MEM ) || defined( WIN32 )
|
1998-09-17 18:35:52 +00:00
|
|
|
memcpy( model_view, MODEL_VIEW, 16*sizeof(GLdouble) );
|
1998-12-03 01:18:16 +00:00
|
|
|
#else
|
1998-09-17 18:35:52 +00:00
|
|
|
bcopy( MODEL_VIEW, model_view, 16*sizeof(GLdouble) );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// This is equivalent to doing a glTranslatef(x, y, z);
|
1998-11-09 23:40:46 +00:00
|
|
|
model_view[12] += (model_view[0]*offset.x() +
|
|
|
|
model_view[4]*offset.y() +
|
1998-10-16 00:51:46 +00:00
|
|
|
model_view[8]*offset.z());
|
1998-11-09 23:40:46 +00:00
|
|
|
model_view[13] += (model_view[1]*offset.x() +
|
|
|
|
model_view[5]*offset.y() +
|
1998-10-16 00:51:46 +00:00
|
|
|
model_view[9]*offset.z());
|
1998-11-09 23:40:46 +00:00
|
|
|
model_view[14] += (model_view[2]*offset.x() +
|
|
|
|
model_view[6]*offset.y() +
|
1998-10-16 00:51:46 +00:00
|
|
|
model_view[10]*offset.z() );
|
1998-09-17 18:35:52 +00:00
|
|
|
// m[15] += (m[3]*x + m[7]*y + m[11]*z);
|
|
|
|
// m[3] m7[] m[11] are 0.0 see LookAt() in views.cxx
|
|
|
|
// so m[15] is unchanged
|
|
|
|
}
|
|
|
|
|
1998-11-09 23:40:46 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
// not defined
|
|
|
|
fgTILE( const fgTILE& );
|
|
|
|
fgTILE& operator = ( const fgTILE& );
|
1998-05-23 14:09:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _TILE_HXX
|
|
|
|
|
|
|
|
|