2
Copyright (C) 2009 Erik Hjortsberg <erik.hjortsberg@gmail.com>
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.
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.
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.
19
#include "ModelBoneProvider.h"
20
#include "components/ogre/model/Model.h"
21
#include "components/ogre/OgreInfo.h"
22
#include <OgreMovableObject.h>
24
#include <OgreTagPoint.h>
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)
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)
42
ModelBoneProvider::~ModelBoneProvider()
44
if (mAttachedObject) {
45
mParentModel.detachObjectFromBone(mAttachedObject->getName());
48
ModelBoneProviderStore::iterator I = std::find(mParent->mChildren.begin(), mParent->mChildren.end(), this);
49
if (I != mParent->mChildren.end()) {
50
mParent->mChildren.erase(I);
55
void ModelBoneProvider::init()
57
if (mAttachedObject) {
58
mAttachedObject->detatchFromParent();
59
Model::AttachPointWrapper wrapper = mParentModel.attachObjectToAttachPoint(mAttachPointName, mAttachedObject);
60
mNode = wrapper.TagPoint;
61
mAttachPointDefinition = wrapper.Definition;
65
Ogre::Node& ModelBoneProvider::getNode() const
70
Ogre::Node* ModelBoneProvider::getParentNode() const
75
INodeProvider* ModelBoneProvider::createChildProvider(Ogre::MovableObject* attachedObject)
77
ModelBoneProvider* childProvider = new ModelBoneProvider(mParentModel, mAttachPointName, attachedObject, this);
78
mChildren.push_back(childProvider);
82
void ModelBoneProvider::setVisible(bool visible)
84
if (mAttachedObject) {
85
mAttachedObject->setVisible(visible);
89
void ModelBoneProvider::setVisualize(const std::string& visualization, bool visualize)
93
bool ModelBoneProvider::getVisualize(const std::string& visualization) const
98
void ModelBoneProvider::setPositionAndOrientation(const Ogre::Vector3& position, const Ogre::Quaternion& orientation)
100
mPosition = position;
101
mOrientation = orientation * mAttachPointDefinition.Rotation;
102
updatePositionAndOrientation();
105
void ModelBoneProvider::updatePositionAndOrientation()
108
mNode->setPosition(getDerivedPosition());
109
mNode->setOrientation(getDerivedOrientation());
111
for (ModelBoneProviderStore::const_iterator I = mChildren.begin(); I != mChildren.end(); ++I) {
112
(*I)->updatePositionAndOrientation();
116
Ogre::Vector3 ModelBoneProvider::getDerivedPosition() const
119
return mParent->getDerivedPosition() + mPosition;
124
Ogre::Quaternion ModelBoneProvider::getDerivedOrientation() const
127
return mParent->getDerivedOrientation() * mOrientation;