1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #include "OgreStableHeaders.h" |
---|
30 | |
---|
31 | #include "OgreTagPoint.h" |
---|
32 | #include "OgreMatrix4.h" |
---|
33 | #include "OgreMatrix3.h" |
---|
34 | #include "OgreEntity.h" |
---|
35 | #include "OgreSceneNode.h" |
---|
36 | #include "OgreSkeleton.h" |
---|
37 | #include "OgreQuaternion.h" |
---|
38 | |
---|
39 | |
---|
40 | namespace Ogre { |
---|
41 | |
---|
42 | //----------------------------------------------------------------------------- |
---|
43 | TagPoint::TagPoint(unsigned short handle, Skeleton* creator) |
---|
44 | : Bone(handle, creator) |
---|
45 | , mParentEntity(0) |
---|
46 | , mChildObject(0) |
---|
47 | , mInheritParentEntityOrientation(true) |
---|
48 | , mInheritParentEntityScale(true) |
---|
49 | { |
---|
50 | } |
---|
51 | //----------------------------------------------------------------------------- |
---|
52 | TagPoint::~TagPoint() |
---|
53 | { |
---|
54 | } |
---|
55 | //----------------------------------------------------------------------------- |
---|
56 | Entity *TagPoint::getParentEntity(void) const |
---|
57 | { |
---|
58 | return mParentEntity; |
---|
59 | } |
---|
60 | //----------------------------------------------------------------------------- |
---|
61 | MovableObject* TagPoint::getChildObject(void) const |
---|
62 | { |
---|
63 | return mChildObject; |
---|
64 | } |
---|
65 | //----------------------------------------------------------------------------- |
---|
66 | void TagPoint::setParentEntity(Entity *pEntity) |
---|
67 | { |
---|
68 | mParentEntity = pEntity; |
---|
69 | } |
---|
70 | //----------------------------------------------------------------------------- |
---|
71 | void TagPoint::setChildObject(MovableObject *pObject) |
---|
72 | { |
---|
73 | mChildObject = pObject; |
---|
74 | } |
---|
75 | //----------------------------------------------------------------------------- |
---|
76 | void TagPoint::setInheritParentEntityOrientation(bool inherit) |
---|
77 | { |
---|
78 | mInheritParentEntityOrientation = inherit; |
---|
79 | needUpdate(); |
---|
80 | } |
---|
81 | //----------------------------------------------------------------------------- |
---|
82 | bool TagPoint::getInheritParentEntityOrientation(void) const |
---|
83 | { |
---|
84 | return mInheritParentEntityOrientation; |
---|
85 | } |
---|
86 | //----------------------------------------------------------------------------- |
---|
87 | void TagPoint::setInheritParentEntityScale(bool inherit) |
---|
88 | { |
---|
89 | mInheritParentEntityScale = inherit; |
---|
90 | needUpdate(); |
---|
91 | } |
---|
92 | //----------------------------------------------------------------------------- |
---|
93 | bool TagPoint::getInheritParentEntityScale(void) const |
---|
94 | { |
---|
95 | return mInheritParentEntityScale; |
---|
96 | } |
---|
97 | //----------------------------------------------------------------------------- |
---|
98 | const Matrix4& TagPoint::_getFullLocalTransform(void) const |
---|
99 | { |
---|
100 | return mFullLocalTransform; |
---|
101 | } |
---|
102 | //----------------------------------------------------------------------------- |
---|
103 | const Matrix4& TagPoint::getParentEntityTransform(void) const |
---|
104 | { |
---|
105 | |
---|
106 | return mParentEntity->_getParentNodeFullTransform(); |
---|
107 | } |
---|
108 | //----------------------------------------------------------------------------- |
---|
109 | void TagPoint::needUpdate(bool forceParentUpdate) |
---|
110 | { |
---|
111 | Bone::needUpdate(forceParentUpdate); |
---|
112 | |
---|
113 | // We need to tell parent entities node |
---|
114 | if (mParentEntity) |
---|
115 | { |
---|
116 | Node* n = mParentEntity->getParentNode(); |
---|
117 | if (n) |
---|
118 | { |
---|
119 | n->needUpdate(); |
---|
120 | } |
---|
121 | |
---|
122 | } |
---|
123 | |
---|
124 | } |
---|
125 | //----------------------------------------------------------------------------- |
---|
126 | void TagPoint::updateFromParentImpl(void) const |
---|
127 | { |
---|
128 | // Call superclass |
---|
129 | Bone::updateFromParentImpl(); |
---|
130 | |
---|
131 | // Save transform for local skeleton |
---|
132 | mFullLocalTransform.makeTransform( |
---|
133 | mDerivedPosition, |
---|
134 | mDerivedScale, |
---|
135 | mDerivedOrientation); |
---|
136 | |
---|
137 | // Include Entity transform |
---|
138 | if (mParentEntity) |
---|
139 | { |
---|
140 | Node* entityParentNode = mParentEntity->getParentNode(); |
---|
141 | if (entityParentNode) |
---|
142 | { |
---|
143 | // Note: orientation/scale inherits from parent node already take care with |
---|
144 | // Bone::_updateFromParent, don't do that with parent entity transform. |
---|
145 | |
---|
146 | // Combine orientation with that of parent entity |
---|
147 | const Quaternion& parentOrientation = entityParentNode->_getDerivedOrientation(); |
---|
148 | if (mInheritParentEntityOrientation) |
---|
149 | { |
---|
150 | mDerivedOrientation = parentOrientation * mDerivedOrientation; |
---|
151 | } |
---|
152 | |
---|
153 | // Incorporate parent entity scale |
---|
154 | const Vector3& parentScale = entityParentNode->_getDerivedScale(); |
---|
155 | if (mInheritParentEntityScale) |
---|
156 | { |
---|
157 | mDerivedScale *= parentScale; |
---|
158 | } |
---|
159 | |
---|
160 | // Change position vector based on parent entity's orientation & scale |
---|
161 | mDerivedPosition = parentOrientation * (parentScale * mDerivedPosition); |
---|
162 | |
---|
163 | // Add altered position vector to parent entity |
---|
164 | mDerivedPosition += entityParentNode->_getDerivedPosition(); |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | if (mChildObject) |
---|
169 | { |
---|
170 | mChildObject->_notifyMoved(); |
---|
171 | } |
---|
172 | } |
---|
173 | //----------------------------------------------------------------------------- |
---|
174 | const LightList& TagPoint::getLights(void) const |
---|
175 | { |
---|
176 | return mParentEntity->queryLights(); |
---|
177 | } |
---|
178 | |
---|
179 | } |
---|