Journals

froghair10 years ago2013-12-04 03:42:13 UTC 14 comments
With coding, I have always been uncomfortable with abstraction, meaning letting the computer do the work for me without really understanding whats going on under the hood. Sure I can tell the computer to draw a cube at such and such coordinates, but how did it know HOW to draw the cube, and how the hell did it project this 3D object onto my flat 2D monitor?

Mappers need not concern themselves with such things, as the beauty of their work is dependent on the landscape, not the raw understanding. But someone looking to modify the game behavior will quickly find themselves lost in a world of vectors and quaternions.

Since playing (and mapping) DukeNukem3D (I was very young) I have been plagued by my lack of understanding of the 3D world. Half-Life made it all the worse. It wasn't until this year while day-dreaming during class that a thought struck me that a 3D object could be projected onto a 2D surface (in our case, the computer screen) by drawing lines from every corner of the object to the perspective point. A plane would sit in front of the perspective point, and where the lines intersected the plane would correspond to the pixel that corner would occupy on the screen.
User posted image
Each corner would know what other corners it was attached to, so lines could be drawn after the projection.

To see if this would work, it seemed easiest to go ahead and choose corner coordinates forward of the XZ plane, and derive parametric equations using the XZ plane as the plane of intersection, with the perspective point being slightly behind it (in the negative Y section). This led to the equations:
User posted image
Where the X, Y, Z coordinates of the perspective point are P1, P2, P3
and the X, Y, Z coordinates of the corner being projected is V1, V2, V3
(After testing, this only works directly behind the origin. Y is the only coordinate the axis the perspective can move along without distorting the object)

Following this, I used the Arduino Development Board in conjunction with the TVout library to create a 3D cube on my old TV (Inspired by the rotating cube that came with the TVout library sample).
User posted image
Its not pretty, its not that impressive, but how can I understand goldsrc if I can't even make a cube from scratch?

3D graphics are really taken for granted these days, and I admit that goldsrc is not the prettiest to look at compared to modern engines. But goldsrc is extremely beautiful and innovative, and perhaps its not until you attempt to write 3D from scratch that you are able to realize that.