> 4D Blocks

> Version 6

  Block Motion
  Scene Language
  Kinds of Blocks
> History


Ever since I wrote the 4D Maze Game, I've thought that the maze world was too static, that to really understand 4D you needed to be able to interact with the world. And, what better way to interact with the world than to play with toy blocks? That's how children learn about 3D, so maybe that could be how we learn about 4D as well.

The idea was clear, but there were two big difficulties. First, clipping is hard. (By "clipping" I mean removing the parts of objects that can't be seen because they're obstructed by other objects.) I'd managed to hack something together for the maze game, but it only worked for interior spaces. Second, physics is hard. Think about all the ways that two blocks can collide in 3D; in 4D it's even more complicated. So, because of those difficulties, I didn't do anything.

Recently, though, I got into a discussion with Ben Blohowiak, who was also thinking about 4D, and when I was explaining the blocks idea, I really wanted to have something I could point to and say, like this, only with clipping and physics. Then I realized it wouldn't be hard to write the stupidest possible block simulator, and I went ahead and did it. That was version 1.

Once I had that, the lack of clipping really bothered me, so I did some reading and gave it a lot of thought, and managed to come up with a reasonable way to do it. The key is, it's pretty easy to clip lines against polygons, and since in the end all I'm drawing is lines, that does it. Also I found an ugly but effective way to tell whether one block is in front of another. That was version 2.

I still have no idea how to do real physics, but I think it wouldn't be too hard to do some fake physics and let the blocks slide around and rotate. So, probably that's next!

* * *

In fact, what happened was that I did one simple animation test with a block sliding off to infinity, and then I became obsessed with the idea of making model trains. The whole thing was completely clear right from the start, I just had to sit down and do it. There were some small technical challenges but no conceptual ones.

Once the train coding was mostly done, I started putting together some files with examples, and that opened up a whole 'nother can of worms. It turned out that there were a lot of interesting geometric examples that I could have built even using version 2 (plus the rotate command). So, I spent a bunch of time on that too.

Back when I was working on the maze game, I thought I was starting to have some intuition about 4D, but now from the geometric examples I can see that I still have a long way to go. I do think the idea of having a fixed vertical direction is very promising, though.

Anyway, now all the work seems to have reached a more or less closed and self-consistent state, and I'm not sure what's next. The idea I'm most excited about is adding ramps, bridges, and trestles to the train sets. I know how to do it, but it'll be easier if I wait until I've reworked the graphics engine, which is something else I want to do later on. I guess we'll see what happens.

* * *

After I finished version 3, I took a day off, and then I started messing with the code again, and basically haven't stopped until now (version 4).

First I added fisheye mode and did a bunch of experiments with scenery.

I was excited about elevated trains, but not at all excited about reworking the graphics engine, so I went ahead with the stupidest possible implementation of elevated trains, and to my happy surprise it worked. At every step there was an obvious next step, and gradually the implementation became less and less stupid, until now it's beautiful.

I spent an inordinate amount of time on the platforms and ramps, adding all kinds of different styles and options and making them appear automatically. The end result is deceptively simple.

The trains remind me of a lot of things from my childhood. We did have some real model trains (mostly N gauge). We also had a set of wooden trains that had a nice figure-eight track with a bridge in the middle. Oh, and there were some plastic trains with an abundance of reddish-purple track; those were great. We had some Hot Wheels track that was bright orange with magenta connectors; I have to admit that that's part of why the track in the game is orange by default. We had some electric racecars with a track made of big black plastic pieces that were a royal pain to snap together. I guess there's just something extremely satisfying about tracks with modular parts.

Anyway, after I finished all the elevated train work (except for the 4D rounded style), I moved on to block motion. I'd been thinking about it in the background the whole time and had a pretty good idea how I wanted to handle it, but it was still a surprise when it went exactly as planned. It was also a lot more fun to move blocks around than I had ever imagined!

This has been a really fun project to work on. There have been a few slow moments, but mostly it's been one interesting problem after another, with a good mix of math and programming problems.