/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.
This commit is contained in:
parent
e641ccb51d
commit
42728f52c2
4 changed files with 249 additions and 147 deletions
|
@ -66,31 +66,22 @@ using namespace std;
|
||||||
class fgTILE;
|
class fgTILE;
|
||||||
class fgMATERIAL;
|
class fgMATERIAL;
|
||||||
|
|
||||||
|
|
||||||
class fgFACE {
|
|
||||||
public:
|
|
||||||
int n1, n2, n3;
|
|
||||||
|
|
||||||
explicit fgFACE( int a = 0, int b =0, int c =0 )
|
|
||||||
: n1(a), n2(b), n3(c) {}
|
|
||||||
|
|
||||||
fgFACE( const fgFACE & image )
|
|
||||||
: n1(image.n1), n2(image.n2), n3(image.n3) {}
|
|
||||||
|
|
||||||
~fgFACE() {}
|
|
||||||
|
|
||||||
bool operator < ( const fgFACE & rhs ) { return n1 < rhs.n1; }
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
operator == ( const fgFACE& lhs, const fgFACE & rhs )
|
|
||||||
{
|
|
||||||
return (lhs.n1 == rhs.n1) && (lhs.n2 == rhs.n2) && (lhs.n3 == rhs.n3);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Object fragment data class
|
// Object fragment data class
|
||||||
class fgFRAGMENT {
|
class fgFRAGMENT {
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct fgFACE {
|
||||||
|
int n1, n2, n3;
|
||||||
|
|
||||||
|
fgFACE( int a = 0, int b =0, int c =0 )
|
||||||
|
: n1(a), n2(b), n3(c) {}
|
||||||
|
|
||||||
|
fgFACE( const fgFACE & image )
|
||||||
|
: n1(image.n1), n2(image.n2), n3(image.n3) {}
|
||||||
|
|
||||||
|
~fgFACE() {}
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// culling data for this object fragment (fine grain culling)
|
// culling data for this object fragment (fine grain culling)
|
||||||
fgPoint3d center;
|
fgPoint3d center;
|
||||||
|
@ -151,7 +142,7 @@ public:
|
||||||
// operators
|
// operators
|
||||||
fgFRAGMENT & operator = ( const fgFRAGMENT & rhs );
|
fgFRAGMENT & operator = ( const fgFRAGMENT & rhs );
|
||||||
|
|
||||||
bool operator < ( const fgFRAGMENT & rhs ) {
|
bool operator < ( const fgFRAGMENT & rhs ) const {
|
||||||
// This is completely arbitrary. It satisfies RW's STL implementation
|
// This is completely arbitrary. It satisfies RW's STL implementation
|
||||||
return bounding_radius < rhs.bounding_radius;
|
return bounding_radius < rhs.bounding_radius;
|
||||||
}
|
}
|
||||||
|
@ -166,6 +157,13 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
operator == ( const fgFRAGMENT::fgFACE& lhs,
|
||||||
|
const fgFRAGMENT::fgFACE& rhs )
|
||||||
|
{
|
||||||
|
return (lhs.n1 == rhs.n1) && (lhs.n2 == rhs.n2) && (lhs.n3 == rhs.n3);
|
||||||
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
operator == ( const fgFRAGMENT & lhs, const fgFRAGMENT & rhs ) {
|
operator == ( const fgFRAGMENT & lhs, const fgFRAGMENT & rhs ) {
|
||||||
return (( lhs.center.x - rhs.center.x ) < FG_EPSILON &&
|
return (( lhs.center.x - rhs.center.x ) < FG_EPSILON &&
|
||||||
|
@ -178,6 +176,33 @@ operator == ( const fgFRAGMENT & lhs, const fgFRAGMENT & rhs ) {
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
// Revision 1.3 1998/09/08 21:40:44 curt
|
// Revision 1.3 1998/09/08 21:40:44 curt
|
||||||
// Updates from Bernie Bright.
|
// Updates from Bernie Bright.
|
||||||
//
|
//
|
||||||
|
|
|
@ -35,20 +35,28 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "Include/fg_stl_config.h"
|
||||||
#include <Debug/fg_debug.h>
|
#include <Debug/fg_debug.h>
|
||||||
#include <Main/options.hxx>
|
#include <Main/options.hxx>
|
||||||
#include <Misc/fgstream.hxx>
|
#include <Misc/fgstream.hxx>
|
||||||
|
#include <Main/views.hxx>
|
||||||
|
#include <Scenery/tile.hxx>
|
||||||
|
|
||||||
#include "material.hxx"
|
#include "material.hxx"
|
||||||
|
#include "fragment.hxx"
|
||||||
#include "texload.h"
|
#include "texload.h"
|
||||||
|
|
||||||
|
|
||||||
// global material management class
|
// global material management class
|
||||||
fgMATERIAL_MGR material_mgr;
|
fgMATERIAL_MGR material_mgr;
|
||||||
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
fgMATERIAL::fgMATERIAL ( void ) {
|
fgMATERIAL::fgMATERIAL ( void )
|
||||||
alpha = 0;
|
: texture_name(""),
|
||||||
|
alpha(0),
|
||||||
|
list_size(0)
|
||||||
|
{
|
||||||
ambient[0] = ambient[1] = ambient[2] = ambient[3] = 0.0;
|
ambient[0] = ambient[1] = ambient[2] = ambient[3] = 0.0;
|
||||||
diffuse[0] = diffuse[1] = diffuse[2] = diffuse[3] = 0.0;
|
diffuse[0] = diffuse[1] = diffuse[2] = diffuse[3] = 0.0;
|
||||||
specular[0] = specular[1] = specular[2] = specular[3] = 0.0;
|
specular[0] = specular[1] = specular[2] = specular[3] = 0.0;
|
||||||
|
@ -60,11 +68,11 @@ int fgMATERIAL::append_sort_list( fgFRAGMENT *object ) {
|
||||||
if ( list_size < FG_MAX_MATERIAL_FRAGS )
|
if ( list_size < FG_MAX_MATERIAL_FRAGS )
|
||||||
{
|
{
|
||||||
list[ list_size++ ] = object;
|
list[ list_size++ ] = object;
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,6 +228,45 @@ fgMATERIAL_MGR::fgMATERIAL_MGR ( void ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
fgMATERIAL::render_fragments()
|
||||||
|
{
|
||||||
|
if ( empty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( current_options.get_textures() )
|
||||||
|
{
|
||||||
|
#ifdef GL_VERSION_1_1
|
||||||
|
xglBindTexture(GL_TEXTURE_2D, texture_id);
|
||||||
|
#elif GL_EXT_texture_object
|
||||||
|
xglBindTextureEXT(GL_TEXTURE_2D, texture_id);
|
||||||
|
#else
|
||||||
|
# error port me
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
xglMaterialfv (GL_FRONT, GL_AMBIENT, ambient);
|
||||||
|
xglMaterialfv (GL_FRONT, GL_DIFFUSE, diffuse);
|
||||||
|
}
|
||||||
|
|
||||||
|
fgTILE* last_tile_ptr = NULL;
|
||||||
|
for ( size_t i = 0; i < list_size; ++i )
|
||||||
|
{
|
||||||
|
fgFRAGMENT* frag_ptr = list[i];
|
||||||
|
current_view.tris_rendered += frag_ptr->num_faces;
|
||||||
|
if ( frag_ptr->tile_ptr != last_tile_ptr )
|
||||||
|
{
|
||||||
|
// new tile, new translate
|
||||||
|
xglLoadMatrixd( frag_ptr->tile_ptr->model_view );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Woohoo!!! We finally get to draw something!
|
||||||
|
// printf(" display_list = %d\n", frag_ptr->display_list);
|
||||||
|
xglCallList( frag_ptr->display_list );
|
||||||
|
last_tile_ptr = frag_ptr->tile_ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Load a library of material properties
|
// Load a library of material properties
|
||||||
int fgMATERIAL_MGR::load_lib ( void ) {
|
int fgMATERIAL_MGR::load_lib ( void ) {
|
||||||
string material_name;
|
string material_name;
|
||||||
|
@ -244,18 +291,19 @@ int fgMATERIAL_MGR::load_lib ( void ) {
|
||||||
in.stream() >> material_name >> token;
|
in.stream() >> material_name >> token;
|
||||||
|
|
||||||
if ( token == '{' ) {
|
if ( token == '{' ) {
|
||||||
cout << "Loading material " << material_name << endl;
|
printf( " Loading material %s\n", material_name.c_str() );
|
||||||
fgMATERIAL m;
|
fgMATERIAL m;
|
||||||
in.stream() >> m;
|
in.stream() >> m;
|
||||||
|
m.load_texture();
|
||||||
material_mgr.material_map[material_name] = m;
|
material_mgr.material_map[material_name] = m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( iterator it = material_map.begin();
|
// iterator last = end();
|
||||||
it != material_map.end(); ++it )
|
// for ( iterator it = begin(); it != last; ++it )
|
||||||
{
|
// {
|
||||||
it->second.load_texture();
|
// (*it).second.load_texture();
|
||||||
}
|
// }
|
||||||
|
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
@ -263,10 +311,10 @@ int fgMATERIAL_MGR::load_lib ( void ) {
|
||||||
|
|
||||||
// Initialize the transient list of fragments for each material property
|
// Initialize the transient list of fragments for each material property
|
||||||
void fgMATERIAL_MGR::init_transient_material_lists( void ) {
|
void fgMATERIAL_MGR::init_transient_material_lists( void ) {
|
||||||
for ( iterator it = material_map.begin();
|
iterator last = end();
|
||||||
it != material_map.end(); ++it )
|
for ( iterator it = begin(); it != last; ++it )
|
||||||
{
|
{
|
||||||
it->second.init_sort_list();
|
(*it).second.init_sort_list();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,9 +322,9 @@ bool
|
||||||
fgMATERIAL_MGR::find( const string& material, fgMATERIAL*& mtl_ptr )
|
fgMATERIAL_MGR::find( const string& material, fgMATERIAL*& mtl_ptr )
|
||||||
{
|
{
|
||||||
iterator it = material_map.find( material );
|
iterator it = material_map.find( material );
|
||||||
if ( it != material_map.end() )
|
if ( it != end() )
|
||||||
{
|
{
|
||||||
mtl_ptr = &(it->second);
|
mtl_ptr = &((*it).second);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +337,44 @@ fgMATERIAL_MGR::~fgMATERIAL_MGR ( void ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
fgMATERIAL_MGR::render_fragments()
|
||||||
|
{
|
||||||
|
current_view.tris_rendered = 0;
|
||||||
|
iterator last = end();
|
||||||
|
for ( iterator current = begin(); current != last; ++current )
|
||||||
|
(*current).second.render_fragments();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.5 1998/09/10 19:07:11 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.
|
||||||
|
//
|
||||||
// Revision 1.4 1998/09/01 19:03:08 curt
|
// Revision 1.4 1998/09/01 19:03:08 curt
|
||||||
// Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
|
// Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
|
||||||
// - The new classes in libmisc.tgz define a stream interface into zlib.
|
// - The new classes in libmisc.tgz define a stream interface into zlib.
|
||||||
|
|
|
@ -63,7 +63,7 @@ class fgFRAGMENT;
|
||||||
// Material property class
|
// Material property class
|
||||||
class fgMATERIAL {
|
class fgMATERIAL {
|
||||||
|
|
||||||
public:
|
private:
|
||||||
// OpenGL texture name
|
// OpenGL texture name
|
||||||
GLuint texture_id;
|
GLuint texture_id;
|
||||||
|
|
||||||
|
@ -80,11 +80,16 @@ public:
|
||||||
// transient list of objects with this material type (used for sorting
|
// transient list of objects with this material type (used for sorting
|
||||||
// by material to reduce GL state changes when rendering the scene
|
// by material to reduce GL state changes when rendering the scene
|
||||||
fgFRAGMENT * list[FG_MAX_MATERIAL_FRAGS];
|
fgFRAGMENT * list[FG_MAX_MATERIAL_FRAGS];
|
||||||
int list_size;
|
size_t list_size;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
fgMATERIAL ( void );
|
fgMATERIAL ( void );
|
||||||
|
|
||||||
|
size_t size() const { return list_size; }
|
||||||
|
bool empty() const { return list_size == 0; }
|
||||||
|
|
||||||
// Sorting routines
|
// Sorting routines
|
||||||
void init_sort_list( void ) {
|
void init_sort_list( void ) {
|
||||||
list_size = 0;
|
list_size = 0;
|
||||||
|
@ -92,10 +97,14 @@ public:
|
||||||
|
|
||||||
int append_sort_list( fgFRAGMENT *object );
|
int append_sort_list( fgFRAGMENT *object );
|
||||||
|
|
||||||
|
void render_fragments();
|
||||||
|
|
||||||
void load_texture();
|
void load_texture();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~fgMATERIAL ( void );
|
~fgMATERIAL ( void );
|
||||||
|
|
||||||
|
friend istream& operator >> ( istream& in, fgMATERIAL& m );
|
||||||
};
|
};
|
||||||
|
|
||||||
istream& operator >> ( istream& in, fgMATERIAL& m );
|
istream& operator >> ( istream& in, fgMATERIAL& m );
|
||||||
|
@ -110,7 +119,11 @@ public:
|
||||||
typedef container::iterator iterator;
|
typedef container::iterator iterator;
|
||||||
typedef container::const_iterator const_iterator;
|
typedef container::const_iterator const_iterator;
|
||||||
|
|
||||||
container material_map;
|
iterator begin() { return material_map.begin(); }
|
||||||
|
const_iterator begin() const { return material_map.begin(); }
|
||||||
|
|
||||||
|
iterator end() { return material_map.end(); }
|
||||||
|
const_iterator end() const { return material_map.end(); }
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
fgMATERIAL_MGR ( void );
|
fgMATERIAL_MGR ( void );
|
||||||
|
@ -123,8 +136,14 @@ public:
|
||||||
|
|
||||||
bool find( const string& material, fgMATERIAL*& mtl_ptr );
|
bool find( const string& material, fgMATERIAL*& mtl_ptr );
|
||||||
|
|
||||||
|
void render_fragments();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~fgMATERIAL_MGR ( void );
|
~fgMATERIAL_MGR ( void );
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
container material_map;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -136,6 +155,33 @@ extern fgMATERIAL_MGR material_mgr;
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.3 1998/09/10 19:07:12 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.
|
||||||
|
//
|
||||||
// Revision 1.2 1998/09/01 19:03:09 curt
|
// Revision 1.2 1998/09/01 19:03:09 curt
|
||||||
// Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
|
// Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
|
||||||
// - The new classes in libmisc.tgz define a stream interface into zlib.
|
// - The new classes in libmisc.tgz define a stream interface into zlib.
|
||||||
|
|
|
@ -266,8 +266,6 @@ static int viewable( fgPoint3d *cp, double radius ) {
|
||||||
|
|
||||||
mat = (double *)(current_view.WORLD_TO_EYE);
|
mat = (double *)(current_view.WORLD_TO_EYE);
|
||||||
|
|
||||||
eye[0] = (x*mat[0] + y*mat[4] + z*mat[8] + mat[12]) * current_view.slope_x;
|
|
||||||
eye[1] = (x*mat[1] + y*mat[5] + z*mat[9] + mat[13]) * current_view.slope_y;
|
|
||||||
eye[2] = x*mat[2] + y*mat[6] + z*mat[10] + mat[14];
|
eye[2] = x*mat[2] + y*mat[6] + z*mat[10] + mat[14];
|
||||||
|
|
||||||
// Check near and far clip plane
|
// Check near and far clip plane
|
||||||
|
@ -277,6 +275,8 @@ static int viewable( fgPoint3d *cp, double radius ) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eye[0] = (x*mat[0] + y*mat[4] + z*mat[8] + mat[12]) * current_view.slope_x;
|
||||||
|
|
||||||
// check right and left clip plane (from eye perspective)
|
// check right and left clip plane (from eye perspective)
|
||||||
x1 = radius * current_view.fov_x_clip;
|
x1 = radius * current_view.fov_x_clip;
|
||||||
if( (eye[2] > -(eye[0]+x1)) || (eye[2] > (eye[0]-x1)) )
|
if( (eye[2] > -(eye[0]+x1)) || (eye[2] > (eye[0]-x1)) )
|
||||||
|
@ -284,6 +284,8 @@ static int viewable( fgPoint3d *cp, double radius ) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eye[1] = (x*mat[1] + y*mat[5] + z*mat[9] + mat[13]) * current_view.slope_y;
|
||||||
|
|
||||||
// check bottom and top clip plane (from eye perspective)
|
// check bottom and top clip plane (from eye perspective)
|
||||||
y1 = radius * current_view.fov_y_clip;
|
y1 = radius * current_view.fov_y_clip;
|
||||||
if( (eye[2] > -(eye[1]+y1)) || (eye[2] > (eye[1]-y1)) )
|
if( (eye[2] > -(eye[1]+y1)) || (eye[2] > (eye[1]-y1)) )
|
||||||
|
@ -302,12 +304,17 @@ static int viewable( fgPoint3d *cp, double radius ) {
|
||||||
v = ¤t_view;
|
v = ¤t_view;
|
||||||
|
|
||||||
MAT3_SET_HVEC(world, cp->x, cp->y, cp->z, 1.0);
|
MAT3_SET_HVEC(world, cp->x, cp->y, cp->z, 1.0);
|
||||||
MAT3mult_vec(eye, world, v->WORLD_TO_EYE);
|
// MAT3mult_vec(eye, world, v->WORLD_TO_EYE);
|
||||||
// printf( "\nworld -> eye = %.2f %.2f %.2f radius = %.2f\n",
|
// printf( "\nworld -> eye = %.2f %.2f %.2f radius = %.2f\n",
|
||||||
// eye[0], eye[1], eye[2], radius);
|
// eye[0], eye[1], eye[2], radius);
|
||||||
|
|
||||||
|
// Use lazy evaluation for calculating eye hvec.
|
||||||
|
#define vec world
|
||||||
|
#define mat v->WORLD_TO_EYE
|
||||||
|
eye[2] = vec[0]*mat[0][2]+vec[1]*mat[1][2]+vec[2]*mat[2][2]+mat[3][2];
|
||||||
|
|
||||||
// Check near clip plane
|
// Check near clip plane
|
||||||
if ( eye[2] - radius > 0.0 ) {
|
if ( eye[2] > radius ) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,58 +328,32 @@ static int viewable( fgPoint3d *cp, double radius ) {
|
||||||
x1 = v->cos_fov_x * radius;
|
x1 = v->cos_fov_x * radius;
|
||||||
y1 = v->sin_fov_x * radius;
|
y1 = v->sin_fov_x * radius;
|
||||||
slope = v->slope_x;
|
slope = v->slope_x;
|
||||||
x0 = x1 - y1 / slope;
|
eye[0] = vec[0]*mat[0][0]+vec[1]*mat[1][0]+vec[2]*mat[2][0]+mat[3][0];
|
||||||
|
|
||||||
// printf("(r) x1 = %.2f y1 = %.2f\n", x1, y1);
|
if ( eye[2] > ((slope * (eye[0] - x1)) + y1) ) {
|
||||||
// printf("eye[0] = %.2f eye[2] = %.2f\n", eye[0], eye[2]);
|
return( false );
|
||||||
// printf("(r) x0 = %.2f slope_x = %.2f radius = %.2f\n",
|
|
||||||
// x0, slope, radius);
|
|
||||||
|
|
||||||
if ( eye[2] > slope * (eye[0] - x0) ) {
|
|
||||||
return(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check left clip plane (from eye perspective)
|
// check left clip plane (from eye perspective)
|
||||||
x1 = -x1;
|
if ( eye[2] > -((slope * (eye[0] + x1)) - y1) ) {
|
||||||
slope = -slope;
|
return( false );
|
||||||
x0 = x1 - y1 / slope;
|
|
||||||
|
|
||||||
// printf("(r) x1 = %.2f y1 = %.2f\n", x1, y1);
|
|
||||||
// printf("eye[0] = %.2f eye[2] = %.2f\n", eye[0], eye[2]);
|
|
||||||
// printf("(r) x0 = %.2f slope_x = %.2f radius = %.2f\n",
|
|
||||||
// x0, slope, radius);
|
|
||||||
|
|
||||||
if ( eye[2] > slope * (eye[0] - x0) ) {
|
|
||||||
return(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check bottom clip plane (from eye perspective)
|
// check bottom clip plane (from eye perspective)
|
||||||
x1 = -(v->cos_fov_y) * radius;
|
x1 = -(v->cos_fov_y) * radius;
|
||||||
y1 = v->sin_fov_y * radius;
|
y1 = v->sin_fov_y * radius;
|
||||||
slope = v->slope_y;
|
slope = v->slope_y;
|
||||||
x0 = x1 - y1 / slope;
|
eye[1] = vec[0]*mat[0][1]+vec[1]*mat[1][1]+vec[2]*mat[2][1]+mat[3][1];
|
||||||
|
#undef vec
|
||||||
|
#undef mat
|
||||||
|
|
||||||
// printf("(r) x1 = %.2f y1 = %.2f\n", x1, y1);
|
if ( eye[2] > ((slope * (eye[1] - x1)) + y1) ) {
|
||||||
// printf("eye[1] = %.2f eye[2] = %.2f\n", eye[1], eye[2]);
|
return( false );
|
||||||
// printf("(r) x0 = %.2f slope_y = %.2f radius = %.2f\n",
|
|
||||||
// x0, slope, radius);
|
|
||||||
|
|
||||||
if ( eye[2] > slope * (eye[1] - x0) ) {
|
|
||||||
return(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check top clip plane (from eye perspective)
|
// check top clip plane (from eye perspective)
|
||||||
x1 = -x1;
|
if ( eye[2] > -((slope * (eye[1] + x1)) - y1) ) {
|
||||||
slope = -slope;
|
return( false );
|
||||||
x0 = x1 - y1 / slope;
|
|
||||||
|
|
||||||
// printf("(r) x1 = %.2f y1 = %.2f\n", x1, y1);
|
|
||||||
// printf("eye[1] = %.2f eye[2] = %.2f\n", eye[1], eye[2]);
|
|
||||||
// printf("(r) x0 = %.2f slope_y = %.2f radius = %.2f\n",
|
|
||||||
// x0, slope, radius);
|
|
||||||
|
|
||||||
if ( eye[2] > slope * (eye[1] - x0) ) {
|
|
||||||
return(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // defined( USE_FAST_FOV_CLIP )
|
#endif // defined( USE_FAST_FOV_CLIP )
|
||||||
|
@ -669,10 +650,7 @@ void fgTileMgrRender( void ) {
|
||||||
|
|
||||||
mtl_ptr = frag_ptr->material_ptr;
|
mtl_ptr = frag_ptr->material_ptr;
|
||||||
// printf(" lookup = %s\n", mtl_ptr->texture_name);
|
// printf(" lookup = %s\n", mtl_ptr->texture_name);
|
||||||
if ( mtl_ptr->list_size < FG_MAX_MATERIAL_FRAGS ) {
|
if ( ! mtl_ptr->append_sort_list( frag_ptr ) ) {
|
||||||
mtl_ptr->list[mtl_ptr->list_size] = frag_ptr;
|
|
||||||
(mtl_ptr->list_size)++;
|
|
||||||
} else {
|
|
||||||
fgPrintf( FG_TERRAIN, FG_ALERT,
|
fgPrintf( FG_TERRAIN, FG_ALERT,
|
||||||
"Overran material sorting array\n" );
|
"Overran material sorting array\n" );
|
||||||
}
|
}
|
||||||
|
@ -705,72 +683,40 @@ void fgTileMgrRender( void ) {
|
||||||
// Pass 2
|
// Pass 2
|
||||||
// traverse the transient per-material fragment lists and render
|
// traverse the transient per-material fragment lists and render
|
||||||
// out all fragments for each material property.
|
// out all fragments for each material property.
|
||||||
map < string, fgMATERIAL, less<string> > :: iterator mapcurrent =
|
|
||||||
material_mgr.material_map.begin();
|
|
||||||
map < string, fgMATERIAL, less<string> > :: iterator maplast =
|
|
||||||
material_mgr.material_map.end();
|
|
||||||
|
|
||||||
xglPushMatrix();
|
xglPushMatrix();
|
||||||
|
material_mgr.render_fragments();
|
||||||
for ( ; mapcurrent != maplast; ++mapcurrent ) {
|
|
||||||
// (char *)key = (*mapcurrent).first;
|
|
||||||
// (fgMATERIAL)value = (*mapcurrent).second;
|
|
||||||
mtl_ptr = &(*mapcurrent).second;
|
|
||||||
|
|
||||||
last_tile_ptr = NULL;
|
|
||||||
|
|
||||||
size = mtl_ptr->list_size;
|
|
||||||
if ( size > 0 ) {
|
|
||||||
if ( textures ) {
|
|
||||||
#ifdef GL_VERSION_1_1
|
|
||||||
xglBindTexture(GL_TEXTURE_2D, mtl_ptr->texture_id);
|
|
||||||
#elif GL_EXT_texture_object
|
|
||||||
xglBindTextureEXT(GL_TEXTURE_2D, mtl_ptr->texture_id);
|
|
||||||
#else
|
|
||||||
# error port me
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
xglMaterialfv (GL_FRONT, GL_AMBIENT, mtl_ptr->ambient);
|
|
||||||
xglMaterialfv (GL_FRONT, GL_DIFFUSE, mtl_ptr->diffuse);
|
|
||||||
}
|
|
||||||
|
|
||||||
// printf("traversing = %s, size = %d\n",
|
|
||||||
// mtl_ptr->texture_name, size);
|
|
||||||
for ( i = 0; i < size; i++ ) {
|
|
||||||
frag_ptr = mtl_ptr->list[i];
|
|
||||||
|
|
||||||
// count up the number of polygons we are drawing in
|
|
||||||
// case someone is interested.
|
|
||||||
total_faces += frag_ptr->num_faces;
|
|
||||||
|
|
||||||
if ( frag_ptr->tile_ptr == last_tile_ptr ) {
|
|
||||||
// same tile as last time, no transform necessary
|
|
||||||
} else {
|
|
||||||
// new tile, new translate
|
|
||||||
// xglLoadMatrixf( frag_ptr->matrix );
|
|
||||||
t = frag_ptr->tile_ptr;
|
|
||||||
xglLoadMatrixd(t->model_view );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Woohoo!!! We finally get to draw something!
|
|
||||||
// printf(" display_list = %d\n", frag_ptr->display_list);
|
|
||||||
xglCallList(frag_ptr->display_list);
|
|
||||||
|
|
||||||
last_tile_ptr = frag_ptr->tile_ptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
xglPopMatrix();
|
xglPopMatrix();
|
||||||
|
|
||||||
v->tris_rendered = total_faces;
|
|
||||||
|
|
||||||
fgPrintf( FG_TERRAIN, FG_DEBUG, "Rendered %d polygons this frame.\n",
|
|
||||||
total_faces);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.35 1998/09/10 19:07:16 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.
|
||||||
|
//
|
||||||
// Revision 1.34 1998/09/09 20:58:09 curt
|
// Revision 1.34 1998/09/09 20:58:09 curt
|
||||||
// Tweaks to loop constructs with STL usage.
|
// Tweaks to loop constructs with STL usage.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue