project-image

Coding History: 3D from Mode7 to DOOM

Created by Eniko

A video series teaching the code behind the early evolution of 3D.

Latest Updates from Our Project:

Reminder for Coding History Backerkit upgrades/addons: cards will be charged in 3 days (March 15)
over 2 years ago – Sat, Mar 12, 2022 at 06:24:03 PM

This is a reminder that if you have upgraded your pledge and/or have added add-ons via Backerkit that your card will be charged 3 days from now on March 15.

Backerkit card charging, episode 1 code complete
over 2 years ago – Tue, Mar 01, 2022 at 05:33:48 PM

Hi everyone! First some logistics for those of you who have added tips or addons via Backerkit. I wasn't aware that I had to manually charge cards, and I know some of you worry about your cards being unexpectedly charged, so here's what I plan to do:

  • Tomorrow (March 1st) I'll lock Backerkit orders with a final notice, this will give anyone 48 hours time to make last minute changes to their order
  • A week and a half later I'll send another Kickstarter update reminding anyone who will be charged that I will be charging cards in a few days so they'll be aware and ready
  • Two weeks later (March 15th) I'll be charging cards for orders locked on March 1st

This should make sure things go smoothly and nobody has any unwelcome surprises.

As for the project, I just finished the main code for the first episode (introduction to 3D basics) yesterday. Here's a gif:

Click the link to see it in full size

(Looks like gifs are still broken on Kickstarter on Firefox, so if you can't see it moving please click on the gif to open the original. Maybe Kickstarter should spend more time on their platform and less on cryptocurrency)

There's four views here, in order from left to right, top to bottom:

1. A simple top-down view as you'd expect from a basic 2D game. The player object rotates and moves through the level.

2. A similar top-down view, but instead of rotating the player, the world rotates around the player, and the way the player faces on the screen stays static. By doing this the information needed to project the geometry in 3D becomes easy: the horizontal distance from the player determines how far left or right from the center of the 3D view a bit of geometry is, while the vertical distance determines the depth of the geometry going into the screen. Those two bits of information are all you need to project points as seen by the player into 3D.

3. This is the same as the previous view but with clipping applied. Because you don't want to see things that are behind the player, any line segment that's fully behind the player (in the dark area) is hidden, and any line segment that crosses the border is split into two parts, one visible, one hidden. With only the visible geometry available, we can project geometry into 3D.

4. Now, knowing the horizontal (left/right) and depth (in/out) distance, it's easy to project points into a 3D perspective. The scale at any given point is 1 divided by depth, so that closer points are bigger while points further away get smaller. To get the x coordinate of the point on screen, just multiply the x distance from view 3 by this scale. The y coordinate on screen is determined by a fixed height in this example, also multiplied by scale. Finally you need to add half the size of the screen's width and height to offset these from the center.

  • depth = ydist
  • scale = 1 / depth
  • xscreen = xdist * scale + screenwidth / 2
  • yscreen = fixedheight * scale + screenheight / 2

Of course the actual video will explain all of this more in-depth (and with a minimum of very simple math), but I figured a short explanation would be interesting.

Also, while tweeting about trying to figure out a good way to explain 2D rotations in this video Freya Holmér came to the rescue and did a very good video on exactly that and you should definitely be checking out that video and her channel!

Unfortunately this is a learning process for me, and one thing I have learned is that I shouldn't write the script before writing the code for an episode. While writing the code I realized there were so many things about the script I would have to change that I might as well start over. At least I'll know for future episodes to do the code first! :D

Another thing that came out of writing the code for this episode is a little library that I'm calling RasterFna. The examples will be built on the FNA library and I realized I needed to be able to do some rastering of shapes like lines, rectangles, circles, ellipses, etc. So I put together a library for FNA that lets you easily do that, and I'll be putting that on Github as its own open source project soon.

Finally, in case anyone's curious: I've not yet made the move to Cyprus because things keep getting in the way, but we've settled on the start of April now as it'll be much easier to fly to where we need to be with our cat. April is when the off-season in Cyprus ends and non-budget airlines start flying there again, and budget airlines are apparently very biased against pets traveling with their owners.

Freya says hi!

Seriously, how can they say no to that face? Anyway, since I haven't moved yet I'm sadly still having near daily migraines from the extreme weather here, which hasn't let up for months now. That has slowed things down, but things should improve on that front in April.

Backerkit surveys have gone out!
almost 3 years ago – Wed, Jan 19, 2022 at 04:53:19 PM

Hi everyone! Just here to let you know that Backerkit surveys have gone out so please check your mailbox for a link to fill those out. I know some of you backed at a lower tier hoping to upgrade/get addons later so you should be able to do that via Backerkit too. Please let me know if there's any issues with the process.

Additionally I know a few people followed the Kickstarter to get updates on late-backer purchase options and there's a store on Backerkit now where you can (should be able to? :D) preorder a late backer pack that includes the tutorial PDF, access to digital episode downloads, prebuilt binaries, wallpapers, and end slate credit.

On the episode front, I've been pretty busy with our big international move but I did do a partial pass of the script for the the 3D basics introduction video. Due to Omicron we had to delay our move by a month as it's just not safe to travel, so I'm hoping to get footage and audio for that episode recorded before we move mid-late February.

Happy holidays / monthly Coding History update
almost 3 years ago – Sun, Dec 26, 2021 at 01:16:45 AM

Hello everyone! We've been very busy with our move, which is why this monthly update is a little on the late side of the month. Unfortunately the weather has been pretty unrelenting in giving me migraines as well, but the good news is that we're moving in one month, so one way or another the migraines are going to stop (Cyprus has extremely stable weather).

I did however get Backerkit set up. I intend to send out what is called a "smoke test" over the week long period between Christmas and New Year's Eve, which sends out Backerkit surveys to about 5% of backers. If nothing burns down in the process (ohhh, that's why they call it a smoke test!) I hope to send the rest out the first week of January.

As for the videos, if the weather chills out over January I should be able to get the script for the first episode written. The place we're moving into at the end of January is furnished, so I should be able to get set up for recording relatively quickly, so if all goes well the first video will hopefully come out late February/early March, but I'll of course keep y'all updated.

I hope you all have a happy and safe holiday period, and may 2022 be a better year than 2021 was.

Backerkit/backer survey update
about 3 years ago – Fri, Nov 19, 2021 at 03:59:54 PM

Hi everyone, it's monthly update time!

Sadly, due to health reasons I haven't made a lot of progress this month. Where I live has decided to flip rapidly between summer and winter, bypassing fall entirely, until it finally (mostly) settled on winter. What this means is that the past month I've had weather-induced migraines on an almost daily basis and so haven't been able to do a whole lot of work.

Needless to say this kind of thing is a big part of why we're moving soon.

I did however manage to get most of the way through setting up Backerkit. What this means is that surveys will start going out in the next couple weeks and you can record your details for crediting and shipping, if you're one of the backers who will be receiving a postcard. I'll of course post an update here when surveys go out so you won't miss them.