navi homeaboutscreenshotsdownloaddevelopmentforum

ParentNode (PNode)


The ParentNode is one element of a Tree spanning all the 3D-elements that have a position and rotation inside of the world.

source:/trunk/src/lib/coord/p_node.h#HEAD Dependencies:


ParentNode has a …

  • Parent (another PNode it is connected to)
    • the topmost is NullParent
    • if the Parent is Null, the Node is free (or the NullParent)
  • list of Children.
    • each child is again a ParentNode
    • each child will be updated acordingly if the Parent is moved/rotated.
  • Position (absolute in the world and relative to its parent)
  • Rotation (absolute in the world and relative to its parent)

ParentNode is not able to …

  • draw itself (this can be done for example with extension WorldEntity)
  • tick itself (this can be done for example with extension WorldEntity)


Whenever you create a new Entity in the World, that is a PNode (ex. WorldEntity Player…), it will automatically be added to the PNode tree. By default each PNode is added to the NullParent as a child.

Now, what is this good for? The cool trick about PNodes is, that whenever you update a PNode in positional or rotational settings, all its Children will be updated as well, as they are linkey to their parent with relative coordinates/rotations. So as the Parent moves the Children will move too.


  void setRelCoor (const Vector& relCoord);
  void setAbsCoor (const Vector& absCoord);

  void setRelDir (const Quaternion& relDir);
  void setAbsDir (const Quaternion& absDir);

  void addChild (PNode* child);
  void setParent (PNode* parent);
  void setParentMode (PARENT_MODE parentMode);

These are the main functions of ParentNode, if you understand them you understand PNode :)
Most of the functions speak for themselves, but setParentMode maybe needs some explanation: There are different modes to connect Children to their Parents:

  • PNODE_LOCAL_ROTATE !< Rotates all the children around their centers.
  • PNODE_ROTATE_MOVEMENT !< Moves all the children around the center of their parent, without the rotation around their own centers.
  • PNODE_MOVEMENT !< Moves all children along with the parent.
  • combined linkage modes
  • PNODE_ALL !< Moves all children around the center of their parent, and also rotates their centers
  • PNODE_ROTATE_AND_MOVE !< Rotates all children around their axis, and moves them as the Parent Moves, but does not rotate around the center of their parent.

DEBUG Functions, that are really usefull when debug ParentNode's, they can put out nice output or paint the nodes of the selected ParentNode, and of all its Children and children's children if you'd like.

  void debug (unsigned int depth = 1, unsigned int level = 0) const;
  void debugDraw(unsigned int depth = 1, float size = 1.0, const Vector& color = Vector(1, 0, 0), unsigned int level = 0) const;

Advanced Topics

The main updating function that is responsible for the whole parent-child-update process is handled in the following function:

  void update (float dt);

This is pure matemathics, with many cases, that you just have understand, if you are developing on the PNode-internal level.

Last modified 9 years ago Last modified on Nov 28, 2007, 12:22:34 AM