Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 29, 2008, 3:26:55 AM (16 years ago)
Author:
landauf
Message:

added camerapositions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2041 r2042  
    3737#include "objects/infos/PlayerInfo.h"
    3838#include "objects/worldentities/Camera.h"
     39#include "objects/worldentities/CameraPosition.h"
    3940#include "overlays/OverlayGroup.h"
    4041
     
    9293
    9394        XMLPortParam(ControllableEntity, "hudtemplate", setHudTemplate, getHudTemplate, xmlelement, mode);
     95        XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemkplate, xmlelement, mode);
     96
     97        XMLPortObject(ControllableEntity, WorldEntity, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);
     98    }
     99
     100    void ControllableEntity::addCameraPosition(CameraPosition* position)
     101    {
     102        this->attach(position);
     103        this->cameraPositions_.push_back(position);
     104    }
     105
     106    CameraPosition* ControllableEntity::getCameraPosition(unsigned int index) const
     107    {
     108        unsigned int i = 0;
     109        for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
     110        {
     111            if (i == index)
     112                return (*it);
     113            ++i;
     114        }
     115        return 0;
     116    }
     117
     118    void ControllableEntity::switchCamera()
     119    {
     120        if (this->camera_)
     121        {
     122            if (this->camera_->getParent() == this && this->cameraPositions_.size() > 0)
     123            {
     124                this->cameraPositions_.front()->attachCamera(this->camera_);
     125            }
     126            else if (this->cameraPositions_.size() > 0)
     127            {
     128                for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
     129                {
     130                    if ((*it) == this->camera_->getParent())
     131                    {
     132                        ++it;
     133                        if (it != this->cameraPositions_.end())
     134                            (*it)->attachCamera(this->camera_);
     135                        else
     136                            (*this->cameraPositions_.begin())->attachCamera(this->camera_);
     137                        break;
     138                    }
     139                }
     140            }
     141            else
     142            {
     143                this->attach(this->camera_);
     144            }
     145        }
    94146    }
    95147
     
    105157        this->playerID_ = player->getObjectID();
    106158        this->bControlled_ = (player->isLocalPlayer() && player->isHumanPlayer());
    107 
    108159        if (this->bControlled_)
    109160        {
     
    111162
    112163            if (!Core::isMaster())
     164            {
     165COUT(0) << "CE: bidirectional synchronization" << std::endl;
    113166                this->setObjectMode(network::direction::bidirectional);
     167            }
    114168        }
    115169    }
     
    145199        this->camera_ = new Camera(this);
    146200        this->camera_->requestFocus();
    147         this->attach(this->camera_);
     201        if (this->cameraPositionTemplate_ != "")
     202            this->addTemplate(this->cameraPositionTemplate_);
     203        if (this->cameraPositions_.size() > 0)
     204            this->cameraPositions_.front()->attachCamera(this->camera_);
     205        else
     206            this->attach(this->camera_);
    148207
    149208        if (this->hudtemplate_ != "")
     
    157216    {
    158217        std::cout << "###### stop local control" << std::endl;
    159         this->detach(this->camera_);
     218        this->camera_->detachFromParent();
    160219        delete this->camera_;
    161220        this->camera_ = 0;
     
    187246    void ControllableEntity::registerVariables()
    188247    {
     248        REGISTERSTRING(this->cameraPositionTemplate_, network::direction::toclient);
     249
    189250        REGISTERDATA(this->server_position_,    network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition));
    190251        REGISTERDATA(this->server_velocity_,    network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerVelocity));
Note: See TracChangeset for help on using the changeset viewer.