[513] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * License notice: |
---|
| 6 | * |
---|
| 7 | * This program is free software; you can redistribute it and/or |
---|
| 8 | * modify it under the terms of the GNU General Public License |
---|
| 9 | * as published by the Free Software Foundation; either version 2 |
---|
| 10 | * of the License, or (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program; if not, write to the Free Software |
---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
| 22 | * ... |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
[497] | 28 | #include <string> |
---|
| 29 | #include <sstream> |
---|
| 30 | |
---|
| 31 | #include "WorldEntity.h" |
---|
| 32 | #include "../core/CoreIncludes.h" |
---|
[554] | 33 | #include "../orxonox.h" |
---|
[583] | 34 | #include "../../tinyxml/tinyxml.h" |
---|
| 35 | #include "../../misc/Tokenizer.h" |
---|
| 36 | #include "../../misc/String2Number.h" |
---|
[497] | 37 | |
---|
| 38 | namespace orxonox |
---|
| 39 | { |
---|
| 40 | CreateFactory(WorldEntity); |
---|
| 41 | |
---|
| 42 | unsigned int WorldEntity::worldEntityCounter_s = 0; |
---|
| 43 | |
---|
| 44 | WorldEntity::WorldEntity() |
---|
| 45 | { |
---|
| 46 | RegisterObject(WorldEntity); |
---|
| 47 | |
---|
[554] | 48 | if (Orxonox::getSingleton()->getSceneManager()) |
---|
[497] | 49 | { |
---|
| 50 | std::ostringstream name; |
---|
| 51 | name << (WorldEntity::worldEntityCounter_s++); |
---|
| 52 | this->setName("WorldEntity" + name.str()); |
---|
[586] | 53 | node_ = Orxonox::getSingleton()->getSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName()); |
---|
[497] | 54 | } |
---|
| 55 | |
---|
| 56 | this->bStatic_ = true; |
---|
| 57 | this->velocity_ = Vector3(0, 0, 0); |
---|
| 58 | this->acceleration_ = Vector3(0, 0, 0); |
---|
| 59 | this->rotationAxis_ = Vector3(0, 1, 0); |
---|
| 60 | this->rotationRate_ = 0; |
---|
| 61 | this->momentum_ = 0; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | WorldEntity::~WorldEntity() |
---|
| 65 | { |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | void WorldEntity::tick(float dt) |
---|
| 69 | { |
---|
| 70 | if (!this->bStatic_) |
---|
| 71 | { |
---|
| 72 | this->velocity_ += (dt * this->acceleration_); |
---|
| 73 | this->translate(dt * this->velocity_); |
---|
| 74 | |
---|
| 75 | this->rotationRate_ += (dt * this->momentum_); |
---|
| 76 | this->rotate(this->rotationAxis_, dt * this->rotationRate_); |
---|
| 77 | } |
---|
| 78 | } |
---|
[583] | 79 | |
---|
| 80 | void WorldEntity::loadParams(TiXmlElement* xmlElem) |
---|
| 81 | { |
---|
| 82 | BaseObject::loadParams(xmlElem); |
---|
| 83 | |
---|
| 84 | if (xmlElem->Attribute("name")) |
---|
| 85 | { |
---|
| 86 | this->setName(xmlElem->Attribute("mesh")); |
---|
| 87 | } |
---|
[589] | 88 | |
---|
[583] | 89 | if (xmlElem->Attribute("position")) |
---|
| 90 | { |
---|
| 91 | std::vector<std::string> pos = tokenize(xmlElem->Attribute("position"),","); |
---|
| 92 | float x, y, z; |
---|
| 93 | String2Number<float>(x, pos[0]); |
---|
| 94 | String2Number<float>(y, pos[1]); |
---|
| 95 | String2Number<float>(z, pos[2]); |
---|
| 96 | this->setPosition(x, y, z); |
---|
| 97 | } |
---|
[589] | 98 | |
---|
[583] | 99 | if (xmlElem->Attribute("direction")) |
---|
| 100 | { |
---|
| 101 | std::vector<std::string> pos = tokenize(xmlElem->Attribute("direction"),","); |
---|
| 102 | float x, y, z; |
---|
| 103 | String2Number<float>(x, pos[0]); |
---|
| 104 | String2Number<float>(y, pos[1]); |
---|
| 105 | String2Number<float>(z, pos[2]); |
---|
| 106 | this->setDirection(x, y, z); |
---|
| 107 | } |
---|
[589] | 108 | |
---|
[583] | 109 | if (xmlElem->Attribute("scale")) |
---|
| 110 | { |
---|
| 111 | std::string scaleStr = xmlElem->Attribute("scale"); |
---|
| 112 | float scale; |
---|
| 113 | String2Number<float>(scale, scaleStr); |
---|
| 114 | this->setScale(scale); |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | void WorldEntity::registerAllVariables() |
---|
| 119 | { |
---|
[567] | 120 | // to be implemented ! |
---|
[565] | 121 | } |
---|
[497] | 122 | } |
---|