30 Jul

Helium pitch-shifter

Would this work?

pitchshifter.png

Maybe the tank needs to be upright and filled with helium and some other gas half and half, so there’s a difference in gas density, which compresses the sound waves making the pitch higher. Like this:

pitch2.png

Of course, some other gases could be used for different effects. I think using a combination that would make the pitch lower would result in clean shifting, a situation where there tends to be a lot of phasing. Then again the acoustics of the tank would have to be perfect. But let me think I invented something really clever at least for a while, OK?

20 Jul

Stuff I’d like to see in every user interface

Here’s something that I think would be very nice to have as a standard feature in all user interfaces. I don’t know how much of it has been already implemented in various interfaces out there but I have tried to add an example if I know of any.

Common UI stuff

  • Universal search. You should be able to search any dialog with a lot of text. I use this feature a lot on web interfaces, thanks to the search feature in any web browser. You almost never use every bit of information in a dialog, so this speeds things up a lot.

    There should be an search function that looked into all the menus and dialogs and told you where that elusive checkbox is. E.g. in a web browser you would type in “Accept cookies” and it would tell you it is in Tools>Options>Privacy.

    Google’s, Yahoo’s and other developers’ desktop searches are a step in this direction but they don’t offer that much new. Google Desktop does have a very handy search dialog (double click the Ctrl-key and the search box is summoned – priceless). However, none of the desktop search software I have seen ever is both nice to use and feature rich. Google’s software surprisingly is much worse to use than the web search when you do anything more complex than just check where a file is (and you know its exact filename).

  • Fuzziness. Everything involving user input should have an amount of fuzziness built-in. People make mistakes, computers don’t. Which results in when a computer uses data from a user, it is only as good as the user.

    For example, that search feature I rambled about above could return the exact result and then a list of items that contain the word “cookie” or a synonym to “accept”. That way the dialog box could have the text “Allow cookies” and it still would be in the search results. You have seen this in action when using Google or a word processor with spell checking (they tend to suggest proper spelling and other near matches).

    The user shouldn’t ever have to put in exact dates, sizes or types. Nor should the program treat dates as absolute values. E.g. when searching for a file created two weeks ago, the program should find also files that were created three weeks ago (in case you remember the date wrong), especially if there weren’t any files created two weeks ago.

    I have to add this does not necessarily make things less accurate. You would still have the best matches first or that the software would only use fuzziness when it can’t find anything with the exact information. And when deleting files or doing something as critical, it would never delete files it thinks are sufficiently similar, obviously.

GUI stuff

  • Pie menus. These should replace the now common hierarchial context menu, they tend to grow very annoying to browse through. It’s because a normal menu usually closes when you move the mouse outside the menu, this means the screen has something like 90% worth of area that closes the menu. A pie menu usually needs a click on the center to close the menu, which is something like 10% of the area. Also, a pie menu is faster to use thanks to muscle memory (you generally select things by the direction, not by the amount of rows you have to move up or down).

    Even though I have played enough video games to have some hand-eye coordination, it is tiresome to use that skill for opening a simple menu (as a side note: The Sims has pie menus which leads me into thinking most people would like to have those outside the game, too).

  • Zoom. You should be able to zoom in and out everything. This includes even text-only information. Imagine how nice it would be to zoom the desktop out to see every window at once. Or, to browse a huge list when you first zoom it 50% out, so that you effectively have twice the amount of information on the screen at once (which doesn’t really slow down skimming). This is easy now that practically every home computer has 3D-acceleration (and enough CPU power too, for rendering vector text on the fly etc.).

    You can see something like this in the beginning of this video. And it really doesn’t even have to be that elaborate. I actually have experimented with this myself in my image viewer, if you mind a little plug.

  • In all, I think most GUI designers should play more games. Video games rely on fast and accurate action and extremely usable interfaces; I think video games are the kind of software that receive most of the criticism when it comes to crappy user interface. While games are about leisure and competition and other software usually isn’t, it doesn’t mean all other software should be clumsy to use and not designed for minimal interface friction.
  • Temporal data on buttons. Buttons should have for example a slight color change if you have clicked it recently. Web browsers do this to visited links. I often have a bunch of console windows open and on the taskbar and in the Alt+Tab menu they all look the same. If they were colored according to the time they have been open or so, I could immediately see in which one I was just working.

    The Windows Start menu does something like this but it’s quite annoying because it hides all items that weren’t just used (it’s very annoying to use otherwise, too – see the rant about pie menus above).

