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

gltriangle.h

00001 /***************************************************************************
00002                           gltriangle.h  -  description
00003                              -------------------
00004     begin                : Thu May 22 2003
00005     copyright            : (C) 2003 by Jacques Gasselin de Richebourg
00006     email                : jacquesgasselin@hotmail.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU Lesser General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *
00024  *                                                                         *
00025  ***************************************************************************/
00026 
00027 #ifndef GLTRIANGLE_H
00028 #define GLTRIANGLE_H
00029 
00030 #include <vector>
00031 
00032 #include "glvector.h"
00033 #include "gltexcoord.h"
00034 
00040 typedef enum {
00041    GLT_SKELETAL = 1,
00042    GLT_POINTS = 2,
00043    GLT_LINES = 4,
00044    GLT_FLAT = 8,
00045    GLT_SMOOTH = 16,
00046    GLT_TEXTURED = 32,
00047    GLT_SHOW_SURFACE_NORMAL = 64,
00048    GLT_SHOW_VERTEX_NORMAL = 128
00049    } GLTenum;
00050    
00051 class GLTriangle
00052 {
00053    //index into a vertex buffer
00054    GLuint index[3];
00055    GLVector surfaceNormal;
00056    
00057 public:
00058    static char tag[20];
00059    
00060    GLTriangle(GLuint a, GLuint b, GLuint c);
00061    ~GLTriangle();
00062 
00063    inline GLuint* get() { return index; }
00064    inline void set(GLuint* i);
00065    inline void set(GLuint a, GLuint b, GLuint c);
00066 
00067    void makeNormal(std::vector<GLVector*>& arr);
00068    GLVector* getNormal();
00069 
00070    inline void glLines(std::vector<GLVector*>& arr)
00071    {
00072       arr[index[0]]->glVertex();
00073       arr[index[1]]->glVertex();
00074       arr[index[1]]->glVertex();
00075       arr[index[2]]->glVertex();
00076       arr[index[2]]->glVertex();
00077       arr[index[0]]->glVertex();
00078    }
00079 
00080    inline void glShowNormal(std::vector<GLVector*>& arr)
00081    {
00082       GLVector temp;
00083 
00084       arr[index[0]]->glVertex();
00085       temp.set(arr[index[0]]->get());
00086       temp += surfaceNormal;
00087       temp.glVertex();
00088       
00089       arr[index[1]]->glVertex();
00090       temp.set(arr[index[1]]->get());
00091       temp += surfaceNormal;
00092       temp.glVertex();
00093 
00094       arr[index[2]]->glVertex();
00095       temp.set(arr[index[2]]->get());
00096       temp += surfaceNormal;
00097       temp.glVertex();
00098 
00099    }
00100    
00101    inline void glTrianglesFlat(std::vector<GLVector*>& arr)
00102    {
00103       surfaceNormal.glNormal();
00104       arr[index[0]]->glVertex();
00105       arr[index[1]]->glVertex();
00106       arr[index[2]]->glVertex();
00107    }
00108       
00109    inline void glTrianglesSmooth(std::vector<GLVector*>& arr, std::vector<GLVector*>& normals)
00110    {
00111       normals[index[0]]->glNormal();
00112       arr[index[0]]->glVertex();
00113       normals[index[1]]->glNormal();
00114       arr[index[1]]->glVertex();
00115       normals[index[2]]->glNormal();
00116       arr[index[2]]->glVertex();
00117    }
00118 
00119    inline void glTrianglesTexturedSmooth(std::vector<GLVector*>& arr, std::vector<GLTexCoord*> tex, std::vector<GLVector*>& normals)
00120    {
00121       normals[index[0]]->glNormal();
00122       tex[index[0]]->glTexCoord();
00123       arr[index[0]]->glVertex();
00124       normals[index[1]]->glNormal();
00125       tex[index[1]]->glTexCoord();
00126       arr[index[1]]->glVertex();
00127       normals[index[2]]->glNormal();
00128       tex[index[2]]->glTexCoord();
00129       arr[index[2]]->glVertex();
00130    }
00131 
00132    inline void glArrayTriangle()
00133    { glArrayElement(index[0]); glArrayElement(index[1]); glArrayElement(index[2]); }
00134 
00135    void saveToStream(std::ostream& out);
00136 };
00137 
00138 #endif

Generated on Wed Feb 4 23:11:34 2004 by doxygen 1.3.3