Skip to main content

An attempt at 3D - 1.5

My attempt at 3D in PyGame, without using OpenGL. Formerly '3D spinning cube test'.


David
(animatinator)
Just a test of the 3D maths I've been attempting to learn recently, which uses only pygame.draw.aaline() - and circles for drawing the points, but that doesn't really count ;-). I cheated slightly by making it simply project the 3D points onto the XY plane so that they're easily mapped to screen co-ordinates, which means that the camera is fixed, but I'll probably change that when I work out how to :P

Changes

Description

This is my attempt at writing a 3D program using only basic drawing functions (i.e. pygame.draw.aaline(), pygame.draw.polygon()). As mentioned above, it has a fixed camera but the object in view can be rotated by dragging it with the mouse.

New in this release

  • Solid face rendering: Faces are also drawn in the right order, thanks to a hackish method I devised which takes the average distance from the camera of each of the vertices in a face and then orders them by depth. You can switch between solid and wireframe rendering with the Z-key.
  • Multiple objects: Are also drawn in the right order now, using a similar method (but using an average of all the vertices in the object). This could probably be done much more quickly with a better algorithm, but as this is only a test I'll just leave it in.
  • Interactivity: Now you can rotate the shape in the view by dragging it with the mouse!
  • An attempt at lighting: I also included a dodgy algorithm which lights faces based on their distance from the camera. At least, it was supposed to do that; it seems more likely that it's based on whatever mood the Python interpreter's in at the time of running. But it looks okay, so I'll just leave it be for now.
  • Now supports pyramids as well as cubes: A friend of mine added in a pyramid primitive, which can be used in conjuntion with the cubes to make more nifty shapes.
  • A more nifty default shape: The same friend of mine also made a funky robot shape using several cubes and pyramids.

Links

Home Page
http://exesoft.blogspot.com
Source
http://uploader.polorix.net//files/123/3D%20test.zip

Releases

An attempt at 3D 1.0 — 8 Jan, 2009

An attempt at 3D 1.5 — 18 Jan, 2009

Pygame.org account Comments

  • Zeyital 2012-07-08 02:00:42

    It is pretty good. I was hoping it to be a little more real. But I don't think pygame is capable.

  • admin7777 2014-10-05 00:29:49

    The polorix URL is broke/deceased ( http://www.pygame.org/project-... ). On http://www.pygame.org/project-... [which is like some kind of weird duplicate page?], links are ok, but....

    Source at date of comment gave windows 7, 32 bit error ...........
    File "*\An attempt at 3D.py", line 139, in Redraw
    pygame.draw.circle(screen, (255,255,255), (point[0], point[1]), 2)
    TypeError: integer argument expected, got float

    And there is no link for 1.5.

    Cheers