Monday, December 4, 2023

Procedural Clocks, Digital and Analog

I want to make 3DWorld's procedural buildings more dynamic and less static. Some of the rooms, in particular in the basements, are often devoid of movement. People and zombies are less common here. One idea I had was to put clocks on the walls, starting with basement swimming pool rooms. I couldn't decide if I wanted to add digital or analog clocks, so I implemented both. These clocks will display the current system time on the user's computer to the nearest second. Today's post will be relatively short.

The best place to put a clock is probably on the center of the wall at one of the long ends of the room. The issue is that the center of the wall often has a door. My fix was to increase the ceiling height in some of these larger pool rooms to make space for placing a clock above the door. The ceilings can be raised any amount up to a floor's height, but limited by the terrain and other buildings above that room. You'll find these taller pool rooms are more common with office buildings because they tend to have deeper basements with more overhead space.

Analog clocks were easier to create. I used a standard clock face texture for the numbers, drawn onto the end of a horizontal cylinder that was placed on the wall. The clock has an hour hand, a minute hand, and a second hand. All three are created from a five vertex polygon with a point at the end. They rotate about the center of the clock in realtime, where each hand moves once a second on the frame where the second transitions to the next one. I decided I preferred the one second increments of the second hand rather than continuous motion. It was more efficient as well, since I only had to update the vertex data once a second rather than once a frame (which is often > 60 per second).

Analog clock above the door on a pool room wall.

Should I add a ticking sound, or would that be too annoying for the player? Just kidding, of course I added a ticking sound. It's not present in the video below, but it's now active when the player is near a clock.

Digital clocks were more difficult. I wanted to make them with the old style of red LED seven segment displays. Should I also add green clocks? I'm not sure. This brought back memories of my time working with these displays in my electronics projects when I was younger. I had to look up one of those projects online to find the tables to map digits from 0-9 to display segments. The code ended up being long enough that I put it in its own source code file. The first table I found online was wrong and produced an incorrect "9" digit. Sigh.

I added a total of six digits (a pair for hours, minutes, and seconds) and two colons. Digital clocks typically don't display seconds, but I wanted the update rate to be more frequent than once a minute.

Digital clock on a pool room wall showing time in HH:MM:SS.

It would be a shame if the player never entered a basement swimming pool room to see my clock artwork. So I added them to office building first floor lobbies as well, on the back walls of the stairs. Now they're difficult to miss. It will also be easier for me to keep track of time and avoid staying up too late working on this project!

Digital clock on the back of the stairs in an office building lobby.

Here's a video of the clocks moving/updating. I don't have the ticking sound enabled here since I went back and added it after writing 90% of this post.


That was pretty fun. I need to find more dynamic objects that I can add. Maybe I should make rooftop signs using seven segment displays. The only problem is that you can't create all of the letters with the limited number of segments. For example, you can't create a 'K', 'M', 'R', or 'W' with only 7 segments. I think it would require at least 15 segments for all numbers, uppercase, and lowercase letters. That would be a much larger table and significantly more effort.

3 comments:

  1. Since analog clocks tick, maybe the digital ones can have a nice 60Hz hum. Speaking of which, the street transformers, security rooms, and breaker rooms could hum as well.

    As far as dynamic objects, have you considered lava lamps? Maybe potted plants and curtains gently swaying in the breeze of the HVAC system? Fish tanks? Pole dancers?

    ReplyDelete
    Replies
    1. I can experiment with 60hz hum to see if it's too annoying to add. Maybe I can have it fade out and only be present when the player is very close to an object. For example, when the player is "flying" near a power transformer but not when on the ground. I'll have to experiment with it.

      Lava lamps could probably be done with a custom shader. The procedurally generated plants I started with already have leaf animation, but it's disabled when indoors. I think it would be interesting to enable it when a nearby door is opened/closed or when the player walks by. I don't know how to animate the 3D model plants such as the ones you created. Curtains seem more difficult because they would require some sort of cloth simulation and custom dynamic vertex data. Fish tanks - maybe, though I expect it would be a lot of work. It sounds like fun though.

      Delete
    2. I added a hum sound to power line transformers, server rooms, utility rooms, open breaker panels, ceiling fans, and elevators. I couldn't get a 60Hz sound to play though. Maybe my speakers or audio system filter it out? So I used something more like 100Hz, but varied it a bit for different sources.

      Plant movement seems too expensive. I did add lava lamps and fish tanks. Currently, the lava lamps don't have any moving liquid. I need to draw it with a custom shader. Fish tanks don't yet have fish.

      Delete