2
// C++ Implementation: EntityCreatorMovementBridge
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2009
9
// This program is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU General Public License as published by
11
// the Free Software Foundation; either version 2 of the License, or
12
// (at your option) any later version.
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program; if not, write to the Free Software
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
27
#include "EntityCreatorMovementBridge.h"
28
#include "EntityCreator.h"
29
#include "components/ogre/manipulation/DetachedEntity.h"
30
#include <OgreSceneNode.h>
31
#include "../MathConverter.h"
37
EntityCreatorMovementBridge::EntityCreatorMovementBridge(EntityCreator& creator, DetachedEntity& entity, Ogre::SceneNode* node)
38
: mEntity(entity), mCreator(creator), mNode(node)
43
EntityCreatorMovementBridge::~EntityCreatorMovementBridge()
48
const WFMath::Quaternion& EntityCreatorMovementBridge::getOrientation() const
50
mOrientation = Ogre2Atlas(mNode->_getDerivedOrientation());
54
const WFMath::Point<3>& EntityCreatorMovementBridge::getPosition() const
56
mPosition = Ogre2Atlas(mNode->_getDerivedPosition());
59
void EntityCreatorMovementBridge::setPosition(const WFMath::Point<3>& position)
61
if (position.isValid()) {
62
///We need to offset into local space.
63
Ogre::Vector3 posOffset = Ogre::Vector3::ZERO;
64
if (mNode->getParent()) {
65
posOffset = mNode->getParent()->_getDerivedPosition();
67
mNode->setPosition(Atlas2Ogre(position) - posOffset);
68
///adjust it so that it moves according to the ground for example
69
// mEntity.adjustPosition(mEntity.getSceneNode()->getPosition());
72
void EntityCreatorMovementBridge::move(const WFMath::Vector<3>& directionVector)
74
if (directionVector.isValid()) {
75
mNode->translate(Atlas2Ogre(directionVector));
76
///adjust it so that it moves according to the ground for example
77
// mEntity.adjustPosition(mEntity.getSceneNode()->getPosition());
80
void EntityCreatorMovementBridge::setRotation (int axis, WFMath::CoordType angle)
82
///not implemented yet
85
void EntityCreatorMovementBridge::yaw(WFMath::CoordType angle)
87
mNode->yaw(Ogre::Degree(angle));
90
void EntityCreatorMovementBridge::setOrientation(const WFMath::Quaternion& rotation)
92
if (rotation.isValid()) {
93
///We need to offset into local space.
94
Ogre::Quaternion rotOffset = Ogre::Quaternion::IDENTITY;
95
if (mNode->getParent()) {
96
rotOffset = mNode->getParent()->_getDerivedOrientation();
98
mNode->setOrientation(Atlas2Ogre(rotation) - rotOffset);
102
void EntityCreatorMovementBridge::finalizeMovement()
104
mCreator.finalizeCreation();
106
void EntityCreatorMovementBridge::cancelMovement()
108
mCreator.stopCreation();