pygame is
Simple DirectMedia Layer is
Site Swing
An attempt at 3D

An attempt at 3D - 1.0

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


Home Page:


click to view original size


An attempt at 3D - 1.5 - Jan 18, 2009
An attempt at 3D - 1.0 - Jan 8, 2009 account Comments

If you wish to leave a comment with your account, please sign in first.

August 15, 2009 2:37pm - David - nickname: (animatinator)
A lot less [fiddly] to install, I mean.
*should check to make certain that he hasn't missed entire words out before posting a comment*
August 15, 2009 2:36pm - David - nickname: (animatinator)
effeeme: Aah, that's clever, thanks :) I didn't think of that at the time.

saluk: Yup, that's the wonky algorithm's fault - it decides on one value for how far away an object is based on the average distance to each of its points, and so any objects that intersect will be drawn incorrectly.

raubana: I've actually been trying OpenGL in C++ recently, and I'd agree that it's definitely faster and quite a bit easier. It's still fun to try writing the rendering stuff yourself though, even if it does end up ridiculously slow and glitchy :P

pywiz32: Thanks :) That idea for the images is pretty much what I would do, although I think it'd be stupidly slow for a high-poly model with several textures. I have a rough idea of how it's done in real 3D engines, but I've never really tried doing it myself - mainly because I probably lack the mathematical calibre ;-).

yanom: I would if I knew how to do things like shadows, texture mapping, rotations about arbitrary points and suchlike; in fact I intend to one of these days. However it would actually be a *lot* slower, mainly because whilst OpenGL is heavily optimised and makes full use of graphics hardware for speedy rendering, my approach is software-based, and written in a scripting language :D
It would be a lot less to install without all the messy OpenGL stuff though.
August 1, 2009 2:57pm - yanom - nickname: (yanom)
are you planning on making a 3d library out of this? it seems like it'd be more efficient in terms of computer rescources because it doesnt require opengl
January 23, 2009 6:46pm - Anonymous - nickname: (pywiz32) - 4/5
WOW! This is really good. Especially for the second release. My guess at doing images: rotate + unfiltered scale.
January 20, 2009 9:09pm - Dylan J. Raub - nickname: (dylanjraub)
Yeah, 3d is hard for me, too. I tried OpenGl for python a long time ago without success, but recently I got help from a couple of executables. It's supper fast and much MUCH easier!
January 19, 2009 1:47pm - patrick mullen - nickname: (saluk)
Sorting doesn't work in all cases, if you rotate in a certain way, the neck is drawn in front of the head.
January 18, 2009 1:05pm - Francesco Mastellone - nickname: (effeemme)
Face lightning, at its simplest, is calculated by multiplying each channel of the color of the face by the result of the dot product between the so called normal vector of the face and a vector of length 1 which defines the direction of the light. You might want to try that out.
January 18, 2009 9:38am - Nathan Woodward - nickname: (thedalailama)
Heh, it looks like the tin man.
January 17, 2009 10:37am - David - nickname: (animatinator)
Thanks for the comments :)
I've now added solid rendering of faces, with a lighting algorithm that doesn't actually work as it's supposed to (but looks okay, so I'm keeping it for now :P ). I'll upload the new .py later, once I've fixed a few bugs :)

@magicaxis: I'm not sure what you mean by missing a word, class Cube() is the class used to create and represent the vertices and edges of the cube.
January 16, 2009 4:07am - Adam Halley-Prinable - nickname: (magicaxis)
(or im an idiot and missed something)
January 16, 2009 4:06am - Adam Halley-Prinable - nickname: (magicaxis)
whats with this?

class Cube():

ur missing a word
January 13, 2009 11:59pm - patrick mullen - nickname: (saluk)
These kinds of experiments sure are fun! Code looks pretty clean.
January 9, 2009 7:19am - Nathan Woodward - nickname: (thedalailama)
Heh, I made one of these about a year ago, yours is much clearer and less dodgy.
January 9, 2009 2:20am - Ian Mallett - nickname: (geometrian)
Pretty neat--reminds me of some code I wrote a while back.

our projects welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
recent releases
Feb 21, 2017

Jan 31, 2017

Jan 24, 2017

Jan 18, 2017

Jan 7, 2017

Dec 30, 2016

Dec 8, 2016

Nov 28, 2016

Nov 27, 2016

... more!
for pygame related questions, comments, and suggestions, please see help (lists, irc)