Nambafa
Graphics tutorials
Downloads: TUT20.zip
╒═══════════════════════════════╕ │ W E L C O M E │ │ To the VGA Trainer Program │ │ │ By │ │ │ DENTHOR of ASPHYXIA │ │ │ ╘═══════════════════════════════╛ │ │ ────────────────────────────────┘ │ ────────────────────────────────┘ --==[ PART 20 ]==-- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ■ Contents - Introduction - Face Sorting =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ■ Introduction Hi all! It has been a _long_ time since my last trainer (as I am sure many of you have noticed) A lot has happened between now and the last trainer... but for once I won't bore you with the details ;) I do have a full time job though, coding C++ applications. I have taken over the production of the PCGPE from Mark Feldman. He is mailing all the articles written so far, and as soon as I get them I will get to work on releasing the PCGPE II. Mark is working on the Windows GPE. This trainer is on 3d hidden face removal and face sorting. I was going to add shading, but that can wait until a later trainer. For conveniance I will build on the 3d code from tut 16(?). The maths for face removal is a bit tricky, but just think back to your old High School trig classes. I have noticed that in my absence, one or two people have started their own trainer series. Read Hornet DemoNews for a great column by Trixter covering some of the more tricky demo effects. Well, on with the trainer! If you would like to contact me, or the team, there are many ways you can do it : 1) Write a message to Grant Smith/Denthor/Asphyxia in private mail on the ASPHYXIA BBS. 2) Write to : Grant Smith P.O.Box 270 Kloof 3640 Natal South Africa 3) Call me (Grant Smith) at (031) 73 2129 (leave a message if you call during varsity). Call +27-31-73-2129 if you call from outside South Africa. (It's YOUR phone bill ;-)) 4) Write to denthor@beastie.cs.und.ac.za in E-Mail. 5) Write to asphyxia@beastie.cs.und.ac.za to get to all of us at once. NB : If you are a representative of a company or BBS, and want ASPHYXIA to do you a demo, leave mail to me; we can discuss it. NNB : If you have done/attempted a demo, SEND IT TO ME! We are feeling quite lonely and want to meet/help out/exchange code with other demo groups. What do you have to lose? Leave a message here and we can work out how to transfer it. We really want to hear from you! http://goth.vironix.co.za/~denthor (WWW) ftp.eng.ufl.edu pub/msdos/demos/code/graph/tutor (FTP) =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ■ Face Sorting There are many ways to sort faces in a 3d object. For now, I will show you just about the easiest one of the lot. Say you have to polygons.... ------P1 ------------------P2 Eye As you can see, P1 has to be drawn before P2. The easiest way to do this is as follows: On startup, find the mid point of each of the polys, through the easy equations, x = (P2.1.x + P2.2.x + P2.3.x + p2.4.x)/4 y = (P2.1.y + P2.2.y + P2.3.y + p2.4.y)/4 z = (P2.1.z + P2.2.z + P2.3.z + p2.4.z)/4 NOTE : For a triangle you would obviously only use three points and divide by three. Anyway, now you have the X,Y,Z of the midpoint of the polygon. You can then rotate this point with the others. When it comes time to draw, you can compare the resulting Z of the midpoint, sort all of the Z items, and then draw them from back to front. In the sample program I use a simple bubble sort... basically, I check the first two values against each other, and swap them if the first is bigger then the second. I continue doing this to all the numbers until I run through the entire list without swapping once. Bubble sorts are standard seven computer science topics... perhaps borrow a text book to find out more about them and other (better) sorting methods. The above isn't perfect, but it should work 90Downloads: TUT20.zip