Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 20, 2005, 12:22:17 AM (19 years ago)
Author:
patrick
Message:

christmas: model loading progress

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/christmas_branche/src/world_entities/world_entity.cc

    r6167 r6169  
    2121
    2222#include "model.h"
     23#include "md2Model.h"
    2324#include "resource_manager.h"
    2425#include "load_param.h"
     
    5657  this->objectListNumber = OM_INIT;
    5758  this->objectListIterator = NULL;
     59  this->supportsLOD = false;
    5860
    5961  this->toList(OM_NULL);
     
    117119              this->loadModel(lodFile, scaling, i);
    118120          }
     121          this->supportsLOD = true;
    119122        return;
    120123      }
     
    134137      {
    135138        PRINTF(4)("fetching MD2 file: %s\n", fileName);
    136         this->setModel((Model*)ResourceManager::getInstance()->load(fileName, MD2, RP_CAMPAIGN), 0);
     139//         MD2Model* m = (MD2Model*)ResourceManager::getInstance()->load(fileName, MD2, RP_CAMPAIGN);
     140        MD2Model* m = new MD2Model(fileName, "/home/boenzlip/orxonox/data/maps/santa_claus.pcx");
     141        m->debug();
     142        //this->setModel((Model*)ResourceManager::getInstance()->load(fileName, MD2, RP_CAMPAIGN), 0);
     143        this->setModel((Model*)m, 0);
    137144      }
    138145  }
     
    154161  {
    155162    Resource* resource = ResourceManager::getInstance()->locateResourceByPointer(this->models[modelNumber]);
    156     if (resource != NULL)
    157       ResourceManager::getInstance()->unload(resource, RP_LEVEL);
    158     else
    159       delete this->models[modelNumber];
    160   }
     163//     if (resource != NULL)
     164    ResourceManager::getInstance()->unload(resource, RP_LEVEL);
     165  }
     166  else
     167    delete this->models[modelNumber];
     168
    161169  this->models[modelNumber] = model;
     170
    162171
    163172//   if (this->model != NULL)
     
    281290}
    282291
     292
     293/**
     294 *  this functions draws the model automaticaly in multiple LOD
     295 */
    283296void WorldEntity::drawLODsafe() const
    284297{
    285   if (!this->models.empty())
    286   {
    287     glMatrixMode(GL_MODELVIEW);
    288     glPushMatrix();
    289 
    290     /* translate */
    291     glTranslatef (this->getAbsCoor ().x,
    292                   this->getAbsCoor ().y,
    293                   this->getAbsCoor ().z);
    294     Vector tmpRot = this->getAbsDir().getSpacialAxis();
    295     glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
     298  if (!unlikely(this->models.empty()))
     299  {
     300    if( likely(this->supportsLOD))
     301    {
     302      glMatrixMode(GL_MODELVIEW);
     303      glPushMatrix();
     304
     305      /* translate */
     306      glTranslatef (this->getAbsCoor ().x,
     307                    this->getAbsCoor ().y,
     308                    this->getAbsCoor ().z);
     309      Vector tmpRot = this->getAbsDir().getSpacialAxis();
     310      glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    296311
    297312
    298313    // This Draws the LOD's
    299     float cameraDistance = (State::getCamera()->getAbsCoor() - this->getAbsCoor()).len();
    300     if (cameraDistance > 30 && this->models.size() >= 3 && this->models[2] != NULL)
     314      float cameraDistance = (State::getCamera()->getAbsCoor() - this->getAbsCoor()).len();
     315      if (cameraDistance > 30 && this->models.size() >= 3 && this->models[2] != NULL)
     316      {
     317        this->models[2]->draw();
     318      }
     319      else if (cameraDistance > 10 && this->models.size() >= 2 && this->models[1] != NULL)
     320      {
     321        this->models[1]->draw();
     322      }
     323      else if (this->models.size() >= 1 && this->models[0] != NULL)
     324      {
     325        this->models[0]->draw();
     326      }
     327      glPopMatrix();
     328    }
     329    else // no LOD
    301330    {
    302        this->models[2]->draw();
     331      glMatrixMode(GL_MODELVIEW);
     332      glPushMatrix();
     333
     334      /* translate */
     335      glTranslatef (this->getAbsCoor ().x,
     336                    this->getAbsCoor ().y,
     337                    this->getAbsCoor ().z);
     338      Vector tmpRot = this->getAbsDir().getSpacialAxis();
     339      glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
     340
     341      this->models[0]->draw();
     342
     343      glPopMatrix();
    303344    }
    304     else if (cameraDistance > 10 && this->models.size() >= 2 && this->models[1] != NULL)
    305     {
    306       this->models[1]->draw();
    307     }
    308     else if (this->models.size() >= 1 && this->models[0] != NULL)
    309     {
    310       this->models[0]->draw();
    311     }
    312     glPopMatrix();
    313   }
     345  }
     346
    314347}
    315348
Note: See TracChangeset for help on using the changeset viewer.