-
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! :)
-
8 days passed ... still, no reply! :(
-
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
-
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.
-
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.
-
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!
-
if you are using Qt it is especially easy to do they also have an example of it in demos/deform folder. check it.