Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6843


Ignore:
Timestamp:
May 3, 2010, 4:21:07 PM (14 years ago)
Author:
kolibri7
Message:

fix of the problem of getting the right scale; cast to WorldEntity doesn't work yet!!! (Compiler error)

Location:
code/branches/lod/src/orxonox/graphics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/lod/src/orxonox/graphics/Model.cc

    r6838 r6843  
    2929#include "Model.h"
    3030
    31 // What's this? With the directory in front the filename, my compiler can't find the file...
    32 //#include <OGRE/OgreEntity.h>
    3331#include <OgreEntity.h>
    3432
     
    7674    }
    7775
     76    float Model::getBiggestScale(Vector3 scale3d)
     77    {
     78        float scaleFactor = scale3d.x;
     79        if(scale3d.y>scaleFactor)
     80            scaleFactor = scale3d.y;
     81        if(scale3d.z>scaleFactor)
     82            scaleFactor = scale3d.z;
     83        return scaleFactor;
     84    }
     85   
    7886    void Model::changedMesh()
    7987    {
     
    93101                //LOD
    94102                if(this->mesh_.getEntity()->getMesh()->getNumLodLevels()==1
    95                     &&this->meshSrc_!="laserbeam.mesh"
    96                     &&this->lodLevel_!=0)
     103                    &&this->meshSrc_!="laserbeam.mesh")
    97104                {
    98                     Vector3 scale3d = this->getScale3D();
    99                     float scaleFactor = scale3d.x;
    100                     if(scale3d.y>scaleFactor)
    101                         scaleFactor = scale3d.y;
    102                     if(scale3d.z>scaleFactor)
    103                         scaleFactor = scale3d.z;
     105                    float scaleFactor = getBiggestScale(this->getScale3D());
     106                    BaseObject* creatorPtr = this->getCreator();
     107                    while(creatorPtr!=0)
     108                    {
     109                        // TODO Cannot cast to WorldEntity
     110                        scaleFactor *= getBiggestScale(((WorldEntity) creatorPtr)->getScale3D());
     111                        creatorPtr = this->getCreator();
     112                    }
    104113                   
    105114                    Level* level_ = this->getLevel();
     
    109118                        setLodLevel(lodInfo->getLodLevel());
    110119                   
    111                     COUT(0) << this->meshSrc_<< " lodLevel_: " << this->lodLevel_ <<" scale: "<< scaleFactor << std::endl;
    112                     //Fuer Asteroiden perfekt
     120                    COUT(0) << "Setting lodLevel for " << this->meshSrc_<< " with lodLevel_: " << this->lodLevel_ <<" and scale: "<< scaleFactor << ":" << std::endl;
    113121
    114122#if OGRE_VERSION >= 0x010700
     
    118126#endif
    119127
    120                     float factor = scaleFactor;
    121                     COUT(0)<<"scaleFactor:"<<scaleFactor<<std::endl;
     128                    if(lodLevel_>0)
     129                    {
     130                        float factor = scaleFactor*5/lodLevel_;
     131                       
     132                        COUT(0)<<"LodLevel set with factor: "<<factor<<std::endl;
    122133
    123                     distList.push_back(70.0f*factor);
    124                     distList.push_back(140.0f*factor);
    125                     distList.push_back(170.0f*factor);
    126                     distList.push_back(200.0f*factor);
    127                     distList.push_back(230.0f*factor);
    128                     distList.push_back(250.0f*factor);
    129                     distList.push_back(270.0f*factor);
    130                     distList.push_back(290.0f*factor);
    131                     distList.push_back(310.0f*factor);
    132                     distList.push_back(330.0f*factor);
     134                        distList.push_back(70.0f*factor);
     135                        distList.push_back(140.0f*factor);
     136                        distList.push_back(170.0f*factor);
     137                        distList.push_back(200.0f*factor);
     138                        distList.push_back(230.0f*factor);
     139                        distList.push_back(250.0f*factor);
     140                        distList.push_back(270.0f*factor);
     141                        distList.push_back(290.0f*factor);
     142                        distList.push_back(310.0f*factor);
     143                        distList.push_back(330.0f*factor);
    133144
    134                     float reductionValue = 0.2f;
     145                        float reductionValue = 0.2f;
    135146
    136                    
    137                     //Generiert LOD-Levels
    138                     this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, reductionValue);
     147                       
     148                        //Generiert LOD-Levels
     149                        this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, reductionValue);
     150                    }
     151                    else
     152                    {
     153                        COUT(0)<<"LodLevel not set because lodLevel("<<lodLevel_<<") was < 0."<<std::endl;
     154                    }
    139155                }
    140156            }
  • code/branches/lod/src/orxonox/graphics/Model.h

    r6691 r6843  
    6161            inline bool getCastShadows() const
    6262                { return this->bCastShadows_; }
    63                                
     63               
    6464        private:
    6565            void changedMesh();
    6666            void changedShadows();
    67                        
    68                         //LoD
    69                         inline void setLodLevel(unsigned short lodLevel)
    70                                 { this->lodLevel_ =  lodLevel; }
    71                         inline unsigned short getLodLevel() const
    72                                 { return this->lodLevel_; }
     67           
     68            //LoD
     69            inline void setLodLevel(unsigned short lodLevel)
     70                { this->lodLevel_ =  lodLevel; }
     71            inline unsigned short getLodLevel() const
     72                { return this->lodLevel_; }
     73            float Model::getBiggestScale(Vector3 scale3d);
    7374
    7475            std::string meshSrc_;
    7576            Mesh mesh_;
    7677            bool bCastShadows_;
    77                        
    78                         //LoD
    79                         unsigned short lodLevel_;
     78           
     79            //LoD
     80            unsigned short lodLevel_;
    8081    };
    8182}
Note: See TracChangeset for help on using the changeset viewer.