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