Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 30, 2011, 9:55:38 AM (14 years ago)
Author:
dafrick
Message:

Make the camera position stay the same between differnet stones in Tetris.

Location:
code/branches/presentation/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/modules/tetris/Tetris.cc

    r8661 r8680  
    233233        if(this->player_ == NULL)
    234234            return;
    235        
     235
     236        unsigned int cameraIndex = 0;
    236237        if(this->activeStone_ != NULL)
     238        {
     239            // Get camera settings
     240            cameraIndex = this->activeStone_->getCurrentCameraIndex();
    237241            this->player_->stopControl();
     242        }
    238243       
    239244        // Make the last stone to be created the active stone.
     
    242247        this->player_->startControl(this->activeStone_);
    243248        this->activeStone_->setVelocity(0.0f, -this->center_->getStoneSpeed(), 0.0f);
     249        this->activeStone_->setCameraPosition(cameraIndex);
    244250    }
    245251
  • code/branches/presentation/src/orxonox/worldentities/ControllableEntity.cc

    r8580 r8680  
    120120
    121121        XMLPortParam(ControllableEntity, "hudtemplate", setHudTemplate, getHudTemplate, xmlelement, mode);
    122         XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemkplate, xmlelement, mode);
     122        XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemplate, xmlelement, mode);
    123123
    124124        XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);
     
    170170        }
    171171        return 0;
     172    }
     173
     174    unsigned int ControllableEntity::getCurrentCameraIndex() const
     175    {
     176        if (this->cameraPositions_.size() <= 0)
     177            return 0;
     178
     179        unsigned int counter = 0;
     180        for (std::list<SmartPtr<CameraPosition> >::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
     181        {
     182            if ((*it) == this->currentCameraPosition_)
     183                break;
     184            counter++;
     185        }
     186        if (counter >= this->cameraPositions_.size())
     187            return 0;
     188
     189        return counter;
     190    }
     191   
     192    bool ControllableEntity::setCameraPosition(unsigned int index)
     193    {
     194        if(this->camera_ != NULL && this->cameraPositions_.size() > 0)
     195        {
     196            if(index >= this->cameraPositions_.size())
     197                index = 0;
     198
     199            CameraPosition* position = this->getCameraPosition(index);
     200            position->attachCamera(this->camera_);
     201            this->currentCameraPosition_ = position;
     202            return true;
     203        }
     204
     205        return false;
    172206    }
    173207
  • code/branches/presentation/src/orxonox/worldentities/ControllableEntity.h

    r8580 r8680  
    116116            inline const std::list<SmartPtr<CameraPosition> >& getCameraPositions() const
    117117                { return this->cameraPositions_; }
     118            unsigned int getCurrentCameraIndex() const;
     119            bool setCameraPosition(unsigned int index);
    118120
    119121            inline void setCameraPositionTemplate(const std::string& name)
    120122                { this->cameraPositionTemplate_ = name; }
    121             inline const std::string& getCameraPositionTemkplate() const
     123            inline const std::string& getCameraPositionTemplate() const
    122124                { return this->cameraPositionTemplate_; }
    123125
Note: See TracChangeset for help on using the changeset viewer.