draw weapon sight cone
BlitzMax Forums/BlitzMax Programming/draw weapon sight cone
| ||
Hi I am using this code below for 2d pan and zoom: http://www.blitzbasic.com/codearcs/codearcs.php?code=2269 It lets you draw polys, which is nice, and I want to draw a triangle to show the sight cone for a gun. I know the range of the weapon and its angle of movement,e.g. 65 degrees each way. =130 degrees and range of 6 squares I can already calculate if the weapon is in range and within the right angle but I dont know how to get the co-ords of a point that is 65 degrees away and a range of 60 units for instance. and of course the sight cone would have to correspond to the angle of the gun:):) |
| ||
The coordinate of a point which 65 degrees away and a range of 60 units away goes something like this. Assuming that your person with the gun is at PersonX,PersonY : Angle=65 Range=60 X = (Cos(Angle)*Range) + PersonX Y = (Sin(Angle)*Range) + PersonY Again, this is working with the 0 angle being right, not up, consistent with your previous question. |
| ||
This might help as well. |
| ||
Glad you're finding my code useful :) Suppose you've got a gun at gunx#,guny#, and its angle is gunangle# You want to draw a cone out from gunx,guny, covering everything within +/- 65 degrees of gunangle and up to 60 units away. This shape is a segment of a circle, but drawing a segment of a circle is a bit tricky, so you've correctly realised you need to draw a poly. We can approximate a circle segment by working out a few points on the edge of the circle, and making a polygon out of them, plus the centre point. SuperStrict Local gunangle:Float 'Gun is at (gunx,guny) pointing in angle 'gunangle' Local gunx:Float Local guny:Float Local numsegments:Int = 12 'split the cone into 12 segments Local poly:Float[(numsegments+1)*2] 'we will store the co-ordinates of the vertices of the polygon her Local anrange:Float=130 'the cone is 130 degrees wide Local coneradius:Float=60 'and reaches 60 units out Local an:Float,x:Float,y:Float poly[0]=gunx 'the first vertex of the cone is the centre poly[1]=guny For Local i:Int=0 To numsegments-1 an=gunangle-anrange/2.0+Float(i)/Float(numsegments)*anrange x=gunx+coneradius*Cos(an) 'gets a point at the given angle and distance away from the gun y=guny+coneradius*Sin(an) poly[i*2+2]=x 'store these co-ordinates in the cone array poly[i*2+3]=y Next DrawPoly poly 'draw the cone |
| ||
thanks gab whoa it actually worked! and luckily I can use the blitz rotation commands to align the lines to the right direction, tonyg thanks for the link warpy, I plugged your code into my game, it looked great because the cone is a poly it can be colored made transparent and filled-in, It didnt respond to scale ill try changing it to zoompoly EDIT: tried that and it worked, now to set the rotation the co-ordinates are messed up when rotation is applied, im trying to see why EDIT: Possibly because of 'handling' I have automidhandle set to true, it does seem to be a 'handle' issue, unless the code is wrong (which I doubt) ![]() |
| ||
What are you doing with rotation? The code I wrote already takes into account the gun's rotation. |
| ||
oh yeah I had to set the rotation to zero it works now thanks! |