Translate_pixel(X, Y, Z) Webpage

Now that we have each hyperspace texture map pixel mapped somewhere in 3D virtual space, namely at its X, Y and Z coordinate (in inches), we need to figure out where each of those pixels will be viewed by the person watching the animation. To do this we need to project each tunnel pixel into the virtual camera's viewport, i.e. we need to perform a perspective projection. You will remember that the viewport is that little 2"x0.8510638" window that sits in the Z=0" plane, with the virtual camera sitting directly behind it at the X=0", Y=0" and Z=-1" location. To project a pixel to the viewport we need to draw a straight line from the X, Y, Z position of the pixel down to the position of the virtual camera. See the diagram below.

(Diagram)


As long as each pixel is located on the positive side of the Z=0 plane, then the line segment must hit the Z=0 plane somewhere. I must make sure that the starting point for every pixel that I run though this function sits on the positive side of the Z=0 plane. If a pixel is on the negative side of the Z=0 plane or it has a Z depth of less than 0.5 inches, then I will ignore the pixel. Now as the above diagram demonstrates, not every pixel in the hyperspace tunnel has to hit the Z=0 plane inside the viewport. If a pixel hits outside the viewport, then I just ignore it.

If the projection of a pixel hits somewhere within the viewport, then I just convert the floating point X and Y coords of where the pixel intersected the viewport into a row and column numbers that range from 0-799 in the X direction to 0-339 in the Y direction. These row and column numbers specify where each pixel will be seen by the user. The origin for this array of rows and columns is in the upper left corner. These same numbers are used by the Viewport Accumulator array which will be talked about on the next webpage.

3D Transformations

Now, we need to make things a little bit more complicated. One of the things that I want to be able to do is view the hyperspace tunnel in other ways than just straight down it. Maybe we want to move off to one side of the tunnel so that we can watch a starship move past us as it goes down the tunnel. See the picture below for an example of this.

(Diagram)


How do we accomplish this? What we need to do is be able to rotate and translate all the pixels in the hyperspace tunnel to some desired orientation and location when we first create the tunnel. To do this we need to apply a 3D transformation to each pixel location that we plotted above.

A 3D transformation is a 4x4 matrix which is used to transform a location in 3D virtual space to some other location in space. A matrix is a compound quantity composed of numbers arranged as a rectangular array of rows and columns. In computer graphics, matrices usually have four rows of numbers and four columns of numbers hence the name 4x4. The final matrix that translates pixels in the tunnel from one location to another is formed by combining other 4x4 matrices together. Each of these other matrices does one specific operation such as rotating points around the X, Y or Z axis or translating (moving) the points down the X, Y or Z axis. If you carefully construct a series of these matrices, combine them together correctly and then apply them to your model, you can move a model around anywhere in virtual space. Unfortunately, it is beyond the scope of this website to go into all the detail that is necessary for you to understand how 3D transformations work using matrix arithmatic. Any computer graphics book will describe this technique since it is a cornerstone in computer graphics.

For each pixel location that we determined from above, we apply a 3D transformation matrix to that 3D virtual space point, and we get ourselves a new point located somewhere else in 3D virtual space. Then we project that new point into the viewport and figure out which pixel on the resulting image that is. Because we know each pixel's texture map row and column values, we can look up to see what the pixel's color value is. Then we lookup that color value in the CLUT and paint that pixel on the screen in the appropriate color. Doing this for each pixel in the tunnel will allow us to create an image of the tunnel on the viewscreen that the user can then see.

But isn't it possible that more than one pixel in the tunnel will project onto the same pixel on the viewport? Yes, and in fact this situation is extremely likely and if we don't handle it in some way then pixels will just keep writing over previous pixels. Instead of just letting each pixel overwrite previous pixels, it might be better to keep a running total of all the pixels that project down onto each viewport pixel and then average all the pixel colors together at the end to come up with one final averaged color for each pixel. The Viewport Accumulator Array was designed specifically to handle this problem.


Last Updated: May 3, 2002
HTML URL: http://geocities.datacellar.net/~special_effect/ht_translate_pixel.html
E-Mail: special_effect.geo@yahoo.com or click here
1