Changeset 1989 for code/branches/objecthierarchy/src/orxonox/objects
- Timestamp:
- Oct 21, 2008, 4:56:41 PM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox/objects
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/objects/Camera.cc
r1911 r1989 47 47 namespace orxonox 48 48 { 49 Camera::Camera() 50 { 51 RegisterObject(Camera); 49 52 50 Camera::Camera(Ogre::SceneNode* node)51 {52 53 this->bHasFocus_ = false; 53 this-> cameraNode_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(node->getName() + "Camera");54 if( node != NULL )55 this->setPositionNode(node);54 this->bDrag_ = false; 55 this->cameraNode_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(); 56 this->setObjectMode(0x0); 56 57 } 57 58 58 59 Camera::~Camera() 59 60 { 60 CameraHandler::getInstance()->releaseFocus(this); 61 GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->removeAndDestroyChild(cameraNode_->getName()); 62 } 63 64 void Camera::setPositionNode(Ogre::SceneNode* node) 65 { 66 this->positionNode_ = node; 67 // set camera to node values according to camera mode 68 } 69 70 void Camera::setTargetNode(Ogre::SceneNode* obj) 71 { 72 this->targetNode_ = obj; 61 if (this->isInitialized()) 62 { 63 CameraHandler::getInstance()->releaseFocus(this); 64 GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->removeAndDestroyChild(this->cameraNode_->getName()); 65 } 73 66 } 74 67 75 68 void Camera::tick(float dt) 76 69 { 77 if (this->positionNode_ != NULL)78 {79 70 // this stuff here may need some adjustments 80 Vector3 offset = this->positionNode_->getWorldPosition() - this->cameraNode_->getWorldPosition(); 81 float coeff = 15.0f * dt; 82 if (coeff > 1.0f) 83 coeff = 1.0f; 71 float coeff = (this->bDrag_) ? min(1.0f, 15.0f * dt) : (1.0f); 84 72 73 Vector3 offset = this->getNode()->getWorldPosition() - this->cameraNode_->getWorldPosition(); 85 74 this->cameraNode_->translate(coeff * offset); 86 75 87 this->cameraNode_->setOrientation(Quaternion::Slerp(1-coeff, this->positionNode_->getWorldOrientation(), this->cameraNode_->getWorldOrientation(), false)); 88 } 76 this->cameraNode_->setOrientation(Quaternion::Slerp(coeff, this->cameraNode_->getWorldOrientation(), this->getWorldOrientation(), false)); 89 77 } 90 78 … … 95 83 void Camera::update() 96 84 { 97 if(this->positionNode_ != NULL) 98 { 99 this->cameraNode_->setPosition(this->positionNode_->getWorldPosition()); 100 this->cameraNode_->setOrientation(this->positionNode_->getWorldOrientation()); 101 } 85 this->cameraNode_->setPosition(this->getWorldPosition()); 86 this->cameraNode_->setOrientation(this->getWorldOrientation()); 102 87 } 103 88 … … 119 104 this->cameraNode_->attachObject(this->cam_); 120 105 } 106 107 void Camera::requestFocus() 108 { 109 CameraHandler::getInstance()->requestFocus(this); 110 } 121 111 } -
code/branches/objecthierarchy/src/orxonox/objects/Camera.h
r1505 r1989 35 35 36 36 #include "OrxonoxPrereqs.h" 37 #include "objects/worldentities/PositionableEntity.h" 37 38 38 39 namespace orxonox 39 40 { 40 class _OrxonoxExport Camera 41 class _OrxonoxExport Camera : public PositionableEntity 41 42 { 42 43 friend class CameraHandler; 43 44 public: 44 Camera( Ogre::SceneNode* node = NULL);45 Camera(); 45 46 virtual ~Camera(); 46 47 void setPositionNode(Ogre::SceneNode* node);48 inline Ogre::SceneNode* getCameraNode() { return this->positionNode_; }49 // maybe also BaseObject50 void setTargetNode(Ogre::SceneNode* obj);51 52 Ogre::Camera* cam_;53 47 54 48 void tick(float dt); 55 49 void update(); 56 inline bool hasFocus() { return this->bHasFocus_; } 50 51 void requestFocus(); 52 inline bool hasFocus() 53 { return this->bHasFocus_; } 54 55 inline void setDrag(bool bDrag) 56 { this->bDrag_ = bDrag; } 57 inline bool getDrag() const 58 { return this->bDrag_; } 57 59 58 60 private: … … 60 62 void setFocus(Ogre::Camera* ogreCam); 61 63 62 private: 63 Ogre::SceneNode* targetNode_; 64 Ogre::SceneNode* positionNode_; 64 Ogre::Camera* cam_; 65 65 Ogre::SceneNode* cameraNode_; 66 66 Ogre::Vector3 oldPos; 67 67 bool bHasFocus_; 68 bool bDrag_; 68 69 }; 69 70 } -
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc
r1953 r1989 122 122 this->players_.insert(player); 123 123 this->playerJoined(player); 124 125 ControllableEntity* newpawn = this->defaultPawn_.fabricate(); 126 player->startControl(newpawn); 124 127 } 125 128 126 129 void Gametype::removePlayer(PlayerInfo* player) 127 130 { 131 player->stopControl(); 128 132 this->players_.erase(player); 129 133 this->playerLeft(player); -
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.h
r1953 r1989 35 35 36 36 #include "core/BaseObject.h" 37 #include "core/Identifier.h" 37 38 #include "network/ClientConnectionListener.h" 39 #include "objects/worldentities/ControllableEntity.h" 38 40 39 41 namespace orxonox … … 71 73 std::set<PlayerInfo*> players_; 72 74 std::map<unsigned int, PlayerInfo*> clients_; 75 SubclassIdentifier<ControllableEntity> defaultPawn_; 73 76 }; 74 77 } -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc
r1953 r1989 41 41 #include "GraphicsEngine.h" 42 42 #include "objects/gametypes/Gametype.h" 43 #include "objects/worldentities/ControllableEntity.h" 43 44 44 45 namespace orxonox … … 56 57 this->bHumanPlayer_ = false; 57 58 this->bFinishedSetup_ = false; 59 60 this->pawn_ = 0; 61 this->pawnID_ = network::OBJECTID_UNKNOWN; 58 62 59 63 this->setConfigValues(); … … 103 107 REGISTERDATA(ping_, network::direction::toclient); 104 108 REGISTERDATA(bHumanPlayer_, network::direction::toclient); 109 REGISTERDATA(pawnID_, network::direction::toclient, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::updatePawn)); 105 110 REGISTERDATA(bFinishedSetup_, network::direction::bidirectional, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::finishedSetup)); 106 111 } … … 160 165 } 161 166 } 167 168 void PlayerInfo::startControl(ControllableEntity* pawn) 169 { 170 pawn->setPlayer(this); 171 this->pawn_ = pawn; 172 this->pawnID_ = pawn->getObjectID(); 173 } 174 175 void PlayerInfo::stopControl() 176 { 177 this->pawn_->removePlayer(); 178 this->pawn_ = 0; 179 this->pawnID_ = network::OBJECTID_UNKNOWN; 180 } 181 182 void PlayerInfo::updatePawn() 183 { 184 this->pawn_ = dynamic_cast<ControllableEntity*>(network::Synchronisable::getSynchronisable(this->pawnID_)); 185 if (this->pawn_ && (this->pawn_->getPlayer() != this)) 186 this->pawn_->setPlayer(this); 187 } 162 188 } -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h
r1953 r1989 52 52 { return this->clientID_; } 53 53 54 inline void setHumanPlayer(bool bHumanPlayer)55 { this->bHumanPlayer_ = bHumanPlayer; }56 54 inline bool isHumanPlayer() const 57 55 { return this->bHumanPlayer_; } 56 57 inline bool isLocalPlayer() const 58 { return this->bLocalPlayer_; } 59 60 void startControl(ControllableEntity* pawn); 61 void stopControl(); 62 63 inline ControllableEntity* getPawn() const 64 { return this->pawn_; } 58 65 59 66 private: … … 62 69 void checkNick(); 63 70 void clientChangedName(); 71 void updatePawn(); 64 72 65 73 unsigned int clientID_; … … 71 79 std::string playerName_; 72 80 std::string nick_; 81 82 ControllableEntity* pawn_; 83 unsigned int pawnID_; 73 84 }; 74 85 } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/MovableEntity.cc
r1968 r1989 44 44 RegisterObject(MovableEntity); 45 45 46 this->velocity_ = Vector3::ZERO; 47 this->acceleration_ = Vector3::ZERO; 48 this->rotationAxis_ = Vector3::ZERO; 49 this->rotationRate_ = 0; 50 this->momentum_ = 0; 51 52 this->overwrite_position_ = Vector3::ZERO; 53 this->overwrite_orientation_ = Quaternion::IDENTITY; 54 46 55 this->registerVariables(); 47 56 } … … 57 66 XMLPortParamTemplate(MovableEntity, "velocity", setVelocity, getVelocity, xmlelement, mode, const Vector3&); 58 67 XMLPortParamTemplate(MovableEntity, "rotationaxis", setRotationAxis, getRotationAxis, xmlelement, mode, const Vector3&); 59 XMLPortParamTemplate(MovableEntity, "rotationrate", setRotationRate, getRotationRate, xmlelement, mode, const Radian&);68 XMLPortParamTemplate(MovableEntity, "rotationrate", setRotationRate, getRotationRate, xmlelement, mode, const Degree&); 60 69 } 61 70 … … 139 148 } 140 149 141 void MovableEntity::yaw(const Radian& angle, Ogre::Node::TransformSpace relativeTo)150 void MovableEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 142 151 { 143 152 this->node_->yaw(angle, relativeTo); … … 145 154 } 146 155 147 void MovableEntity::pitch(const Radian& angle, Ogre::Node::TransformSpace relativeTo)156 void MovableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 148 157 { 149 158 this->node_->pitch(angle, relativeTo); … … 151 160 } 152 161 153 void MovableEntity::roll(const Radian& angle, Ogre::Node::TransformSpace relativeTo)162 void MovableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 154 163 { 155 164 this->node_->roll(angle, relativeTo); -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/MovableEntity.h
r1968 r1989 59 59 void setOrientation(const Quaternion& orientation); 60 60 void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 61 void yaw(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);62 void pitch(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);63 void roll(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);61 void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 62 void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 63 void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 64 64 void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); 65 65 void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); … … 86 86 { return this->rotationAxis_; } 87 87 88 inline void setRotationRate(const Degree& angle) 89 { this->rotationRate_ = angle; } 88 90 inline void setRotationRate(const Radian& angle) 89 91 { this->rotationRate_ = angle; } 90 inline void setRotationRate(const Degree& angle) 91 { this->rotationRate_ = angle; } 92 inline const Radian& getRotationRate() const 92 inline const Degree& getRotationRate() const 93 93 { return this->rotationRate_; } 94 94 95 inline void setMomentum(const Degree& angle) 96 { this->momentum_ = angle; } 95 97 inline void setMomentum(const Radian& angle) 96 98 { this->momentum_ = angle; } 97 inline void setMomentum(const Degree& angle) 98 { this->momentum_ = angle; } 99 inline const Radian& getMomentum() const 99 inline const Degree& getMomentum() const 100 100 { return this->momentum_; } 101 101 … … 111 111 Vector3 acceleration_; 112 112 Vector3 rotationAxis_; 113 RadianrotationRate_;114 Radianmomentum_;113 Degree rotationRate_; 114 Degree momentum_; 115 115 116 116 Vector3 overwrite_position_; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/PositionableEntity.h
r1968 r1989 58 58 inline void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 59 59 { this->node_->rotate(rotation, relativeTo); } 60 inline void yaw(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)60 inline void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 61 61 { this->node_->yaw(angle, relativeTo); } 62 inline void pitch(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)62 inline void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 63 63 { this->node_->pitch(angle, relativeTo); } 64 inline void roll(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)64 inline void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 65 65 { this->node_->roll(angle, relativeTo); } 66 66 inline void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/WorldEntity.cc
r1948 r1989 39 39 namespace orxonox 40 40 { 41 const Vector3 WorldEntity::FRONT = Vector3::NEGATIVE_UNIT_Z; 42 const Vector3 WorldEntity::BACK = Vector3::UNIT_Z; 43 const Vector3 WorldEntity::LEFT = Vector3::NEGATIVE_UNIT_X; 44 const Vector3 WorldEntity::RIGHT = Vector3::UNIT_X; 45 const Vector3 WorldEntity::DOWN = Vector3::NEGATIVE_UNIT_Y; 46 const Vector3 WorldEntity::UP = Vector3::UNIT_Y; 47 41 48 WorldEntity::WorldEntity() 42 49 { … … 46 53 this->parent_ = 0; 47 54 this->parentID_ = (unsigned int)-1; 55 56 this->node_->setPosition(Vector3::ZERO); 57 this->node_->setOrientation(Quaternion::IDENTITY); 48 58 49 59 this->registerVariables(); -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/WorldEntity.h
r1940 r1989 54 54 { return this->node_; } 55 55 56 static const Vector3 FRONT; 57 static const Vector3 BACK; 58 static const Vector3 LEFT; 59 static const Vector3 RIGHT; 60 static const Vector3 DOWN; 61 static const Vector3 UP; 62 56 63 virtual void setPosition(const Vector3& position) = 0; 57 64 inline void setPosition(float x, float y, float z) … … 71 78 inline void setOrientation(const Vector3& axis, const Radian& angle) 72 79 { this->setOrientation(Quaternion(angle, axis)); } 80 inline void setOrientation(const Vector3& axis, const Degree& angle) 81 { this->setOrientation(Quaternion(angle, axis)); } 73 82 inline const Quaternion& getOrientation() const 74 83 { return this->node_->getOrientation(); } … … 77 86 78 87 virtual void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 88 inline void rotate(const Vector3& axis, const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 89 { this->rotate(Quaternion(angle, axis), relativeTo); } 79 90 inline void rotate(const Vector3& axis, const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 80 91 { this->rotate(Quaternion(angle, axis), relativeTo); } 81 92 82 virtual void yaw(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 83 virtual void pitch(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 84 virtual void roll(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 93 virtual void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 94 inline void yaw(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 95 { this->yaw(Degree(angle), relativeTo); } 96 virtual void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 97 inline void pitch(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 98 { this->pitch(Degree(angle), relativeTo); } 99 virtual void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 100 inline void roll(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 101 { this->roll(Degree(angle), relativeTo); } 85 102 86 103 virtual void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0; … … 131 148 inline void setDirection_xmlport(const Vector3& direction) 132 149 { this->setDirection(direction); } 133 inline void yaw_xmlport(const Radian& angle)150 inline void yaw_xmlport(const Degree& angle) 134 151 { this->yaw(angle); } 135 inline void pitch_xmlport(const Radian& angle)152 inline void pitch_xmlport(const Degree& angle) 136 153 { this->pitch(angle); } 137 inline void roll_xmlport(const Radian& angle)154 inline void roll_xmlport(const Degree& angle) 138 155 { this->roll(angle); } 139 156
Note: See TracChangeset
for help on using the changeset viewer.