Stretching an image between 2 points at an angle.

BlitzMax Forums/BlitzMax Beginners Area/Stretching an image between 2 points at an angle.

Ryan Burnside(Posted 2009) [#1]
I recently created a little project that looks like glowing lines like on the old vector based arcade games. I noticed that my lines were not being drawn at the correct position after further investigation.

I have a 16x16 pixel texture that must be stretched between two points to give the impression of a beam of light. It gets more complex however, the two points may be at an angle from each other. It turns out that the drawimagerect() command acts odd when you add rotation into the mix. By default the texture is "automidhandled". I would be willing to change this if necessary but the 2 points must touch the very center of their respective edges on the texture.


This is the effect I need given a 16x16 pixel texture being stretched between 2 points of varying distance.


Here is the thread, you can see how I assumed it was working but another user mentions that it is indeed drawing a bit off. You can see my source there too with the line textures.
http://www.blitzbasic.com/Community/posts.php?topic=87785


sswift(Posted 2009) [#2]
Why are you using drawimagerect? I use setscale and setrotation and then drawimage.


ImaginaryHuman(Posted 2009) [#3]
Get rid of the automidhandle by doing AutoMidHandle False when you load the image. Then set the image's handle to the middle left side of the image. This can then anchor at point 1, then just rotate by the angle direction of point 2 and draw it. ?


Ryan Burnside(Posted 2009) [#4]
Thanks guys, I was not able to figure out how to set the image handle to the middle left side as ImaginaryHuman said. I was able to get it done with sswift's method however. (It cost an extra operation to find the center of the line)


GfK(Posted 2009) [#5]
I was not able to figure out how to set the image handle to the middle left side as ImaginaryHuman said
You almost typed the answer in the above sentence - SetImageHandle myImage,0,8.

ImaginaryHuman's method is what I'm using and its plenty fast enough. Also I use DrawImageRect so I don't have to fanny about with the scale although I guess it comes down to preference.

After finding the vector and using SetRotation, I can use DrawImageRect myImage,X,Y,W,H, where X and Y are the coords of the first point, W is the distance, in pixels, between the two points, and H should be 1 if you want the image to be 100% of its original height.


ImaginaryHuman(Posted 2009) [#6]
Interesting idea to use a long image with drawimagerect instead of trying to scale it.