[Solved] Drawing Circles and Lines in Panda?

Hello All,

For my game i need to draw portion of Circle on Screen (either in 3d or in 2D) when portion is proportionnal to a variable.

However i’ve not found how to draw directly Circle or lines in panda ( ie not by using a model or an actor).

Does someone has a clue on how to do it?

You can use the LineSegs class to create line segments easily; it’s not too much work from there to draw a circular arc:

def makeArc(angleDegrees = 360, numSteps = 16):
    ls = LineSegs()

    angleRadians = deg2Rad(angleDegrees)

    for i in range(numSteps + 1):
        a = angleRadians * i / numSteps
        y = math.sin(a)
        x = math.cos(a)

        ls.drawTo(x, 0, y)

    node = ls.create()
    return NodePath(node)

If you want a solid pie wedge, it’s probably easiest to use the egg library:

def makeWedge(angleDegrees = 360, numSteps = 16):
    data = EggData()

    vp = EggVertexPool('fan')
    data.addChild(vp)

    poly = EggPolygon()
    data.addChild(poly)

    v = EggVertex()
    v.setPos(Point3D(0, 0, 0))
    poly.addVertex(vp.addVertex(v))

    angleRadians = deg2Rad(angleDegrees)

    for i in range(numSteps + 1):
        a = angleRadians * i / numSteps
        y = math.sin(a)
        x = math.cos(a)

        v = EggVertex()
        v.setPos(Point3D(x, 0, y))
        poly.addVertex(vp.addVertex(v))

    node = loadEggData(data)
    return NodePath(node)

David

Thanks :slight_smile:

But i though egg data was not included yet in Panda release
(at least the scene editor still raise an error about it)

Hmm, so it isn’t. But you can correct this minor oversight yourself; just run the following command in the Windows command shell:


genPyCode libpandaegg

David

I’ve run the genpycode stuff and now scene editor works perfect.
I’ll try the sample code you provided tonight.

what does exactly the genpycode?
is there some other lib where i could apply it to get more features ( hungry smile)?

genPyCode is the program that generates the Python wrapper classes around the actual C++ classes. Whenever you do something like:


n = NodePath('foo')

you are actually creating two objects: a C++ NodePath object, and a Python NodePath wrapper that redirects all of your Python calls into the C++ object. It’s genPyCode that generates all of the code to define the Python wrappers–basically everything that you bring in when you import pandac.PandaModules.

Normally, genPyCode is run on all of the libraries that Panda3D is compiled with, so that you have all of the C++ objects available in Python. By mistake, we omitted libpandaegg, so you had all of the objects except the ones in the egg library.

So, no, sorry–there’s no other secret libraries you can suddenly gain access to via genPyCode. :slight_smile:

David

Sorry i didnt reply before.
It’ve tested this Works!!!

Working code:

bezier
arc
circle line

Bezier Arc Circle Line working code