Misc. features

  • Non-permanent pause. A pause feature should have some kind of optional time limit. I often click “pause all” on µtorrent when I want to watch a streaming video or so, and then forget to resume the downloads after I don’t need the extra bandwidth. There should be a “pause for 15 minutes” style option. Google Desktop has this feature and I think it’s very nicely thought considering you want to continue the indexing ASAP.
17 Jul

Nanopond Screensaver

[This is an archive post from my old homepage]

For those who don’t know what Nanopond is: Adam Ierymenko’s Nanopond a minimal (absolutely tiny) artificial life system based on randomly mutating and evolving computer programs that eventually get more and more efficient in copying their program thanks to natural selection. While it does not have as diverse dynamic as Ray’s Tierra but it is more interesting to look at.

See a time-lapse video of evolution in action:

This screensaver is a quick hack of Nanopond that allows it’s use as a Windows screensaver. Does not support passwords or anything fancy but it saves the pond when the saver exits. Delete nanopond.1 in the Windows directory to start over.

The pond size (and the screen resolution) is the standard 640×480, but the pond depth has been set to 64 to minimize the pond state file size (with the default settings it’s around 80 megabytes, now around 20 MB).

Download – Binaries and the source code. Extract nanopond.scr (optimized for Pentium MMX) or nanopond_athlonxp.scr (optimized for AMD Athlon XP) in your Windows directory. You need the SDL libraries.

11 Jul

Hardware-accelerated 2D collision detection in OpenGL

NB: Here is a better post about the below algorithm. Includes source code.

The idea

Did you know you can do pixel accurate collision detection using the OpenGL stencil buffer and occlusion queries? I got this idea while working on a 2D/3D game engine (think of a side-scroller but with 3D objects).

The idea is actually very similar to how you do collision checking on most 8-bit computers and consoles: when drawing the sprites on screen, the graphics chip automatically keeps track if it drew a pixel on something that was already there. OpenGL doesn’t do that by default (especially because this is not a 3D method) but we can fake it. This is how I do it:

  1. Each model has it’s bounding box which is translated and rotated with the object

  2. Each potential collision between two objects is checked:

    1. Project each corner of the bounding box on the screen plane (gluProject()). You can project all the object vertices if you want more accuracy

    2. Get the smallest rectangle that fits around the projected points

    3. Using this rectangle check if the objects are anywhere near each other, i.e. check if the rectangles overlap. If the rectangles do overlap:

      1. Use the first object to draw a stencil shape (i.e. use the same drawing code you use to draw the object on the screen but enable GL_STENCIL_TEST and put the stencil function in the GL_ALWAYS mode). You need to clear the stencil buffer, I do this with the scissor area set so I clear just the needed area.

      2. Use the second object to do an occlusion query using the stencil – draw only if the stencil is set (again, reuse the code for drawing the object in general but enable stencil test and start the occlusion query before drawing).

      3. The objects collide if there are any pixels drawn, i.e. the objects shared some pixels and the query returns a non-zero value

  3. Draw the scene, next frame etc.

(Text on yellow is what I’m talking about here)

Discussion and improvements


Now, this isn’t exactly a fast technique and you probably will have good results with normal multiple bounding box/rectangle checking even if that isn’t as accurate as this method. However, this should work with anything you can draw on the screen with OpenGL, including alpha textures (i.e. 2D sprites) and you don’t need to keep track of any extra bounding boxes.

One thing I like is that you automatically get a bit more sophisticated collision checking: even if this method is inherently 2D, you can use the far and near clipping planes to make the objects not collide if an object is actually behind another object. If you use perspective, you can stop the player colliding with a floor that stretches to infinity (which of course when projected in 2D only goes from the bottom of the screen to the middle of the screen) – just draw the part of the floor that is at the same the depth as the player.

You can also optimize this a lot. In my case, I get more speed using the rectangle check above and limiting collisions (e.g. no check between two enemies, checking only player and landscape collisions, testing only the rectangle if it is a static square tile etc.). I also don’t draw the stencil every time I check an object pair and obviously cache rects if the orientation of the object doesn’t change much.

Not much examples here but you should get this working in a few days by just googling for occlusion queries, stencil buffer and OpenGL (assuming you already do know how to draw stuff on screen and realize how the object translation and rotation works etc.). There are a ton of tutorials on the Net about drawing reflections and whatnot using stencil, which is precisely what we do here, only that we don’t show the reflection and only count the pixels.

Links