Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 6, 2016, 1:56:26 PM (8 years ago)
Author:
landauf
Message:

let Planet inherit from Model to avoid code duplication (especially lod levels).
since model is a static entity, all planets with rotation and/or dynamic physics need to be attached to a movableentity now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ogre1.9/src/modules/objects/Planet.cc

    r10624 r11128  
    4747     * @brief Constructor
    4848     */
    49     Planet::Planet(Context* context) : MovableEntity(context)
     49    Planet::Planet(Context* context) : Model(context)
    5050    {
    5151        RegisterObject(Planet);
     52        this->setLodEnabled(false);
    5253        this->registerVariables();
    5354    }
     
    5859    Planet::~Planet()
    5960    {
    60         if (this->isInitialized() && this->mesh_.getEntity())
    61             this->detachOgreObject(this->mesh_.getEntity());
    6261    }
    6362
     
    8786    }
    8887
    89     void Planet::changedMesh()
     88    void Planet::changedAtmosphere()
    9089    {
    9190        if( GameMode::showsGraphics() )
    9291        {
    93             if (this->mesh_.getEntity())
    94                 this->detachOgreObject(this->mesh_.getEntity());
    95 
    96             this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);
    97 
    98             if (this->mesh_.getEntity())
     92            if (this->getMesh().getEntity())
    9993            {
    100                 this->attachOgreObject(this->mesh_.getEntity());
    101                 this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
    102                 this->mesh_.setVisible(this->isVisible());
    103 
    104                 float scaleFactor = this->getScale();
    105 
    106 #if OGRE_VERSION >= 0x010800
    107                 Ogre::ProgressiveMesh::LodValueList distList;
    108 #elif OGRE_VERSION >= 0x010700
    109                 Ogre::Mesh::LodValueList distList;
    110 #else
    111                 Ogre::Mesh::LodDistanceList distList;
    112 #endif
    113 
    114                 distList.push_back(10.0f*scaleFactor);
    115                 distList.push_back(19.0f*scaleFactor);
    116                 distList.push_back(27.0f*scaleFactor);
    117                 distList.push_back(34.0f*scaleFactor);
    118                 distList.push_back(40.0f*scaleFactor);
    119                 distList.push_back(45.0f*scaleFactor);
    120                 distList.push_back(49.0f*scaleFactor);
    121                 distList.push_back(52.0f*scaleFactor);
    122                 distList.push_back(54.0f*scaleFactor);
    123                 distList.push_back(55.0f*scaleFactor);
    124 
    125                 float reductionValue = 0.2f;
    126 
    127 #if OGRE_VERSION >= 0x010800
    128                 Ogre::ProgressiveMesh::generateLodLevels(this->mesh_.getEntity()->getMesh().get(), distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL,
    129                     reductionValue);
    130 #else
    131                 this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, reductionValue);
    132 #endif
    133                 billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->atmosphere_, Vector3(0,0,0));
     94                this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->atmosphere_, Vector3(0,0,0));
    13495
    13596                this->attachOgreObject(this->billboard_.getBillboardSet());
    13697                this->billboard_.getBillboardSet()->setUseAccurateFacing(true);
    137                 this->setCastShadows(true);
    138                 this->billboard_.getBillboardSet()->setRenderQueueGroup(this->mesh_.getEntity()->getRenderQueueGroup());
    139                 this->mesh_.setCastShadows(true);
     98                this->billboard_.getBillboardSet()->setRenderQueueGroup(this->getMesh().getEntity()->getRenderQueueGroup());
    14099            }
    141100        }
    142     }
    143 
    144     void Planet::changedShadows()
    145     {
    146         this->mesh_.setCastShadows(this->bCastShadows_);
    147101    }
    148102
     
    154108        XMLPortParam(Planet, "atmospheresize", setAtmosphereSize, getAtmosphereSize, xmlelement,mode);
    155109        XMLPortParam(Planet, "imagesize", setImageSize, getImageSize, xmlelement,mode);
    156         XMLPortParam(Planet, "mesh", setMeshSource, getMeshSource, xmlelement, mode);
    157         XMLPortParam(Planet, "shadow", setCastShadows, getCastShadows, xmlelement, mode).defaultValues(true);
    158110    }
    159111
    160112    void Planet::registerVariables()
    161113    {
    162         registerVariable(this->atmosphere_, VariableDirection::ToClient);
     114        registerVariable(this->atmosphere_, VariableDirection::ToClient, new NetworkCallback<Planet>(this, &Planet::changedAtmosphere));
    163115        registerVariable(this->atmosphereSize, VariableDirection::ToClient);
    164116        registerVariable(this->imageSize, VariableDirection::ToClient);
    165         // Note: the meshSrc should be synchronised after atmosphere and other values, because the meshSrc callback setts the atmosphere billboards
    166         registerVariable(this->meshSrc_, VariableDirection::ToClient, new NetworkCallback<Planet>(this, &Planet::changedMesh));
    167         registerVariable(this->bCastShadows_, VariableDirection::ToClient, new NetworkCallback<Planet>(this, &Planet::changedShadows));
    168117    }
    169118
     
    171120    {
    172121        SUPER(Planet, changedVisibility);
    173         if (this->isInitialized())
    174         {
    175             this->mesh_.setVisible(this->isVisible());
    176             this->billboard_.setVisible(this->isVisible());
    177         }
     122
     123        this->billboard_.setVisible(this->isVisible());
    178124    }
    179125}
Note: See TracChangeset for help on using the changeset viewer.