~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/widgets/EntityCreatorMovementBridge.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Implementation: EntityCreatorMovementBridge
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2009
 
8
//
 
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.
 
13
// 
 
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.
 
18
// 
 
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.//
 
22
//
 
23
#ifdef HAVE_CONFIG_H
 
24
#include "config.h"
 
25
#endif
 
26
 
 
27
#include "EntityCreatorMovementBridge.h"
 
28
#include "EntityCreator.h"
 
29
#include "components/ogre/manipulation/DetachedEntity.h"
 
30
#include <OgreSceneNode.h>
 
31
#include "../MathConverter.h"
 
32
 
 
33
namespace EmberOgre {
 
34
 
 
35
namespace Gui {
 
36
 
 
37
EntityCreatorMovementBridge::EntityCreatorMovementBridge(EntityCreator& creator, DetachedEntity& entity, Ogre::SceneNode* node)
 
38
: mEntity(entity), mCreator(creator), mNode(node)
 
39
{
 
40
}
 
41
 
 
42
 
 
43
EntityCreatorMovementBridge::~EntityCreatorMovementBridge()
 
44
{
 
45
}
 
46
 
 
47
 
 
48
const WFMath::Quaternion& EntityCreatorMovementBridge::getOrientation() const
 
49
{
 
50
        mOrientation = Ogre2Atlas(mNode->_getDerivedOrientation());
 
51
        return mOrientation;
 
52
}
 
53
 
 
54
const WFMath::Point<3>& EntityCreatorMovementBridge::getPosition() const
 
55
{
 
56
        mPosition = Ogre2Atlas(mNode->_getDerivedPosition());
 
57
        return mPosition;
 
58
}
 
59
void EntityCreatorMovementBridge::setPosition(const WFMath::Point<3>& position)
 
60
{
 
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();
 
66
                }
 
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());
 
70
        }
 
71
}
 
72
void EntityCreatorMovementBridge::move(const WFMath::Vector<3>& directionVector)
 
73
{
 
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());
 
78
        }
 
79
}
 
80
void EntityCreatorMovementBridge::setRotation (int axis, WFMath::CoordType angle)
 
81
{
 
82
        ///not implemented yet
 
83
}
 
84
 
 
85
void EntityCreatorMovementBridge::yaw(WFMath::CoordType angle)
 
86
{
 
87
        mNode->yaw(Ogre::Degree(angle));
 
88
}
 
89
 
 
90
void EntityCreatorMovementBridge::setOrientation(const WFMath::Quaternion& rotation)
 
91
{
 
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();
 
97
                }
 
98
                mNode->setOrientation(Atlas2Ogre(rotation) - rotOffset);
 
99
        }
 
100
}
 
101
 
 
102
void EntityCreatorMovementBridge::finalizeMovement()
 
103
{
 
104
        mCreator.finalizeCreation();
 
105
}
 
106
void EntityCreatorMovementBridge::cancelMovement()
 
107
{
 
108
        mCreator.stopCreation();
 
109
}
 
110
 
 
111
}
 
112
 
 
113
}