Thread: lens drawing algorithm

  1. #1
    Banned
    Join Date
    Nov 2007
    Posts
    678

    lens drawing algorithm

    someone here once posted a simple algorithm to draw a filled circle, it was very good, i used that to draw the spot light effect.

    now if someone can help me with lens drawing logic it will be great
    i used SDL and in that you have an array of integers (for 32 bit mode) containing all the pixels, so i have full control over pixels.

    i just hope someone has a lens drawing logic! a pseudo code will do just fine!

  2. #2
    Banned
    Join Date
    Nov 2007
    Posts
    678
    8 days passed ... still, no reply!

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you are after an algorithm to draw something like this () representing a lens, then the it will help you to know that a lens like that is normally two spherical surfaces - so draw like a circle, but reduce the distance in X by some amount, and you will have something that looks like a lens.

    Or put another way, draw a circle segment where the center is on the other side of the lens, and don't draw past the mid-point of the lens element.

    Of course, lenses come in all sorts of shapes and forms, you can have (**( lenses for example. (** should be replaced by solid fill).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    From your explanation I was not sure exactly what you're after. do you mean a fisheye type lens effect? If so, then theres some code here Its in basic but it should give you an idea of the logic/maths involved. Hopefully that helps.

    Alternatively If you just want to highlight an area that the spotlight is on then its just a matter of blending the colours (perhaps at varying degrees) with white.

  5. #5
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    I think most people are confused by what you mean by a "lens drawing algorithm." As you can see, the two people who responded before me had very different responses. One thought you might be talking about the actual polygonal representation of a lens (such as the lens of a pair of eyeglasses or a camera), while the other thought you might be talking about various different types of lens effects that might occur.

    You need to be more specific.
    My Website

    "Circular logic is good because it is."

  6. #6
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Oh
    I am really sorry about not being clear enough! I will try to explain as best as possible.

    Initially I did not know how to draw a filled circle, then I saw someone's pseudo code for a filled circle, that was pretty easy to understand. Now using that logic, I copied pixels from one image to my drawing surface, (pixels were copied in the shape of a circle), I managed to darken the pixels near the perimeter of circle, now my drawing surface contains all black background, and, pixels in circle shape copied from image, having some darkening effects near the perimeter.

    This little improvement over the basic filled-circle drawing logic gave me a nice spotlight like effect

    Not I thought lets make a lens instead of the spot-light, and yeah my lens (when view from side) has this shape ().
    Now moving such shaped lens would zoom the image a little, and may be make it appear a little swollen (right word?) also.

    Oh, after searching for right word, I think, I need an effect similar to moving a magnifier-glass over an image.

    I hope it's not too hard to explain for someone, I mean, the logic for magnifier glass like effect


    Edit: mike_g, I am trying your link, it's currently not opening
    Edit2: mike_g, the filled circle drawing logic was also posted by You!
    Last edited by manav; 04-30-2008 at 12:10 AM.

  7. #7
    Banned
    Join Date
    May 2008
    Location
    Four Dots Planet
    Posts
    72
    if you are using Qt it is especially easy to do they also have an example of it in demos/deform folder. check it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Algorithm for drawing arc?
    By 6tr6tr in forum C++ Programming
    Replies: 7
    Last Post: 01-09-2009, 02:26 AM
  2. Line Drawing Algorithm
    By Axpen in forum Game Programming
    Replies: 15
    Last Post: 08-01-2005, 06:30 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM