Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Mesh3DS Class Reference

#include <3dsmesh.h>

Inheritance diagram for Mesh3DS:

Inheritance graph
Collaboration diagram for Mesh3DS:

Collaboration graph
List of all members.

Public Member Functions

 Mesh3DS (const M3DScene &scene, const std::string &texturePath)
void normalize (const Vec3f &centerOffset)
bool pick (const Ray3d &ray, double &distance)
void render (unsigned int attributes, const Frustum &, float lod)
void render (unsigned int attributes, float lod)
void render (float lod)
 ~Mesh3DS ()

Private Types

typedef std::vector< VertexList * > VertexListVec

Private Attributes

VertexListVec vertexLists

Member Typedef Documentation

typedef std::vector<VertexList*> Mesh3DS::VertexListVec [private]
 

Definition at line 33 of file 3dsmesh.h.


Constructor & Destructor Documentation

Mesh3DS::Mesh3DS const M3DScene scene,
const std::string texturePath
 

Definition at line 55 of file 3dsmesh.cpp.

References compareVertexLists(), convertToVertexList(), M3DModel::getTriMesh(), and vertexLists.

00056 {
00057     for (unsigned int i = 0; i < scene.getModelCount(); i++)
00058     {
00059         M3DModel* model = scene.getModel(i);
00060         if (model != NULL)
00061         {
00062             for (unsigned int j = 0; j < model->getTriMeshCount(); j++)
00063             {
00064                 M3DTriangleMesh* mesh = model->getTriMesh(j);
00065                 if (mesh != NULL)
00066                 {
00067                     vertexLists.insert(vertexLists.end(),
00068                                        convertToVertexList(*mesh, scene, texturePath));
00069                 }
00070             }
00071         }
00072     }
00073 
00074     // Sort the vertex lists to make sure that the transparent ones are
00075     // rendered after the opaque ones and material state changes are minimized.
00076     sort(vertexLists.begin(), vertexLists.end(), compareVertexLists);
00077 }

Mesh3DS::~Mesh3DS  ) 
 

Definition at line 80 of file 3dsmesh.cpp.

References vertexLists.

00081 {
00082     for (VertexListVec::iterator i = vertexLists.begin(); i != vertexLists.end(); i++)
00083         if (*i != NULL)
00084             delete *i;
00085 }


Member Function Documentation

void Mesh3DS::normalize const Vec3f centerOffset  ) 
 

Definition at line 216 of file 3dsmesh.cpp.

References AxisAlignedBox::getCenter(), AxisAlignedBox::getExtents(), AxisAlignedBox::include(), vertexLists, Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z.

00217 {
00218     AxisAlignedBox bbox;
00219 
00220     VertexListVec::iterator i;
00221     for (i = vertexLists.begin(); i != vertexLists.end(); i++)
00222         bbox.include((*i)->getBoundingBox());
00223 
00224     Point3f center = bbox.getCenter() + centerOffset;
00225     Vec3f extents = bbox.getExtents();
00226     float maxExtent = extents.x;
00227     if (extents.y > maxExtent)
00228         maxExtent = extents.y;
00229     if (extents.z > maxExtent)
00230         maxExtent = extents.z;
00231 
00232     for (i = vertexLists.begin(); i != vertexLists.end(); i++)
00233         (*i)->transform(Point3f(0, 0, 0) - center, 2.0f / maxExtent);
00234 }

bool Mesh3DS::pick const Ray3d ray,
double &  distance
 

Definition at line 189 of file 3dsmesh.cpp.

References distance(), and vertexLists.

00190 {
00191     double maxDistance = 1.0e30;
00192     double closest = maxDistance;
00193 
00194     for (VertexListVec::const_iterator iter = vertexLists.begin();
00195          iter != vertexLists.end(); iter++)
00196     {
00197         double d = maxDistance;
00198         if ((*iter)->pick(r, d) && d < closest)
00199             closest = d;
00200     }    
00201 
00202     if (closest != maxDistance)
00203     {
00204         distance = closest;
00205         return true;
00206     }
00207     else
00208     {
00209         return false;
00210     }
00211 }

void Mesh3DS::render unsigned int  attributes,
const Frustum ,
float  lod
 

Definition at line 183 of file 3dsmesh.cpp.

