One for the nerds/programmers.

Joined
Feb 27, 2011
Posts
17,323
Likes collected
94,800
Location
UK
Funster No
15,452
MH
Self Build
Exp
Since 2005
In this thread we discussed maths teachers, and it reminded me of my time doing 3D programming using matrices and algebra and having to back to school aged 21/22 to learn the maths I should have learned before.

It took me back to one of my favourite Eureka moments when programming. You know that feeling that olympic gold medalists get when you achieved something.

I think this one may be interesting enough for some of you. (or perhaps not :eek::p)

Back before there were 3D libraries to display 3D objects on screen and animate them for you. You had to draw each individual pixel,

Roughly speaking.
You would first build a pixel plotting routine where you drew to x,y on the screen and set the colour.
Then you would build a line drawing routine that would plot each pixel in a line between two points (x1, y1, x2, y2, colour)
Then you would draw a an enclosed surface, say a triangle or a square known as a polygon.

The bit I am getting so excited about, remember is that on those old computers the speed of the CPU was 7MHz, 3D was heavily mathematically intensive and those CPUs didn't do floating point math only integer.
So if you weren't smart and didn't optimize you would be lucky to draw more than a couple of cubes on screen and animate them.

So we had to do two things. Back face culling (Don't draw things facing away) and hidden surface removal (don't show stuff hidden by other stuff) so you didn't draw the same pixel twice.

Now it is the back face culling that triggered my memory and got me excited again.

A technique I learned back then, remember this was before the internet etc.

Using this cube as an example.

1790014430283.png


When laying out the coordinates of each point of each cubes face we would define them as 4 sets of coordinate which if facing towards us would be in clockwise order.
Once you have defined all 6 faces you could tell whether to draw it or not simply by using a bit of algebra to see if the face was clockwise or anti clockwise. If it was anti clockwise you would cull it from the draw list before it even got close to the screen drawing routines.

This is the algebraic formula.
1790014602190.png


As you can see, it just used subtraction and multiplication which on an integer only CPU was blisteringly fast.

The beauty of this formula is that although it only used 3 coordinate Xa, Ya -> Xc, Yc, it would work on any polygon from a triangle to something with 10+ sides providing the surface was flat and you didn't start it on a concave portion of the polygon.

I am not sure I was clear there so here is something to test it with.

Imagine you are looking at a square. You imagine the coordinates of each point, use a range of say 0 - 5 so 1st is top left (0,0) next is top right is (5,0) bottom right is (5,5) and bottom left is (0,5). If you then flip the square, imagine turning the paper over so you are looking at it from the back (yes we used tracing paper to test some things out) You will see now that if you go from 1st to 2nd to 3rd it is now anti clockwise from the front.

That was it. A very simple technique which in most games cut the number of surfaces you had to consider in half. Meaning the game ran almost twice as fast (not really but close for this example).

And each cull took about 12 lines of machine code/assembly.

Sorry I got excited and wanted to share a cool memory from back in the day of geeking out over maths due to programming.

* If you don't realise how slow 7MHz was. It is 0.007 GHz The current computer I am working on boost to 4.5GHz which is 4,500Mhz which is 642 times fast just in clock cycles. and that was a 16 bit vs my 64 bit, and my current cpu has pipelining, parallel operations multiple cores and on much better silicon. So things were slow and tight back then. which is why the challenge was much more fun back then than today.
 
I don't know if many remember or even care :p But back then filled polygons weren't really a thing. Elite had been out since 1984 and it set the standard for 3D graphics.
Then Cryptoburners came out with a 3D demo with a cracking good sound track in 1990 showing real time 3D graphics with filled polygons.
I believe this inspired the game Hunter which was the first proper open world 3D game back then and got my bosses excited about the possibilities.

Here is a couple of videos from that very exciting time for me.

Fantastic Hunt for 7th October from 1990 with an epic Sound track beginning to end.
To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.


and Hunter
To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.


Remember this is on really old computers which is perhaps not impressive today but all modern 3D games originated with Elite, Hunter and this demo.
It was a race to see how many filled polygons you could get on screen at full 50 fps... Fun times.
 
Heck, this makes my thread crystal clear!

No offence intended.😀
 
I will stick to the simpler stuff .....

Programming my GPS tracker server in BBC Basic.
 

Join us or log in to post a reply.

To join in you must be a member of MotorhomeFun

Join MotorhomeFun

Join us, it quick and easy!

Log in

Already a member? Log in here.

Forum posts reflect the views of individual users and not MotorhomeFun.
MotorhomeFun does not endorse or verify user-generated content.

Back
Top