Cubelor, eater of souls (stereogram generator) Michael Fahmie --DESCRIPTION: First off, what is a stereogram? It's an image which gives a different picture to the right and the left eyes to generate a 3d image. A common way of completing this is by projecting both images onto the same screen and using a filter to block the images selectively. Another form of stereo grams combines the behind the screen leaving what looks to be random pixels until the focus of your eyes falls upon the imaginary screen to which the images were projected. It was in this way that I did my project. Consider the model below. Ex Eyes -------> @____@ _ / \ | / \ | Ez / Sx \ | Screen -> /____________\ - _ / \ | / \ | Nz / Fx \ | /____________________\ - _ / \ | / \ | Iz / Bx \ | /____________________________\ - Ex is the distance between the eyes of the viewer Sx is the width of the screen Fx is the width of the front of the virtual image Bx is the width of the back of the virtual image Ez is the distance from your eyes to the screen Nz is the "null space" the distance from the screen to the front of the image Iz is the "Image space" the distance from the front of the image to the back of the image The only real values in the model above are Ex, Sx, and Ez. Nz, Iz, Fx, and Bx are all virtual amounts. Nz and Iz are user specified, and Fx and Bx can be calculated using simular trianges. Fx = Ex + (Sx-Ex)[(Ez+Nz)/Ez] Bx = Ex + (Sx-Ex)[(Ez+Nz+Iz)/Ez] Images seen on the screen are projections of the virtual image. By drawing a line from each eye through a pixel it will land on the virtual image. Thus you lose the ability to selectively color, since each pixel represents 2 objects. Since color doesnt matter the first thing I did was fill the 2 dimensional array which was made for holding the final color data, with random colors. Starting at the left and moving to the right on Sx, I casted a line from the left eye through the pixel onto the image. Then assuming this color was correct for that object, I drew a line back through the screen to the right eye from the image, changing the color of the pixel that the line intersected with, and locking it to prevent future change. Eyes -------> @____@ _ /| /|\ | //| / | \ | Ez // | / | \ | Screen -> /____________\ - _ / / | | \ | / / /| | \ | Nz / / / | | \ | /____________________\ - _ / // | | \ | / / G | | \ | Iz / IM | | \ | /_______A_E__________________\ - The methods of simular trianges can be employed again here to determine the bases of the trianges created by these lines. Using the base dimensions who can then quite easily solve for the pixel number where Sx is intersected by the right eye's line. @ <----Left eye /| / | /--| /SLx| / | /_____| ILx @ <----Right eye /| / | /--| /SRx| / | /_____| IRx SLx = x -(Sx - Ex) ILx = [(Ez+Nz+Depth)/Ez]*SLx IRx = ILx - Ex SRx = (Ez*IRx)/(Ez + Nz + Depth) where x is equal to the current pixel you are scanning on Sx and Depth is equal to the distance between the front of the image space and the image. Once you have these values you copy the color of the pixel that the left eye line intersects to the pixel that the right eye line intersects, then you set a flag that registers that changed pixel as locked. Moving down Sx always assuming that the image you see with the left eye is correct, and drawing the right eye view to match, you will create a stereogram. --PROBLEMS FACED: Debugging was quite difficult here... I had to stare at the image until I was confident that something went wrong and there was no image. Also rendering a high quality stereogram would take hours... To get around this I hardcoded some images and introduced the "Percision" variable. yeah i know its mispelled now... but i like it anyway. Percision determines basically the resolution of the stereogram. with Percision 1 making it full, Percision 2 = half, Percision 3 = a third, etc. Another small but not insignificant problem was the internet documentation I found. I tried my best to apply it, but ended up doing all the math from scratch. The Internet source did however point me in the right direction with the trapazoid model and the simular triangles strategy. Another fun problem is running the program in high Percision modes, at 1 and most of the time at 2, the program renders the image completely, displays it, and then when you do something like perhaps move the mouse or click on another window, it crashes. This only happens in the high res modes, so i believe the program hogs memory and is often forced out of that memory causing a crash. This problem could have likely been solved by writting to a file instead of memory. --Instructions: Draw out a picture using the program 4 interface. And when you are happy with it click on the black button in the lower left hand corner marked "Stereo Render Image". You should not be in Perspective mode, because the stereo image rendering adds depth to a flat image, the result wouldnt be favoriable. Distance between eyes: Slider from 0 to 400, leftmost being 0 Distance to screen: Slider from 0 to 5000, bottom of all sliders is 0 Distance to image front: slider from 0 to 2000 Depth of imageL slider from 0 to 10000 Percision: can be at values from 1 to 5. This value determines the pixel size, and the subsequent time take. 1 would yeild 1 pixel sized readings and rectangles, 5 would yeild 5 x 5 sized pixels and run over 25 times faster than 1. Guide Marker Width: casts a red strip of variable width so that people are able easily line up the stereo gram. Renders take from a few minutes to a few hours, it is reccomended to do a percision 5 view of a picture to see if things are set right first. Once a picture is rendered you must use a screenshot utility to get the picture, clicking on the render button again will return you to the 3d drawing mode. --Sources: using Yahoo, I found a website that gave techincal discriptions of stereograms, they also provided sample psuedo code. They're theory was good and it was ultimately what i used to do this program, but following the psuedo code was impossible, i had to take their basic principles and start again from scratch. this is the site: http://library.thinkquest.org/2647/misc/stertech.htm --Conclusion I thought stereograms were alot easier, I'm very glad I picked this topic and was able to finish it. Except for one thing Gopalla warned me about... i really really hope one of the graders can see stereograms!