light gun / CRT related question

Sharky Forums


Results 1 to 5 of 5

Thread: light gun / CRT related question

  1. #1
    Sushi zaza's Avatar
    Join Date
    Nov 2003
    Posts
    3

    light gun / CRT related question

    Hello,

    I have a technical question concerning the raster beams on a CRT screen : I'd like to build a device based on the light gun principle, which means that I have to find a way to know when the electron beam starts to draw the computer screen, and what his position is on the screen at a given time. The thing is that I have no idea how to do this, mainly if anyone could give me tips on the following points it would be of great help :

    - is there a programming language that would be more adequate than others to do this kind of operations ? (are there some routines in C++ that could do that ?)

    - is it possible to do this for the TV's raster beam ?

    I'm not sure whether this is the right forum for this kind of questions, but even a vague idea would be of great help, since I have difficulties finding technical info on this subject.

    Thanks for your help

    Zaza.

  2. #2
    To my understanding, most light guns use the following method:

    When you fire the light gun, a program quickly draw several different small white rectangles many times. The light gun, which is actually a light detector, try to record the result every time. Then the program analyse the result to determine where the light gun points to. A simplest example: the program draws four white rectangles, top-left, top-right, bottom-left, bottom-right, one per frame. If the light gun detects white at third frame, you know it points to bottom-left.

    The hard part is to sync the light gun to the monitor. The most bullet-proof way is to connect the v-sync to the light gun. A not-so-bullet-proof way is, fill the monitor with black, then white, and you use the white to sync the light gun. Of course, you need to know the refresh rate of the monitor.

    It is possible to make a more "interesting" light gun. For example, you can put a small camera on the gun, and try to analyse the captured image to figure out where the gun points to.

  3. #3
    Sushi zaza's Avatar
    Join Date
    Nov 2003
    Posts
    3
    thanks a lot for your answer, but there are still things that are obscure for me : I really don't see practically how I can synchronize the gun with te monitor.

    My objective is the following : I want to build a pointing device based on the principle of light guns, but which doesn't have a trigger. Thus, I thought that I would blacken the screen and then paint it white at regular intervals (small enough not to be seen, but fast enough for a smooth movement on the screen). So tell me if I'm wrong but if I understant correctly what you said :

    - I have to know when the computer starts to draw the blank screen ; I suppose it is easy to get since I decide when I draw the screen white (t0);

    - I have to know when the device responds to the white spot on the screen (t1);

    - I have to know how long it takes to draw the entire screen with the refresh rate (r)

    so %screen_drawn = (t1-t0) * r (supposing t1-t0

    But even then, I only know the % of screen that has been drawn until the device responded, but I have no way to get the pixel coordinates corresponding to the position pointed by the device, since I do not know the number of lines and columns... Or is there a point that I've missed ?

    Lastly, do you know whether simple programming language like C++ can give you access to such informations as the refresh rate of the pc of the size of the screen ?

    Thanks a lot for your help, hoping my questions are not trivial...

  4. #4
    OK, so your device responds to you when it see white?

    Note that you can't just fill the screen white, and try to measure the time the screen renders to a specific position, because it's just too unreliable. You have to render small rectangles by yourself. That is, if you divide the screen into 16 locations, you'll need to draw 16 rectangles, one per frame. Using a binary search-like trick you can reduce to just four frames (explained later).

    Actually, if your device responds in real-time, you don't need to sync at all. You can just draw a white rectange, and wait for the device to respond. If it responds, you know it points to the location where you draws the rectangle. Otherwise, you can proceed to the next rectangle.

    If your device can't respond very quickly, you need to know the refresh rate of the monitor. The information is easy to get. In Win32, use EnumDisplaySettings. However, if you use LCD monitor, its actual refresh rate may be slower. So you may want to test refresh rate by yourself. However, if you use only CRT, you don't need to worry about this.

    There are some tricks you can use to speed up, especially if your device responds in realtime. For example, you can device the monitor into two halves, decide which half the device points to, and proceed only in the half. This is just like a binary search.

  5. #5
    Sushi zaza's Avatar
    Join Date
    Nov 2003
    Posts
    3
    Thanks a lot for your answer, I'll look into this solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •