Home
Products
Community
Manuals
Contact
Login or Signup

Best way to create a crosshair?

BlitzPlus Forums/BlitzPlus Beginners Area/Best way to create a crosshair?

Paul Murray(Posted 1+ years ago) #1
I want to have a crosshair similar to the image below but I'm not entirely sure the best way to do it.

*Edit* - It would probably help if I added the pic



Ways I can see are;

A. Use lines and an oval, but even with nothing in the program but these, I get a choppy framerate.

B. Use a large image and offset it so it's position at MouseX() and MouseY()

Or

Make the crosshair from images of lines / an oval. I havn't tried this but it seems like quite a fiddly way to go about it.

I want the lines to always appear to come from the sides of the program, similar to the crosshair you can set up in 3DS Max and similarly in AutoCAD.

Any ideas?


Grey Alien(Posted 1+ years ago) #2
draw the lines with rect (1 pixel wide) as it's quicker. Make the circle in a paint package as a bitmap and load it in and use DrawImage to show it. Turn off debug to see what your real final framerate will be.


WolRon(Posted 1+ years ago) #3
*Concurs with Grey Alien*


Grey Alien(Posted 1+ years ago) #4
:-)


Rck(Posted 1+ years ago) #5
Its faster with images all around

and here it is, you asked for it...

change the comments around the rect drawing to see the difference with some combinations and possibly increase the loop amount




Buggy(Posted 1+ years ago) #6
What's wrong with a crosshair image?


Paul Murray(Posted 1+ years ago) #7
Because I never wanted to see the ends of the lines, the image would have to be twice the size of the graphics window.

I guess it's quicker to use smaller, seperate images than one huge one.


Plash(Posted 1+ years ago) #8
Graphics(800, 600, 0, 2)
SetBuffer(BackBuffer())
HidePointer()

While KeyDown(1) = False
	Cls()
		mx=MouseX():my=MouseY()
		Line(0, my, 800, my)
		Line(mx, 0, mx, 600)
		Oval(mx - 20, my - 20, 40, 40, 0)
	Flip()
Wend


...... simple.


Rob Farley(Posted 1+ years ago) #9
http://www.blitzbasic.com/codearcs/codearcs.php?code=1067

And use an image for the circle


xlsior(Posted 1+ years ago) #10
Syco: Like Grey Alien said: "draw the lines with rect (1 pixel wide) as it's quicker"

Drawing a rectangle 1 pixel high (or wide) is faster than drawing a line, since the algorithm is much simpler -- it doesn't have to do any calculations for angles, but can just fill a straight chunk of memory with your color value.


Rck(Posted 1+ years ago) #11
Syco's post does help one understand the idea of what you're trying to do but is over 10X slower than my code. (Even uses lines instead of rects, people don't understand simplifications of code can lead to massive slowdows; i.e. x^2 is slower than x*x)

some whipped-up code to show the dif in speed.


It is because things like ^ and Line are generalized and you are forgetting the special cases you are dealing with.


Drawing any things like plot, rect, oval, text, whatever, straight to the backbuffer is just ugly and can lead to slowdowns where images were designed to be used (repetition). My code above is nice and worrying about images that go offscreen should only be a concern for cell phone programming, etc.

Just remove the for loop that runs 1000x repeat and ull see the real speed.