Panda3D Samples Code

In panda3d I work on the samples to get knowledge about panda3d, In solar-systems code there is a hprInterval fuction which make planets to orbit around sun, I want to visible see that orbit but I cannot find and method to that. Is anyone know how can I draw that orbit so I can see the path of planets?

```
self.orbit_period_earth = Sequence(
self.orbit_root_earth.hprInterval(
self.yearscale, (360, 0, 0)),
Func(messenger.send, "newYear"))
self.day_period_earth = self.earth.hprInterval(
self.dayscale, (360, 0, 0))
```

I donâ€™t think that thereâ€™s a single method that will cause a trail to be drawn.

However, there are a number of ways that it could be implemented, I daresay. Perhaps the simplest would be to use MeshDrawer, and to have it draw a â€ślinked segmentâ€ť, using points at intervals along the course of the orbit.

Note in that API link both of the relevant methods there: â€ślinkSegmentâ€ť and â€ślinkSegmentEndâ€ť. Both are important, I believe

Note also that, despite the manual page, a MeshDrawer object neednâ€™t be re-drawn every frame: you can draw the geometry once and then leave it in place, I do believe.

1 Like

Thanks for the answer. Mesh drawer seems logical but I solve that with this code.

```
orbit = LineSegs()
# Set the thickness and color of the orbit line
orbit.setThickness(3)
orbit.setColor(1, 1, 1, 1)
# Set the starting point of the orbit We can play with this variable to change orbit position (with drawTo metdod)
orbit.moveTo(math.cos(math.radians(0))*1.2, math.sin(math.radians(0))*1.2, 0)
# Use a for loop to draw a circle around the center point
# with a radius of 1 unit
for angle in range(0, 360):
x = math.cos(math.radians(angle))
y = math.sin(math.radians(angle))
orbit.drawTo(x*1.2, y*1.2, 0)
# Create a NodePath to render the orbit
orbit_np = orbit.create()
self.earth.attachNewNode(orbit_np)
```

1 Like

Yup, LineSegs should work well indeed, I would imagine!

1 Like