]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Graphic/Models.cpp
Removed unused members in Model class
[lugaru.git] / Source / Graphic / Models.cpp
index a1f17fbcddbb4d50fbf1824a2375d1443a066b49..d414dbde0f343b70a19c18bc7e2c80bdb39d538d 100644 (file)
@@ -395,7 +395,7 @@ bool Model::loadnotex(const std::string& filename)
 {
     FILE *tfile;
     long i;
-    int TriangleNum;
+    short triangleNum;
 
     type = notextype;
     color = 0;
@@ -405,7 +405,7 @@ bool Model::loadnotex(const std::string& filename)
     // read model settings
 
     fseek(tfile, 0, SEEK_SET);
-    funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum);
+    funpackf(tfile, "Bs Bs", &vertexNum, &triangleNum);
 
     // read the model data
     deallocate();
@@ -414,14 +414,14 @@ bool Model::loadnotex(const std::string& filename)
 
     owner = (int*)malloc(sizeof(int) * vertexNum);
     vertex = (XYZ*)malloc(sizeof(XYZ) * vertexNum);
-    Triangles.resize(TriangleNum);
-    vArray = (GLfloat*)malloc(sizeof(GLfloat) * TriangleNum * 24);
+    Triangles.resize(triangleNum);
+    vArray = (GLfloat*)malloc(sizeof(GLfloat) * triangleNum * 24);
 
     for (i = 0; i < vertexNum; i++) {
         funpackf(tfile, "Bf Bf Bf", &vertex[i].x, &vertex[i].y, &vertex[i].z);
     }
 
