00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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