ModelRendererTree.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <graph/ModelRendererTree.h>
00022 #include <graph/OptionsDisplay.h>
00023 #include <3dsparse/TreeModelFactory.h>
00024 #include <image/ImageFactory.h>
00025 #include <GLEXT/GLStateExtension.h>
00026 #include <GLEXT/GLGlobalState.h>
00027 #include <GLEXT/GLTexture.h>
00028 #include <GLEXT/GLInfo.h>
00029 
00030 bool ModelRendererTree::skipPre_ = false;
00031 
00032 // Pine
00033 GLTexture ModelRendererTree::pineTextureA_;
00034 GLTexture ModelRendererTree::pineTextureB_;
00035 GLuint ModelRendererTree::treePineList = 0;
00036 GLuint ModelRendererTree::treePineSmallList = 0;
00037 GLuint ModelRendererTree::treePineSnowList = 0;
00038 GLuint ModelRendererTree::treePineSnowSmallList = 0;
00039 GLuint ModelRendererTree::treePine2List = 0;
00040 GLuint ModelRendererTree::treePine2SmallList = 0;
00041 GLuint ModelRendererTree::treePine2SnowList = 0;
00042 GLuint ModelRendererTree::treePine2SnowSmallList = 0;
00043 GLuint ModelRendererTree::treePine3List = 0;
00044 GLuint ModelRendererTree::treePine3SmallList = 0;
00045 GLuint ModelRendererTree::treePine3SnowList = 0;
00046 GLuint ModelRendererTree::treePine3SnowSmallList = 0;
00047 GLuint ModelRendererTree::treePine4List = 0;
00048 GLuint ModelRendererTree::treePine4SmallList = 0;
00049 GLuint ModelRendererTree::treePine4SnowList = 0;
00050 GLuint ModelRendererTree::treePine4SnowSmallList = 0;
00051 GLuint ModelRendererTree::treePineBurntList = 0;
00052 GLuint ModelRendererTree::treePineBurntSmallList = 0;
00053 GLuint ModelRendererTree::treePineYellowList = 0;
00054 GLuint ModelRendererTree::treePineYellowSmallList = 0;
00055 GLuint ModelRendererTree::treePineLightList = 0;
00056 GLuint ModelRendererTree::treePineLightSmallList = 0;
00057 
00058 // Palm
00059 GLTexture ModelRendererTree::palmTextureA_;
00060 GLTexture ModelRendererTree::palmTextureB_;
00061 GLuint ModelRendererTree::treePalmList = 0;
00062 GLuint ModelRendererTree::treePalmSmallList = 0;
00063 GLuint ModelRendererTree::treePalm2List = 0;
00064 GLuint ModelRendererTree::treePalm2SmallList = 0;
00065 GLuint ModelRendererTree::treePalm3List = 0;
00066 GLuint ModelRendererTree::treePalm3SmallList = 0;
00067 GLuint ModelRendererTree::treePalm4List = 0;
00068 GLuint ModelRendererTree::treePalm4SmallList = 0;
00069 GLuint ModelRendererTree::treePalmBList = 0;
00070 GLuint ModelRendererTree::treePalmB2List = 0;
00071 GLuint ModelRendererTree::treePalmB3List = 0;
00072 GLuint ModelRendererTree::treePalmB4List = 0;
00073 GLuint ModelRendererTree::treePalmB5List = 0;
00074 GLuint ModelRendererTree::treePalmB6List = 0;
00075 GLuint ModelRendererTree::treePalmB7List = 0;
00076 GLuint ModelRendererTree::treePalmBurntList = 0;
00077 GLuint ModelRendererTree::treePalmBurntSmallList = 0;
00078 
00079 // Oak
00080 GLTexture ModelRendererTree::oakTextureA_;
00081 GLuint ModelRendererTree::treeOakList = 0;
00082 GLuint ModelRendererTree::treeOakSmallList = 0;
00083 GLuint ModelRendererTree::treeOak2List = 0;
00084 GLuint ModelRendererTree::treeOak2SmallList = 0;
00085 GLuint ModelRendererTree::treeOak3List = 0;
00086 GLuint ModelRendererTree::treeOak3SmallList = 0;
00087 GLuint ModelRendererTree::treeOak4List = 0;
00088 GLuint ModelRendererTree::treeOak4SmallList = 0;
00089 
00090 
00091 static void drawPineLevel(float texX, float texY,
00092                 float width, float height, float lowheight, 
00093                 float texWidth = 0.125f, float count = 5.0f, bool doubleSide = false,
00094                 float angOffset = 0.0f)
00095 {
00096         glBegin(GL_TRIANGLE_FAN);
00097                 glTexCoord2f(texX, texY);
00098                 glNormal3f(0.0f, 0.0f, 1.0f);
00099                 glVertex3f(0.0f, 0.0f, height);
00100                 for (float i=360.0f; i>=0.0f; i-=360.0f / count)
00101                 {
00102                         float diff = RAND * 40.0f - 20.0f;
00103                         glTexCoord2f(
00104                                 texX + (sinf((i + angOffset)/180.0f * PI) * texWidth), 
00105                                 texY + (cosf((i + angOffset)/180.0f * PI) * texWidth));
00106                         glNormal3f(
00107                                 sinf((i+diff)/180.0f * PI) * (height - lowheight),
00108                                 cosf((i+diff)/180.0f * PI) * (height - lowheight),
00109                                 width);
00110                         glVertex3f(
00111                                 sinf(i/180.0f * PI) * width, 
00112                                 cosf(i/180.0f * PI) * width, 
00113                                 lowheight);
00114                 }
00115         glEnd();
00116 
00117         if (doubleSide)
00118         {
00119         glBegin(GL_TRIANGLE_FAN);
00120                 glTexCoord2f(texX, texY);
00121                 glNormal3f(0.0f, 0.0f, 1.0f);
00122                 glVertex3f(0.0f, 0.0f, height);
00123                 for (float i=0.0f; i<=360.0f; i+=360.0f / count)
00124                 {
00125                         float diff = RAND * 40.0f - 20.0f;
00126                         glTexCoord2f(
00127                                 texX + (sinf((i + angOffset)/180.0f * PI) * texWidth), 
00128                                 texY + (cosf((i + angOffset)/180.0f * PI) * texWidth));
00129                         glNormal3f(
00130                                 -sinf((i+diff)/180.0f * PI) * (height - lowheight),
00131                                 -cosf((i+diff)/180.0f * PI) * (height - lowheight),
00132                                 -width);
00133                         glVertex3f(
00134                                 sinf(i/180.0f * PI) * width, 
00135                                 cosf(i/180.0f * PI) * width, 
00136                                 lowheight);
00137                 }
00138         glEnd();
00139         }
00140 }
00141 
00142 static void drawPineTrunc(float width, float height, float lowheight,
00143         float x = 0.875f, float y = 0.0f, float w = 0.125f, float h = 0.1f,
00144         float steps = 3.0f)
00145 {
00146         glBegin(GL_TRIANGLE_FAN);
00147                 glTexCoord2f(x , y);
00148                 glNormal3f(0.0, 0.0f, 1.0f);
00149                 glVertex3f(0.0f, 0.0f, height);
00150                 for (float i=360.0f; i>=0.0f; i-=360.0f / steps)
00151                 {
00152                         glTexCoord2f(x + w*(float(int(i*5.0f)%360)/360.0f), y + h);
00153                         glNormal3f(
00154                                 sinf(i/180.0f * PI),
00155                                 cosf(i/180.0f * PI),
00156                                 0.0f);
00157                         glVertex3f(
00158                                 sinf(i/180.0f * PI) * width, 
00159                                 cosf(i/180.0f * PI) * width, 
00160                                 lowheight);
00161                 }
00162         glEnd();
00163 }
00164 
00165 static void drawPalmTrunc(float width, float height, float count,
00166         float x = 0.0f, float y = 0.0f,
00167         float w = 1.0f, float h = 0.125f)
00168 {
00169         bool tex = false;
00170         glBegin(GL_QUAD_STRIP);
00171                 for (float i=360.0f; i>=0.0f; i-=360.0f / count)
00172                 {
00173                         glNormal3f(
00174                                 sinf(i/180.0f * PI), 
00175                                 cosf(i/180.0f * PI), 
00176                                 0.0f);
00177                         if (tex) glTexCoord2f(x, y);
00178                         else glTexCoord2f(x, y + h);
00179                         glVertex3f(
00180                                 sinf(i/180.0f * PI) * (width - 0.1f), 
00181                                 cosf(i/180.0f * PI) * (width - 0.1f), 
00182                                 height);
00183                         if (tex) glTexCoord2f(x + w, y);
00184                         else glTexCoord2f(x + w, y + h);
00185                         glVertex3f(
00186                                 sinf(i/180.0f * PI) * width, 
00187                                 cosf(i/180.0f * PI) * width, 
00188                                 0.0f);
00189                         tex = !tex;
00190                 }
00191         glEnd();
00192         glBegin(GL_TRIANGLE_FAN);
00193                 glTexCoord2f(x + w, y);
00194                 glNormal3f(0.0, 0.0f, 1.0f);
00195                 glVertex3f(0.0f, 0.0f, height + 0.05f);
00196                 for (float i=360.0f; i>=0.0f; i-=360.0f / count)
00197                 {
00198                         if (tex) glTexCoord2f(x + w, y);
00199                         else glTexCoord2f(x + w, y + h);
00200                         glNormal3f(
00201                                 sinf(i/180.0f * PI), 
00202                                 cosf(i/180.0f * PI), 
00203                                 0.0f);
00204                         glVertex3f(
00205                                 sinf(i/180.0f * PI) * 0.03f, 
00206                                 cosf(i/180.0f * PI) * 0.03f, 
00207                                 height - 0.01f);
00208                         tex = !tex;
00209                 }
00210         glEnd();
00211 }
00212 
00213 static void drawPalmLevel(
00214                 float width1, float w2, float height, float height2,
00215                 float count, float texX, float texY)
00216 {
00217         glBegin(GL_QUADS);
00218                 for (float i=360.0f; i>=0.0f;)
00219                 {
00220                         float diff = 0.5f * RAND - 0.25f;
00221                         float width2 = (w2 * RAND * 0.3f) + (0.7f * w2);
00222                         
00223                         Vector A1(
00224                                 sinf((i-15.0f)/180.0f * PI) * width1, 
00225                                 cosf((i-15.0f)/180.0f * PI) * width1, 
00226                                 height);
00227                         Vector A2(
00228                                 sinf(i/180.0f * PI) * width1, 
00229                                 cosf(i/180.0f * PI) * width1, 
00230                                 height2);
00231                         Vector A3(
00232                                 sinf(i/180.0f * PI) * width2, 
00233                                 cosf(i/180.0f * PI) * width2, 
00234                                 height2 + diff);
00235                         Vector A4(
00236                                 sinf((i-15.0f)/180.0f * PI) * width2, 
00237                                 cosf((i-15.0f)/180.0f * PI) * width2, 
00238                                 height + diff);
00239 
00240                         Vector AN = ((A3 - A4) * (A3 - A2));
00241                         glNormal3fv(AN);
00242                         glTexCoord2f(texX, texY);
00243                         glVertex3fv(A1);
00244                         glTexCoord2f(texX, texY + 0.123f);
00245                         glVertex3fv(A2);
00246                         glTexCoord2f(texX + 0.37f, texY + 0.123f);
00247                         glVertex3fv(A3);
00248                         glTexCoord2f(texX + 0.37f, texY);
00249                         glVertex3fv(A4);
00250 
00251                         Vector B1(
00252                                 sinf((i-15.0f)/180.0f * PI) * width2, 
00253                                 cosf((i-15.0f)/180.0f * PI) * width2, 
00254                                 height + diff);
00255                         Vector B2(
00256                                 sinf(i/180.0f * PI) * width2, 
00257                                 cosf(i/180.0f * PI) * width2, 
00258                                 height2 + diff);
00259                         Vector B3(
00260                                 sinf(i/180.0f * PI) * width1, 
00261                                 cosf(i/180.0f * PI) * width1, 
00262                                 height2);
00263                         Vector B4(
00264                                 sinf((i-15.0f)/180.0f * PI) * width1, 
00265                                 cosf((i-15.0f)/180.0f * PI) * width1, 
00266                                 height);
00267                         Vector BN = ((B1 - B3) * (B2 - B1));
00268                         glNormal3fv(BN);
00269                         glTexCoord2f(texX + 0.37f, texY);
00270                         glVertex3fv(B1);
00271                         glTexCoord2f(texX + 0.37f, texY + 0.123f);
00272                         glVertex3fv(B2);
00273                         glTexCoord2f(texX, texY + 0.123f);
00274                         glVertex3fv(B3);
00275                         glTexCoord2f(texX, texY);
00276                         glVertex3fv(B4);
00277 
00278                         Vector C1(
00279                                 sinf((i+15.0f)/180.0f * PI) * width2, 
00280                                 cosf((i+15.0f)/180.0f * PI) * width2, 
00281                                 height + diff);
00282                         Vector C2(
00283                                 sinf(i/180.0f * PI) * width2, 
00284                                 cosf(i/180.0f * PI) * width2, 
00285                                 height2 + diff);
00286                         Vector C3(
00287                                 sinf(i/180.0f * PI) * width1, 
00288                                 cosf(i/180.0f * PI) * width1, 
00289                                 height2);
00290                         Vector C4(
00291                                 sinf((i+15.0f)/180.0f * PI) * width1, 
00292                                 cosf((i+15.0f)/180.0f * PI) * width1, 
00293                                 height);
00294 
00295                         Vector CN = ((C2 - C1) * (C3 - C2));
00296                         glNormal3fv(CN);
00297                         glTexCoord2f(texX + 0.37f, texY);
00298                         glVertex3fv(C1);
00299                         glTexCoord2f(texX + 0.37f, texY + 0.123f);
00300                         glVertex3fv(C2);
00301                         glTexCoord2f(texX, texY + 0.123f);
00302                         glVertex3fv(C3);
00303                         glTexCoord2f(texX, texY);
00304                         glVertex3fv(C4);
00305 
00306                         Vector D1(
00307                                 sinf((i+15.0f)/180.0f * PI) * width1, 
00308                                 cosf((i+15.0f)/180.0f * PI) * width1, 
00309                                 height);
00310                         Vector D2(
00311                                 sinf(i/180.0f * PI) * width1, 
00312                                 cosf(i/180.0f * PI) * width1, 
00313                                 height2);
00314                         Vector D3(
00315                                 sinf(i/180.0f * PI) * width2, 
00316                                 cosf(i/180.0f * PI) * width2, 
00317                                 height2 + diff);
00318                         Vector D4(
00319                                 sinf((i+15.0f)/180.0f * PI) * width2, 
00320                                 cosf((i+15.0f)/180.0f * PI) * width2, 
00321                                 height + diff);
00322 
00323                         Vector DN = ((D4 - D3) * (D2 - D4));
00324                         glNormal3fv(DN);
00325                         glTexCoord2f(texX, texY);
00326                         glVertex3fv(D1);
00327                         glTexCoord2f(texX, texY + 0.123f);
00328                         glVertex3fv(D2);
00329                         glTexCoord2f(texX + 0.37f, texY + 0.123f);
00330                         glVertex3fv(D3);
00331                         glTexCoord2f(texX + 0.37f, texY);
00332                         glVertex3fv(D4);
00333 
00334                         i-= (360.0f / (count + (count-1) * RAND));
00335                 }
00336         glEnd();
00337 
00338 }
00339 
00340 ModelRendererTree::ModelRendererTree(Model *model, ModelID &id) : 
00341         model_(model), treeType_(0)
00342 {
00343         const char *modelName = id.getMeshName();
00344         const char *skinName = id.getSkinName();
00345         bool burnt = modelName[0] == 'B';
00346         bool snow = skinName[0] == 'S';
00347 
00348         TreeModelFactory::TreeType normalType, burntType;
00349         TreeModelFactory::getTypes(&modelName[2], snow, 
00350                 normalType, burntType);
00351         treeType_ = (burnt?burntType:normalType);
00352 }
00353 
00354 ModelRendererTree::~ModelRendererTree()
00355 {
00356 }
00357 
00358 void ModelRendererTree::draw(float currentFrame, 
00359         float distance, float fade, bool setState)
00360 {
00361         drawBottomAligned(currentFrame, distance, fade, setState);
00362 }
00363 
00364 void ModelRendererTree::drawBottomAligned(float currentFrame, 
00365         float distance, float fade, bool setState)
00366 {
00367         GLGlobalState globalState(0);
00368         if (!skipPre_) drawInternalPre(setState);
00369         drawInternal(distance, fade, setState);
00370 }
00371 
00372 void ModelRendererTree::drawInternalPre(bool setState)
00373 {
00374         // Create the tree textures and models
00375         static bool listsCreated = false;
00376         if (!listsCreated)
00377         {
00378                 listsCreated = true;
00379                 {
00380                         std::string file1 = S3D::getDataFile("data/textures/pine2.bmp");
00381                         std::string file2 = S3D::getDataFile("data/textures/pine2a.bmp");
00382                         ImageHandle map = ImageFactory::loadImageHandle(file1.c_str(), file2.c_str(), false);
00383                         DIALOG_ASSERT(map.getBits());
00384                         pineTextureA_.create(map, true);
00385                 }
00386                 {
00387                         std::string file1 = S3D::getDataFile("data/textures/pine3.bmp");
00388                         std::string file2 = S3D::getDataFile("data/textures/pine3a.bmp");
00389                         ImageHandle map = ImageFactory::loadImageHandle(file1.c_str(), file2.c_str(), false);
00390                         DIALOG_ASSERT(map.getBits());
00391                         pineTextureB_.create(map, true);
00392                 }
00393                 {
00394                         std::string file1 = S3D::getDataFile("data/textures/pine.bmp");
00395                         std::string file2 = S3D::getDataFile("data/textures/pinea.bmp");
00396                         ImageHandle map = ImageFactory::loadImageHandle(file1.c_str(), file2.c_str(), false);
00397                         DIALOG_ASSERT(map.getBits());
00398                         palmTextureA_.create(map, true);
00399                 }
00400                 {
00401                         std::string file1 = S3D::getDataFile("data/textures/palm2.bmp");
00402                         std::string file2 = S3D::getDataFile("data/textures/palm2a.bmp");
00403                         ImageHandle map = ImageFactory::loadImageHandle(file1.c_str(), file2.c_str(), false);
00404                         DIALOG_ASSERT(map.getBits());
00405                         palmTextureB_.create(map, true);
00406                 }
00407                 {
00408                         std::string file1 = S3D::getDataFile("data/textures/oak.bmp");
00409                         std::string file2 = S3D::getDataFile("data/textures/oaka.bmp");
00410                         ImageHandle map = ImageFactory::loadImageHandle(file1.c_str(), file2.c_str(), false);
00411                         DIALOG_ASSERT(map.getBits());
00412                         oakTextureA_.create(map, true);
00413                 }
00414 
00415                 glNewList(treePineList = glGenLists(1), GL_COMPILE);
00416                         drawPineTrunc(0.1f, 1.1f, 0.0f);
00417                         drawPineLevel(0.625f, 0.875f, 0.7f, 0.3f, 0.1f);
00418                         drawPineLevel(0.375f, 0.875f, 0.5f, 0.7f, 0.2f);
00419                         drawPineLevel(0.125f, 0.875f, 0.3f, 1.1f, 0.5f);
00420                 glEndList();
00421                 glNewList(treePineSmallList = glGenLists(1), GL_COMPILE);
00422                         drawPineLevel(0.625f, 0.875f, 0.7f, 1.1f, 0.1f);
00423                 glEndList();
00424 
00425                 glNewList(treePineSnowList = glGenLists(1), GL_COMPILE);
00426                         drawPineTrunc(0.1f, 1.1f, 0.0f);
00427                         drawPineLevel(0.625f, 0.625f, 0.7f, 0.3f, 0.1f);
00428                         drawPineLevel(0.375f, 0.625f, 0.5f, 0.7f, 0.2f);
00429                         drawPineLevel(0.125f, 0.625f, 0.3f, 1.1f, 0.5f);
00430                 glEndList();
00431                 glNewList(treePineSnowSmallList = glGenLists(1), GL_COMPILE);
00432                         drawPineLevel(0.625f, 0.625f, 0.7f, 1.1f, 0.1f);
00433                 glEndList();
00434 
00435                 glNewList(treePineYellowList = glGenLists(1), GL_COMPILE);
00436                         drawPineTrunc(0.1f, 1.1f, 0.0f);
00437                         drawPineLevel(0.625f, 0.375f, 0.7f, 0.3f, 0.1f);
00438                         drawPineLevel(0.375f, 0.375f, 0.5f, 0.7f, 0.2f);
00439                         drawPineLevel(0.125f, 0.375f, 0.3f, 1.1f, 0.5f);
00440                 glEndList();
00441                 glNewList(treePineYellowSmallList = glGenLists(1), GL_COMPILE);
00442                         drawPineLevel(0.625f, 0.375f, 0.7f, 1.1f, 0.1f);
00443                 glEndList();
00444 
00445                 glNewList(treePineLightList = glGenLists(1), GL_COMPILE);
00446                         drawPineTrunc(0.1f, 1.1f, 0.0f);
00447                         drawPineLevel(0.625f, 0.125f, 0.7f, 0.3f, 0.1f);
00448                         drawPineLevel(0.375f, 0.125f, 0.5f, 0.7f, 0.2f);
00449                         drawPineLevel(0.125f, 0.125f, 0.3f, 1.1f, 0.5f);
00450                 glEndList();
00451                 glNewList(treePineLightSmallList = glGenLists(1), GL_COMPILE);
00452                         drawPineLevel(0.625f, 0.125f, 0.7f, 1.1f, 0.1f);
00453                 glEndList();
00454 
00455                 glNewList(treePineBurntList = glGenLists(1), GL_COMPILE);
00456                         glColor3f(0.3f, 0.3f, 0.3f);
00457                         drawPineTrunc(0.1f, 1.1f, 0.0f);
00458                         drawPineLevel(0.875f, 0.875f, 0.7f, 0.3f, 0.1f);
00459                         drawPineLevel(0.875f, 0.875f, 0.5f, 0.7f, 0.2f);
00460                         drawPineLevel(0.875f, 0.875f, 0.3f, 1.1f, 0.5f);
00461                 glEndList();
00462                 glNewList(treePineBurntSmallList = glGenLists(1), GL_COMPILE);
00463                         glColor3f(0.3f, 0.3f, 0.3f);
00464                         drawPineTrunc(0.1f, 1.1f, 0.0f);
00465                         drawPineLevel(0.875f, 0.875f, 0.7f, 1.1f, 0.1f);
00466                 glEndList();
00467 
00468                 glNewList(treePine2List = glGenLists(1), GL_COMPILE);
00469                         drawPineTrunc(0.1f, 1.1f, 0.0f);
00470                         drawPineLevel(0.18f, 0.836f, 0.7f, 0.3f, 0.1f, 0.18f, 8.0f);
00471                         drawPineLevel(0.18f, 0.836f, 0.5f, 0.7f, 0.2f, 0.18f, 8.0f);
00472                         drawPineLevel(0.18f, 0.836f, 0.3f, 1.1f, 0.5f, 0.18f, 8.0f);
00473                 glEndList();
00474                 glNewList(treePine2SmallList = glGenLists(1), GL_COMPILE);
00475                         drawPineLevel(0.18f, 0.836f, 0.7f, 1.1f, 0.1f, 0.18f, 8.0f);
00476                 glEndList();
00477 
00478                 glNewList(treePine3List = glGenLists(1), GL_COMPILE);
00479                         drawPineTrunc(0.1f, 1.1f, 0.0f);
00480                         drawPineLevel(0.18f, 0.5f, 0.7f, 0.3f, 0.1f, 0.18f, 8.0f);
00481                         drawPineLevel(0.18f, 0.5f, 0.5f, 0.7f, 0.2f, 0.18f, 8.0f);
00482                         drawPineLevel(0.18f, 0.5f, 0.3f, 1.1f, 0.5f, 0.18f, 8.0f);
00483                 glEndList();
00484                 glNewList(treePine3SmallList = glGenLists(1), GL_COMPILE);
00485                         drawPineLevel(0.18f, 0.5f, 0.7f, 1.1f, 0.1f, 0.18f, 8.0f);
00486                 glEndList();
00487 
00488                 glNewList(treePine4List = glGenLists(1), GL_COMPILE);
00489                         drawPineTrunc(0.1f, 1.1f, 0.0f);
00490                         drawPineLevel(0.18f, 0.172f, 0.7f, 0.3f, 0.1f, 0.18f, 8.0f);
00491                         drawPineLevel(0.18f, 0.172f, 0.5f, 0.7f, 0.2f, 0.18f, 8.0f);
00492                         drawPineLevel(0.18f, 0.172f, 0.3f, 1.1f, 0.5f, 0.18f, 8.0f);
00493                 glEndList();
00494                 glNewList(treePine4SmallList = glGenLists(1), GL_COMPILE);
00495                         drawPineLevel(0.18f, 0.172f, 0.7f, 1.1f, 0.1f, 0.18f, 8.0f);
00496                 glEndList();
00497 
00498                 glNewList(treePine2SnowList = glGenLists(1), GL_COMPILE);
00499                         drawPineTrunc(0.1f, 1.1f, 0.0f);
00500                         drawPineLevel(0.52f, 0.836f, 0.7f, 0.3f, 0.1f, 0.18f, 8.0f);
00501                         drawPineLevel(0.52f, 0.836f, 0.5f, 0.7f, 0.2f, 0.18f, 8.0f);
00502                         drawPineLevel(0.52f, 0.836f, 0.3f, 1.1f, 0.5f, 0.18f, 8.0f);
00503                 glEndList();
00504                 glNewList(treePine2SnowSmallList = glGenLists(1), GL_COMPILE);
00505                         drawPineLevel(0.52f, 0.836f, 0.7f, 1.1f, 0.1f, 0.18f, 8.0f);
00506                 glEndList();
00507 
00508                 glNewList(treePine3SnowList = glGenLists(1), GL_COMPILE);
00509                         drawPineTrunc(0.1f, 1.1f, 0.0f);
00510                         drawPineLevel(0.52f, 0.5f, 0.7f, 0.3f, 0.1f, 0.18f, 8.0f);
00511                         drawPineLevel(0.52f, 0.5f, 0.5f, 0.7f, 0.2f, 0.18f, 8.0f);
00512                         drawPineLevel(0.52f, 0.5f, 0.3f, 1.1f, 0.5f, 0.18f, 8.0f);
00513                 glEndList();
00514                 glNewList(treePine3SnowSmallList = glGenLists(1), GL_COMPILE);
00515                         drawPineLevel(0.52f, 0.5f, 0.7f, 1.1f, 0.1f, 0.18f, 8.0f);
00516                 glEndList();
00517 
00518                 glNewList(treePine4SnowList = glGenLists(1), GL_COMPILE);
00519                         drawPineTrunc(0.1f, 1.1f, 0.0f);
00520                         drawPineLevel(0.52f, 0.172f, 0.7f, 0.3f, 0.1f, 0.18f, 8.0f);
00521                         drawPineLevel(0.52f, 0.172f, 0.5f, 0.7f, 0.2f, 0.18f, 8.0f);
00522                         drawPineLevel(0.52f, 0.172f, 0.3f, 1.1f, 0.5f, 0.18f, 8.0f);
00523                 glEndList();
00524                 glNewList(treePine4SnowSmallList = glGenLists(1), GL_COMPILE);
00525                         drawPineLevel(0.52f, 0.172f, 0.7f, 1.1f, 0.1f, 0.18f, 8.0f);
00526                 glEndList();
00527 
00528                 glNewList(treePalmList = glGenLists(1), GL_COMPILE);
00529                         drawPalmTrunc(0.07f, 0.7f, 5.0f);
00530                         drawPalmLevel(0.0f, 0.6f, 0.6f, 0.8f, 7.0f, 0.0f, 0.365f);
00531                 glEndList();
00532                 glNewList(treePalmSmallList = glGenLists(1), GL_COMPILE);
00533                         drawPalmTrunc(0.07f, 0.7f, 3.0f);
00534                         drawPalmLevel(0.0f, 0.6f, 0.6f, 0.8f, 3.0f, 0.0f, 0.365f);
00535                 glEndList();
00536 
00537                 glNewList(treePalm2List = glGenLists(1), GL_COMPILE);
00538                         drawPalmTrunc(0.07f, 0.7f, 5.0f);
00539                         drawPalmLevel(0.0f, 0.6f, 0.6f, 0.8f, 7.0f, 0.39f, 0.365f);
00540                 glEndList();
00541                 glNewList(treePalm2SmallList = glGenLists(1), GL_COMPILE);
00542                         drawPalmTrunc(0.07f, 0.7f, 3.0f);
00543                         drawPalmLevel(0.0f, 0.6f, 0.6f, 0.8f, 3.0f, 0.39f, 0.365f);
00544                 glEndList();
00545 
00546                 glNewList(treePalm3List = glGenLists(1), GL_COMPILE);
00547                         drawPalmTrunc(0.07f, 0.7f, 5.0f);
00548                         drawPalmLevel(0.0f, 0.6f, 0.6f, 0.8f, 7.0f, 0.0f, 0.25f);
00549                 glEndList();
00550                 glNewList(treePalm3SmallList = glGenLists(1), GL_COMPILE);
00551                         drawPalmTrunc(0.07f, 0.7f, 3.0f);
00552                         drawPalmLevel(0.0f, 0.6f, 0.6f, 0.8f, 3.0f, 0.0f, 0.25f);
00553                 glEndList();
00554 
00555                 glNewList(treePalm4List = glGenLists(1), GL_COMPILE);
00556                         drawPalmTrunc(0.07f, 0.7f, 5.0f);
00557                         drawPalmLevel(0.0f, 0.6f, 0.6f, 0.8f, 7.0f, 0.39f, 0.25f);
00558                 glEndList();
00559                 glNewList(treePalm4SmallList = glGenLists(1), GL_COMPILE);
00560                         drawPalmTrunc(0.07f, 0.7f, 3.0f);
00561                         drawPalmLevel(0.0f, 0.6f, 0.6f, 0.8f, 3.0f, 0.39f, 0.25f);
00562                 glEndList();
00563 
00564                 glNewList(treePalmBList = glGenLists(1), GL_COMPILE);
00565                         drawPalmTrunc(0.07f, 0.5f, 5.0f, 0.664f, 0.0f, 0.172f, 0.656f);
00566                         drawPineLevel(0.164f, 0.836f, 0.5f, 0.4f, 0.3f, 0.164f, 8.0f, true, 15.0f);
00567                         drawPineLevel(0.164f, 0.836f, 0.4f, 0.5f, 0.4f, 0.164f, 8.0f, false);
00568                 glEndList();
00569                 glNewList(treePalmB2List = glGenLists(1), GL_COMPILE);
00570                         drawPalmTrunc(0.07f, 0.5f, 5.0f, 0.664f, 0.0f, 0.172f, 0.656f);
00571                         drawPineLevel(0.5f, 0.836f, 0.5f, 0.4f, 0.3f, 0.164f, 8.0f, true, 15.0f);
00572                         drawPineLevel(0.5f, 0.836f, 0.4f, 0.5f, 0.4f, 0.164f, 8.0f, false);
00573                 glEndList();
00574                 glNewList(treePalmB3List = glGenLists(1), GL_COMPILE);
00575                         drawPalmTrunc(0.07f, 0.5f, 5.0f, 0.664f, 0.0f, 0.172f, 0.656f);
00576                         drawPineLevel(0.836f, 0.836f, 0.5f, 0.4f, 0.3f, 0.164f, 8.0f, true, 15.0f);
00577                         drawPineLevel(0.836f, 0.836f, 0.4f, 0.5f, 0.4f, 0.164f, 8.0f, false);
00578                 glEndList();
00579                 glNewList(treePalmB4List = glGenLists(1), GL_COMPILE);
00580                         drawPalmTrunc(0.07f, 0.5f, 5.0f, 0.664f, 0.0f, 0.172f, 0.656f);
00581                         drawPineLevel(0.164f, 0.5f, 0.5f, 0.4f, 0.3f, 0.164f, 8.0f, true, 15.0f);
00582                         drawPineLevel(0.164f, 0.5f, 0.4f, 0.5f, 0.4f, 0.164f, 8.0f, false);
00583                 glEndList();
00584                 glNewList(treePalmB5List = glGenLists(1), GL_COMPILE);
00585                         drawPalmTrunc(0.07f, 0.5f, 5.0f, 0.664f, 0.0f, 0.172f, 0.656f);
00586                         drawPineLevel(0.5f, 0.5f, 0.5f, 0.4f, 0.3f, 0.164f, 8.0f, true, 15.0f);
00587                         drawPineLevel(0.5f, 0.5f, 0.4f, 0.5f, 0.4f, 0.164f, 8.0f, false);
00588                 glEndList();
00589                 glNewList(treePalmB6List = glGenLists(1), GL_COMPILE);
00590                         drawPalmTrunc(0.07f, 0.5f, 5.0f, 0.664f, 0.0f, 0.172f, 0.656f);
00591                         drawPineLevel(0.164f, 0.164f, 0.5f, 0.4f, 0.3f, 0.164f, 8.0f, true, 15.0f);
00592                         drawPineLevel(0.164f, 0.164f, 0.4f, 0.5f, 0.4f, 0.164f, 8.0f, false);
00593                 glEndList();
00594                 glNewList(treePalmB7List = glGenLists(1), GL_COMPILE);
00595                         drawPalmTrunc(0.07f, 0.5f, 5.0f, 0.664f, 0.0f, 0.172f, 0.656f);
00596                         drawPineLevel(0.164f, 0.5f, 0.5f, 0.4f, 0.3f, 0.164f, 8.0f, true, 15.0f);
00597                         drawPineLevel(0.164f, 0.5f, 0.4f, 0.5f, 0.4f, 0.164f, 8.0f, false);
00598                 glEndList();
00599 
00600                 glNewList(treePalmBurntList = glGenLists(1), GL_COMPILE);
00601                         glColor3f(0.3f, 0.3f, 0.3f);
00602                         drawPalmTrunc(0.07f, 0.7f, 5.0f);
00603                 glEndList();
00604                 glNewList(treePalmBurntSmallList = glGenLists(1), GL_COMPILE);
00605                         glColor3f(0.3f, 0.3f, 0.3f);
00606                         drawPalmTrunc(0.07f, 0.7f, 3.0f);
00607                 glEndList();
00608 
00609                 glNewList(treeOakList = glGenLists(1), GL_COMPILE);
00610                         drawPineTrunc(0.02f, 0.75f, 0.0f, 0.836f, 0.0f, 0.164f, 0.164f, 8.0f);
00611                         drawPineLevel(0.5f, 0.836f, 0.4f, 0.5f, 0.3f, 0.164f, 8.0f, false, 15.0f);
00612                         drawPineLevel(0.164f, 0.836f, 0.3f, 0.6f, 0.5f, 0.164f, 8.0f, false);
00613                         drawPineLevel(0.5f, 0.836f, 0.2f, 0.8f, 0.6f, 0.164f, 8.0f, true, 15.0f);
00614                 glEndList();
00615                 glNewList(treeOakSmallList = glGenLists(1), GL_COMPILE);
00616                         drawPineTrunc(0.02f, 0.75f, 0.0f, 0.836f, 0.0f, 0.164f, 0.164f, 8.0f);
00617                         drawPineLevel(0.164f, 0.836f, 0.3f, 0.6f, 0.5f, 0.164f, 8.0f, true);
00618                 glEndList();    
00619 
00620                 glNewList(treeOak2List = glGenLists(1), GL_COMPILE);
00621                         drawPineTrunc(0.02f, 0.75f, 0.0f, 0.836f, 0.0f, 0.164f, 0.164f, 8.0f);
00622                         drawPineLevel(0.164f, 0.5f, 0.4f, 0.5f, 0.3f, 0.164f, 8.0f, false, 15.0f);
00623                         drawPineLevel(0.836f, 0.836f, 0.3f, 0.6f, 0.5f, 0.164f, 8.0f, false);
00624                         drawPineLevel(0.164f, 0.5f, 0.2f, 0.8f, 0.6f, 0.164f, 8.0f, true, 15.0f);
00625                 glEndList();
00626                 glNewList(treeOak2SmallList = glGenLists(1), GL_COMPILE);
00627                         drawPineTrunc(0.02f, 0.75f, 0.0f, 0.836f, 0.0f, 0.164f, 0.164f, 8.0f);
00628                         drawPineLevel(0.836f, 0.836f, 0.3f, 0.6f, 0.5f, 0.164f, 8.0f, true);
00629                 glEndList();    
00630 
00631                 glNewList(treeOak3List = glGenLists(1), GL_COMPILE);
00632                         drawPineTrunc(0.02f, 0.75f, 0.0f, 0.836f, 0.0f, 0.164f, 0.164f, 8.0f);
00633                         drawPineLevel(0.836f, 0.5f, 0.4f, 0.5f, 0.3f, 0.164f, 8.0f, false, 15.0f);
00634                         drawPineLevel(0.5f, 0.5f, 0.3f, 0.6f, 0.5f, 0.164f, 8.0f, false);
00635                         drawPineLevel(0.836f, 0.5f, 0.2f, 0.8f, 0.6f, 0.164f, 8.0f, true, 15.0f);
00636                 glEndList();
00637                 glNewList(treeOak3SmallList = glGenLists(1), GL_COMPILE);
00638                         drawPineTrunc(0.02f, 0.75f, 0.0f, 0.836f, 0.0f, 0.164f, 0.164f, 8.0f);
00639                         drawPineLevel(0.5f, 0.5f, 0.3f, 0.6f, 0.5f, 0.164f, 8.0f, true);
00640                 glEndList();    
00641 
00642                 glNewList(treeOak4List = glGenLists(1), GL_COMPILE);
00643                         drawPineTrunc(0.02f, 0.75f, 0.0f, 0.836f, 0.0f, 0.164f, 0.164f, 8.0f);
00644                         drawPineLevel(0.5f, 0.164f, 0.4f, 0.5f, 0.3f, 0.164f, 8.0f, false, 15.0f);
00645                         drawPineLevel(0.164f, 0.164f, 0.3f, 0.6f, 0.5f, 0.164f, 8.0f, false);
00646                         drawPineLevel(0.5f, 0.164f, 0.2f, 0.8f, 0.6f, 0.164f, 8.0f, true, 15.0f);
00647                 glEndList();
00648                 glNewList(treeOak4SmallList = glGenLists(1), GL_COMPILE);
00649                         drawPineTrunc(0.02f, 0.75f, 0.0f, 0.836f, 0.0f, 0.164f, 0.164f, 8.0f);
00650                         drawPineLevel(0.164f, 0.164f, 0.3f, 0.6f, 0.5f, 0.164f, 8.0f, true);
00651                 glEndList();    
00652         }
00653 
00654         unsigned int state = 0;
00655         if (setState)
00656         {
00657                 state = GLState::TEXTURE_ON;
00658                 bool vertexLighting = OptionsDisplay::instance()->getNoModelLighting();
00659                 if (!vertexLighting)
00660                 {
00661                         state |= 
00662                                 GLState::NORMALIZE_ON | 
00663                                 GLState::LIGHTING_ON | 
00664                                 GLState::LIGHT1_ON;
00665 
00666                         Vector4 ambientColor(0.4f, 0.4f, 0.4f, 1.0f);
00667                         Vector4 diffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
00668                         Vector4 specularColor(0.0f, 0.0f, 0.0f, 1.0f);
00669                         Vector4 emissiveColor(0.0f, 0.0f, 0.0f, 1.0f);
00670                         float shininess = 0.0f;
00671                         glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambientColor);
00672                         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuseColor);
00673                         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specularColor);
00674                         glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emissiveColor);
00675                         glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
00676                 }
00677                 else
00678                 {
00679                         state |= 
00680                                 GLState::NORMALIZE_OFF | 
00681                                 GLState::LIGHTING_OFF | 
00682                                 GLState::LIGHT1_OFF;
00683 
00684                         glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00685                 }
00686         }
00687         GLGlobalState globalState(state);
00688 }
00689 
00690 void ModelRendererTree::drawInternal(float distance, float fade, bool setState)
00691 {
00692         // Figure out which display list to call
00693         GLTexture *texture = 0;
00694         GLuint treeList = 0;
00695         GLuint smallTreeList = 0;
00696         switch(treeType_)
00697         {
00698         case TreeModelFactory::ePineNormal:
00699                 texture = &pineTextureA_;
00700                 treeList = treePineList;
00701                 smallTreeList = treePineSmallList;
00702                 break;
00703         case TreeModelFactory::ePine2:
00704                 texture = &pineTextureB_;
00705                 treeList = treePine2List;
00706                 smallTreeList = treePine2SmallList;
00707                 break;
00708         case TreeModelFactory::ePine3:
00709                 texture = &pineTextureB_;
00710                 treeList = treePine3List;
00711                 smallTreeList = treePine3SmallList;
00712                 break;
00713         case TreeModelFactory::ePine4:
00714                 texture = &pineTextureB_;
00715                 treeList = treePine4List;
00716                 smallTreeList = treePine4SmallList;
00717                 break;
00718         case TreeModelFactory::ePine2Snow:
00719                 texture = &pineTextureB_;
00720                 treeList = treePine2SnowList;
00721                 smallTreeList = treePine2SnowSmallList;
00722                 break;
00723         case TreeModelFactory::ePine3Snow:
00724                 texture = &pineTextureB_;
00725                 treeList = treePine3SnowList;
00726                 smallTreeList = treePine3SnowSmallList;
00727                 break;
00728         case TreeModelFactory::ePine4Snow:
00729                 texture = &pineTextureB_;
00730                 treeList = treePine4SnowList;
00731                 smallTreeList = treePine4SnowSmallList;
00732                 break;
00733         case TreeModelFactory::ePineBurnt:
00734                 texture = &pineTextureA_;
00735                 treeList = treePineBurntList;
00736                 smallTreeList = treePineBurntSmallList;
00737                 break;
00738         case TreeModelFactory::ePineSnow:
00739                 texture = &pineTextureA_;
00740                 treeList = treePineSnowList;
00741                 smallTreeList = treePineSnowSmallList;
00742                 break;
00743         case TreeModelFactory::ePineYellow:
00744                 texture = &pineTextureA_;
00745                 treeList = treePineYellowList;
00746                 smallTreeList = treePineYellowSmallList;
00747                 break;
00748         case TreeModelFactory::ePineLight:
00749                 texture = &pineTextureA_;
00750                 treeList = treePineLightList;
00751                 smallTreeList = treePineLightSmallList;
00752                 break;
00753         case TreeModelFactory::ePalmNormal:
00754                 texture = &palmTextureA_;
00755                 treeList = treePalmList;
00756                 smallTreeList = treePalmSmallList;
00757                 break;
00758         case TreeModelFactory::ePalm2:
00759                 texture = &palmTextureA_;
00760                 treeList = treePalm2List;
00761                 smallTreeList = treePalm2SmallList;
00762                 break;
00763         case TreeModelFactory::ePalm3:
00764                 texture = &palmTextureA_;
00765                 treeList = treePalm3List;
00766                 smallTreeList = treePalm3SmallList;
00767                 break;
00768         case TreeModelFactory::ePalm4:
00769                 texture = &palmTextureA_;
00770                 treeList = treePalm4List;
00771                 smallTreeList = treePalm4SmallList;
00772                 break;
00773         case TreeModelFactory::ePalmB:
00774                 texture = &palmTextureB_;
00775                 treeList = treePalmBList;
00776                 smallTreeList = treePalmBList;
00777                 break;
00778         case TreeModelFactory::ePalmB2:
00779                 texture = &palmTextureB_;
00780                 treeList = treePalmB2List;
00781                 smallTreeList = treePalmB2List;
00782                 break;
00783         case TreeModelFactory::ePalmB3:
00784                 texture = &palmTextureB_;
00785                 treeList = treePalmB3List;
00786                 smallTreeList = treePalmB3List;
00787                 break;
00788         case TreeModelFactory::ePalmB4:
00789                 texture = &palmTextureB_;
00790                 treeList = treePalmB4List;
00791                 smallTreeList = treePalmB4List;
00792                 break;
00793         case TreeModelFactory::ePalmB5:
00794                 texture = &palmTextureB_;
00795                 treeList = treePalmB5List;
00796                 smallTreeList = treePalmB5List;
00797                 break;
00798         case TreeModelFactory::ePalmB6:
00799                 texture = &palmTextureB_;
00800                 treeList = treePalmB6List;
00801                 smallTreeList = treePalmB6List;
00802                 break;
00803         case TreeModelFactory::ePalmB7:
00804                 texture = &palmTextureB_;
00805                 treeList = treePalmB7List;
00806                 smallTreeList = treePalmB7List;
00807                 break;
00808         case TreeModelFactory::ePalmBurnt:
00809                 texture = &palmTextureA_;
00810                 treeList = treePalmBurntList;
00811                 smallTreeList = treePalmBurntSmallList;
00812                 break;
00813         case TreeModelFactory::eOak:
00814                 texture = &oakTextureA_;
00815                 treeList = treeOakList;
00816                 smallTreeList = treeOakSmallList;
00817                 break;
00818         case TreeModelFactory::eOak2:
00819                 texture = &oakTextureA_;
00820                 treeList = treeOak2List;
00821                 smallTreeList = treeOak2SmallList;
00822                 break;
00823         case TreeModelFactory::eOak3:
00824                 texture = &oakTextureA_;
00825                 treeList = treeOak3List;
00826                 smallTreeList = treeOak3SmallList;
00827                 break;
00828         case TreeModelFactory::eOak4:
00829                 texture = &oakTextureA_;
00830                 treeList = treeOak4List;
00831                 smallTreeList = treeOak4SmallList;
00832                 break;
00833         };
00834 
00835         DIALOG_ASSERT(texture && treeList && smallTreeList);
00836         if (setState)
00837         {
00838                 texture->draw();
00839         }
00840         
00841         if (OptionsDisplay::instance()->getLowTreeDetail() || distance > 125.0f)
00842         {
00843                 glCallList(smallTreeList);
00844                 GLInfo::addNoTriangles(20);
00845         }
00846         else 
00847         {
00848                 glCallList(treeList);
00849                 GLInfo::addNoTriangles(10);
00850         }
00851 }
00852 

Generated on Mon Feb 16 15:14:46 2009 for Scorched3D by  doxygen 1.5.3