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 | #ifndef _Node_H__ |
---|
30 | #define _Node_H__ |
---|
31 | |
---|
32 | #include "OgrePrerequisites.h" |
---|
33 | |
---|
34 | #include "OgreMatrix3.h" |
---|
35 | #include "OgreMatrix4.h" |
---|
36 | #include "OgreQuaternion.h" |
---|
37 | #include "OgreString.h" |
---|
38 | #include "OgreRenderable.h" |
---|
39 | #include "OgreIteratorWrappers.h" |
---|
40 | |
---|
41 | namespace Ogre { |
---|
42 | |
---|
43 | |
---|
44 | /** Class representing a general-purpose node an articulated scene graph. |
---|
45 | @remarks |
---|
46 | A node in the scene graph is a node in a structured tree. A node contains |
---|
47 | information about the transformation which will apply to |
---|
48 | it and all of it's children. Child nodes can have transforms of their own, which |
---|
49 | are combined with their parent's transformations. |
---|
50 | @par |
---|
51 | This is an abstract class - concrete classes are based on this for specific purposes, |
---|
52 | e.g. SceneNode, Bone |
---|
53 | */ |
---|
54 | class _OgreExport Node : public Renderable |
---|
55 | { |
---|
56 | public: |
---|
57 | /** Enumeration denoting the spaces which a transform can be relative to. |
---|
58 | */ |
---|
59 | enum TransformSpace |
---|
60 | { |
---|
61 | /// Transform is relative to the local space |
---|
62 | TS_LOCAL, |
---|
63 | /// Transform is relative to the space of the parent node |
---|
64 | TS_PARENT, |
---|
65 | /// Transform is relative to world space |
---|
66 | TS_WORLD |
---|
67 | }; |
---|
68 | typedef HashMap<String, Node*> ChildNodeMap; |
---|
69 | typedef MapIterator<ChildNodeMap> ChildNodeIterator; |
---|
70 | typedef ConstMapIterator<ChildNodeMap> ConstChildNodeIterator; |
---|
71 | |
---|
72 | /** Listener which gets called back on Node events. |
---|
73 | */ |
---|
74 | class _OgreExport Listener |
---|
75 | { |
---|
76 | public: |
---|
77 | Listener() {} |
---|
78 | virtual ~Listener() {} |
---|
79 | /** Called when a node gets updated. |
---|
80 | @remarks |
---|
81 | Note that this happens when the node's derived update happens, |
---|
82 | not every time a method altering it's state occurs. There may |
---|
83 | be several state-changing calls but only one of these calls, |
---|
84 | when the node graph is fully updated. |
---|
85 | */ |
---|
86 | virtual void nodeUpdated(const Node*) {} |
---|
87 | /** Node is being destroyed */ |
---|
88 | virtual void nodeDestroyed(const Node*) {}; |
---|
89 | /** Node has been attached to a parent */ |
---|
90 | virtual void nodeAttached(const Node*) {}; |
---|
91 | /** Node has been detached from a parent */ |
---|
92 | virtual void nodeDetached(const Node*) {}; |
---|
93 | }; |
---|
94 | |
---|
95 | protected: |
---|
96 | /// Pointer to parent node |
---|
97 | Node* mParent; |
---|
98 | /// Collection of pointers to direct children; hashmap for efficiency |
---|
99 | ChildNodeMap mChildren; |
---|
100 | |
---|
101 | typedef std::set<Node*> ChildUpdateSet; |
---|
102 | /// List of children which need updating, used if self is not out of date but children are |
---|
103 | mutable ChildUpdateSet mChildrenToUpdate; |
---|
104 | /// Flag to indicate own transform from parent is out of date |
---|
105 | mutable bool mNeedParentUpdate; |
---|
106 | /// Flag indicating that all children need to be updated |
---|
107 | mutable bool mNeedChildUpdate; |
---|
108 | /// Flag indicating that parent has been notified about update request |
---|
109 | mutable bool mParentNotified ; |
---|
110 | /// Flag indicating that the node has been queued for update |
---|
111 | mutable bool mQueuedForUpdate; |
---|
112 | |
---|
113 | /// Friendly name of this node, can be automatically generated if you don't care |
---|
114 | String mName; |
---|
115 | |
---|
116 | /// Incremented count for next name extension |
---|
117 | static unsigned long msNextGeneratedNameExt; |
---|
118 | |
---|
119 | /// Stores the orientation of the node relative to it's parent. |
---|
120 | Quaternion mOrientation; |
---|
121 | |
---|
122 | /// Stores the position/translation of the node relative to its parent. |
---|
123 | Vector3 mPosition; |
---|
124 | |
---|
125 | /// Stores the scaling factor applied to this node |
---|
126 | Vector3 mScale; |
---|
127 | |
---|
128 | /// Stores whether this node inherits orientation from it's parent |
---|
129 | bool mInheritOrientation; |
---|
130 | |
---|
131 | /// Stores whether this node inherits scale from it's parent |
---|
132 | bool mInheritScale; |
---|
133 | |
---|
134 | /// Material pointer should this node be rendered |
---|
135 | mutable MaterialPtr mpMaterial; |
---|
136 | |
---|
137 | /// Only available internally - notification of parent. |
---|
138 | virtual void setParent(Node* parent); |
---|
139 | |
---|
140 | /** Cached combined orientation. |
---|
141 | @par |
---|
142 | This member is the orientation derived by combining the |
---|
143 | local transformations and those of it's parents. |
---|
144 | This is updated when _updateFromParent is called by the |
---|
145 | SceneManager or the nodes parent. |
---|
146 | */ |
---|
147 | mutable Quaternion mDerivedOrientation; |
---|
148 | |
---|
149 | /** Cached combined position. |
---|
150 | @par |
---|
151 | This member is the position derived by combining the |
---|
152 | local transformations and those of it's parents. |
---|
153 | This is updated when _updateFromParent is called by the |
---|
154 | SceneManager or the nodes parent. |
---|
155 | */ |
---|
156 | mutable Vector3 mDerivedPosition; |
---|
157 | |
---|
158 | /** Cached combined scale. |
---|
159 | @par |
---|
160 | This member is the position derived by combining the |
---|
161 | local transformations and those of it's parents. |
---|
162 | This is updated when _updateFromParent is called by the |
---|
163 | SceneManager or the nodes parent. |
---|
164 | */ |
---|
165 | mutable Vector3 mDerivedScale; |
---|
166 | |
---|
167 | /** Triggers the node to update it's combined transforms. |
---|
168 | @par |
---|
169 | This method is called internally by Ogre to ask the node |
---|
170 | to update it's complete transformation based on it's parents |
---|
171 | derived transform. |
---|
172 | */ |
---|
173 | virtual void _updateFromParent(void) const; |
---|
174 | |
---|
175 | /** Class-specific implementation of _updateFromParent. |
---|
176 | @remarks |
---|
177 | Splitting the implementation of the update away from the update call |
---|
178 | itself allows the detail to be overridden without disrupting the |
---|
179 | general sequence of updateFromParent (e.g. raising events) |
---|
180 | */ |
---|
181 | virtual void updateFromParentImpl(void) const; |
---|
182 | |
---|
183 | |
---|
184 | /** Internal method for creating a new child node - must be overridden per subclass. */ |
---|
185 | virtual Node* createChildImpl(void) = 0; |
---|
186 | |
---|
187 | /** Internal method for creating a new child node - must be overridden per subclass. */ |
---|
188 | virtual Node* createChildImpl(const String& name) = 0; |
---|
189 | |
---|
190 | /// The position to use as a base for keyframe animation |
---|
191 | Vector3 mInitialPosition; |
---|
192 | /// The orientation to use as a base for keyframe animation |
---|
193 | Quaternion mInitialOrientation; |
---|
194 | /// The scale to use as a base for keyframe animation |
---|
195 | Vector3 mInitialScale; |
---|
196 | |
---|
197 | /// Cached derived transform as a 4x4 matrix |
---|
198 | mutable Matrix4 mCachedTransform; |
---|
199 | mutable bool mCachedTransformOutOfDate; |
---|
200 | |
---|
201 | /** Node listener - only one allowed (no list) for size & performance reasons. */ |
---|
202 | Listener* mListener; |
---|
203 | |
---|
204 | typedef std::vector<Node*> QueuedUpdates; |
---|
205 | static QueuedUpdates msQueuedUpdates; |
---|
206 | |
---|
207 | |
---|
208 | public: |
---|
209 | /** Constructor, should only be called by parent, not directly. |
---|
210 | @remarks |
---|
211 | Generates a name. |
---|
212 | */ |
---|
213 | Node(); |
---|
214 | /** Constructor, should only be called by parent, not directly. |
---|
215 | @remarks |
---|
216 | Assigned a name. |
---|
217 | */ |
---|
218 | Node(const String& name); |
---|
219 | |
---|
220 | virtual ~Node(); |
---|
221 | |
---|
222 | /** Returns the name of the node. */ |
---|
223 | const String& getName(void) const; |
---|
224 | |
---|
225 | /** Gets this node's parent (NULL if this is the root). |
---|
226 | */ |
---|
227 | virtual Node* getParent(void) const; |
---|
228 | |
---|
229 | /** Returns a quaternion representing the nodes orientation. |
---|
230 | */ |
---|
231 | virtual const Quaternion & getOrientation() const; |
---|
232 | |
---|
233 | /** Sets the orientation of this node via a quaternion. |
---|
234 | @remarks |
---|
235 | Orientatings, unlike other transforms, are not always inherited by child nodes. |
---|
236 | Whether or not orientatings affect the orientation of the child nodes depends on |
---|
237 | the setInheritOrientation option of the child. In some cases you want a orientating |
---|
238 | of a parent node to apply to a child node (e.g. where the child node is a part of |
---|
239 | the same object, so you want it to be the same relative orientation based on the |
---|
240 | parent's orientation), but not in other cases (e.g. where the child node is just |
---|
241 | for positioning another object, you want it to maintain it's own orientation). |
---|
242 | The default is to inherit as with other transforms. |
---|
243 | @par |
---|
244 | Note that rotations are oriented around the node's origin. |
---|
245 | */ |
---|
246 | virtual void setOrientation( const Quaternion& q ); |
---|
247 | |
---|
248 | /** Sets the orientation of this node via quaternion parameters. |
---|
249 | @remarks |
---|
250 | Orientatings, unlike other transforms, are not always inherited by child nodes. |
---|
251 | Whether or not orientatings affect the orientation of the child nodes depends on |
---|
252 | the setInheritOrientation option of the child. In some cases you want a orientating |
---|
253 | of a parent node to apply to a child node (e.g. where the child node is a part of |
---|
254 | the same object, so you want it to be the same relative orientation based on the |
---|
255 | parent's orientation), but not in other cases (e.g. where the child node is just |
---|
256 | for positioning another object, you want it to maintain it's own orientation). |
---|
257 | The default is to inherit as with other transforms. |
---|
258 | @par |
---|
259 | Note that rotations are oriented around the node's origin. |
---|
260 | */ |
---|
261 | virtual void setOrientation( Real w, Real x, Real y, Real z); |
---|
262 | |
---|
263 | /** Resets the nodes orientation (local axes as world axes, no rotation). |
---|
264 | @remarks |
---|
265 | Orientatings, unlike other transforms, are not always inherited by child nodes. |
---|
266 | Whether or not orientatings affect the orientation of the child nodes depends on |
---|
267 | the setInheritOrientation option of the child. In some cases you want a orientating |
---|
268 | of a parent node to apply to a child node (e.g. where the child node is a part of |
---|
269 | the same object, so you want it to be the same relative orientation based on the |
---|
270 | parent's orientation), but not in other cases (e.g. where the child node is just |
---|
271 | for positioning another object, you want it to maintain it's own orientation). |
---|
272 | The default is to inherit as with other transforms. |
---|
273 | @par |
---|
274 | Note that rotations are oriented around the node's origin. |
---|
275 | */ |
---|
276 | virtual void resetOrientation(void); |
---|
277 | |
---|
278 | /** Sets the position of the node relative to it's parent. |
---|
279 | */ |
---|
280 | virtual void setPosition(const Vector3& pos); |
---|
281 | |
---|
282 | /** Sets the position of the node relative to it's parent. |
---|
283 | */ |
---|
284 | virtual void setPosition(Real x, Real y, Real z); |
---|
285 | |
---|
286 | /** Gets the position of the node relative to it's parent. |
---|
287 | */ |
---|
288 | virtual const Vector3 & getPosition(void) const; |
---|
289 | |
---|
290 | /** Sets the scaling factor applied to this node. |
---|
291 | @remarks |
---|
292 | Scaling factors, unlike other transforms, are not always inherited by child nodes. |
---|
293 | Whether or not scalings affect the size of the child nodes depends on the setInheritScale |
---|
294 | option of the child. In some cases you want a scaling factor of a parent node to apply to |
---|
295 | a child node (e.g. where the child node is a part of the same object, so you want it to be |
---|
296 | the same relative size based on the parent's size), but not in other cases (e.g. where the |
---|
297 | child node is just for positioning another object, you want it to maintain it's own size). |
---|
298 | The default is to inherit as with other transforms. |
---|
299 | @par |
---|
300 | Note that like rotations, scalings are oriented around the node's origin. |
---|
301 | */ |
---|
302 | virtual void setScale(const Vector3& scale); |
---|
303 | |
---|
304 | /** Sets the scaling factor applied to this node. |
---|
305 | @remarks |
---|
306 | Scaling factors, unlike other transforms, are not always inherited by child nodes. |
---|
307 | Whether or not scalings affect the size of the child nodes depends on the setInheritScale |
---|
308 | option of the child. In some cases you want a scaling factor of a parent node to apply to |
---|
309 | a child node (e.g. where the child node is a part of the same object, so you want it to be |
---|
310 | the same relative size based on the parent's size), but not in other cases (e.g. where the |
---|
311 | child node is just for positioning another object, you want it to maintain it's own size). |
---|
312 | The default is to inherit as with other transforms. |
---|
313 | @par |
---|
314 | Note that like rotations, scalings are oriented around the node's origin. |
---|
315 | */ |
---|
316 | virtual void setScale(Real x, Real y, Real z); |
---|
317 | |
---|
318 | /** Gets the scaling factor of this node. |
---|
319 | */ |
---|
320 | virtual const Vector3 & getScale(void) const; |
---|
321 | |
---|
322 | /** Tells the node whether it should inherit orientation from it's parent node. |
---|
323 | @remarks |
---|
324 | Orientatings, unlike other transforms, are not always inherited by child nodes. |
---|
325 | Whether or not orientatings affect the orientation of the child nodes depends on |
---|
326 | the setInheritOrientation option of the child. In some cases you want a orientating |
---|
327 | of a parent node to apply to a child node (e.g. where the child node is a part of |
---|
328 | the same object, so you want it to be the same relative orientation based on the |
---|
329 | parent's orientation), but not in other cases (e.g. where the child node is just |
---|
330 | for positioning another object, you want it to maintain it's own orientation). |
---|
331 | The default is to inherit as with other transforms. |
---|
332 | @param inherit If true, this node's orientation will be affected by its parent's orientation. |
---|
333 | If false, it will not be affected. |
---|
334 | */ |
---|
335 | virtual void setInheritOrientation(bool inherit); |
---|
336 | |
---|
337 | /** Returns true if this node is affected by orientation applied to the parent node. |
---|
338 | @remarks |
---|
339 | Orientatings, unlike other transforms, are not always inherited by child nodes. |
---|
340 | Whether or not orientatings affect the orientation of the child nodes depends on |
---|
341 | the setInheritOrientation option of the child. In some cases you want a orientating |
---|
342 | of a parent node to apply to a child node (e.g. where the child node is a part of |
---|
343 | the same object, so you want it to be the same relative orientation based on the |
---|
344 | parent's orientation), but not in other cases (e.g. where the child node is just |
---|
345 | for positioning another object, you want it to maintain it's own orientation). |
---|
346 | The default is to inherit as with other transforms. |
---|
347 | @remarks |
---|
348 | See setInheritOrientation for more info. |
---|
349 | */ |
---|
350 | virtual bool getInheritOrientation(void) const; |
---|
351 | |
---|
352 | /** Tells the node whether it should inherit scaling factors from it's parent node. |
---|
353 | @remarks |
---|
354 | Scaling factors, unlike other transforms, are not always inherited by child nodes. |
---|
355 | Whether or not scalings affect the size of the child nodes depends on the setInheritScale |
---|
356 | option of the child. In some cases you want a scaling factor of a parent node to apply to |
---|
357 | a child node (e.g. where the child node is a part of the same object, so you want it to be |
---|
358 | the same relative size based on the parent's size), but not in other cases (e.g. where the |
---|
359 | child node is just for positioning another object, you want it to maintain it's own size). |
---|
360 | The default is to inherit as with other transforms. |
---|
361 | @param inherit If true, this node's scale will be affected by its parent's scale. If false, |
---|
362 | it will not be affected. |
---|
363 | */ |
---|
364 | virtual void setInheritScale(bool inherit); |
---|
365 | |
---|
366 | /** Returns true if this node is affected by scaling factors applied to the parent node. |
---|
367 | @remarks |
---|
368 | See setInheritScale for more info. |
---|
369 | */ |
---|
370 | virtual bool getInheritScale(void) const; |
---|
371 | |
---|
372 | /** Scales the node, combining it's current scale with the passed in scaling factor. |
---|
373 | @remarks |
---|
374 | This method applies an extra scaling factor to the node's existing scale, (unlike setScale |
---|
375 | which overwrites it) combining it's current scale with the new one. E.g. calling this |
---|
376 | method twice with Vector3(2,2,2) would have the same effect as setScale(Vector3(4,4,4)) if |
---|
377 | the existing scale was 1. |
---|
378 | @par |
---|
379 | Note that like rotations, scalings are oriented around the node's origin. |
---|
380 | */ |
---|
381 | virtual void scale(const Vector3& scale); |
---|
382 | |
---|
383 | /** Scales the node, combining it's current scale with the passed in scaling factor. |
---|
384 | @remarks |
---|
385 | This method applies an extra scaling factor to the node's existing scale, (unlike setScale |
---|
386 | which overwrites it) combining it's current scale with the new one. E.g. calling this |
---|
387 | method twice with Vector3(2,2,2) would have the same effect as setScale(Vector3(4,4,4)) if |
---|
388 | the existing scale was 1. |
---|
389 | @par |
---|
390 | Note that like rotations, scalings are oriented around the node's origin. |
---|
391 | */ |
---|
392 | virtual void scale(Real x, Real y, Real z); |
---|
393 | |
---|
394 | /** Moves the node along the cartesian axes. |
---|
395 | @par |
---|
396 | This method moves the node by the supplied vector along the |
---|
397 | world cartesian axes, i.e. along world x,y,z |
---|
398 | @param |
---|
399 | d Vector with x,y,z values representing the translation. |
---|
400 | @param |
---|
401 | relativeTo The space which this transform is relative to. |
---|
402 | */ |
---|
403 | virtual void translate(const Vector3& d, TransformSpace relativeTo = TS_PARENT); |
---|
404 | /** Moves the node along the cartesian axes. |
---|
405 | @par |
---|
406 | This method moves the node by the supplied vector along the |
---|
407 | world cartesian axes, i.e. along world x,y,z |
---|
408 | @param |
---|
409 | x |
---|
410 | @param |
---|
411 | y |
---|
412 | @param |
---|
413 | z Real x, y and z values representing the translation. |
---|
414 | @param |
---|
415 | relativeTo The space which this transform is relative to. |
---|
416 | */ |
---|
417 | virtual void translate(Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT); |
---|
418 | /** Moves the node along arbitrary axes. |
---|
419 | @remarks |
---|
420 | This method translates the node by a vector which is relative to |
---|
421 | a custom set of axes. |
---|
422 | @param |
---|
423 | axes A 3x3 Matrix containg 3 column vectors each representing the |
---|
424 | axes X, Y and Z respectively. In this format the standard cartesian |
---|
425 | axes would be expressed as: |
---|
426 | <pre> |
---|
427 | 1 0 0 |
---|
428 | 0 1 0 |
---|
429 | 0 0 1 |
---|
430 | </pre> |
---|
431 | i.e. the identity matrix. |
---|
432 | @param |
---|
433 | move Vector relative to the axes above. |
---|
434 | @param |
---|
435 | relativeTo The space which this transform is relative to. |
---|
436 | */ |
---|
437 | virtual void translate(const Matrix3& axes, const Vector3& move, TransformSpace relativeTo = TS_PARENT); |
---|
438 | /** Moves the node along arbitrary axes. |
---|
439 | @remarks |
---|
440 | This method translates the node by a vector which is relative to |
---|
441 | a custom set of axes. |
---|
442 | @param |
---|
443 | axes A 3x3 Matrix containg 3 column vectors each representing the |
---|
444 | axes X, Y and Z respectively. In this format the standard cartesian |
---|
445 | axes would be expressed as |
---|
446 | <pre> |
---|
447 | 1 0 0 |
---|
448 | 0 1 0 |
---|
449 | 0 0 1 |
---|
450 | </pre> |
---|
451 | i.e. the identity matrix. |
---|
452 | @param |
---|
453 | x,y,z Translation components relative to the axes above. |
---|
454 | @param |
---|
455 | relativeTo The space which this transform is relative to. |
---|
456 | */ |
---|
457 | virtual void translate(const Matrix3& axes, Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT); |
---|
458 | |
---|
459 | /** Rotate the node around the Z-axis. |
---|
460 | */ |
---|
461 | virtual void roll(const Radian& angle, TransformSpace relativeTo = TS_LOCAL); |
---|
462 | #ifndef OGRE_FORCE_ANGLE_TYPES |
---|
463 | inline void roll(Real degrees, TransformSpace relativeTo = TS_LOCAL) { |
---|
464 | roll ( Angle(degrees), relativeTo ); |
---|
465 | } |
---|
466 | #endif//OGRE_FORCE_ANGLE_TYPES |
---|
467 | |
---|
468 | /** Rotate the node around the X-axis. |
---|
469 | */ |
---|
470 | virtual void pitch(const Radian& angle, TransformSpace relativeTo = TS_LOCAL); |
---|
471 | #ifndef OGRE_FORCE_ANGLE_TYPES |
---|
472 | inline void pitch(Real degrees, TransformSpace relativeTo = TS_LOCAL) { |
---|
473 | pitch ( Angle(degrees), relativeTo ); |
---|
474 | } |
---|
475 | #endif//OGRE_FORCE_ANGLE_TYPES |
---|
476 | |
---|
477 | /** Rotate the node around the Y-axis. |
---|
478 | */ |
---|
479 | virtual void yaw(const Radian& angle, TransformSpace relativeTo = TS_LOCAL); |
---|
480 | #ifndef OGRE_FORCE_ANGLE_TYPES |
---|
481 | inline void yaw(Real degrees, TransformSpace relativeTo = TS_LOCAL) { |
---|
482 | yaw ( Angle(degrees), relativeTo ); |
---|
483 | } |
---|
484 | #endif//OGRE_FORCE_ANGLE_TYPES |
---|
485 | |
---|
486 | /** Rotate the node around an arbitrary axis. |
---|
487 | */ |
---|
488 | virtual void rotate(const Vector3& axis, const Radian& angle, TransformSpace relativeTo = TS_LOCAL); |
---|
489 | #ifndef OGRE_FORCE_ANGLE_TYPES |
---|
490 | inline void rotate(const Vector3& axis, Real degrees, TransformSpace relativeTo = TS_LOCAL) { |
---|
491 | rotate ( axis, Angle(degrees), relativeTo ); |
---|
492 | } |
---|
493 | #endif//OGRE_FORCE_ANGLE_TYPES |
---|
494 | |
---|
495 | /** Rotate the node around an aritrary axis using a Quarternion. |
---|
496 | */ |
---|
497 | virtual void rotate(const Quaternion& q, TransformSpace relativeTo = TS_LOCAL); |
---|
498 | |
---|
499 | /** Gets a matrix whose columns are the local axes based on |
---|
500 | the nodes orientation relative to it's parent. */ |
---|
501 | virtual Matrix3 getLocalAxes(void) const; |
---|
502 | |
---|
503 | /** Creates an unnamed new Node as a child of this node. |
---|
504 | @param |
---|
505 | translate Initial translation offset of child relative to parent |
---|
506 | @param |
---|
507 | rotate Initial rotation relative to parent |
---|
508 | */ |
---|
509 | virtual Node* createChild( |
---|
510 | const Vector3& translate = Vector3::ZERO, |
---|
511 | const Quaternion& rotate = Quaternion::IDENTITY ); |
---|
512 | |
---|
513 | /** Creates a new named Node as a child of this node. |
---|
514 | @remarks |
---|
515 | This creates a child node with a given name, which allows you to look the node up from |
---|
516 | the parent which holds this collection of nodes. |
---|
517 | @param |
---|
518 | translate Initial translation offset of child relative to parent |
---|
519 | @param |
---|
520 | rotate Initial rotation relative to parent |
---|
521 | */ |
---|
522 | virtual Node* createChild(const String& name, const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY); |
---|
523 | |
---|
524 | /** Adds a (precreated) child scene node to this node. If it is attached to another node, |
---|
525 | it must be detached first. |
---|
526 | @param child The Node which is to become a child node of this one |
---|
527 | */ |
---|
528 | virtual void addChild(Node* child); |
---|
529 | |
---|
530 | /** Reports the number of child nodes under this one. |
---|
531 | */ |
---|
532 | virtual unsigned short numChildren(void) const; |
---|
533 | |
---|
534 | /** Gets a pointer to a child node. |
---|
535 | @remarks |
---|
536 | There is an alternate getChild method which returns a named child. |
---|
537 | */ |
---|
538 | virtual Node* getChild(unsigned short index) const; |
---|
539 | |
---|
540 | /** Gets a pointer to a named child node. |
---|
541 | */ |
---|
542 | virtual Node* getChild(const String& name) const; |
---|
543 | |
---|
544 | /** Retrieves an iterator for efficiently looping through all children of this node. |
---|
545 | @remarks |
---|
546 | Using this is faster than repeatedly calling getChild if you want to go through |
---|
547 | all (or most of) the children of this node. |
---|
548 | Note that the returned iterator is only valid whilst no children are added or |
---|
549 | removed from this node. Thus you should not store this returned iterator for |
---|
550 | later use, nor should you add / remove children whilst iterating through it; |
---|
551 | store up changes for later. Note that calling methods on returned items in |
---|
552 | the iterator IS allowed and does not invalidate the iterator. |
---|
553 | */ |
---|
554 | virtual ChildNodeIterator getChildIterator(void); |
---|
555 | |
---|
556 | /** Retrieves an iterator for efficiently looping through all children of this node. |
---|
557 | @remarks |
---|
558 | Using this is faster than repeatedly calling getChild if you want to go through |
---|
559 | all (or most of) the children of this node. |
---|
560 | Note that the returned iterator is only valid whilst no children are added or |
---|
561 | removed from this node. Thus you should not store this returned iterator for |
---|
562 | later use, nor should you add / remove children whilst iterating through it; |
---|
563 | store up changes for later. Note that calling methods on returned items in |
---|
564 | the iterator IS allowed and does not invalidate the iterator. |
---|
565 | */ |
---|
566 | virtual ConstChildNodeIterator getChildIterator(void) const; |
---|
567 | |
---|
568 | /** Drops the specified child from this node. |
---|
569 | @remarks |
---|
570 | Does not delete the node, just detaches it from |
---|
571 | this parent, potentially to be reattached elsewhere. |
---|
572 | There is also an alternate version which drops a named |
---|
573 | child from this node. |
---|
574 | */ |
---|
575 | virtual Node* removeChild(unsigned short index); |
---|
576 | /** Drops the specified child from this node. |
---|
577 | @remarks |
---|
578 | Does not delete the node, just detaches it from |
---|
579 | this parent, potentially to be reattached elsewhere. |
---|
580 | There is also an alternate version which drops a named |
---|
581 | child from this node. |
---|
582 | */ |
---|
583 | virtual Node* removeChild(Node* child); |
---|
584 | |
---|
585 | /** Drops the named child from this node. |
---|
586 | @remarks |
---|
587 | Does not delete the node, just detaches it from |
---|
588 | this parent, potentially to be reattached elsewhere. |
---|
589 | */ |
---|
590 | virtual Node* removeChild(const String& name); |
---|
591 | /** Removes all child Nodes attached to this node. Does not delete the nodes, just detaches them from |
---|
592 | this parent, potentially to be reattached elsewhere. |
---|
593 | */ |
---|
594 | virtual void removeAllChildren(void); |
---|
595 | |
---|
596 | /** Gets the orientation of the node as derived from all parents. |
---|
597 | */ |
---|
598 | virtual const Quaternion & _getDerivedOrientation(void) const; |
---|
599 | |
---|
600 | /** Gets the position of the node as derived from all parents. |
---|
601 | */ |
---|
602 | virtual const Vector3 & _getDerivedPosition(void) const; |
---|
603 | |
---|
604 | /** Gets the scaling factor of the node as derived from all parents. |
---|
605 | */ |
---|
606 | virtual const Vector3 & _getDerivedScale(void) const; |
---|
607 | |
---|
608 | /** Gets the full transformation matrix for this node. |
---|
609 | @remarks |
---|
610 | This method returns the full transformation matrix |
---|
611 | for this node, including the effect of any parent node |
---|
612 | transformations, provided they have been updated using the Node::_update method. |
---|
613 | This should only be called by a SceneManager which knows the |
---|
614 | derived transforms have been updated before calling this method. |
---|
615 | Applications using Ogre should just use the relative transforms. |
---|
616 | */ |
---|
617 | virtual const Matrix4& _getFullTransform(void) const; |
---|
618 | |
---|
619 | /** Internal method to update the Node. |
---|
620 | @note |
---|
621 | Updates this node and any relevant children to incorporate transforms etc. |
---|
622 | Don't call this yourself unless you are writing a SceneManager implementation. |
---|
623 | @param |
---|
624 | updateChildren If true, the update cascades down to all children. Specify false if you wish to |
---|
625 | update children separately, e.g. because of a more selective SceneManager implementation. |
---|
626 | @param |
---|
627 | parentHasChanged This flag indicates that the parent xform has changed, |
---|
628 | so the child should retrieve the parent's xform and combine it with its own |
---|
629 | even if it hasn't changed itself. |
---|
630 | */ |
---|
631 | virtual void _update(bool updateChildren, bool parentHasChanged); |
---|
632 | |
---|
633 | /** Sets a listener for this Node. |
---|
634 | @remarks |
---|
635 | Note for size and performance reasons only one listener per node is |
---|
636 | allowed. |
---|
637 | */ |
---|
638 | virtual void setListener(Listener* listener) { mListener = listener; } |
---|
639 | |
---|
640 | /** Gets the current listener for this Node. |
---|
641 | */ |
---|
642 | virtual Listener* getListener(void) const { return mListener; } |
---|
643 | |
---|
644 | /** Overridden from Renderable. |
---|
645 | @remarks |
---|
646 | This is only used if the SceneManager chooses to render the node. This option can be set |
---|
647 | for SceneNodes at SceneManager::setDisplaySceneNodes, and for entities based on skeletal |
---|
648 | models using Entity::setDisplayBones() |
---|
649 | */ |
---|
650 | const MaterialPtr& getMaterial(void) const; |
---|
651 | /** Overridden from Renderable. |
---|
652 | @remarks |
---|
653 | This is only used if the SceneManager chooses to render the node. This option can be set |
---|
654 | for SceneNodes at SceneManager::setDisplaySceneNodes, and for entities based on skeletal |
---|
655 | models using Entity::setDisplaySkeleton() |
---|
656 | */ |
---|
657 | void getRenderOperation(RenderOperation& op); |
---|
658 | /** Overridden from Renderable. |
---|
659 | @remarks |
---|
660 | This is only used if the SceneManager chooses to render the node. This option can be set |
---|
661 | for SceneNodes at SceneManager::setDisplaySceneNodes, and for entities based on skeletal |
---|
662 | models using Entity::setDisplaySkeleton() |
---|
663 | */ |
---|
664 | void getWorldTransforms(Matrix4* xform) const; |
---|
665 | /** @copydoc Renderable::getWorldOrientation */ |
---|
666 | const Quaternion& getWorldOrientation(void) const; |
---|
667 | /** @copydoc Renderable::getWorldPosition */ |
---|
668 | const Vector3& getWorldPosition(void) const; |
---|
669 | |
---|
670 | /** Sets the current transform of this node to be the 'initial state' ie that |
---|
671 | position / orientation / scale to be used as a basis for delta values used |
---|
672 | in keyframe animation. |
---|
673 | @remarks |
---|
674 | You never need to call this method unless you plan to animate this node. If you do |
---|
675 | plan to animate it, call this method once you've loaded the node with it's base state, |
---|
676 | ie the state on which all keyframes are based. |
---|
677 | @par |
---|
678 | If you never call this method, the initial state is the identity transform, ie do nothing. |
---|
679 | */ |
---|
680 | virtual void setInitialState(void); |
---|
681 | |
---|
682 | /** Resets the position / orientation / scale of this node to it's initial state, see setInitialState for more info. */ |
---|
683 | virtual void resetToInitialState(void); |
---|
684 | |
---|
685 | /** Gets the initial position of this node, see setInitialState for more info. |
---|
686 | @remarks |
---|
687 | Also resets the cumulative animation weight used for blending. |
---|
688 | */ |
---|
689 | virtual const Vector3& getInitialPosition(void) const; |
---|
690 | |
---|
691 | /** Gets the initial orientation of this node, see setInitialState for more info. */ |
---|
692 | virtual const Quaternion& getInitialOrientation(void) const; |
---|
693 | |
---|
694 | /** Gets the initial position of this node, see setInitialState for more info. */ |
---|
695 | virtual const Vector3& getInitialScale(void) const; |
---|
696 | |
---|
697 | /** Overridden, see Renderable */ |
---|
698 | Real getSquaredViewDepth(const Camera* cam) const; |
---|
699 | |
---|
700 | /** To be called in the event of transform changes to this node that require it's recalculation. |
---|
701 | @remarks |
---|
702 | This not only tags the node state as being 'dirty', it also requests it's parent to |
---|
703 | know about it's dirtiness so it will get an update next time. |
---|
704 | @param forceParentUpdate Even if the node thinks it has already told it's |
---|
705 | parent, tell it anyway |
---|
706 | */ |
---|
707 | virtual void needUpdate(bool forceParentUpdate = false); |
---|
708 | /** Called by children to notify their parent that they need an update. |
---|
709 | @param forceParentUpdate Even if the node thinks it has already told it's |
---|
710 | parent, tell it anyway |
---|
711 | */ |
---|
712 | virtual void requestUpdate(Node* child, bool forceParentUpdate = false); |
---|
713 | /** Called by children to notify their parent that they no longer need an update. */ |
---|
714 | virtual void cancelUpdate(Node* child); |
---|
715 | |
---|
716 | /** Queue a 'needUpdate' call to a node safely. |
---|
717 | @ramarks |
---|
718 | You can't call needUpdate() during the scene graph update, e.g. in |
---|
719 | response to a Node::Listener hook, because the graph is already being |
---|
720 | updated, and update flag changes cannot be made reliably in that context. |
---|
721 | Call this method if you need to queue a needUpdate call in this case. |
---|
722 | */ |
---|
723 | static void queueNeedUpdate(Node* n); |
---|
724 | /** Process queued 'needUpdate' calls. */ |
---|
725 | static void processQueuedUpdates(void); |
---|
726 | |
---|
727 | /** @copydoc Renderable::getLights */ |
---|
728 | const LightList& getLights(void) const; |
---|
729 | |
---|
730 | |
---|
731 | |
---|
732 | }; |
---|
733 | |
---|
734 | } //namespace |
---|
735 | |
---|
736 | #endif |
---|