How do I change a hierarchy without passing it a root element?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: How do I change a hierarchy without passing it a root element?

  1. #1
    Join Date
    Dec 2010
    Posts
    648

    How do I change a hierarchy without passing it a root element?

    I got a mesh which has an edge with a specific transformation (translation + orientation).
    When this configuration/transformation is changed, its neighbours are to be updated.
    This structure is kept inside a tree so that when a root "frame" is passed to a method like UpdateHierachy,
    the mesh will recursively update itself.
    If, I don't pass this method the root element, which is in my case, how do I change the rest of the structure?
    The reason to do this is because I want to say move the door, the windows and furniture will move along with it
    , get the idea? I think you do..

    Thanks
    Jack
    Last edited by lucky6969b; August 6th, 2013 at 07:20 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,605

    Re: How do I change a hierarchy without passing it a root element?

    I guess your "UpdateHierachy" method has to work the same way for every node you pass in, whether it is the root or any other one.
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2010
    Posts
    648

    Re: How do I change a hierarchy without passing it a root element?

    The thing I am worried about is UpdateHierachy is only able to scan downwards from the top of the tree, and is unable to go back up one level.

  4. #4
    Join Date
    Nov 2002
    Location
    Sofia, Bulgaria
    Posts
    661

    Re: How do I change a hierarchy without passing it a root element?

    Why would it need to go up?

    While it is true that each of your nodes can have a pointer to its parent (and use it go "up a level"), a trivial tree traverse doesn't need it,

    Consider this dfs:

    Code:
    void Node::UpdateHierachy(const Matrix& transform)
    {
        UpdateSelf(transform);
        
        for(auto child : m_children)
        {
            child.UpdateHierachy(transform);
        }
    }
    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames

  5. #5
    Join Date
    Dec 2010
    Posts
    648

    Re: How do I change a hierarchy without passing it a root element?

    Code:
    House
      Window
          Window Frame
          Window Glass
      Door
          Door Frame
          Door Body
    If I change the transformation of Door Frame, how can I change the rest of the transformation of the house parts?
    Since House and Window cannot be accessed by UpdateHierarchy?
    UpdateHierarchy(DoorFrame);

    will not update the transformation of other parts of the house.
    Thanks
    Jack

  6. #6
    Join Date
    Nov 2002
    Location
    Sofia, Bulgaria
    Posts
    661

    Re: How do I change a hierarchy without passing it a root element?

    Er... Why should it? This should work in reverse order. When you change the transformation of the door, the handle and other parts should be changed and not vice versa. Why should changing the position of the door, do anything to the position of the house?
    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames

  7. #7
    Join Date
    Dec 2010
    Posts
    648

    Re: How do I change a hierarchy without passing it a root element?

    I have to tell the whole story, mine is a warehouse simulation, when a lorry comes in, it has to park exactly to the location of the dock leveler,
    However, this has to be pre-computed where the dock leveler is and work backwards to calculate the position of the truck.
    So I got a transformation of the dock leveler, match it to the trailer position, and work backwards to the position of other parts of the truck. Note that some parts of the truck aren't necessarily the children of this trailer, but the parent of it
    Last edited by lucky6969b; August 7th, 2013 at 06:26 AM.

  8. #8
    Join Date
    Apr 1999
    Posts
    27,446

    Re: How do I change a hierarchy without passing it a root element?

    Quote Originally Posted by lucky6969b View Post
    I have to tell the whole story, mine is a warehouse simulation, when a lorry comes in, it has to park exactly to the location of the dock leveler,
    So does you application design take in consideration all of your requirements? If it does, then what's the problem? If it doesn't, then you need to redesign your application.

    Regards,

    Paul McKenzie

  9. #9
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,016

    Re: How do I change a hierarchy without passing it a root element?

    Quote Originally Posted by lucky6969b View Post
    I have to tell the whole story, mine is a warehouse simulation, when a lorry comes in, it has to park exactly to the location of the dock leveler,
    However, this has to be pre-computed where the dock leveler is and work backwards to calculate the position of the truck.
    So I got a transformation of the dock leveler, match it to the trailer position, and work backwards to the position of other parts of the truck. Note that some parts of the truck aren't necessarily the children of this trailer, but the parent of it
    I concur with what others have said: it seems that the control flow of your program is conflicting with the design of your data structure. That is, if the truck is modeled as the parent of the trailer and the trailer does not know about the truck, then it should be the truck that moves the trailer and not the other way round.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center