(VB) Making a bot... Get pixels in a circle.
Yeah, that''s what my method would do. Was I unclear? Maybe I''m not getting what you''re doing...
Get the image you want to search.
Create a "mask buffer" with the same dimensions (more on this in a second...)
Create buffers/arrays to hold "regions" (again, more in a sec...)
Initialize a "region". Start at the corner of the image and recursively walk through adjoining pixels. If the colors match within a given threshold, add them to the current "region" (it''s up to you to define exactly what you want this data structure to be). Every time you add a pixel to a region, mark that pixel out in your mask buffer. Do this until you run out of matching pixels.
Initialize a second region. Scan through the mask buffer until you find a pixel that isn''t part of a region. Recursively walk though, matching colors and adding the pixels to the new region (only if they aren''t already in one).
Repeat until you''ve broken the image into regions. In your example, you''d have 4 - the white outer, the white inner, the black, and the red.
Now, this is where your data structure matters. You could have added something to your region structure that said "the primary color of this region is X". If you do that, you can scan through your regions and concentrate on the red ones.
So, you''re looking at red regions... Now, let''s say your region structure recorded the X, Y positions of each pixel in the region. You can use these to find the centroid of the region in "image space" (look up centroid). In your case, the centroid will be the center of the red circle.
Now that you have the centroid, some basic trig can be used to find the angle between the center of the image and the center of the circle.
Voila! There might be an easier way to solve the exact example you gave, but this way should be a decent general solution. You can use this method to identify the relationship between two objects, etc. etc.
Create a "mask buffer" with the same dimensions (more on this in a second...)
Create buffers/arrays to hold "regions" (again, more in a sec...)
Initialize a "region". Start at the corner of the image and recursively walk through adjoining pixels. If the colors match within a given threshold, add them to the current "region" (it''s up to you to define exactly what you want this data structure to be). Every time you add a pixel to a region, mark that pixel out in your mask buffer. Do this until you run out of matching pixels.
Initialize a second region. Scan through the mask buffer until you find a pixel that isn''t part of a region. Recursively walk though, matching colors and adding the pixels to the new region (only if they aren''t already in one).
Repeat until you''ve broken the image into regions. In your example, you''d have 4 - the white outer, the white inner, the black, and the red.
Now, this is where your data structure matters. You could have added something to your region structure that said "the primary color of this region is X". If you do that, you can scan through your regions and concentrate on the red ones.
So, you''re looking at red regions... Now, let''s say your region structure recorded the X, Y positions of each pixel in the region. You can use these to find the centroid of the region in "image space" (look up centroid). In your case, the centroid will be the center of the red circle.
Now that you have the centroid, some basic trig can be used to find the angle between the center of the image and the center of the circle.
Voila! There might be an easier way to solve the exact example you gave, but this way should be a decent general solution. You can use this method to identify the relationship between two objects, etc. etc.
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
Let me show you what i have done so far:
------------------------------------------------------
'' Angle ship is heading....
Const nAngle = (11.25 / 180) * 3.1415
AngleSpot = 16645629
SPos.X = Pic.ScaleWidth / 2
SPos.Y = Pic.ScaleHeight / 2
For A = 0 To 32
DoEvents
ShipAngle.X = SPos.X + 15 * Cos(A * nAngle)
ShipAngle.Y = SPos.Y + 15 * Sin(A * nAngle)
tmpF = GetPixel(Pic.hdc, ShipAngle.X, ShipAngle.Y)
If tmpF = AngleSpot Then
tmpW = SPos.X - ShipAngle.X
tmpH = SPos.Y - ShipAngle.Y
ShipAngle.A = Atn(tmpW / tmpH)
GoTo Cont
End If
Next A
Cont:
----------------------------------------------------
This works, because i manage to find that red spot, BUT, I''m not able to calculate the angle anyway.. Can antone correct my code?
------------------------------------------------------
'' Angle ship is heading....
Const nAngle = (11.25 / 180) * 3.1415
AngleSpot = 16645629
SPos.X = Pic.ScaleWidth / 2
SPos.Y = Pic.ScaleHeight / 2
For A = 0 To 32
DoEvents
ShipAngle.X = SPos.X + 15 * Cos(A * nAngle)
ShipAngle.Y = SPos.Y + 15 * Sin(A * nAngle)
tmpF = GetPixel(Pic.hdc, ShipAngle.X, ShipAngle.Y)
If tmpF = AngleSpot Then
tmpW = SPos.X - ShipAngle.X
tmpH = SPos.Y - ShipAngle.Y
ShipAngle.A = Atn(tmpW / tmpH)
GoTo Cont
End If
Next A
Cont:
----------------------------------------------------
This works, because i manage to find that red spot, BUT, I''m not able to calculate the angle anyway.. Can antone correct my code?
Shouldn''t Atn(tmpW / tmpH) be Atn(tmpH / tmpW)?
I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader''s Realm
I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader''s Realm
How large is your circle? If it''s quite large, you can get away with a relatively small number of samples...
Besides, is speed a real concern here?
Cédric
Besides, is speed a real concern here?
Cédric
hmm.. not very important.. but.. i now know how to get the coordinates of the red spot, and i allready have the coordinates of the big circle... So how do i now calculate the angle???
quote:
Original post by cedricl
How large is your circle?
Why not visit the UniBall website and see for yourself (the download is not that big, less than 1mb). Just connect to the server and you can start playing the popular multiplayer game.
... I''m playin that game allready, and i''m making a bot for it.. so.. How can i calculate the angle out of theese two co-ordinates?
F.ex if the co-ordinates of the red spot was:
X = 12, Y = 12
And the co-ordinates of the white spot (center of big circle) was:
X = 20, Y = 25...
How can i now figure out the angle?
F.ex if the co-ordinates of the red spot was:
X = 12, Y = 12
And the co-ordinates of the white spot (center of big circle) was:
X = 20, Y = 25...
How can i now figure out the angle?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement