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

« back to all changes in this revision

Viewing changes to src/components/ogre/model/ModelBoneProvider.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-10-22 23:21:17 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20091022232117-isr8u3402qmu7ilo
Tags: 0.5.7-1
* New upstream release.
  - Compile against current ogre (Closes: #551431)
  - Removed debian/patches/ember-gcc4.4.patch. Merged upstream.
  - Updated Depends on ember-media.
* Add libboost-thread-dev tp Build-Depends.
* Make debian/rules independent from upstream version.
* Updated watch file to allow automatic download of new upstream
  tarballs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 Copyright (C) 2009 Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
3
 
 
4
 This program is free software; you can redistribute it and/or modify
 
5
 it under the terms of the GNU General Public License as published by
 
6
 the Free Software Foundation; either version 2 of the License, or
 
7
 (at your option) any later version.
 
8
 
 
9
 This program is distributed in the hope that it will be useful,
 
10
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 GNU General Public License for more details.
 
13
 
 
14
 You should have received a copy of the GNU General Public License
 
15
 along with this program; if not, write to the Free Software
 
16
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 */
 
18
 
 
19
#include "ModelBoneProvider.h"
 
20
#include "components/ogre/model/Model.h"
 
21
#include "components/ogre/OgreInfo.h"
 
22
#include <OgreMovableObject.h>
 
23
#include <OgreNode.h>
 
24
#include <OgreTagPoint.h>
 
25
 
 
26
namespace EmberOgre
 
27
{
 
28
namespace Model
 
29
{
 
30
ModelBoneProvider::ModelBoneProvider(Model& parentModel, const std::string& attachPointName, Ogre::MovableObject* movableObject) :
 
31
        mParentModel(parentModel), mAttachPointName(attachPointName), mNode(0), mAttachedObject(movableObject), mParent(0), mPosition(Ogre::Vector3::ZERO), mOrientation(Ogre::Quaternion::IDENTITY)
 
32
{
 
33
        init();
 
34
}
 
35
 
 
36
ModelBoneProvider::ModelBoneProvider(Model& parentModel, const std::string& attachPointName, Ogre::MovableObject* movableObject, ModelBoneProvider* parent) :
 
37
        mParentModel(parentModel), mAttachPointName(attachPointName), mNode(0), mAttachedObject(movableObject), mParent(parent), mPosition(Ogre::Vector3::ZERO), mOrientation(Ogre::Quaternion::IDENTITY)
 
38
{
 
39
        init();
 
40
}
 
41
 
 
42
ModelBoneProvider::~ModelBoneProvider()
 
43
{
 
44
        if (mAttachedObject) {
 
45
                mParentModel.detachObjectFromBone(mAttachedObject->getName());
 
46
        }
 
47
        if (mParent) {
 
48
                ModelBoneProviderStore::iterator I = std::find(mParent->mChildren.begin(), mParent->mChildren.end(), this);
 
49
                if (I != mParent->mChildren.end()) {
 
50
                        mParent->mChildren.erase(I);
 
51
                }
 
52
        }
 
53
}
 
54
 
 
55
void ModelBoneProvider::init()
 
56
{
 
57
        if (mAttachedObject) {
 
58
                mAttachedObject->detatchFromParent();
 
59
                Model::AttachPointWrapper wrapper = mParentModel.attachObjectToAttachPoint(mAttachPointName, mAttachedObject);
 
60
                mNode = wrapper.TagPoint;
 
61
                mAttachPointDefinition = wrapper.Definition;
 
62
        }
 
63
}
 
64
 
 
65
Ogre::Node& ModelBoneProvider::getNode() const
 
66
{
 
67
        return *mNode;
 
68
}
 
69
 
 
70
Ogre::Node* ModelBoneProvider::getParentNode() const
 
71
{
 
72
        return 0;
 
73
}
 
74
 
 
75
INodeProvider* ModelBoneProvider::createChildProvider(Ogre::MovableObject* attachedObject)
 
76
{
 
77
        ModelBoneProvider* childProvider = new ModelBoneProvider(mParentModel, mAttachPointName, attachedObject, this);
 
78
        mChildren.push_back(childProvider);
 
79
        return childProvider;
 
80
}
 
81
 
 
82
void ModelBoneProvider::setVisible(bool visible)
 
83
{
 
84
        if (mAttachedObject) {
 
85
                mAttachedObject->setVisible(visible);
 
86
        }
 
87
}
 
88
 
 
89
void ModelBoneProvider::setVisualize(const std::string& visualization, bool visualize)
 
90
{
 
91
}
 
92
 
 
93
bool ModelBoneProvider::getVisualize(const std::string& visualization) const
 
94
{
 
95
        return false;
 
96
}
 
97
 
 
98
void ModelBoneProvider::setPositionAndOrientation(const Ogre::Vector3& position, const Ogre::Quaternion& orientation)
 
99
{
 
100
        mPosition = position;
 
101
        mOrientation = orientation * mAttachPointDefinition.Rotation;
 
102
        updatePositionAndOrientation();
 
103
}
 
104
 
 
105
void ModelBoneProvider::updatePositionAndOrientation()
 
106
{
 
107
        if (mNode) {
 
108
                mNode->setPosition(getDerivedPosition());
 
109
                mNode->setOrientation(getDerivedOrientation());
 
110
        }
 
111
        for (ModelBoneProviderStore::const_iterator I = mChildren.begin(); I != mChildren.end(); ++I) {
 
112
                (*I)->updatePositionAndOrientation();
 
113
        }
 
114
}
 
115
 
 
116
Ogre::Vector3 ModelBoneProvider::getDerivedPosition() const
 
117
{
 
118
        if (mParent) {
 
119
                return mParent->getDerivedPosition() + mPosition;
 
120
        }
 
121
        return mPosition;
 
122
}
 
123
 
 
124
Ogre::Quaternion ModelBoneProvider::getDerivedOrientation() const
 
125
{
 
126
        if (mParent) {
 
127
                return mParent->getDerivedOrientation() * mOrientation;
 
128
        }
 
129
        return mOrientation;
 
130
}
 
131
 
 
132
}
 
133
}