-1

In a 2d scene graph: When I perform a transformation like a rotation or other in a node, how I should apply these operations in children nodes? If I apply the operation in each children, it can take much time. I thought when the app render the scene, in each node down the global rotation is added with the current node rotation. The same with translation and scale. When is rising in the graph, those global properties is subtracted. Is there a better way?

tshepang
  • 12,111
  • 21
  • 91
  • 136
carlos prado
  • 49
  • 2
  • 6

1 Answers1

3

You need to use a stack on which you push and pop the current transformation matrix.

def calculateTransformRecursive(self):

  pushGlobalTransform();
  self.calculateAndStoreGlobalTransform();
  for node in self.nodes:
    node.calculateTransformRecursive();
  popGlobalTransform();

This way every node has a global transformation at drawing time, and there's no need to "undo" transformations when going up the tree.

Marc
  • 116
  • 1
  • 3