I'm creating a procedurally generated city and I'm having trouble with the logic behind adding buildings after the L System has added all of the roads.
I've done a lot of research as this is my final year project but unfortunately can't find a lot on adding buildings in, but more about adding roads.
My program uses L Systems to draw each road and when intersecting another road or changes direction it adds the road to an undirected planar graph. The roads added are just lines at the moment and don't have width yet as I would like to get the underlying logic of adding buildings sorted before adding this in. Roads drawn by the L System will be at randomised angles, not right angles.
My original method to find where to place the buildings was to rotate clockwise around the graph to find the polygons within the roads, then add the buildings inside the polygons found. I currently can't seem to get this working due to roads that are dead ends and moving around a graph clockwise doesn't seem to produce correct results.
The main problem is that a building placed at the intersection of a road could overlap the road. I would like the buildings to be placed somewhat similar to the game Subversion.
If there are any other methods to what I have tried I would love to hear your ideas.
Any help will be much appreciated.
Your problem is located at
"
then add the buildings inside the polygons found. I currently can't seem to get this working and it also has issues with if the road is a dead end.
"
Geometrically speaking yu should be able to define a polygon and see if the base of the building fits into that polygon.
Either using the java polygons or do it yourself
Specifically what goes wrong will get you specific answers
Related
I am currently making a map generator using Java. I am using arrays to store coordinates, which are then used to draw land. So I also have cities, and I want to draw the most direct path from city a to city b without crossing the water, AKA, only using the coordinates that are stored as land. How can I do this? I have tried many algorithms a;ready, like solving systems to make sure things do not overlap (which takes too long, as i have 75,000 points) and also finding the nearest city that does not have any water in between the two, found by drawing a best fit line and solving just one systems (extremely inaccurate and probably just wrong). Thanks for all the help in advance!
Hi everyone i'm working in a tile-based game engine and i got a bit stuck with units movement. Overall you can think it as a Tower Defense game where units have to follow a path (brown tiles), here comes the example image:
As you can see there are numbers in the Tiles with represent the drawing order. So when the map is initalized i take all the tiles that are of the type 1 (brown) and add them to an ArrayList.
Problem is that those ArrayList Tiles are in the drawing order. So my Units will start moving from tile 58 cause is the first tile from the drawing order.
How would you order the brown tiles starting from left (nº97) till right (nº118)?
I can think about taking the first tile that is the 97 by knowing that is the one with the lowest X position but from there what?
I think you're formatting your information in a strange way to solve this problem. If your units are starting at tile 58, then somewhere you're telling them to start at the first drawn tile? Optimally, if you want to have different maps, wouldn't you want to be able to define a particular point on the grid and tell them to start from there?
(Without knowing more about your code structure, it's hard to say how you'd do that.)
Once you've defined a point for them to start from and a point for them to end on, you could then use A* or D* search to define a path for the entities to take along your grid. That would also give you a lot more options in your design-- you could have the player modify the grid throughout the game and force the units to take a new path.
I'm current working on a pet project that allows a user to create a graph (vertices/edges) on screen in Java. I have the vertices implemented as JComponents but I have the edges implemented as Line2D's. When a user is moving the mouse across the canvas, if it is within a certain threshold of proximity to one of the edges (or Line2D's) that edge (the closest to the mouse) is highlighted.
My question deals with the way I implement which edge is closest to the mouse. Right now I have a mouselistener that detects movement; every time the mouse is moved my program cycles through all the lines (edges) and determines the closest one using Line2D's ptDistSeg() function. If this is within the threshold, then it is highlighted (using a thicker stroke in the paintcomponent).
To me this seems very inefficient as it has to recalculate all edge distances from the mouse every time it is moved. For the vertices this isn't a problem as the mouselisteners are associated with each vertex and therefore the vertices know when they need to handle the event. Unfortunately I can't do this with the edges as they are represented as Line2D's which can't implement a mouseListener.
So is there a more efficient way to find the closest edge or should I implement the edges a different way?
Thanks.
There's probably a better data structure for this out there somewhere, but one option would be to compute the axis-aligned bounding box of each edge to get one rectangle per edge, then to store all of these rectangles in a spatial data structure like an R-tree. R-trees support efficient queries of the form "give me all rectangles overlapping some point," so you could use that to filter down all the line segments to just those that might potentially hit the mouse point, then just test those.
The drawbacks here are that moving nodes around will require a lot of R-tree rebuilding due to the cost of changing the bounding boxes and that you'd need to find a good R-tree library, since R-trees aren't very easy to implement from scratch.
Hope this helps!
I read this article http://www.iforce2d.net/b2dtut/ghost-vertices which explained a solution to my box2d bodies getting stuck at the intersections of multiple small fixtures supposed to be making up a platform and it says to use EdgeShapes to use the ghost vertices but after rereading a few times I am still very confused as to how to apply this ghost vertices method of solving my problem.
Ghost vertices are automatically calculated in libgdx so you don't get stuck in the ground. I had the same problem. Instead of using rectangles use EdgeShape and put in the vertices instead and you'll be fine!
As much as i understood, ghost vertices are ignored by the collission detection, but treated like normal edges by the collission response.
So if you collide with the "main-edge", the calculation of the collission response starts. Here, there is no "main-edge" anymore. Instead the ghost-vertex (the one, closer to the collision point), forms a new, continuous shape, together with the "main-edge".
So i guess, the ghost vertices can be like the adjacent edges, simmulating a continuous plattform.
This solution actually should solve the problem, while other solutions are only some kind of workarround, which in many cases are enough.
You could, for example, try to "cut" the edges or use a circle shape if possible. In some situations it might be enough.
Well, I'm developing a application using Java3D, which can solve Rubik's cube showing the user step-step solution.
I did my Algorithm part perfectly, and now the issue is with 3D cube,
Till now, i've created 27 cubes as in real one.
The problem is that, inorder to rotate a face clockwise or anti-clockwise, I should add those individual cubes to a group which in turn can be used to rotate the face anti-clockwise or clockwise direction as i said, but indeed the nodes in edges have to be in multiple groups, so that they can rotate either on X axis or Y axis or else we can take two axis of rotation.
so, my question now is, how to add a node to multiple groups ?
Or if it is not possible, Well then there must be a way to construct a Rubiks cube and to rotate its faces, How to do that!
Can you help me with this!!
Adding the cubes to BranchGroups and dynamically updating them or managing multiple groups sounds complicated.
Perhaps consider keeping the cubes independent. Create three transforms: one to rotate clockwise/counter-clockwise 90 degrees about each of the three axes. To rotate a face, apply the same transform to each of the cubes in that face -- since they are all rotating about the same axis anyways.