I’m feeling the itch to code, but I think I need to let Good Robot alone right now. If you’ve ever noticed how some people tend to drive faster when they get lost, then you have a good idea of how I feel right now. I feel like there’s something wrong with my game, and I want to HURRY UP AND FIX IT so I can stop worrying about it. But hasty changes aren’t any better than hasty driving. I need to wait for some of the feedback and suggestions to sink in, and until then I can twiddle my thumbs doing something else.
So let’s make a screensaver.
When I was a kid, I was fascinated by infinite tunnels. I used to picture plunging down an infinite circular tunnel as I drifted off to sleep. I’m not sure where this came from. Dr. Who existed back then, but I’m pretty sure I hadn’t seen it yet. Was there some other sci-fi show that used the endless tunnel gag in the opening sequence? Maybe Lost in Space or Twilight Zone? I can’t remember.
Anyway, I want to make one.
So, I open an empty project and use this example to set up the boilerplate code. Windows screensavers are odd creatures. When written in C or C++, you don’t have a
main (). In non-programmer talk, you don’t start with the usual first bit of code common to nearly all c++ programs. Instead, that code is packed in this external library. That library handles creating a window and all the other stuff that’s common to all screensavers. (Like, if there’s any input, the program exits.) You don’t have to worry about window resizing, menus, and a bunch of other stuff. This is a good thing, since it saves you from having to write (or more likely, copy & paste) a couple hundred lines of code. This saves you a lot of work, although it also makes your program about as non-portable as possible.
I start by making a simple straight tube of polygons and having the camera fly down it.
Of course, a straight tube is pretty boring. You can’t even tell you’re moving unless the walls have some texture. But I’m not sure I’m crazy about introducing textures to this. I’m aiming for something a little more abstract. I mean, if I use a texture then I’ll be stuck with bricks or metal or whatever texture I pick. And since I’m doing this for fun I don’t want to trouble myself with the un-fun task of making an interface where the user can choose textures. Yuck.
Hm. I try just coloring the polygons, but it’s still kind of boring. I try adding lighting, and it’s actually even less interesting. The lighting makes the tube look kind of flat and lifeless.
|Not sure what the rectangle is in this shot. I think it’s a leftover from the example code.|
The wireframe is kind of interesting, though. Even making the tunnel twist around doesn’t do much to liven it up. What if I made the wireframe glow? Then I could have the camera flying through glowing rings, which might be kind of fun.
I fiddle with this for a while. I suppose if I was smart I’d have taken more screenshots of the work in progress, but I wasn’t and I didn’t. After about an hour of experimentation and tweaking, I find myself flying through what amounts to a series of glowing hoops.
|At last, a simulation that gives us the view from a croquet ball at a rave.|
I’m not sure I can even re-trace the steps of what might very generously be called logic to get from there to here. It was very much a process of doing random crap just to see what it would look like.
But still. Boring. Endless tunnels are boring. What works for a few seconds in the Dr. Who opening is kind of dull when deprived of titles and names and theme music and Tardises. We need more.
Well, variety would help. Lets have the shape of the tunnel deform as we go.
I’m kind of shocked at how dull the thing looks in stillframe. In motion it’s fast-moving and visually stimulating. Once in a while I catch myself staring during testing, hypnotized by the color and motion.
What we have here is a blend of many, many sine waves. Sine waves govern the lengths of the line segments of the hoops, so sometimes it’s round and sometimes it’s more octagonal or hexagonal. Sine waves govern the height and width of the hoops, so sometimes the passage is tight and sometimes it’s wide but low and sometimes it’s tall but narrow. Three different overlapping sine waves are used to create the side-to-side curves.
For movement: The camera just moves from the center of one hoop to the next. As you proceed, it takes the hoop behind you and places it at the end of the tunnel to give the “infinite tunnel” effect. The camera aims itself at the hoop a few steps ahead, which means it begins turning just slightly before you reach the curve. This seems more natural and less mechanical than just turning in unison with the curves. I’ve also got it banking very slightly, so when you go around a big bend you kind of lean into it a bit. If the above screenshots look sort of comically empty, I’ll defend it by saying it feels better than it looks.
Maybe some vertical hills would be nice? Also, maybe I ought to do something about this rainbow puke color scheme?
|Ah. Now we can puke over motion sickness instead of the color scheme.|
It suddenly feels very roller coaster. So I add some… numbers? To make it go faster downhill and slow down on the uphill. To call this primitive stuff “physics” is like calling a flip-book of Aquaman fan-fiction “cinema”, but in practice it feels about right.
In fact, it feels so much like a roller-coaster that I kind of want to…
|So it’s a roller coaster. Sue me.|
So we set out to make an infinite tunnel and wound up with a roller coaster made of glowsticks. I guess that’s okay. I think we’re done here.
This was just an afternoon project. Sure, there’s a ton of stuff we could do with it from here, but all of that is boring interface and tweaking and I’m bored now. So I guess I’ll just put the source up for others to play with.
That’s the code and project file, which was created using Visual Studio Express 2010. main.cpp is the boilerplate screensaver stuff. gltypes.cpp is my general-purpose toolkit for 3D vector math (the exact same code is in Good Robot) and is ALWAYS under construction. render.cpp is the interesting stuff and if you want to play with the polygons that’s where you’ll want to go.
I’m releasing this under a wtfpl license, which is basically: Do what you like, commercial or free, public or private, educational or stupid. Give credit or don’t. Sell it or don’t. Paypal tips (see donate button, right) are always appreciated if you just really, really find code useful, but I’m not releasing this to get money and I don’t expect it.
If you’re not the coding type, you can get the screensaver itself here:
Just unzip that sucker and throw it in your windows/system32 directory and it should appear in your list of screen savers. Windows only. Sorry. If you want a port, maybe you can bug one of your programmer friends to have a go at the source. Trust me. Your programmer friends LOVE random tasks like porting half-assed windows applications.
Well, that was a quick afternoon lark. Hope it was at least mildly amusing for you.
What is Vulkan?
What is this Vulkan stuff? A graphics engine? A game engine? A new flavor of breakfast cereal? And how is it supposed to make PC games better?
Another PC Golden Age?
Is it real? Is PC gaming returning to its former glory? Sort of. It's complicated.
MMO Population Problems
Computers keep getting more powerful. So why do the population caps for massively multiplayer games stay about the same?
What was the problem with the Playstation 3 hardware and why did Sony build it that way?
The Best of 2014
My picks for what was important, awesome, or worth talking about in 2014.