A bit of a background, I am working on a home brew engine for learning and hobby purposes, based on XNA, though thats not really relevant for this question, I am faced with a bit of a design dilemma:
The engine is split in different systems, that manage hierarchies of objects, in this problem GUI elements, Collision structures and Nested transformations are the hierarchies in conflict, all three systems use nTrees as the main object structure, i.e. a GUIs, Collision structures and transformations are composed by trees of those kinds of objects.
When a child is added to an object, the transformation will reflect the same hierarchy, the transformation of a child GUI will be itself a child of that GUI's parent's transformation. Thus when the parent is transformed all children are affected accordingly.
It works very well for the composition but collision checking, for mouse interaction in this case, presents a problem.
Collision structures do the same thing, a collision structure might be complex, and each component of the tree has its own transformation, and the hierarchy of that transformation reflects the hierarchy of the collision tree.
Hierarchy allows collision to only turn true when the check between two leaf nodes is true.
Since collisions are a component of a GUI, their transformation is added to the transformation tree of the GUI, at first I made the collision structure reflect the GUI structure in the same way transformation did, but that resulted in collision transofrmations having two parents, one from the owner gui and one from the parent collision body. So I had to stop doing that, now the collision structure of a GUI is independent of that of the parent.
When trying to identify the gui under the mouse pointer now, I end up having multiple results, because if the mouse is over a button, both the button and the parent gui it belongs to are under the mouse, since their collision bodies do not belong to the same hierarchy.
Giving no collision body to the parent GUI simplifies the problem, but it forces the parent to be non interactive, so its not a good solution. I'm about to try having the parent pass the collision event to its childs when handling it, but I was wondering if someone can think of a more elegant solution.
Hierarchy conflict
Started by NEXUSKill, Nov 02 2012 08:02 AM
1 reply to this topic
#1 Members - Reputation: 308
Posted 02 November 2012 - 08:02 AM
Game making is godlike
LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272
LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272
Sponsor:
#2 Members - Reputation: 427
Posted 02 November 2012 - 02:14 PM
Your existing solution seems to be the only viable one. Basically, your system should be set up so that initially you're checking the cursor against the root node and if it's a hit, then check the cursor against the root's children. This should happen recursively until you no longer have children nodes that are 'colliding' with the cursor, at which point you can either have a node respond whether or not it has children that are 'hit' by the cursor OR only responds (perform some function) if no children are 'hit'.
I hope that made sense. The point is that a node should react to a hit if none of its children are hit, otherwise the child should react (unless it has further children that might be hit as well)..
I hope that made sense. The point is that a node should react to a hit if none of its children are hit, otherwise the child should react (unless it has further children that might be hit as well)..






