I'm working on a tile-based 2D game and having a minor issue with the map generation.
The general concept is that it creates one room by default and then builds off of any existing rooms until X number of rooms have been built or Y number of tries have failed.
The issue I'm coming into is probably simple and I just can't wrap my mind around it, but how would I go about removing the circled tiles? Each map generated is procedural, so I won't know exactly when spots like the circled ones show up and I can easily spot them with my eyes... I just can't think of an all encompassing way to handle them AFTER the map is already generated.
The goal is to never have walls doubled up where they aren't needed to be. I am not wanting to change the way the map is generated, but rather modify it after the fact. I also do not want to lose corners of rooms or similar.
I really feel like what I'm trying to do would have a name in image editing or similar, but that's certainly not my forte.
Your circled items are ambiguous because in certain situation you could remove the one circled by you or the otherside without breaking the rules (no mixing rooms neither open to external black tiles).
In any case I should think a little bit more about it but they just seem the tile that after being removed don't join two rooms neither have any adjacent (diagonal included) black tile.
I guess you could assign to every room a number and then remove any tile that:
doesn't connect two floor tiles with different numbers
neither have ajacent black blocks
Maybe you could do it also without numbering rooms but you will have to understand if all neighbours are from the same room or not by exploiting side adjacency.
I'd comment instead of answer if I could, as I can't I'll give an answer a go.
How're you storing the details of the level? You seem to want to know where two horizontal or two vertical walls are touching and delete them as long as they aren't corners.
It seems like you need a rule or two like...
if it's a horizontal wall and there is a tile either side, delete any above or below.
if it's a vertical wall and there is a tile above and below, delete any to the left or right
Related
I've searched the Internet and maybe I'm missing some correct keywords but I managed to find nothing like this. I only found the poly-lines (or just the lines) which are not exactly the graphs. I would like to generate a graph outline (of radius r) as seen in the picture. Is there something already available? I would like to avoid reinventing the wheel so to speak.
If anyone can at hint me at something or at least at some basic principle how to do it it would be great. Otherwise I'll "invent" one on my own of course.
Optimally in C#.
Update: I need to calculate outline polygon, not just visually draw it. The green points represents the resulting polygon. Also the "inner" holes are ignored completely. Only one outline polygon should be enough.
Update 2: Better picture to show some more extreme cases. Also the edges of graph never overlap so no need to accommodate for that.
Update 3: Picture updated yet again to reflect the bevel joins.
First, for every "line piece" from point A to B, generate the rectangle to it (all 4 points as "path", so to say). Then search two overlapping rectangles and merge them:
Merging is a bit complicated, the idea: Start with calculating the angle of all 8 lines (eg. if the rectangles are traversed clockwise). Then traverse one rectangle until the first line-line-intersection, check with the angles which direction is "outside", and move along the crossing line of the second rectangle ... until you arrive at the start point again => Now you traversed the shape of both together (and hopefully saved it somewhere).
Merge until only one large piece is left (or multiple non-overlapping pieces). In theory, starting from any point, you can traverse the whole shape, but thereĀ“s another problem: Holes are possible.
If one shape has two or more disjuct sets of points (where no point from set 2 is reachable from set 1 and vice-versa), all but one disjunct path is of a hole. An easy possibility to get the real outer border is to search for an extremum, ie. the point with the largest or smallest X or Y coordinate (only one of the 4 combinations in enough). This point surely is a part of the outer border.
I am currently working on a project which we have a set of photos of trucks going by a camera. I need to detect what type of truck it is (how many wheels it has). So I am using EMGU to try to detect this.
Problem I have is I cannot seem to be able to detect the wheels using EMGU's HoughCircle detection, it doesn't detect all the wheels and will also detect random circles in the foliage.
So I don't know what I should try next, I tried implementing SURF algo to match wheels between them but this does not seem to work either since they aren't exactly the same, is there a way I could implement a "loose" SURF algo?
This is what I start with.
This is what I get after the Hough Circle detection. Many erroneous detections, has some are not even close to having a circle and the back wheels are detected as a single one for some reason.
Would it be possible to either confirm that the detected circle are actually wheels using SURF and matching them between themselves? I am a bit lost on what I should do next, any help would be greatly appreciated.
(sorry for the bad English)
UPDATE
Here is what i did.
I used blob tracking to be able to find the blob in my set of photos. With this I effectively can locate the moving truck. Then i split the rectangle of the blob in two and take the lower half from there i know i get the zone that should contain the wheels which greatly increases the detection. I will then run a light intensity loose check on the wheels i get. Since they are in general more black i should get a decently low value for those and can discard anything that is too white, 180/255 and up. I also know that my circles radius cannot be greater than half the detection zone divided by half.
In this answer I describe an approach that was tested successfully with the following images:
The image processing pipeline begins by either downsampling the input image, or performing a color reduction operation to decrease the amount data (colors) in the image. This creates smaller groups of pixels to work with. I chose to downsample:
The 2nd stage of the pipeline performs a gaussian blur in order to smooth/blur the images:
Next, the images are ready to be thresholded, i.e binarized:
The 4th stage requires executing Hough Circles on the binarized image to locate the wheels:
The final stage of the pipeline would be to draw the circles that were found over the original image:
This approach is not a robust solution. It's meant only to inspire you to continue your search for answers.
I don't do C#, sorry. Good luck!
First, the wheels projections are ellipses and not circles. Second, some background gradient can easily produce circle-like object so there should be no surprise here. The problem with ellipses of course is that they have 5 DOF and not 3DOF as circles. Note thatfive dimensional Hough space becomes impractical. Some generalized Hough transforms can probably solve ellipse problem at the expense of a lot of additional false alarm (FA) circles. To counter FA you have to verify that they really are wheels that belong to a truck and nothing else.
You probably need to start with specifying your problem in terms of objects and backgrounds rather than wheel detection. This is important since objects would create a visual context to detect wheels and background analysis will show how easy would it be to segment a truck (object) on the first place. If camera is static one can use motion to detect background. If background is relatively uniform a gaussian mixture models of its colors may help to eliminate much of it.
I strongly suggest using:
http://cvlabwww.epfl.ch/~lepetit/papers/hinterstoisser_pami11.pdf
and the C# implementation:
https://github.com/dajuric/accord-net-extensions
(take a look at samples)
This algorithm can achieve real-time performance by using more than 2000 templates (20-30 fps) - so you can cover ellipse (projection) and circle shape cases.
You can modify hand tracking sample (FastTemplateMatchingDemo)
by putting your own binary templates (make them in Paint :-))
P.S:
To suppress false-positives some kind of tracking is also incorporated. The link to the library that I have posted also contains some tracking algortihms like: Discrete Kalman Filter and Particle Filter all with samples!
This library is still under development so there is possibility that something will not work.
Please do not hesitate sending me a message.
I'm looking for some idea's on how to create the 2d layout (walk path) of a game.
The tiles will be 32x32 pixels aswell as the character moving on the tiles.
I've thought of two ways currently, havn't tried any of them out yet.
The game will be shown in a window of about 400x300 or 512x356 something.. not much bigger than that where the game map itself could be bigger then 1000x1000. So only a portion of the map will be visible most times.
So here's my 2 options as far as I've thought of them.
[1]: Create the entire map at the start (which might increase the loading times but it will make it more easy to move the map around) including each object, player, enemies etc etc.
[2]: Create only the map seen and 1 tile around it (which is not visible) so I can make that one visible with a story board and remove the row / column which is out of bounds and create a column again.
Which means, If I have a room of 5x5 tiles, and I load 7x7 tiles. If I move right, I move all the tiles left and keep the player in the middle of the screen. Then I remove the far left set of tiles and create a new set of tiles on the right side, which will hopefully be done before the storyboard has finished moving.
In the second method all I have to consider is objects that are larger then 32x32. How could I best react on those.. However, this is a problem I'd like to address later.. Right now I prefer to know people's opinions and possible better methods.
I do apoligize if this question is no apropriate for stackoverflow.
Just be careful with the "load" word. Loading, means taking the data from the disk/drive and putting it memory. For that, you should load all the current world/map at once, before the game start. Trust me, you don't want to get yourself in dynamic loading stuff while the map is running.
But you only need to load the definition of your map, you don't need to create the instance of the object at that point. So you can create the instance from the map definition as the player walks... but are you really that constraint in memory? I can understand that for a game like Minecraft or Terraria where the map contains virtually millions of tiles... But for 32x32, you can consider making them all when you load the definition.
Of course, whatever the solution, you should only draw/compute/collide/update the tiles that are visible on screen.
I am working with C# OpenTK, but any code in C++ OpenGL is fine, i understand it.
I have a list of Markers. A Marker is defined as a 2 coordinate, and a pointer to the next marker in the loop. Essentially, if you were to follow the path of those pointers, you would eventually reach the Marker you started with. This is how shapes are initially defined.
One of those 'loops' may not be all the markers in the list. Multiple 'loops' may be contained. Take the letter 'A' for example:
This shape here would be defined by 2 'loops'. One is the outline (8 Markers), while the other loop would be the triangle within (3 Markers).
(Marker - Pointer)
1-2, 2-3, 3-4, 4-5, 5-6, 6-7, 7-8, 8-1
9-10, 10-11, 11-9
I need a method that will allow me to draw something like this to the screen. The solutions stated here would correctly solve the issue on a bitmap level (going through pixel after pixel to check if it within the polygon), however would be quite inefficient, especially given the fact that these markers shall be moved continuously at run time.
It is required that these shapes should be able to include things such as the triangle in an A (inverting), and preferably would allow for overlapping boundaries of the 'loops', but this second thing is not a necessity.
I'm guessing the direction taken will either be some sort of conversion to triangles, or some fancy trick with built in OpenGL features.
You're looking for triangulation with holes.
Check out the General Polygon Clipper (GPC).
I'm making a game in C# and XNA, and I was trying to come up with a method to render massive terrains without using a tremendous amount of memory or passing the poly limit hard-coded into XNA.
My solution so far is to create a massive heightmap, and that heightmap is loaded into memory at the beginning of the game in the initialization phase. Then, terrain is only generated nearest to the camera. This is accomplished by projecting a triangle whose vertex is the character and the other two endpoints extend to the sides of the character's viewing area. Then, all the pixels inside that triangle on the heightmap are rendered and drawn into the game, thus only rendering what is seen.
The problem is, I've successfully found (I think, can't test until I get terrain rendering) the three vertices of the triangle. Now I need to find a list of the coordinates for every single pixel inside that triangle - whole numbers only, because I just need a list of pixels to render.
I know it sounds a little confusing, so here's the gist of it:
I have an image, and I project a triangle onto that image. The only thing I know about that triangle are the three vertices. I need a list of the pixels inside that triangle.
I've been Googling around for maybe 20 minutes now, and I figured I midas well go ahead and post something here due to the fact that what I'm trying to do isn't all that common. If I find an answer, I'll be sure to post it here.
But until then, can anyone tell me how to accomplish this?
Edit: A formula, please. If you can provide a formula or algorithm, and an explanation, that would be just perfect.
Edit: I've posted a new question, as I've ditched this method of rendering large terrains. The question is here.
Start here:
http://mathworld.wolfram.com/TriangleInterior.html
One of the non-trivial problems, not mentioned there, that you have to deal with is the pixelization along the boundary.