[346] | 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 modify |
---|
| 8 | * it under the terms of the GNU General Public License as published by |
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 10 | * (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, see <http://www.gnu.org/licenses/>. |
---|
| 19 | * |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
| 22 | * Reto Grieder |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | #include "OgreSceneNode.h" |
---|
| 29 | #include "OgreVector3.h" |
---|
| 30 | |
---|
| 31 | #include "inertial_node.h" |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | namespace orxonox { |
---|
| 35 | using namespace Ogre; |
---|
| 36 | |
---|
| 37 | InertialNode::InertialNode(SceneNode *node, Vector3 speed) |
---|
| 38 | : node_(node), speed_(speed), childListSize_(4), childListIndex_(0), |
---|
| 39 | parentNode_(NULL) |
---|
| 40 | { |
---|
| 41 | childList_ = new InertialNode*[childListSize_]; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | InertialNode::InertialNode(orxonox::InertialNode *parentNode, Vector3 speed) |
---|
| 46 | : parentNode_(parentNode), childListSize_(4), childListIndex_(0), speed_(speed) |
---|
| 47 | { |
---|
| 48 | childList_ = new InertialNode*[childListSize_]; |
---|
| 49 | node_ = parentNode_->getSceneNode()->createChildSceneNode(); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | InertialNode::~InertialNode() |
---|
| 54 | { |
---|
| 55 | if (childList_) |
---|
| 56 | { |
---|
| 57 | for (int i = 0; i < childListIndex_; i++) |
---|
| 58 | if (childList_[i]) |
---|
| 59 | delete childList_[i]; |
---|
| 60 | delete childList_; |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | InertialNode* InertialNode::createChildNode() |
---|
| 66 | { |
---|
| 67 | InertialNode *temp = new InertialNode(this); |
---|
| 68 | addChild(temp); |
---|
| 69 | return temp; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | InertialNode* InertialNode::getParentNode() |
---|
| 74 | { |
---|
| 75 | return parentNode_; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | SceneNode* InertialNode::getSceneNode() |
---|
| 80 | { |
---|
| 81 | return node_; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | Vector3 InertialNode::getSpeed() |
---|
| 86 | { |
---|
| 87 | return speed_; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | Vector3 InertialNode::getWorldSpeed() |
---|
| 92 | { |
---|
| 93 | // go through the tree of Inertial nodes |
---|
| 94 | Vector3 speed = speed_; |
---|
| 95 | InertialNode *temp = parentNode_; |
---|
| 96 | while (temp != NULL) |
---|
| 97 | { |
---|
| 98 | speed = temp->getSceneNode()->getOrientation() * speed + temp->getSpeed(); |
---|
| 99 | temp = temp->getParentNode(); |
---|
| 100 | } |
---|
| 101 | return speed; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | void InertialNode::addSpeed(Vector3 speed) |
---|
| 106 | { |
---|
| 107 | speed_ += speed; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | void InertialNode::addChild(orxonox::InertialNode *node) |
---|
| 112 | { |
---|
| 113 | if (childListIndex_ == childListSize_) |
---|
| 114 | { |
---|
| 115 | // redimension the array |
---|
| 116 | InertialNode **tempArray = new InertialNode*[2*childListSize_]; |
---|
| 117 | for (int i = 0; i < childListSize_; i++) |
---|
| 118 | tempArray[i] = childList_[i]; |
---|
| 119 | childListSize_ *= 2; |
---|
| 120 | delete childList_; |
---|
| 121 | childList_ = tempArray; |
---|
| 122 | } |
---|
| 123 | childList_[childListIndex_++] = node; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | } |
---|