July 29, 2008

A Trackball Camera for Pyglet

A week or so ago, I needed to write a simple OpenGL demonstration program. I decided to use pyglet since it is such a great utility. Of course, it is always nice to be able to move around your demo, so I looked for a "trackball" to control the camera. But, I came up empty.

So, to scratch that itch, I remembered & found the old GLUT example code in trackball.c and ported it to python. It wasn't that hard to do, but looking at how the code worked it brought back that in 1993 every cycle certainly counted. I refactored it significantly.

I also pushed the manipulation of the GL_MODELVIEW matrix into this class. It seemed a nice way to separate the code and make it into a proper camera. Anyway, a short while later and out popped my code and you can get it by going to

To use it, there are just a few public entrypoints.

Initialize the camera with a radius from the center/focus point:

tbcam = TrackballCamera(5.0)

After adjusting your projection matrix, set the modelview matrix.


On each primary mouse click, scale the x & y to [-1,1] and call:

tbcam.mouse_roll(x,y,False) # the final flag indicates this is a 'click' not a 'drag'

On each primary mouse drag:


Mouse movements adjust the modelview projection matrix directly.

There is also a routine for mouse_zoom(x,y)

I hope you can find this useful.

May 25, 2008


I few months ago, I wrote a simple commandline utility demonstrating how to use the WiiRemote Framework to connect to the Wii controller and capture events. Inspired and enabled by the darwiin-remote project. I just wanted something simpler to use as a starting point for my own projects.

This code is written using (and includes) the svn repository WiiRemote Framework 0.6 code.

Output is sent to stdout for all wii remote messages. Output to stderr for all other "informative" messages. This allows for easy use of unix pipes.

How to:

Build using xcode. Open a Terminal, type (without quotes)
  cd [where you put wii2stdout]
then follow the instructions. When the wii remote is connected, you will see lots of accelerator events.

Press the "home" button to exit wii2stdout cleanly.

If you use it, drop me a line & let me know. Grab the code here: http://www.rogerandwendy.com/roger/code/wii2stdout-2008.05.25.tar.gz

Music/Midi & Mac Update

A comment on my earlier post reminded me that I should publish my latest Midi code.

I've updated my code a bit in the (gasp) 3 1/2 years since I posted that original code. In the meantime, I've taken to using a client/server model. It turns out that GarageBand doesn't seem to take kindly to a midi connection appearing and disappearing often. So, the server is started once per session and keeps the midi connection alive. The client connects over a socket to the server and translates from text input to a simple protocol. The client can appear & disappear without affecting GarageBand.

As a disclaimer, this is not my prettiest code--it basically works but is not all that robust. Get the code at http://rogerandwendy.com/roger/mac/mtl-2008.05.24.tar.gz

If you use it for anything, drop me a line or a comment to let me know.