Browse Source

add get_node()

David Rose 23 years ago
parent
commit
fd2c841ca9
2 changed files with 28 additions and 1 deletions
  1. 27 1
      panda/src/pgraph/workingNodePath.cxx
  2. 1 0
      panda/src/pgraph/workingNodePath.h

+ 27 - 1
panda/src/pgraph/workingNodePath.cxx

@@ -21,9 +21,13 @@
 
 ////////////////////////////////////////////////////////////////////
 //     Function: WorkingNodePath::get_num_nodes
-//       Access: Public
+//       Access: Published
 //  Description: Returns the number of nodes in the path from the root
 //               to the current node.
+//
+//               Since a WorkingNodePath always consists of, at
+//               minimum, a nonempty parent NodePath and one child
+//               node, this method will always return at least 2.
 ////////////////////////////////////////////////////////////////////
 int WorkingNodePath::
 get_num_nodes() const {
@@ -34,6 +38,28 @@ get_num_nodes() const {
   return _next->get_num_nodes() + 1;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: WorkingNodePath::get_node
+//       Access: Published
+//  Description: Returns the nth node of the path, where 0 is the
+//               referenced (bottom) node and get_num_nodes() - 1 is
+//               the top node.  This requires iterating through the
+//               path.
+////////////////////////////////////////////////////////////////////
+PandaNode *WorkingNodePath::
+get_node(int index) const {
+  nassertr(index >= 0, NULL);
+  if (index == 0) {
+    return _node;
+  }
+
+  if (_next == (WorkingNodePath *)NULL) {
+    return get_node_path().get_node(index - 1);
+  }
+
+  return _next->get_node(index - 1);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: WorkingNodePath::r_get_node_path
 //       Access: Private

+ 1 - 0
panda/src/pgraph/workingNodePath.h

@@ -56,6 +56,7 @@ public:
   INLINE PandaNode *node() const;
 
   int get_num_nodes() const;
+  PandaNode *get_node(int index) const;
 
 private:
   PT(NodePathComponent) r_get_node_path() const;