c# xna data structures

Started by
11 comments, last by TheTroll 16 years, 6 months ago
anyone know of any reusable data structures for c# xna. the one im looking for is a graph.
Advertisement
Your question is extremely vague, details would be nice. Are you talking about a scene graph?
I'm not familiar with a scene graph. but here is what im doing:

I want to load a bunch of points that are connected with lines. Then later on there will be some path finding from start point to end point.


Here are 2 I found, but found very difficutl to implement.
http://msdn2.microsoft.com/en-us/library/aa289152(VS.71).aspx

http://www.ziggyware.com/readarticle.php?article_id=130

I would suggest just using a List<Point>. This would not only keep the order for you, but would also allow for easy iteration.

theTroll
I have thought about using List<> but it doesnt take long for it to become a mess.


1: Starting with root, Add all the points to a List<point>

2: create an index (one number for each point)
3: for each point add all lines connected with List<line>
for each line store 2 points it connects to (using index number)

Here it gets messy (travesing)
4: starting with root, check first line -> child point -> first line -> child etc until there are no more children or you hit the destination.
If I hit destination store(Points,length total)

Some of the lines and points should be set to false, but more then likely other children and lines will be using them.

what the graph will likely look like
http://www.leda-tutorial.org/en/unofficial/Pictures/SaarlandAndDual.png
Is there a formula you use for drawing the lines?

I have an idea but need more information.

theTroll
Reading the site how to make the graph but the baseball game is on and it is late, I will try to read the site when I get up and see if I can come up with something. I have an idea but need to make sure it will work.

theTroll
I first collect all points (vector2) on the map, make all the points connect with a line. (both stored in seperate List<>'s)

I then collect all the obsticals (squares / four lines). check if any of the of the point lines collide with the obstical lines if yes mark line as false.

draw all the lines that are still true.

thats as far as i got.

So first we get all points.

Next we connect ALL points with a line?

Then we start deleting the lines where they cross?

Do I have that correct?

theTroll
http://www.codeplex.com/quickgraph

Im currently trying to get familierized with this library. So you dont have to go on (for now anyways).

But i am still curious what your idea was.


What the graph may look like
Example
objects on the map
4 nodes, (vector2 x, y is being used).

2 obstacles, squares (vectore2 x, y, plus width and height being used)

I now have List<objects>
index 0 nodes index 1 obstacles

Create lines
Run 2 loops for nodes
List<List<line>>[0]add()
// every possible pair of nodes, i only record the vector2's,
//node isnt connected at this time with the line

// do the same with obstacles, each obstacle is made up of 4 lines

// do a collision test, each nodeline against each obstacle
// once a hit is detected the nodeline is made false.

print all the node and squares
print all the nodelines

(and again you dont have to do this, either way thanks for your help)

This topic is closed to new replies.

Advertisement