-    for (i = 0; i < TriangleNum; i++) {
+    for (i = 0; i < triangleNum; i++) {
         short vertex[6];
         funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[0], &vertex[1], &vertex[2], &vertex[3], &vertex[4], &vertex[5]);
         Triangles[i].vertex[0] = vertex[0];
@@ -458,7 +458,7 @@ bool Model::load(const std::string& filename)
 {
     FILE *tfile;
     long i;
-    int TriangleNum;
+    short triangleNum;
 
     LOGFUNC;
 
@@ -474,7 +474,7 @@ bool Model::load(const std::string& filename)
     // read model settings
 
     fseek(tfile, 0, SEEK_SET);
-    funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum);
+    funpackf(tfile, "Bs Bs", &vertexNum, &triangleNum);
 
     // read the model data
     deallocate();
@@ -484,14 +484,14 @@ bool Model::load(const std::string& filename)
     owner = (int*)malloc(sizeof(int) * vertexNum);
     vertex = (XYZ*)malloc(sizeof(XYZ) * vertexNum);
     normals = (XYZ*)malloc(sizeof(XYZ) * vertexNum);
-    Triangles.resize(TriangleNum);
-    vArray = (GLfloat*)malloc(sizeof(GLfloat) * TriangleNum * 24);
+    Triangles.resize(triangleNum);
+    vArray = (GLfloat*)malloc(sizeof(GLfloat) * triangleNum * 24);
 
     for (i = 0; i < vertexNum; i++) {
         funpackf(tfile, "Bf Bf Bf", &vertex[i].x, &vertex[i].y, &vertex[i].z);
     }
 
-    for (i = 0; i < TriangleNum; i++) {
+    for (i = 0; i < triangleNum; i++) {
         short vertex[6];
         funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[0], &vertex[1], &vertex[2], &vertex[3], &vertex[4], &vertex[5]);
         Triangles[i].vertex[0] = vertex[0];
@@ -530,7 +530,7 @@ bool Model::loaddecal(const std::string& filename)
 {
     FILE *tfile;
     long i, j;
-    int TriangleNum;
+    short triangleNum;
 
     LOGFUNC;
 
@@ -545,7 +545,7 @@ bool Model::loaddecal(const std::string& filename)
     // read model settings
 
     fseek(tfile, 0, SEEK_SET);
-    funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum);
+    funpackf(tfile, "Bs Bs", &vertexNum, &triangleNum);
 
     // read the model data
 
@@ -556,14 +556,14 @@ bool Model::loaddecal(const std::string& filename)
     owner = (int*)malloc(sizeof(int) * vertexNum);
     vertex = (XYZ*)malloc(sizeof(XYZ) * vertexNum);
     normals = (XYZ*)malloc(sizeof(XYZ) * vertexNum);
-    Triangles.resize(TriangleNum);
-    vArray = (GLfloat*)malloc(sizeof(GLfloat) * TriangleNum * 24);
+    Triangles.resize(triangleNum);
+    vArray = (GLfloat*)malloc(sizeof(GLfloat) * triangleNum * 24);
 
     for (i = 0; i < vertexNum; i++) {
         funpackf(tfile, "Bf Bf Bf", &vertex[i].x, &vertex[i].y, &vertex[i].z);
     }
 
-    for (i = 0; i < TriangleNum; i++) {
+    for (i = 0; i < triangleNum; i++) {
         short vertex[6];
         funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[0], &vertex[1], &vertex[2], &vertex[3], &vertex[4], &vertex[5]);
         Triangles[i].vertex[0] = vertex[0];
@@ -602,7 +602,7 @@ bool Model::loadraw(const std::string& filename)
 {
     FILE *tfile;
     long i;
-    int TriangleNum;
+    short triangleNum;
 
     LOGFUNC;
 
@@ -616,7 +616,7 @@ bool Model::loadraw(const std::string& filename)
     // read model settings
 
     fseek(tfile, 0, SEEK_SET);
-    funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum);
+    funpackf(tfile, "Bs Bs", &vertexNum, &triangleNum);
 
     // read the model data
     deallocate();
@@ -625,15 +625,15 @@ bool Model::loadraw(const std::string& filename)
 
     owner = (int*)malloc(sizeof(int) * vertexNum);
     vertex = (XYZ*)malloc(sizeof(XYZ) * vertexNum);
-    Triangles.resize(TriangleNum);
-    vArray = (GLfloat*)malloc(sizeof(GLfloat) * TriangleNum * 24);
+    Triangles.resize(triangleNum);
+    vArray = (GLfloat*)malloc(sizeof(GLfloat) * triangleNum * 24);
 
 
     for (i = 0; i < vertexNum; i++) {
         funpackf(tfile, "Bf Bf Bf", &vertex[i].x, &vertex[i].y, &vertex[i].z);
     }
 
-    for (i = 0; i < TriangleNum; i++) {
+    for (i = 0; i < triangleNum; i++) {
         short vertex[6];
         funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[0], &vertex[1], &vertex[2], &vertex[3], &vertex[4], &vertex[5]);
         Triangles[i].vertex[0] = vertex[0];
@@ -821,30 +821,33 @@ void Model::drawimmediate()
     glBegin(GL_TRIANGLES);
     for (unsigned int i = 0; i < Triangles.size(); i++) {
         glTexCoord2f(Triangles[i].gx[0], Triangles[i].gy[0]);
-        if (color)
+        if (color) {
             glColor3f(normals[Triangles[i].vertex[0]].x, normals[Triangles[i].vertex[0]].y, normals[Triangles[i].vertex[0]].z);
-        if (!color && !flat)
-            glNormal3f(normals[Triangles[i].vertex[0]].x, normals[Triangles[i].vertex[0]].y, normals[Triangles[i].vertex[0]].z);
-        if (!color && flat)
+        } else if (flat) {
             glNormal3f(Triangles[i].facenormal.x, Triangles[i].facenormal.y, Triangles[i].facenormal.y);
+        } else {
+            glNormal3f(normals[Triangles[i].vertex[0]].x, normals[Triangles[i].vertex[0]].y, normals[Triangles[i].vertex[0]].z);
+        }
         glVertex3f(vertex[Triangles[i].vertex[0]].x, vertex[Triangles[i].vertex[0]].y, vertex[Triangles[i].vertex[0]].z);
 
         glTexCoord2f(Triangles[i].gx[1], Triangles[i].gy[1]);
-        if (color)
+        if (color) {
             glColor3f(normals[Triangles[i].vertex[1]].x, normals[Triangles[i].vertex[1]].y, normals[Triangles[i].vertex[1]].z);
-        if (!color && !flat)
-            glNormal3f(normals[Triangles[i].vertex[1]].x, normals[Triangles[i].vertex[1]].y, normals[Triangles[i].vertex[1]].z);
-        if (!color && flat)
+        } else if (flat) {
             glNormal3f(Triangles[i].facenormal.x, Triangles[i].facenormal.y, Triangles[i].facenormal.y);
+        } else {
+            glNormal3f(normals[Triangles[i].vertex[1]].x, normals[Triangles[i].vertex[1]].y, normals[Triangles[i].vertex[1]].z);
+        }
         glVertex3f(vertex[Triangles[i].vertex[1]].x, vertex[Triangles[i].vertex[1]].y, vertex[Triangles[i].vertex[1]].z);
 
         glTexCoord2f(Triangles[i].gx[2], Triangles[i].gy[2]);
-        if (color)
+        if (color) {
             glColor3f(normals[Triangles[i].vertex[2]].x, normals[Triangles[i].vertex[2]].y, normals[Triangles[i].vertex[2]].z);
-        if (!color && !flat)
-            glNormal3f(normals[Triangles[i].vertex[2]].x, normals[Triangles[i].vertex[2]].y, normals[Triangles[i].vertex[2]].z);
-        if (!color && flat)
+        } else if (flat) {
             glNormal3f(Triangles[i].facenormal.x, Triangles[i].facenormal.y, Triangles[i].facenormal.y);
+        } else {
+            glNormal3f(normals[Triangles[i].vertex[2]].x, normals[Triangles[i].vertex[2]].y, normals[Triangles[i].vertex[2]].z);
+        }
         glVertex3f(vertex[Triangles[i].vertex[2]].x, vertex[Triangles[i].vertex[2]].y, vertex[Triangles[i].vertex[2]].z);
     }
     glEnd();
@@ -859,43 +862,20 @@ void Model::draw()
     glEnableClientState(GL_VERTEX_ARRAY);
     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 
-    if (!color)
-        glInterleavedArrays( GL_T2F_N3F_V3F, 8 * sizeof(GLfloat), &vArray[0]);
-    if (color)
+    if (color) {
         glInterleavedArrays( GL_T2F_C3F_V3F, 8 * sizeof(GLfloat), &vArray[0]);
+    } else {
+        glInterleavedArrays( GL_T2F_N3F_V3F, 8 * sizeof(GLfloat), &vArray[0]);
+    }
     textureptr.bind();
 
     glDrawArrays(GL_TRIANGLES, 0, Triangles.size() * 3);
 
-    if (!color)
-        glDisableClientState(GL_NORMAL_ARRAY);
-    if (color)
+    if (color) {
         glDisableClientState(GL_COLOR_ARRAY);
-    glDisableClientState(GL_VERTEX_ARRAY);
-    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-}
-
-//TODO: phase out in favor of Texture
-void Model::drawdifftex(GLuint texture)
-{
-    glEnableClientState(GL_NORMAL_ARRAY);
-    glEnableClientState(GL_VERTEX_ARRAY);
-    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-    if (!color)
-        glInterleavedArrays( GL_T2F_N3F_V3F, 8 * sizeof(GLfloat), &vArray[0]);
-    if (color)
-        glInterleavedArrays( GL_T2F_C3F_V3F, 8 * sizeof(GLfloat), &vArray[0]);
-
-    glBindTexture(GL_TEXTURE_2D, (unsigned long)texture);
-    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
-    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
-
-    glDrawArrays(GL_TRIANGLES, 0, Triangles.size() * 3);
-
-    if (!color)
+    } else {
         glDisableClientState(GL_NORMAL_ARRAY);
-    if (color)
-        glDisableClientState(GL_COLOR_ARRAY);
+    }
     glDisableClientState(GL_VERTEX_ARRAY);
     glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 }
@@ -905,10 +885,11 @@ void Model::drawdifftex(Texture texture)
     glEnableClientState(GL_NORMAL_ARRAY);
     glEnableClientState(GL_VERTEX_ARRAY);
     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-    if (!color)
-        glInterleavedArrays( GL_T2F_N3F_V3F, 8 * sizeof(GLfloat), &vArray[0]);
-    if (color)
+    if (color) {
         glInterleavedArrays( GL_T2F_C3F_V3F, 8 * sizeof(GLfloat), &vArray[0]);
+    } else {
+        glInterleavedArrays( GL_T2F_N3F_V3F, 8 * sizeof(GLfloat), &vArray[0]);
+    }
 
     texture.bind();
     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
@@ -916,10 +897,11 @@ void Model::drawdifftex(Texture texture)
 
     glDrawArrays(GL_TRIANGLES, 0, Triangles.size() * 3);
 
-    if (!color)
-        glDisableClientState(GL_NORMAL_ARRAY);
-    if (color)
+    if (color) {
         glDisableClientState(GL_COLOR_ARRAY);
+    } else {
+        glDisableClientState(GL_NORMAL_ARRAY);
+    }
     glDisableClientState(GL_VERTEX_ARRAY);
     glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 }
@@ -1196,8 +1178,7 @@ void Model::deallocate()
 
 Model::Model()
   : vertexNum(0),
-    hastexture(0),
-    type(0), oldtype(0),
+    type(0),
     owner(0),
     vertex(0),
     normals(0),