1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * Martin Stypinski |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "OrxonoxStableHeaders.h" |
---|
30 | #include "MovableEntity.h" |
---|
31 | |
---|
32 | #include "objects/Scene.h" |
---|
33 | |
---|
34 | #include "core/CoreIncludes.h" |
---|
35 | #include "core/XMLPort.h" |
---|
36 | |
---|
37 | namespace orxonox |
---|
38 | { |
---|
39 | MovableEntity::MovableEntity(BaseObject* creator) : WorldEntity(creator) |
---|
40 | { |
---|
41 | RegisterObject(MovableEntity); |
---|
42 | |
---|
43 | this->registerVariables(); |
---|
44 | } |
---|
45 | |
---|
46 | MovableEntity::~MovableEntity() |
---|
47 | { |
---|
48 | } |
---|
49 | |
---|
50 | void MovableEntity::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
51 | { |
---|
52 | SUPER(MovableEntity, XMLPort, xmlelement, mode); |
---|
53 | } |
---|
54 | |
---|
55 | void MovableEntity::registerVariables() |
---|
56 | { |
---|
57 | } |
---|
58 | |
---|
59 | void MovableEntity::setPosition(const Vector3& position){ |
---|
60 | // Here the code |
---|
61 | if(isDynamic() && bAddedToPhysicalWorld_){ |
---|
62 | this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); |
---|
63 | this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); |
---|
64 | } |
---|
65 | this->node_->setPosition(position); |
---|
66 | positionChanged(); |
---|
67 | } |
---|
68 | |
---|
69 | void MovableEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo){ |
---|
70 | if(isDynamic() && bAddedToPhysicalWorld_){ |
---|
71 | this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); |
---|
72 | this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); |
---|
73 | } |
---|
74 | this->node_->translate(distance, relativeTo); |
---|
75 | translateChanged(); |
---|
76 | } |
---|
77 | |
---|
78 | void MovableEntity::setOrientation(const Quaternion& orientation){ |
---|
79 | if(isDynamic() && bAddedToPhysicalWorld_){ |
---|
80 | this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); |
---|
81 | this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); |
---|
82 | } |
---|
83 | this->node_->setOrientation(orientation); |
---|
84 | orientationChanged(); |
---|
85 | } |
---|
86 | |
---|
87 | void MovableEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo){ |
---|
88 | if(isDynamic() && bAddedToPhysicalWorld_){ |
---|
89 | this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); |
---|
90 | this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); |
---|
91 | } |
---|
92 | this->node_->rotate(rotation, relativeTo); |
---|
93 | rotateChanged(); |
---|
94 | } |
---|
95 | |
---|
96 | void MovableEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo){ |
---|
97 | if(isDynamic() && bAddedToPhysicalWorld_){ |
---|
98 | this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); |
---|
99 | this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); |
---|
100 | } |
---|
101 | this->node_->yaw(angle, relativeTo); |
---|
102 | yawChanged(); |
---|
103 | } |
---|
104 | |
---|
105 | void MovableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo){ |
---|
106 | if(isDynamic() && bAddedToPhysicalWorld_){ |
---|
107 | this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); |
---|
108 | this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); |
---|
109 | } |
---|
110 | this->node_->pitch(angle, relativeTo); |
---|
111 | pitchChanged(); |
---|
112 | } |
---|
113 | |
---|
114 | void MovableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo){ |
---|
115 | if(isDynamic() && bAddedToPhysicalWorld_){ |
---|
116 | this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); |
---|
117 | this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); |
---|
118 | } |
---|
119 | this->node_->roll(angle, relativeTo); |
---|
120 | rollChanged(); |
---|
121 | } |
---|
122 | |
---|
123 | void MovableEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector){ |
---|
124 | if(isDynamic() && bAddedToPhysicalWorld_){ |
---|
125 | this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); |
---|
126 | this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); |
---|
127 | } |
---|
128 | this->node_->lookAt(target, relativeTo, localDirectionVector); |
---|
129 | lookAtChanged(); |
---|
130 | } |
---|
131 | |
---|
132 | void MovableEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector){ |
---|
133 | if(isDynamic() && bAddedToPhysicalWorld_){ |
---|
134 | this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); |
---|
135 | this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); |
---|
136 | } |
---|
137 | this->node_->setDirection(direction, relativeTo, localDirectionVector); |
---|
138 | directionChanged(); |
---|
139 | } |
---|
140 | |
---|
141 | } |
---|