GP2X Suggestions For Pygame Code Problem...


dodgyville

Member
Joined
Oct 15, 2005
Messages
176
Location
Melbourne
Website
Visit site
Hi everyone,

I have a pretty special pygame game almost complete. However, I am stumped by one part. I need some 3D drawing routines for pygame.

I have my list of polygons I wish to draw, and x,y,z location and roll,pitch,yaw information for both the object and the camera. What I really need is a "draw_polygons" def. Speed is not important, but ease of use might be.

Ideally:

draw_polygons(surf, cameraInfo, objectPolygons, objectInfo)


It's a port of a well known game. :)

Luke
 
Well you can use pygame.draw.polygon repeatedly, but that may be not be very fast if there are lots of polys to draw.

Plus, you'll have to do the perspective transforms yourself.

Edit: you know, x' = (x * C) / z, y' = (y * C) / z, all that. Don't know how pitch, roll and yaw factor into those though.
 
I don't really believe in handing out fully functional source code to answer a question. Also I would need to know what your data looks like, what your using for up/front/side, besides I don't have time to figure out/write/test/debug this right now. So here is a link and a tip:

Wikipedia article

I would use pygame.draw.polygon but I would lock the surface before doing anything, draw all my polygons, then unlock.
Code:
def pdrawer(myNiftyTriangleData, mySurface):
    mySurface.lock()
    rects = []
    for triangle in myNiftyTriangleData:
        # This is the bit I don't want to figure out
        rect = drawTriangle(triangle, mySurface) # I suggest you don't use a function call here
        rects.append(rect)
    mySurface.unlock()
    return rects
 
Back
Top