Changeset 1293 for code/trunk/src/orxonox/objects
- Timestamp:
- May 15, 2008, 5:44:55 PM (17 years ago)
- Location:
- code/trunk/src/orxonox/objects
- Files:
-
- 15 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/objects/Ambient.cc
r1209 r1293 57 57 RegisterObject(Ambient); 58 58 Ambient::instance_s = this; 59 registerAllVariables(); 59 60 } 60 61 … … 63 64 } 64 65 66 bool Ambient::create(){ 67 GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(ambientLight_); 68 return true; 69 } 70 71 void Ambient::registerAllVariables(){ 72 registerVar(&ambientLight_, sizeof(ColourValue), network::DATA); 73 74 } 75 65 76 void Ambient::loadParams(TiXmlElement* xmlElem) 66 77 { … … 83 94 { 84 95 GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(colour); 96 ambientLight_=colour; 85 97 } 86 98 … … 96 108 97 109 XMLPortParamLoadOnly(Ambient, "colourvalue", setAmbientLight, xmlelement, mode); 110 create(); 98 111 } 99 112 } -
code/trunk/src/orxonox/objects/Ambient.h
r1056 r1293 34 34 #include "util/Math.h" 35 35 #include "core/BaseObject.h" 36 #include "network/Synchronisable.h" 36 37 37 38 namespace orxonox 38 39 { 39 class _OrxonoxExport Ambient : public BaseObject 40 class _OrxonoxExport Ambient : public BaseObject, network::Synchronisable 40 41 { 41 42 public: … … 46 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 48 void setAmbientLight(const ColourValue& colour); 49 bool create(); 50 void registerAllVariables(); 48 51 49 52 static void setAmbientLightTest(const ColourValue& colour) … … 52 55 private: 53 56 static Ambient* instance_s; 57 ColourValue ambientLight_; 54 58 55 59 }; -
code/trunk/src/orxonox/objects/Camera.cc
r1209 r1293 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Benjamin Knecht 26 26 * 27 27 */ … … 29 29 #include "OrxonoxStableHeaders.h" 30 30 #include "Camera.h" 31 #include "CameraHandler.h" 31 32 32 33 #include <string> … … 47 48 namespace orxonox 48 49 { 49 CreateFactory(Camera);50 50 51 Camera::Camera() 51 Camera::Camera(Ogre::SceneNode* node) 52 { 53 this->bHasFocus_ = false; 54 this->cameraNode_ = GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(node->getName() + "Camera"); 55 if( node != NULL ) 56 this->setPositionNode(node); 57 } 58 59 Camera::~Camera() 60 { 61 CameraHandler::getInstance()->releaseFocus(this); 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; 73 } 74 75 void Camera::tick(float dt) 76 { 77 if(this->positionNode_ != NULL) { 78 // this stuff here may need some adjustments 79 Vector3 offset = this->positionNode_->getWorldPosition() - this->cameraNode_->getPosition(); 80 this->cameraNode_->translate(15*dt*offset); 81 82 this->cameraNode_->setOrientation(Quaternion::Slerp(0.7, this->positionNode_->getWorldOrientation(), this->cameraNode_->getWorldOrientation(), false)); 83 } 84 } 85 86 /** 87 don't move anything before here! here the Ogre camera is set to values of this camera 88 always call update after changes 89 */ 90 void Camera::update() 91 { 92 if(this->positionNode_ != NULL) 52 93 { 53 RegisterObject(Camera); 94 this->cameraNode_->setPosition(this->positionNode_->getWorldPosition()); 95 this->cameraNode_->setOrientation(this->positionNode_->getWorldOrientation()); 54 96 } 97 } 55 98 56 Camera::~Camera() 57 { 58 } 99 /** 100 what to do when camera loses focus (do not request focus in this function!!) 101 this is called by the CameraHandler singleton class to notify the camera 102 */ 103 void Camera::removeFocus() 104 { 105 this->bHasFocus_ = false; 106 this->cameraNode_->detachObject(this->cam_); 107 } 59 108 60 void Camera::loadParams(TiXmlElement* xmlElem) 61 { 62 Ogre::SceneManager* mgr = GraphicsEngine::getSingleton().getSceneManager(); 63 64 if (xmlElem->Attribute("name") && xmlElem->Attribute("pos") && xmlElem->Attribute("lookat") && xmlElem->Attribute("node")) 65 { 66 // <Camera name="Camera" pos="0,0,-250" lookat="0,0,0" /> 67 68 std::string name = xmlElem->Attribute("name"); 69 std::string pos = xmlElem->Attribute("pos"); 70 std::string lookat = xmlElem->Attribute("lookat"); 71 72 Ogre::Camera *cam = mgr->createCamera(name); 73 74 float x, y, z; 75 SubString posVec(xmlElem->Attribute("pos"), ','); 76 convertValue<std::string, float>(&x, posVec[0]); 77 convertValue<std::string, float>(&y, posVec[1]); 78 convertValue<std::string, float>(&z, posVec[2]); 79 80 cam->setPosition(Vector3(x,y,z)); 81 82 posVec = SubString(xmlElem->Attribute("lookat"), ','); 83 convertValue<std::string, float>(&x, posVec[0]); 84 convertValue<std::string, float>(&y, posVec[1]); 85 convertValue<std::string, float>(&z, posVec[2]); 86 87 cam->lookAt(Vector3(x,y,z)); 88 89 std::string node = xmlElem->Attribute("node"); 90 91 Ogre::SceneNode* sceneNode = (Ogre::SceneNode*)mgr->getRootSceneNode()->createChildSceneNode(node); //getChild(node); 92 sceneNode->attachObject((Ogre::MovableObject*)cam); 93 94 // FIXME: unused var 95 //Ogre::Viewport* vp = 96 GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam); 97 98 99 COUT(4) << "Loader: Created camera "<< name << std::endl << std::endl; 100 } 101 } 109 void Camera::setFocus(Ogre::Camera* ogreCam) 110 { 111 this->bHasFocus_ = true; 112 this->cam_ = ogreCam; 113 this->cam_->setOrientation(this->cameraNode_->getWorldOrientation()); 114 this->cameraNode_->attachObject(this->cam_); 115 } 102 116 } -
code/trunk/src/orxonox/objects/Camera.h
r1056 r1293 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Benjamin Knecht 26 26 * 27 27 */ … … 30 30 #define _Camera_H__ 31 31 32 #include <OgrePrerequisites.h> 33 #include <OgreSceneNode.h> 34 #include <OgreCamera.h> 35 32 36 #include "OrxonoxPrereqs.h" 33 34 #include "core/BaseObject.h"35 37 36 38 namespace orxonox 37 39 { 38 class _OrxonoxExport Camera : public BaseObject40 class _OrxonoxExport Camera 39 41 { 40 public: 41 Camera(); 42 virtual ~Camera(); 42 friend class CameraHandler; 43 public: 44 Camera(Ogre::SceneNode* node = NULL); 45 virtual ~Camera(); 43 46 47 void setPositionNode(Ogre::SceneNode* node); 48 inline Ogre::SceneNode* getCameraNode() { return this->positionNode_; } 49 // maybe also BaseObject 50 void setTargetNode(Ogre::SceneNode* obj); 44 51 45 void loadParams(TiXmlElement* xmlElem); 52 void tick(float dt); 53 void update(); 54 inline bool hasFocus() { return this->bHasFocus_; } 46 55 47 private: 56 private: 57 void removeFocus(); 58 void setFocus(Ogre::Camera* ogreCam); 48 59 49 60 private: 61 Ogre::SceneNode* targetNode_; 62 Ogre::SceneNode* positionNode_; 63 Ogre::SceneNode* cameraNode_; 64 Ogre::Vector3 oldPos; 65 Ogre::Camera* cam_; 66 bool bHasFocus_; 50 67 }; 51 68 } -
code/trunk/src/orxonox/objects/Explosion.cc
r1056 r1293 45 45 CreateFactory(Explosion); 46 46 47 Explosion::Explosion(WorldEntity* owner) 47 Explosion::Explosion(WorldEntity* owner) : 48 lifetime_(0.4), 49 particle_(0) 48 50 { 49 51 RegisterObject(Explosion); 50 51 this->particle_ = 0;52 this->lifetime_ = 0.4;53 52 54 53 if (owner) -
code/trunk/src/orxonox/objects/Model.cc
r1209 r1293 49 49 } 50 50 51 void Model::loadParams(TiXmlElement* xmlElem)52 {53 WorldEntity::loadParams(xmlElem);54 55 if (xmlElem->Attribute("mesh"))56 {57 meshSrc_ = xmlElem->Attribute("mesh");58 }59 create();60 }61 62 51 /** 63 52 @brief XML loading and saving. … … 73 62 XMLPortParamLoadOnly(Model, "mesh", setMesh, xmlelement, mode); 74 63 75 create();64 Model::create(); 76 65 } 77 66 … … 82 71 83 72 bool Model::create(){ 84 WorldEntity::create(); 73 if(!WorldEntity::create()) 74 return false; 85 75 if ((this->meshSrc_ != "") && (this->meshSrc_.size() > 0)) 86 76 { 87 77 this->mesh_.setMesh(meshSrc_); 88 78 this->attachObject(this->mesh_.getEntity()); 89 COUT(4) << "Loader : Created model" << std::endl;79 COUT(4) << "Loader (Model.cc): Created model" << std::endl; 90 80 } 91 81 return true; … … 93 83 94 84 void Model::registerAllVariables(){ 95 WorldEntity::registerAllVariables(); 85 // WorldEntity::registerAllVariables(); 86 COUT(5) << "Model.cc:registering new meshsrc with size: " << meshSrc_.length()+1 << " this: " << this << std::endl; 96 87 registerVar(&meshSrc_, meshSrc_.length() + 1, network::STRING); 97 88 } -
code/trunk/src/orxonox/objects/Model.h
r1056 r1293 43 43 Model(); 44 44 virtual ~Model(); 45 virtual void loadParams(TiXmlElement* xmlElem);46 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 46 void setMesh(const std::string& meshname); -
code/trunk/src/orxonox/objects/NPC.cc
r1056 r1293 36 36 CreateFactory(NPC); 37 37 38 NPC::NPC() 38 NPC::NPC() : 39 movable_(true) 39 40 { 40 41 RegisterObject(NPC); 41 movable_ = true;42 registerAllVariables(); 42 43 } 43 44 … … 59 60 this->translate(location); 60 61 movable_ = movable; 62 } 63 64 void NPC::registerAllVariables(){ 65 Model::registerAllVariables(); 66 registerVar(&movable_, sizeof(movable_), network::DATA); 67 } 68 69 bool NPC::create(){ 70 Model::create(); 71 return true; 61 72 } 62 73 -
code/trunk/src/orxonox/objects/NPC.h
r1056 r1293 52 52 void update(); 53 53 void setValues(Vector3 location, Vector3 speed, Vector3 acceleration, bool movable); 54 void registerAllVariables(); 55 bool create(); 54 56 55 57 private: -
code/trunk/src/orxonox/objects/Projectile.cc
r1056 r1293 42 42 CreateFactory(Projectile); 43 43 44 Projectile::Projectile(SpaceShip* owner) 44 Projectile::Projectile(SpaceShip* owner) : 45 owner_(owner) 45 46 { 46 47 RegisterObject(Projectile); 47 48 48 49 this->setConfigValues(); 49 50 this->owner_ = owner;51 50 52 51 this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1); -
code/trunk/src/orxonox/objects/Skybox.cc
r1209 r1293 47 47 { 48 48 RegisterObject(Skybox); 49 registerAllVariables(); 49 50 } 50 51 … … 57 58 if (xmlElem->Attribute("src")) 58 59 { 59 s td::string skyboxSrc= xmlElem->Attribute("src");60 this->setSkybox(skyboxSrc);60 skyboxSrc_ = xmlElem->Attribute("src"); 61 this->create(); 61 62 62 COUT(4) << "Loader: Set skybox: "<< skyboxSrc << std::endl << std::endl;63 COUT(4) << "Loader: Set skybox: "<< skyboxSrc_ << std::endl << std::endl; 63 64 } 64 65 } … … 69 70 } 70 71 72 void Skybox::setSkyboxSrc(const std::string& src){ 73 skyboxSrc_ = src; 74 } 75 71 76 /** 72 77 @brief XML loading and saving. … … 79 84 BaseObject::XMLPort(xmlelement, mode); 80 85 81 XMLPortParamLoadOnly(Skybox, "src", setSkybox, xmlelement, mode); 86 XMLPortParamLoadOnly(Skybox, "src", setSkyboxSrc, xmlelement, mode); 87 create(); 82 88 } 89 90 bool Skybox::create(){ 91 this->setSkybox(skyboxSrc_); 92 return true; 93 } 94 95 void Skybox::registerAllVariables(){ 96 registerVar(&skyboxSrc_, skyboxSrc_.length()+1 ,network::STRING); 97 } 98 83 99 } -
code/trunk/src/orxonox/objects/Skybox.h
r1056 r1293 33 33 34 34 #include "core/BaseObject.h" 35 #include "network/Synchronisable.h" 35 36 36 37 namespace orxonox 37 38 { 38 class _OrxonoxExport Skybox : public BaseObject 39 class _OrxonoxExport Skybox : public BaseObject, public network::Synchronisable 39 40 { 40 41 public: … … 45 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 47 void setSkybox(const std::string& skyboxname); 48 49 bool create(); 50 void registerAllVariables(); 51 void setSkyboxSrc(const std::string &src); 47 52 48 53 private: 54 std::string skyboxSrc_; 49 55 50 56 -
code/trunk/src/orxonox/objects/SpaceShip.cc
r1219 r1293 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Benjamin Knecht 26 26 * 27 27 */ … … 37 37 #include <OgreSceneNode.h> 38 38 39 #include "CameraHandler.h" 39 40 #include "tinyxml/tinyxml.h" 40 41 #include "ois/OIS.h" … … 50 51 #include "core/XMLPort.h" 51 52 #include "core/ConsoleCommand.h" 53 #include "network/Client.h" 52 54 53 55 namespace orxonox … … 62 64 SpaceShip* SpaceShip::instance_s; 63 65 64 SpaceShip::SpaceShip() 66 SpaceShip::SpaceShip() : 67 //testvector_(0,0,0), 68 //bInvertYAxis_(false), 69 setMouseEventCallback_(false), 70 bLMousePressed_(false), 71 bRMousePressed_(false), 72 camNode_(0), 73 cam_(0), 74 camName_("CamNode"), 75 tt_(0), 76 redNode_(0), 77 greenNode_(0), 78 blinkTime_(0.0f), 79 chNearNode_(0), 80 chFarNode_(0), 81 timeToReload_(0.0f), 82 //reloadTime_(0.0f), 83 maxSideAndBackSpeed_(0.0f), 84 maxSpeed_(0.0f), 85 maxRotation_(0.0f), 86 translationAcceleration_(0.0f), 87 rotationAcceleration_(0.0f), 88 translationDamping_(0.0f), 89 rotationDamping_(0.0f), 90 maxRotationRadian_(0), 91 rotationAccelerationRadian_(0), 92 rotationDampingRadian_(0), 93 zeroRadian_(0), 94 mouseXRotation_(0), 95 mouseYRotation_(0), 96 mouseX_(0.0f), 97 mouseY_(0.0f), 98 emitterRate_(0.0f), 99 server_(false) 65 100 { 66 101 RegisterObject(SpaceShip); … … 71 106 this->setConfigValues(); 72 107 73 this->setMouseEventCallback_ = false;74 this->bLMousePressed_ = false;75 this->bRMousePressed_ = false;76 this->mouseX_ = 0;77 this->mouseY_ = 0;78 79 this->camNode_ = 0;80 81 this->tt_ = 0;82 this->redNode_ = 0;83 this->greenNode_ = 0;84 this->blinkTime_ = 0;85 86 this->timeToReload_ = 0;87 88 this->maxSpeed_ = 0;89 this->maxSideAndBackSpeed_ = 0;90 this->maxRotation_ = 0;91 this->translationAcceleration_ = 0;92 this->rotationAcceleration_ = 0;93 this->translationDamping_ = 0;94 this->rotationDamping_ = 0;95 96 this->maxRotationRadian_ = 0;97 this->rotationAccelerationRadian_ = 0;98 this->rotationDampingRadian_ = 0;99 this->zeroRadian_ = Radian(0);100 108 101 109 this->setRotationAxis(1, 0, 0); 102 110 this->setStatic(false); 103 /*104 this->moveForward_ = 0;105 this->rotateUp_ = 0;106 this->rotateDown_ = 0;107 this->rotateRight_ = 0;108 this->rotateLeft_ = 0;109 this->loopRight_ = 0;110 this->loopLeft_ = 0;111 this->brakeForward_ = 0;112 this->brakeRotate_ = 0;113 this->brakeLoop_ = 0;114 this->speedForward_ = 0;115 this->speedRotateUpDown_ = 0;116 this->speedRotateRightLeft_ = 0;117 this->speedLoopRightLeft_ = 0;118 this->maxSpeedForward_ = 0;119 this->maxSpeedRotateUpDown_ = 0;120 this->maxSpeedRotateRightLeft_ = 0;121 this->maxSpeedLoopRightLeft_ = 0;122 this->accelerationForward_ = 0;123 this->accelerationRotateUpDown_ = 0;124 this->accelerationRotateRightLeft_ = 0;125 this->accelerationLoopRightLeft_ = 0;126 127 this->speed = 250;128 this->loop = 100;129 this->rotate = 10;130 this->mouseX = 0;131 this->mouseY = 0;132 this->maxMouseX = 0;133 this->minMouseX = 0;134 this->moved = false;135 136 this->brakeRotate(rotate*10);137 this->brakeLoop(loop);138 */139 // this->create();140 141 111 142 112 COUT(3) << "Info: SpaceShip was loaded" << std::endl; … … 147 117 if (this->tt_) 148 118 delete this->tt_; 119 if(setMouseEventCallback_) 120 InputManager::removeMouseHandler("SpaceShip"); 121 if (this->cam_) 122 delete this->cam_; 149 123 } 150 124 … … 158 132 159 133 void SpaceShip::registerAllVariables(){ 160 Model::registerAllVariables(); 161 162 134 registerVar( &camName_, camName_.length()+1, network::STRING, 0x1); 135 registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1); 136 registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1); 137 registerVar( &maxRotation_, sizeof(maxRotation_), network::DATA, 0x1); 138 registerVar( &translationAcceleration_, sizeof(translationAcceleration_), network::DATA, 0x1); 139 registerVar( &rotationAcceleration_, sizeof(rotationAcceleration_), network::DATA, 0x1); 140 registerVar( &rotationAccelerationRadian_, sizeof(rotationAccelerationRadian_), network::DATA, 0x1); 141 registerVar( &translationDamping_, sizeof(translationDamping_), network::DATA, 0x1); 142 registerVar( &rotationDamping_, sizeof(rotationDamping_), network::DATA, 0x1); 143 registerVar( &rotationDampingRadian_, sizeof(rotationDampingRadian_), network::DATA, 0x1); 163 144 164 145 } … … 166 147 void SpaceShip::init() 167 148 { 149 if ((server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==objectID ) )) 150 { 151 if (!setMouseEventCallback_) 152 { 153 InputManager::addMouseHandler(this, "SpaceShip"); 154 setMouseEventCallback_ = true; 155 } 156 } 157 168 158 // START CREATING THRUSTER 169 159 this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); … … 191 181 this->greenBillboard_.setBillboardSet("Examples/Flare", ColourValue(0.0, 1.0, 0.0), 1); 192 182 193 this->redNode_ = this->getNode()->createChildSceneNode(this->getName() + "red", Vector3(0.3, 4. 7, -0.3));183 this->redNode_ = this->getNode()->createChildSceneNode(this->getName() + "red", Vector3(0.3, 4.0, -0.3)); 194 184 this->redNode_->setInheritScale(false); 195 this->greenNode_ = this->getNode()->createChildSceneNode(this->getName() + "green", Vector3(0.3, -4. 7, -0.3));185 this->greenNode_ = this->getNode()->createChildSceneNode(this->getName() + "green", Vector3(0.3, -4.0, -0.3)); 196 186 this->greenNode_->setInheritScale(false); 197 187 … … 218 208 this->chFarNode_->setScale(0.4, 0.4, 0.4); 219 209 210 createCamera(); 220 211 // END of testing crosshair 221 212 } … … 232 223 Model::loadParams(xmlElem); 233 224 this->create(); 225 this->getFocus(); 234 226 /* 235 227 if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft")) … … 246 238 247 239 COUT(4) << "Loader: Initialized spaceship steering with values " << maxSpeedForward_ << " " << maxSpeedRotateUpDown_ << " " << maxSpeedRotateRightLeft_ << " " << maxSpeedLoopRightLeft_ << " " << std::endl; 248 240 } 249 241 */ 250 242 if (xmlElem->Attribute("maxSpeed") && xmlElem->Attribute("maxSideAndBackSpeed") && xmlElem->Attribute("maxRotation") && xmlElem->Attribute("transAcc") && xmlElem->Attribute("rotAcc") && xmlElem->Attribute("transDamp") && xmlElem->Attribute("rotDamp")) … … 272 264 273 265 COUT(4) << "Loader: Initialized SpaceShip" << std::endl; 274 275 276 277 278 279 266 } 267 268 if (xmlElem->Attribute("camera")) 269 { 270 this->setCamera(); 271 } 280 272 } 281 273 282 274 void SpaceShip::setCamera(const std::string& camera) 283 275 { 284 Ogre::Camera *cam = GraphicsEngine::getSingleton().getSceneManager()->createCamera("ShipCam"); 285 this->camNode_ = this->getNode()->createChildSceneNode("CamNode"); 286 /* 287 // node->setInheritOrientation(false); 288 cam->setPosition(Vector3(0,50,-150)); 289 cam->lookAt(Vector3(0,20,0)); 290 cam->roll(Degree(0)); 291 */ 292 293 cam->setPosition(Vector3(-200,0,35)); 276 camName_=camera; 277 // change camera attributes here, if you want to ;) 278 } 279 280 void SpaceShip::getFocus(){ 281 COUT(4) << "requesting focus" << std::endl; 282 if(network::Client::getSingleton()==0 || network::Client::getSingleton()->getShipID()==objectID) 283 CameraHandler::getInstance()->requestFocus(cam_); 284 285 } 286 287 void SpaceShip::createCamera(){ 288 // COUT(4) << "begin camera creation" << std::endl; 289 this->camNode_ = this->getNode()->createChildSceneNode(camName_); 290 COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl; 291 this->camNode_->setPosition(Vector3(-50,0,10)); 292 Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); 293 Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1)); 294 camNode_->setOrientation(q1*q2); 295 COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl; 296 cam_ = new Camera(this->camNode_); 297 298 cam_->setTargetNode(this->getNode()); 294 299 // cam->setPosition(Vector3(0,-350,0)); 295 cam->lookAt(Vector3(0,0,35));296 cam->roll(Degree(-90));297 298 this->camNode_->attachObject(cam);299 GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam); 300 if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){ 301 this->setBacksync(true); 302 CameraHandler::getInstance()->requestFocus(cam_); 303 } 304 300 305 } 301 306 … … 333 338 XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode); 334 339 XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode); 340 server_=true; // TODO: this is only a hack 341 SpaceShip::create(); 342 getFocus(); 335 343 } 336 344 … … 343 351 } 344 352 345 bool SpaceShip::mouseMoved(const OIS::MouseEvent &e)353 bool SpaceShip::mouseMoved(const MouseState& state) 346 354 { 347 355 /* … … 360 368 if (this->bRMousePressed_) 361 369 { 362 this->camNode_->roll(Degree(- e.state.X.rel * 0.10));363 this->camNode_->yaw(Degree( e.state.Y.rel * 0.10));364 } 365 else 366 { 367 float minDimension = e.state.height;368 if ( e.state.width < minDimension)369 minDimension = e.state.width;370 371 this->mouseX_ += e.state.X.rel;370 this->camNode_->roll(Degree(-state.X.rel * 0.10)); 371 this->camNode_->yaw(Degree(state.Y.rel * 0.10)); 372 } 373 else 374 { 375 float minDimension = state.height; 376 if (state.width < minDimension) 377 minDimension = state.width; 378 379 this->mouseX_ += state.X.rel; 372 380 if (this->mouseX_ < -minDimension) 373 381 this->mouseX_ = -minDimension; … … 375 383 this->mouseX_ = minDimension; 376 384 377 this->mouseY_ += e.state.Y.rel;385 this->mouseY_ += state.Y.rel; 378 386 if (this->mouseY_ < -minDimension) 379 387 this->mouseY_ = -minDimension; … … 403 411 } 404 412 405 bool SpaceShip::mouse Pressed(const OIS::MouseEvent &e, OIS::MouseButtonIDid)406 { 407 if (id == OIS::MB_Left)413 bool SpaceShip::mouseButtonPressed(const MouseState& state, MouseButton::Enum id) 414 { 415 if (id == MouseButton::Left) 408 416 this->bLMousePressed_ = true; 409 else if (id == OIS::MB_Right)417 else if (id == MouseButton::Right) 410 418 this->bRMousePressed_ = true; 411 419 … … 413 421 } 414 422 415 bool SpaceShip::mouse Released(const OIS::MouseEvent &e, OIS::MouseButtonIDid)416 { 417 if (id == OIS::MB_Left)423 bool SpaceShip::mouseButtonReleased(const MouseState& state, MouseButton::Enum id) 424 { 425 if (id == MouseButton::Left) 418 426 this->bLMousePressed_ = false; 419 else if (id == OIS::MB_Right)427 else if (id == MouseButton::Right) 420 428 { 421 429 this->bRMousePressed_ = false; … … 428 436 void SpaceShip::tick(float dt) 429 437 { 430 if (!setMouseEventCallback_) 431 { 432 InputManager::addMouseHandler(this, "SpaceShip"); 433 setMouseEventCallback_ = true; 434 } 438 if (this->cam_) 439 this->cam_->tick(dt); 435 440 436 441 if (this->redNode_ && this->greenNode_) … … 450 455 if (this->bLMousePressed_ && this->timeToReload_ <= 0) 451 456 { 452 new Projectile(this); 457 Projectile *p = new Projectile(this); 458 p->setBacksync(true); 453 459 this->timeToReload_ = this->reloadTime_; 454 460 } 455 456 OIS::Keyboard* mKeyboard = InputManager::getKeyboard();457 461 458 462 … … 522 526 } 523 527 524 if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) 528 if( (network::Client::getSingleton() && network::Client::getSingleton()->getShipID() == objectID) || server_ ) 529 { 530 COUT(4) << "steering our ship: " << objectID << std::endl; 531 if (InputManager::isKeyDown(KeyCode::Up) || InputManager::isKeyDown(KeyCode::W)) 525 532 this->acceleration_.x = this->translationAcceleration_; 526 else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))533 else if(InputManager::isKeyDown(KeyCode::Down) || InputManager::isKeyDown(KeyCode::S)) 527 534 this->acceleration_.x = -this->translationAcceleration_; 528 else535 else 529 536 this->acceleration_.x = 0; 530 537 531 if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))538 if (InputManager::isKeyDown(KeyCode::Right) || InputManager::isKeyDown(KeyCode::D)) 532 539 this->acceleration_.y = -this->translationAcceleration_; 533 else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))540 else if (InputManager::isKeyDown(KeyCode::Left) || InputManager::isKeyDown(KeyCode::A)) 534 541 this->acceleration_.y = this->translationAcceleration_; 535 else542 else 536 543 this->acceleration_.y = 0; 537 544 538 if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))545 if (InputManager::isKeyDown(KeyCode::Delete) || InputManager::isKeyDown(KeyCode::Q)) 539 546 this->momentum_ = Radian(-this->rotationAccelerationRadian_); 540 else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))547 else if (InputManager::isKeyDown(KeyCode::PageDown) || InputManager::isKeyDown(KeyCode::E)) 541 548 this->momentum_ = Radian(this->rotationAccelerationRadian_); 542 else549 else 543 550 this->momentum_ = 0; 551 }/*else 552 COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/ 544 553 545 554 WorldEntity::tick(dt); -
code/trunk/src/orxonox/objects/SpaceShip.h
r1219 r1293 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Benjamin Knecht 26 26 * 27 27 */ … … 34 34 #include <OgrePrerequisites.h> 35 35 36 #include "core/InputHandler.h" 36 #include "core/InputInterfaces.h" 37 #include "Camera.h" 37 38 #include "Model.h" 38 39 #include "../tools/BillboardSet.h" … … 62 63 void setRotDamp(float value); 63 64 65 void getFocus(); 66 64 67 static void setMaxSpeedTest(float value) 65 68 { SpaceShip::instance_s->setMaxSpeed(value); } 66 69 67 bool mouseMoved(const OIS::MouseEvent &e); 68 bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id); 69 bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id); 70 bool mouseHeld(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; } 70 bool mouseButtonPressed (const MouseState& state, MouseButton::Enum id); 71 bool mouseButtonReleased(const MouseState& state, MouseButton::Enum id); 72 bool mouseButtonHeld (const MouseState& state, MouseButton::Enum id) { return true; } 73 bool mouseMoved (const MouseState& state); 74 bool mouseScrolled (const MouseState& state) { return true; } 71 75 72 76 73 77 private: 78 void createCamera(); 74 79 static SpaceShip* instance_s; 75 80 … … 81 86 82 87 Ogre::SceneNode* camNode_; 88 Camera* cam_; 89 std::string camName_; 90 83 91 84 92 ParticleInterface* tt_; … … 117 125 118 126 float emitterRate_; 127 bool server_; 119 128 }; 120 129 } -
code/trunk/src/orxonox/objects/WorldEntity.cc
r1209 r1293 45 45 unsigned int WorldEntity::worldEntityCounter_s = 0; 46 46 47 WorldEntity::WorldEntity() 47 WorldEntity::WorldEntity() : 48 velocity_ (0, 0, 0), 49 acceleration_(0, 0, 0), 50 rotationAxis_(0, 1, 0), 51 rotationRate_(0), 52 momentum_ (0), 53 node_ (0), 54 bStatic_ (true) 48 55 { 49 56 RegisterObject(WorldEntity); 50 51 //create();52 53 this->bStatic_ = true;54 this->velocity_ = Vector3(0, 0, 0);55 this->acceleration_ = Vector3(0, 0, 0);56 this->rotationAxis_ = Vector3(0, 1, 0);57 this->rotationRate_ = 0;58 this->momentum_ = 0;59 57 60 58 if (GraphicsEngine::getSingleton().getSceneManager()) … … 67 65 registerAllVariables(); 68 66 } 69 else70 {71 this->node_ = 0;72 }73 67 } 68 74 69 75 70 WorldEntity::~WorldEntity() 76 71 { 72 // just to make sure we clean out all scene nodes 73 if(this->getNode()) 74 this->getNode()->removeAndDestroyAllChildren(); 77 75 } 78 76 … … 81 79 if (!this->bStatic_) 82 80 { 81 // COUT(4) << "acceleration: " << this->acceleration_ << " velocity: " << this->velocity_ << std::endl; 83 82 this->velocity_ += (dt * this->acceleration_); 84 83 this->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL); … … 94 93 BaseObject::loadParams(xmlElem); 95 94 create(); 96 /*97 if (xmlElem->Attribute("position"))98 {99 std::vector<std::string> pos = tokenize(xmlElem->Attribute("position"),",");100 float x, y, z;101 String2Number<float>(x, pos[0]);102 String2Number<float>(y, pos[1]);103 String2Number<float>(z, pos[2]);104 this->setPosition(x, y, z);105 }106 107 if (xmlElem->Attribute("direction"))108 {109 std::vector<std::string> pos = tokenize(xmlElem->Attribute("direction"),",");110 float x, y, z;111 String2Number<float>(x, pos[0]);112 String2Number<float>(y, pos[1]);113 String2Number<float>(z, pos[2]);114 this->setDirection(x, y, z);115 }116 117 if (xmlElem->Attribute("yaw") || xmlElem->Attribute("pitch") || xmlElem->Attribute("roll"))118 {119 float yaw = 0.0, pitch = 0.0, roll = 0.0;120 if (xmlElem->Attribute("yaw"))121 String2Number<float>(yaw,xmlElem->Attribute("yaw"));122 123 if (xmlElem->Attribute("pitch"))124 String2Number<float>(pitch,xmlElem->Attribute("pitch"));125 126 if (xmlElem->Attribute("roll"))127 String2Number<float>(roll,xmlElem->Attribute("roll"));128 129 this->yaw(Degree(yaw));130 this->pitch(Degree(pitch));131 this->roll(Degree(roll));132 }133 134 if (xmlElem->Attribute("scale"))135 {136 std::string scaleStr = xmlElem->Attribute("scale");137 float scale;138 String2Number<float>(scale, scaleStr);139 this->setScale(scale);140 }141 142 if (xmlElem->Attribute("rotationAxis"))143 {144 std::vector<std::string> pos = tokenize(xmlElem->Attribute("rotationAxis"),",");145 float x, y, z;146 String2Number<float>(x, pos[0]);147 String2Number<float>(y, pos[1]);148 String2Number<float>(z, pos[2]);149 this->setRotationAxis(x, y, z);150 }151 152 if (xmlElem->Attribute("rotationRate"))153 {154 float rotationRate;155 String2Number<float>(rotationRate, xmlElem->Attribute("rotationRate"));156 this->setRotationRate(Degree(rotationRate));157 if (rotationRate != 0)158 this->setStatic(false);159 }160 161 create();162 */163 95 } 96 164 97 165 98 void WorldEntity::setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll) … … 188 121 189 122 XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true); 123 124 WorldEntity::create(); 190 125 } 191 126 … … 194 129 { 195 130 // register coordinates 196 registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA );197 registerVar( (void*) &(this->getPosition().y), sizeof(this->getPosition().y), network::DATA );198 registerVar( (void*) &(this->getPosition().z), sizeof(this->getPosition().z), network::DATA );131 registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA, 0x3); 132 registerVar( (void*) &(this->getPosition().y), sizeof(this->getPosition().y), network::DATA, 0x3); 133 registerVar( (void*) &(this->getPosition().z), sizeof(this->getPosition().z), network::DATA, 0x3); 199 134 // register orientation 200 registerVar( (void*) &(this->getOrientation().w), sizeof(this->getOrientation().w), network::DATA); 201 registerVar( (void*) &(this->getOrientation().x), sizeof(this->getOrientation().x), network::DATA); 202 registerVar( (void*) &(this->getOrientation().y), sizeof(this->getOrientation().y), network::DATA); 203 registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA); 204 // not needed at the moment, because we don't have prediction yet 135 registerVar( (void*) &(this->getOrientation().w), sizeof(this->getOrientation().w), network::DATA, 0x3); 136 registerVar( (void*) &(this->getOrientation().x), sizeof(this->getOrientation().x), network::DATA, 0x3); 137 registerVar( (void*) &(this->getOrientation().y), sizeof(this->getOrientation().y), network::DATA, 0x3); 138 registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA, 0x3); 205 139 // register velocity_ 206 registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA); 207 registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA); 208 registerVar( (void*) &(this->getVelocity().z), sizeof(this->getVelocity().z), network::DATA); 209 // register rotationAxis/rate 210 registerVar( (void*) &(this->getRotationRate()), sizeof(this->getRotationRate()), network::DATA); 211 registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA); 212 registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA); 213 registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA); 140 // registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA, 0x3); 141 // registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA, 0x3); 142 // registerVar( (void*) &(this->getVelocity().z), sizeof(this->getVelocity().z), network::DATA, 0x3); 143 // // register rotationAxis/rate 144 // registerVar( (void*) &(this->getRotationRate()), sizeof(this->getRotationRate()), network::DATA, 0x3); 145 // registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA, 0x3); 146 // registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA, 0x3); 147 // registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA, 0x3); 148 // register scale of node 149 registerVar( (void*) &(this->getScale().x), sizeof(this->getScale().x), network::DATA, 0x3); 150 registerVar( (void*) &(this->getScale().y), sizeof(this->getScale().y), network::DATA, 0x3); 151 registerVar( (void*) &(this->getScale().z), sizeof(this->getScale().z), network::DATA, 0x3); 152 //register staticity 153 registerVar( (void*) &(this->bStatic_), sizeof(this->bStatic_), network::DATA, 0x3); 154 //register acceleration 155 // register velocity_ 156 // registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3); 157 // registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3); 158 // registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3); 214 159 } 215 160
Note: See TracChangeset
for help on using the changeset viewer.