Question

in my Silverlight 3 application, I display a tree. A self made user control is used for the treenodes, the LineArrow object for the connections. After initial displaying the tree, I want the nodes to move by the following "physical properties"

  • there is a gravitational force, that pulls the node down
  • there is a force vector to its parent
  • it's children draws it to their middle

Naturally, my User Controls will overlap soon. But I do not want them to overlap. In physics terms, I want them to be solid objects and enforce the physical rule that no 2 objects can inhabit the same space.

Any suggestions how to tackle this problem? I do not want to use a physics engine like farseer for this, because the described part is the only physics to be used within my project.

Thanks in advance,
Frank

Was it helpful?

Solution

You can model them as 'nearly solid' objects simply by adding a very large force between them whenever they overlap. Calculate the center to center vector, normalize it, maybe multiply by the overlap and then apply that as a force to each object.

Even if you don't use the full Farseer library you may still find some useful classes in it like Vector2.

OTHER TIPS

Are your controls of a squarish shape? Or can you generate bounding boxes? If so, you could create a System.Windows.Rect struct for each one, and use the Rect.Insersect method to test intersection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top