The Beeb Bodybuilding Course Part 117 By Mike Cook Twin Peeps One of the great driving forces behind my love of computing is my curiosity, I want to know what an idea will look like when itÕs realised; the other great driving force is my bank manager! Well when I had the idea for this monthÕs project I just had to complete it because I wanted to see what it looked like. Whilst I could see that the idea would work I really had no idea how good it would be. It all came about when the editor was telling me about 3D glasses and accompanying software. This set me thinking about producing a related hardware project; one that would not only give you a stereoscopic 3D view but allow you to see 3D in full colour. The human vision system is a complex arrangement but the basic requirement for stereoscopic vision and depth perception is that each eye is presented with a different view. There are other requirements as well, those views have to be consistent with expectations but I will go into that later. When we use coloured glasses each eye receives only the colour selected by the filters, however, there are other methods that can be used to separate out the images. In the cinema you can use polarised light to project two different images onto the screen. Each eye view has a different angle of polarisation and these are separated by polarised glasses. As no coloured filters are involved you get the effect in full colour. Some years ago a games console had an accessory that allowed stereoscopic 3D vision. It was a pair of glasses made from a liquid crystal compound. The lenses could be made to go opaque when a voltage was applied to them. By alternating the voltage every frame scan you could feed a different image into each eye. The problem with these glasses was that they were not very good as the level of opacity that could be achieved was quite poor. Good versions of these glasses do exist but cost well over £1500! Now with that as a background I came up with the idea of separating the images on the screen using a rotating shutter. The idea itself is quite simple, the left eye view and the right eye view are flashed alternatively on the screen. The screen is looked at through a pair of shutters that alternatively cover and open over each eye in turn. In that way each eye receives a different image. My first thoughts on how to make the shutter was to have a motor turning a disc with holes cut out of it. These should be arranged so that you would look through the disc and see through only one eye at any time. However, when I made such an arrangement it became clear it would not work. There were two snags, first of all my eyes were not far enough apart to see through each side of the disc at the same time, this could have been solved by an arrangement of mirrors if it hadnÕt been for the second problem. This was that fact that the computer screen draws its picture from top to bottom. Now this is fine for the hole in the disc moving from top to bottom but the other eye has the hole moving in the opposite direction. As this is in the opposite direction from the computerÕs scan it simply did not work. This was how I discovered that the shutters for each eye had to be moving in the same direction as the displayÕs scan. Now this either involved some complex arrangement of gears and pulleys, or using two motors. As you can see, I opted for the latter and so my Twin Peeps machine was born. This arrangement has also been dubbed The Twin Windmills or ÒThe Nose TrimmerÓ (!) by some of my colleagues. The basic arrangement is shown in Figure I, it consists of two motors each with a five blade light chopper. The idea is that you look at your computer display through the space at the point between the line joining the two motors centres. The blades ensure that only one eye at a time will see the screen. Of course for this to work the motors have to be turning at exactly the same speed and have to be synchronised with the scan of the computer. This might sound like quite a complex feat of control but to our rescue comes the phase locked loop. We have used the phase locked loop in the past in the Morse Code detector, there it was used as a tone detector but here we are using it in a totally different way. Look at figure II, this shows the basic arrangement of a phase locked loop. What happens is that any difference in phase between the reference signal and that from the voltage controlled oscillator produces a voltage output from the phase comparator. This voltage is then filtered and applied to the voltage controlled oscillator thus changing its output. This then forms a loop because a change in the voltage controlled oscillator will change the output of the phase discriminator. Things are arranged so that the loop will stabilise and the output of the voltage controlled oscillator will exactly match, in frequency and phase, that of the reference signal. When this happens we say the loop is in lock. This has many applications but what we need here is to synchronise the motor to the computerÕs display. The frame sync pulse indicates that the display is starting a new scan, this will be our reference signal. The motor is fitted with a reflective optical detector that gives a signal when the chopper blade is moved in front of it. As the speed of the motor depends upon the voltage applied to it, and the motor speed controls the speed of the output from the optical sensor we have in effect a voltage controlled oscillator, this is shown in figure III. Now all we have to do is produce the electronics to allow the motors to be synchronised with the display. This is shown in figure IV. As you can see, some of the circuitry is duplicated to allow for the control of the two motors. First of all we need access to the frame sync pulse. On some models this can be obtained directly from the monitor output pin, however, pin 4 will deliver a combined sync signal. Alternatively you might like to use the video output connector but again this is not fitted on all models. The combined sync or composite video signal is fed to a sync separator chip and the resultant frame sync pulse is sent to a divide by two circuit. This generates a square wave which is high for one frame sync pulse and low for the next. This sort of signal is available from pin 7 of the sync separator but only when the computer is running in an interlaced mode. Personally I find this much too flickery for normal use on my setup. The output of the divider is then fed to the reference input of the PLLs (phase locked loops). In order to get the phase between the two motors correct you need to feed the two PLLs with complementary signals, this is no problem as the divider provides these signals. However, due to the hardware inside the computer you need to be able to alter the phase to each PLL by 180 degrees. Therefore I have used a double pole change over switch that I have labelled the phase switch. Finally the output of the PLL is taken to a transistor which controls the motor. This transistor is also fed with a small fixed current, this allows fine adjustment to the locked phase of the motor so the two blades can be precisely set up. The positioning of the optical sensors can be critical, the optimum sensing distance for the ones I have used is 5 mm, if positioned closer they will not work reliably. Therefore when setting it up test that the outputs of the 74LS13 are switching, use an oscilloscope or LED to make sure that each blade is being sensed. Now for the software, the trick here is to use vertical sync event to swap the displayed screen bank. This is why this system can only be used on the 32 bit machines. However, you could do the same thing with the Master but I have not written the software because I do not have easy access to that model of computer nowadays. Having set up the bank swapping all you have to do is to draw each image into a separate screen bank. If you draw an object that is in the same position in each screen bank it will appear to be in the same plane as the screen. If the object is displaced to the right in the other screen bank it will appear to be in front of the screen. If placed to the left it will appear to be behind the screen, see the diagrams. I have written a set of demonstration programs that illustrate the different ways of producing a stereoscopic 3D image, these are supplied on the subscription disc or can be ordered from Musbury Consultants. There is also a version for coloured glasses of those suitable for that technique. When you first run the program the bank swapping routine can be in any phase, that is a limitation on the computerÕs hardware. Therefore you need to alter the phase switch on the synchronisation electronics, make sure you can see the words ÒLeft EyeÓ only through your left eye. Then run the first demo, this simply puts a full screen of red for the right eye and green for the left eye. Stand back from the blades and you should see alternate triangles of red and green in the place of the blades. Adjust the phase fine adjustment on each motors until they are centred on the line joining the centres of the two motors. The simplest way to produce a stereoscopic 3D image is to switch to one bank, draw the picture, then switch to the other bank and draw it again. This works best when you are showing screen dumps. Most of the time you want to use the familiar move and draw, therefore there is a procedure that takes X and Y data as well as displacement or depth and draws the line in the appropriate place in each bank. This could have been implemented as a module but I preferred to leave it as a basic procedure. There is no room on the subscription disc to have any screen dump examples but these are available on the disc from Musbury Consultants. These can be produced from either a video digitiser or a ray tracing package like Render Bender. Using a digitiser can be a little more tricky than it sounds, basically you have to take two pictures of the same scene shifting the camera about 8 mm to the right for the second exposure. However, you have to be careful not to introduce any rotation in the cameras pointing direction or you will not see any 3D effect. I did this by picking an object that I wanted to appear in the plane of the screen and marking it on the computerÕs display with a reinforcing ring, the type used in loose leaf ring binders. When I took the second picture I made sure that the camera was panned so that the same object appeared in the same place. I did not have as much success with Render Bender as I expected. There are two points to watch here. First of all the viewpoint must be specified as an angle from the observer and not a co-ordinate in the scene, otherwise the geometry is all wrong and you get no 3D effect. Secondly you have to watch how the background behaves, this can also ruin the effect. The most successful technique I found was to draw two frames where the objects were moved to the left by a varying amounts depending on there distance from the view point. As I said at the start, the production of two different views is only part of the brain seeing a stereoscopic 3D picture, the picture also has to be consistent with what you expect. For example suppose there are two objects that overlap, you expect the one that obscures part of the other to be closer to your eye. If the two images fed to each eye contradict this expectation the brain becomes confused and is likely to see this as a flat picture. You can see an example of this by swapping the phase switch whilst viewing an image. Take the tunnel demonstration, there are no other depth cues here and altering the phase switch will flip the tunnel into being a pyramid. However, if you try this with the multi coloured balls you will not see the depth flip. This is because there are other depth cues in the picture like the grid in the plane of the screen and the overlapping of the balls. All the demonstrations use the broadcast TV modes, that is the non-multi-sync modes. The sync separator will extract the frame sync from any mode screen but there are some snags. Mode 20 will work fine but mode 21 will not. This is because Risc OS 2 will not allow you to allocate more than 480K screen memory and there isnÕt enough there for two banks. The same thing applies to VGA modes like 28, and there is a further snag. Here the frame sync rate is about 16 mS and not the normal 20 mS. This means that the motors will have to run faster in order to lock, I managed this with my system by upping the motor voltage to 15 volts. All the parts of this system are available from Musbury Consultants. However, as the motors are expensive I have arrange for three kits, one for the electronics and the other two for the motors. I used servo motors with attached gear boxes for ease of construction but these are quite expensive. I have found some alternative lower cost motors that should work, however, you could use motors you have to hand or from another supplier. The basic requirement is that one shutter blade must pass in front of the eye in 1/50 th of a second and the gap between the blades in the same time. Now you can change either the motors free running speed or the number of blades so that this requirement is met. You can use the formula:- N = 1500/R or R = 1500/N where R is the motor speed in RPM and N is the number of the shutter blades. I used N = 5 which gave the motor speed, R, as 300 RPM. In fact the gear box and motor combination I used produced 250 RPM at 12 volts and so I had to run the motor voltage a little higher at 14 volts to get the correct speed. This is not very critical as the synchronising electronics can compensate for a reasonable spread of motor supply voltages. The low cost motors run at 330 RPM so they will require a slightly lower voltage. It is likely that you will have some motors but not know their speed. You can find out if they are suitable with a simple experiment. Make a shutter using any number of blades but remember it has to be an odd number. Then while running the red / green screen demo adjust the voltage fed to the motors with a variable bench supply and see the point where you can get stationary stroboscopic red / green triangles. If the triangles are too small you can use fewer blades. I used cardboard to make the blades. Anything else can be a little hard on the nose if you look too close! The side of the blades facing the optical sensors had white paper stuck on them and the side you look through were painted black. This improved the contrast. Unlike the use of coloured filter glasses this system works best in bright light. I found with the lights turned off the persistence of the phosphor on the screen coupled with the increased sensitivity of my eyes allowed me to see a ghost of the image that was supposed to be shuttered out. To fix the blades on the motor I broke open a knob designed to be fixed onto a rotary volume control, I glued the metal insert onto the cardboard and used the grub screw to attach it to the gearbox shaft. Well after all that what does it look like? I must say I was very impressed, the 3D effect was quite stunning. My favourite picture is the view of the Lorentz attractor, you can see this curve being drawn in space in front of the screen. You can see exactly how one loop fits inside another and never crosses itself. Onlookers see a flickering tangled mess of lines but you can see the beautiful twin butterfly wings. ItÕs one of those projects you simply must see to appreciate. In fact in terms of impressiveness I reckon itÕs my best to date.