Rotating One NodePath Around Another

I want to rotate one NodePath around another, maintaining the distance betwen them. I mean something like a weight swinging on the end of a taut string, or a moon traveling a circular orbit around a planet. Just computing the position in python isn’t that hard, but it’s ugly. What is the panda way of doing this?

I guess we should put a page on this in the manual; it does come up from time to time.

In a nutshell:

planet = loader.loadModel('planet')
moon = loder.loadModel('moon')

orbitRing = NodePath('orbitRing')
orbitRing.reparentTo(planet)
orbitRing.setPos(100, 0, 0)
moon.reparentTo(orbitRing)

def doOrbit(task):
  orbitRing.setH(task.time)
  return Task.cont

I suggest taking a look at the solar system demo program for more details.

David

Great example; this is one of the first things that really excited me about Panda!

In your Panda installation directory, take a look at the Solar System tutorial (“samples\Basic-Tutorials–Lesson-1-Solar-System”). It will walk you through the process of setting up the render tree.

Essentially, objects in Panda can be placed in a tree of “parent” and “child” nodes, and any movements applied to a parent are also applied to all of its children. So if you create a parent node that is centered at the axis of rotation, then place an object as the child of the node and set its position (I usually use setY) to some distance D, then when you rotate the parent, the child will appear to rotate around the axis while staying D units from it.

Best of luck,
Mark

Wonderful!

Really appreciate your patience with such an obvious question.