Pygame 3D wireframe viewer

I've been thinking about moving some of my simulations into the third (spatial) dimension for a while now. Actually creating a 3D simulation is relatively easy, it's just a matter of giving each point in space an additional coordinate. The difficulty is visualising the simulation. There's no easy way to transfer a 3D simulation to a 2D screen (or our 2D retinas). Clearly, there are, however, ways to represent 3D objects on a 2D screen, it just requires a quite a lot of calculations. But having spent a fair amout of time using trigonometry for my particle simulation, I thought I might at least give it a go.

Although it would probably make more sense to learn how to use software specific designed for 3D graphics, I'd rather stick with Pygame and attempt to learn (or even derive) the fundamentals of 3D graphical display for myself. Pygame may well turn out to be too slow to deal with 3D graphics (especially using algorithms I've written, which are likely to be far from optimum), but I'd like to see how far I can get. It might also be a good opportunity to learn how to use the GPU, which would take care of some of the speed issues.

I've started to write a tutorial here.

Below is a video demonstrating a simple program I wrote to view a wireframe stored as a .obj file. The video shows a classic wireframe teapot rotating three axes, one after another. The poor quality is a result of converting the video to an AVI for YouTube rather than an issue with my program.

Comments

Wow, I'd be really interested to know more about this, I'd like to have an understanding of how 3d "works", at a low level. This series helped with some of my questions but half the applets no longer seem to work. I think Pygame might be a better platform for understanding these 3d basics.

Thanks for your enthusiasm. I've started to get a grip with the basics and it seems to work well with Pygame. I'll try to write something about it soon. That link looks very handy.

I might also see what I can do with the HTML5 canvas, which would allow me to put examples people can play with on my website.

Hey Peter

I don't know if it's the direction you want to go, but Burster plugin for blender might give you some good ideas. If you don't know Blender it's an open source 3D program and can be displayed interactively in a browser  using Burster plugin. It looks like early days but opens a lot of opportunity for the future.

Peter Grayson

 

Thanks for the tip. I downloaded Blender just a few weeks ago and have been slowly working out how to use it so I'll have look at the Burster plugin.

Post new comment

The content of this field is kept private and will not be shown publicly.