I rewrote my whole 3D system several times, changed objects definitions, I also used some ideas from the Elite game code and I added some additional improvements to reduce amount of calculations, so the program is shorter and faster. I also made the z=x, z=-x, z=y, z=-y clipping system of 3D lines, but I couldn't make it to compute precisely, so it didn't work well enough after projecting the coordinates to the screen. Moreover, my horizon isn't in the centre of the drawing area, so I had to multiply y and -y by constants like 0.975 etc., so finally I returned to 2D clipping.Joefish wrote: ↑Thu Jul 15, 2021 5:48 pm As for Z-buffers and the like, if you meet the following conditions:
- All your objects rest on the ground
- All your objects are either vertical columns or pyramidal / tapering upward (no overhangs, tunnels or arches)
- The viewpoint can never go below ground level
Then you only need a 1-D height buffer. You draw objects from nearest to furthest, and for each X-position you record the highest pixel drawn. Then for further objects, you only draw the parts of them that appear higher up the screen than what you've already drawn. Sky Ranger does this effect, though it gets it wrong sometimes.
- The view never needs to roll
It's all OK, but I removed the wall filling (erasing) part, because I couldn't make it work correctly when objects were partially behing the camera (z<1), it didn't fill the whole polygon. So distant objects aren't hidden anymore.
So I would like to try the above idea of a 1D height buffer, because Sky Ranger draws the city very fast, so it looks good to me. I understand the basic idea, but I don't know exactly how it works. When I draw edges of an object, how can I know which pixel on an x-position is the highest? Does it mean that when I draw a line, I record the y-position for each pixel of the line during drawing? And then I do the same thing for every other line of the object and during drawing I compare every pixel? And then I draw another object and during drawing lines, for every pixel I decide if I draw the pixel or not? Wouldn't it significantly slow line drawing?