The OFF.aoff file contains information about the object. The most important one there is the location of the surface specification file (usually object name.geom). This file also contains other attributes - and file names relevant to this object.
The OFF surface specification begins with the number of points, the number of polygons and the number of segments.
For starters, let me just throw in that while our universe may be infinite in all directions, that doesn't make for good programming. We have to limit ourselves to small enough numbers that we can multiply them together without overflowing them, we can divide them without crashing our systems, and we can add them without accidentally flipping a sign bit.
Now, the fun begins. The simplest form of defining the Universe is to flat out say that the Universe stretches over these coordinates, say in the bounding box of <-65536, -65536, -65536> to <65536, 65536, 65536>. This is often referred to as a Universal Coordinate system or an Absolute Coordinate system. Then, each object in the Universe will be centered about some coordinate in that range. This includes your viewpoint. Several strategies are available for dealing with the edge of the Universe. One can make the Universe wrap around so that an object leaving the cube at < X, Y, 65536> will re-appear in the Universe at < X, Y, -65536>. Or, one can make objects bounce or stop at the edge of the Universe. And, given any approach, one can have the edge of the Universe be transparent or opaque.
In an Absolute Coordinate system, all objects must be shown from the position of your viewpoint. This involves lots of interesting math that we'll get into later. But, in general, an objects position with respect to you is it's absolute position - your absolute position (with all kinds of hell breaking loose if you can see past the edge of the Universe). Then, after this position is calculated, it must be rotated based on your orientation in the Universe.
Another possibility for defining space is a Relative Coordinate system or a View-Centered Coordinate system. In this sort of system, the Viewpoint is always at coordinates <0,0,0> and everything else in the Universe is based relatively to this home position. This causes funky math to come into play when dealing with velocities of objects, but... it does wonders for not having to deal with the 'edge of the Universe'. This is the Schroedinger's cat method of the 'edge of the Universe'.... in the truest sense of out of sight is out of mind. Small provisions have to be made if objects aren't to wrap around. But... a Relative Coordinate system can be used to give the illusion of infinite space on a finite machine. (Yes, even your 486/66DX is finite).
I'll leave spherical coordinates to a later version if people think they'll be of use...
In a Relative Coordinate system, position is also fairly straight forward. The view-point always has position VECT={ 0, 0, 0 };. Other objects follow the same sort of system that they would in Absolute Coordinate systems.
But, taking that for granted now.... you have to pick an orientation for your view. I personally prefer to have the X-axis run from left to right across the center of my screen. I also like to have the Y-axis run from the bottom of my screen; and I also like to have the Z-axis running from me straight into my screen. With some tweaking of plus and minus signs and a bit of re-ordering, all of the math here-in can be modified to reflect any orientation of the coordinate system. Some people prefer to have the Y-axis heading into the screen with the Z-axis going vertically. It's all a matter of how you want to define stuff.
Given that you've agreed with me that Z can go into the screen, what 3-angles do you need? (Here's where I stand the biggest chance of mucking up the terms.) You need roll, pitch, and yaw. (I often mix up roll and yaw and such... so if you can follow along without getting locked into my terminology, future FAQ's will correct it.)
Look at your monitor as you're reading this. Now tilt your head so that your right ear is on your right shoulder. This change in orientation is roll (or yaw... but I call it roll).
Ok, now sit up straight again. Now bring your chin down to meet your chest. (Hmmm... LOOK BACK NOW!!!, whew... glad you heard me.) That motion was pitch.
Ok, now look over your right shoulder keeping your head vertical to see who's behind you. (LOOK BACK AGAIN!!.) Ok... that was yaw (or roll, but I call it yaw).
That's the basics. Now, what do I do with them? Well, here's where a nice book on Matrix Arithmetic will help you out. You have to use these three angles to make a Transformation matrix. [See the section on Matrix Math]. Here is a typical method of doing these transformations: [Note, if you don't have Z going into your screen you'll have to munge these considerably].
"There are many ways to do this. Some approaches map the viewing rectangle onto the scene, by shooting rays through each pixel center and assigning color according to the object hit by the ray. Other approaches map the scene onto the viewing rectangle, by drawing each object into the region, keeping track of which object is in front of which.
The mapping mentioned above is also referred to as a 'projection', and the two most popular projections are perspective projection and parallel projection. For example, to do a parallel projection of a scene onto a viewing rectangle, you can just discard the Z coordinate, and 'clip' the objects to the viewing rectangle (discard portions that lie outside the region). To do a perspective projection, dividing each the x and the y by some multiple or the Z-depth is the usual approach.
For details on 3D rendering, the Foley, van Dam, Feiner and Hughes book, reading. Chapter 6 is 'Viewing in 3D', and chapter 15 is 'Visible-Surface Determination'. For more information go to chapter 16 for shading, chapter 19 for clipping, and branch out from there."
The Cross-Product of two vectors is a bit more complex (it is the determinant of the matrix with the direction vector as the first row, the first vector as the second row, and the second vector as the third row):
if X is a matrix that is m rows and n columns (an m-by-n (or mxn) matrix)
and Y is a matrix that is n rows and r columns (nxr), then the product
X * Y ==> m[i][j] = sum{ a=0, a
Some important things to remember about matrix multiplication: (The following assume X and Y and Z are matrices and I is an identity matrix)
The Painter's Algorithm is probably the most intuitive for the beginner, one of the easiest to implement, and the hardest to get right. The Painter's Algorithm, quite simply, is Paint the from back to front. Once it has been determined which polygons will be drawn, it is necessary to sort them from furthest away to closest. Then, starting with the furthest polygon and moving to the closest, draw them.
The tricky part of the Painter's Algorithm is determining when one polygon is closer or farther than another. The closest to satisfactory method I've found uses this criteria -- Surface A is further away then surface B if:
Z-Buffering is a buzzword that's finally come down to reality. It's been replaced by 'texture-mapping' and 'bump-mapping' and 'realtime raytracing' as the 'what's fancy' buzzword. Z-buffering is costly in terms of memory and processing time, but gives beautiful results. If you've got some freedom with your memory usage and a bit of processor time to spare, and you're ok with filling your own polygons, then Z- buffering may be for you.
To Z-buffer, one keeps a 2d-array of numbers (shorts or ints
usually) the same dimensions as the viewport. As each
The expense of Z-Buffering is having to set each element to the MAX Z VALUE after each frame and keeping track of the Z-value for every pixel in the Screen Buffer and every pixel in the polygon you're drawing. In most applications, it is unnecessary to keep track of the Z-values of any more than the vertices of a polygon.
And, my favorite of the bunch (but the nastiest to store in an object file, is BSP-trees. BSP-tree stands for Binary Space Partition tree. They are based the idea that surfaces of most objects don't change positions relative to each other. Objects whose surfaces change relative positions cannot be (to my knowledge) easily used with BSP- trees.
The first step in using BSP-trees is to break up your object into a 'good' object. But, I can't think of a way to describe a 'good' object without just telling you how to make one. So, here's a general algorithm for making a BSP-tree object from ye average object:
Now comes the interesting bit. Now that the object is a 'good' BSP-tree object, it is time for the drawing algorithm. This is fairly straight- forward.
stereograms:
I highly reccomend this book for the person seriously interested in understanding Computer Graphics concepts for 2-D image-generation and 3-D representation. As a warning though, if you're struggling to follow vector math and such, you might not spend the $60-$80 bucks on this one yet.
I've never seen this book. I've got an add for it in front of me. (Sorry, no ISBN number listed). I would guess it's a very low- density version of some of the 3-D things from Foley. The book boasts sample source code on MS/PC-DOS floppy included. "This one is for all graphics enthusiasts who want a detailed look at 3-D graphics and modeling. Also features discussions of popular ray tracinge methods and computer animation." [sic]
I've never seen this one, but it comes net-recommended.