References render().

00184 {
00185     render(attributes, lod);
00186 }

void Mesh3DS::render unsigned int  attributes,
float  lod
 

Definition at line 94 of file 3dsmesh.cpp.

References Texture::bind(), Color::blue(), ResourceManager< T >::find(), GetTextureManager(), Color::green(), InvalidResource, vp::parameter(), Color::red(), and vertexLists.

00095 {
00096     TextureManager* textureManager = GetTextureManager();
00097     ResourceHandle currentTexture = InvalidResource;
00098     bool specularOn = false;
00099     bool blendOn = false;
00100     Color black(0.0f, 0.0f, 0.0f);
00101 
00102     int count = 0;
00103     for (VertexListVec::iterator i = vertexLists.begin(); i != vertexLists.end(); i++)
00104     {
00105         // Don't mess with the material, texture, blend function, etc. if the
00106         // multipass attribute is set--when the multipass flag is on, all this
00107         // state will have been set up by the caller in order to produce some
00108         // effect (e.g. shadows).
00109         if ((attributes & Multipass) == 0)
00110         {
00111             // Ugly hack to set the diffuse color parameters when vertex
00112             // programs are enabled.
00113             if (attributes & VertexProgParams)
00114                 vp::parameter(20, (*i)->getDiffuseColor());
00115 
00116             // All the vertex lists should have been sorted so that the
00117             // transparent ones are after the opaque ones.  Thus we can assume
00118             // that once we find a transparent vertext list, it's ok to leave
00119             // blending on.
00120             if (!blendOn && (*i)->getDiffuseColor().alpha() <= 254.0f / 255.0f)
00121             {
00122                 glEnable(GL_BLEND);
00123                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00124             }
00125 
00126             Color specular = (*i)->getSpecularColor();
00127             float shininess = (*i)->getShininess();
00128             ResourceHandle texture = (*i)->getTexture();
00129             bool useSpecular = (specular != black);
00130 
00131             if (specularOn && !useSpecular)
00132             {
00133                 float matSpecular[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
00134                 float zero = 0.0f;
00135                 glMaterialfv(GL_FRONT, GL_SPECULAR, matSpecular);
00136                 glMaterialfv(GL_FRONT, GL_SHININESS, &zero);
00137             }
00138             if (useSpecular)
00139             {
00140                 float matSpecular[4] = { specular.red(), specular.green(),
00141                                              specular.blue(), 1.0f };
00142                 glMaterialfv(GL_FRONT, GL_SPECULAR, matSpecular);
00143                 glMaterialfv(GL_FRONT, GL_SHININESS, &shininess);
00144             }
00145             specularOn = useSpecular;
00146 
00147             if (currentTexture != texture)
00148             {
00149                 if (texture == InvalidResource)
00150                 {
00151                     glDisable(GL_TEXTURE_2D);
00152                 }
00153                 else
00154                 {
00155                     if (currentTexture == InvalidResource)
00156                         glEnable(GL_TEXTURE_2D);
00157                     Texture* t = textureManager->find(texture);
00158                     if (t != NULL)
00159                         t->bind();
00160                 }
00161                 currentTexture = texture;
00162             }
00163         }
00164         
00165         (*i)->render();
00166     }
00167 
00168     if (specularOn)
00169     {
00170         float matSpecular[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
00171         float zero = 0.0f;
00172         glMaterialfv(GL_FRONT, GL_SPECULAR, matSpecular);
00173         glMaterialfv(GL_FRONT, GL_SHININESS, &zero);
00174     }
00175 
00176     if (blendOn)
00177     {
00178         glDisable(GL_BLEND);
00179         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
00180     }
00181 }

void Mesh3DS::render float  lod  ) 
 

Definition at line 88 of file 3dsmesh.cpp.

Referenced by render().

00089 {
00090     render(Normals | Colors, lod);
00091 }


Member Data Documentation

VertexListVec Mesh3DS::vertexLists [private]
 

Definition at line 34 of file 3dsmesh.h.

Referenced by Mesh3DS(), normalize(), pick(), render(), and ~Mesh3DS().


The documentation for this class was generated from the following files:
Generated on Sat Jan 14 22:33:28 2006 for Celestia by  doxygen 1.4.1