00001 /* 00002 Sheep - A Rigid Body Dynamics Engine 00003 Copyright (C) 2001-2004 Francois Beaune 00004 Contact: http://toxicengine.sourceforge.net/ 00005 00006 This file is part of Sheep. 00007 00008 Sheep is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 Sheep is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with Sheep; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 #ifndef SHEEP_RENDERER_GLMESH_H 00024 #define SHEEP_RENDERER_GLMESH_H 00025 00026 #include "common/math/aabb3.h" 00027 #include "common/math/vector2.h" 00028 #include "common/math/vector3.h" 00029 #include "sgnode.h" 00030 00031 #include <GL/glut.h> 00032 #include <vector> 00033 00034 namespace sheep { 00035 00036 class Material; 00037 00038 class GLMesh : public SGNode { 00039 public: 00040 enum RenderingMode { 00041 IMMEDIATE_MODE, 00042 DISPLAY_LIST 00043 }; 00044 00045 class SubMesh { 00046 public: 00047 struct Face { 00048 int m_v0, m_v1, m_v2; 00049 int m_n0, m_n1, m_n2; 00050 int m_t0, m_t1, m_t2; 00051 }; 00052 00053 typedef std::vector<Vector2> Vector2Vector; 00054 typedef Vector2Vector::iterator Vector2VectorIt; 00055 typedef Vector2Vector::const_iterator Vector2VectorConstIt; 00056 00057 typedef std::vector<Vector3> Vector3Vector; 00058 typedef Vector3Vector::iterator Vector3VectorIt; 00059 typedef Vector3Vector::const_iterator Vector3VectorConstIt; 00060 00061 typedef std::vector<Face> FaceVector; 00062 typedef FaceVector::iterator FaceVectorIt; 00063 typedef FaceVector::const_iterator FaceVectorConstIt; 00064 00065 Vector3Vector m_vertices; 00066 Vector3Vector m_normals; 00067 Vector2Vector m_texcoords; 00068 FaceVector m_faces; 00069 00070 SubMesh(); 00071 ~SubMesh(); 00072 00073 void SetMaterial(Material *m); 00074 Material *GetMaterial(); 00075 00076 void SetupRendering(RenderingMode mode); 00077 00078 void Render() const; 00079 void DisplayNormals() const; 00080 00081 private: 00082 Material *m_material; 00083 00084 RenderingMode m_rendering_mode; 00085 GLuint m_list_name; //!< OpenGL display list name. 00086 00087 void do_rendering() const; 00088 }; 00089 00090 typedef std::vector<SubMesh *> SubMeshVector; 00091 typedef SubMeshVector::const_iterator SubMeshVectorConstIt; 00092 00093 SubMeshVector m_sub_meshes; 00094 00095 GLMesh(); 00096 virtual ~GLMesh(); 00097 00098 //! The submesh must be fully defined and ready to be rendered 00099 //! when it is inserted. 00100 void Insert(SubMesh *m); 00101 00102 int GetVertexCount() const; 00103 int GetFaceCount() const; 00104 00105 const AABB3 &GetAABB() const; 00106 00107 //! Flip faces and normals. Don't forget to call 00108 //! SetupRendering() before rendering the mesh. 00109 void FlipFaces(); 00110 00111 //! Changes the rendering mode of the mesh. Default 00112 //! rendering mode is IMMEDIATE. Call this method if 00113 //! the mesh has been modified since the last call 00114 //! (call it before calling the Render() method). 00115 void SetupRendering(RenderingMode mode); 00116 00117 // virtual void Traverse(); 00118 00119 void Render() const; 00120 void DisplayNormals() const; 00121 00122 private: 00123 int m_vertex_count; //!< Total number of vertices. 00124 int m_face_count; //!< Total number of faces. 00125 AABB3 m_aabb; //!< Axis-aligned bounding box. 00126 }; 00127 00128 #include "glmesh.inl" 00129 00130 } 00131 00132 #endif // !SHEEP_RENDERER_GLMESH_H
1.3.6