Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/OgreMain/src/OgreBone.cpp @ 48

Last change on this file since 48 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 5.1 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#include "OgreStableHeaders.h"
30
31#include "OgreBone.h"
32#include "OgreSkeleton.h"
33
34namespace Ogre {
35
36    //---------------------------------------------------------------------
37    Bone::Bone(unsigned short handle, Skeleton* creator) 
38        : Node(), mHandle(handle), mManuallyControlled(false), mCreator(creator)
39    {
40    }
41    //---------------------------------------------------------------------
42    Bone::Bone(const String& name, unsigned short handle, Skeleton* creator) 
43        : Node(name), mHandle(handle), mManuallyControlled(false), mCreator(creator)
44    {
45    }
46    //---------------------------------------------------------------------
47    Bone::~Bone()
48    {
49    }
50    //---------------------------------------------------------------------
51    Bone* Bone::createChild(unsigned short handle, const Vector3& translate, 
52        const Quaternion& rotate)
53    {
54        Bone* retBone = mCreator->createBone(handle);
55        retBone->translate(translate);
56        retBone->rotate(rotate);
57        this->addChild(retBone);
58        return retBone;
59    }
60    //---------------------------------------------------------------------
61    Node* Bone::createChildImpl(void)
62    {
63        return mCreator->createBone();
64    }
65    //---------------------------------------------------------------------
66    Node* Bone::createChildImpl(const String& name)
67    {
68        return mCreator->createBone(name);
69    }
70    //---------------------------------------------------------------------
71    void Bone::setBindingPose(void)
72    {
73        setInitialState();
74
75        // Save inverse derived position/scale/orientation, used for calculate offset transform later
76        mBindDerivedInversePosition = - _getDerivedPosition();
77        mBindDerivedInverseScale = Vector3::UNIT_SCALE / _getDerivedScale();
78        mBindDerivedInverseOrientation = _getDerivedOrientation().Inverse();
79    }
80    //---------------------------------------------------------------------
81    void Bone::reset(void)
82    {
83        resetToInitialState();
84    }
85    //---------------------------------------------------------------------
86    void Bone::setManuallyControlled(bool manuallyControlled) 
87        {
88        mManuallyControlled = manuallyControlled;
89                mCreator->_notifyManualBoneStateChange(this);
90    }
91    //---------------------------------------------------------------------
92    bool Bone::isManuallyControlled() const {
93        return mManuallyControlled;
94    }
95    //---------------------------------------------------------------------
96    void Bone::_getOffsetTransform(Matrix4& m) const
97    {
98        // Combine scale with binding pose inverse scale,
99        // NB just combine as equivalent axes, no shearing
100        Vector3 scale = _getDerivedScale() * mBindDerivedInverseScale;
101
102        // Combine orientation with binding pose inverse orientation
103        Quaternion rotate = _getDerivedOrientation() * mBindDerivedInverseOrientation;
104
105        // Combine position with binding pose inverse position,
106        // Note that translation is relative to scale & rotation,
107        // so first reverse transform original derived position to
108        // binding pose bone space, and then transform to current
109        // derived bone space.
110        Vector3 translate = _getDerivedPosition() + rotate * (scale * mBindDerivedInversePosition);
111
112        m.makeTransform(translate, scale, rotate);
113    }
114    //---------------------------------------------------------------------
115    unsigned short Bone::getHandle(void) const
116    {
117        return mHandle;
118    }
119        //---------------------------------------------------------------------
120        void Bone::needUpdate(bool forceParentUpdate)
121        {
122                Node::needUpdate(forceParentUpdate);
123
124                if (isManuallyControlled())
125                {
126                        // Dirty the skeleton if manually controlled so animation can be updated
127                        mCreator->_notifyManualBonesDirty();
128                }
129
130        }
131
132
133
134
135
136}
137
Note: See TracBrowser for help on using the repository browser.