Blehh, OOP is killing me..

This is a discussion on Blehh, OOP is killing me.. within the C++ Programming forums, part of the General Programming Boards category; Okay, so I set a "Parent" pointer in this function Code: CSceneNode * ParentNode; void SetParentNode(CSceneNode* Parent) { ParentNode = ...

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964

    Blehh, OOP is killing me..

    Okay, so I set a "Parent" pointer in this function
    Code:
    	CSceneNode * ParentNode;
    
    	void SetParentNode(CSceneNode* Parent)
    	{
    		ParentNode = Parent;
    	}
    This sets the class adding a child as the parent of the child it just created, like so...

    Code:
    	std::list<CSceneNode*> m_lstChildren;
    
    	void AddChild( CSceneNode* pNode )
    	{
    		pNode->SetParentNode(this);
    	    m_lstChildren.push_back(pNode);
    	}
    Here is where it gets funky..

    In the geometry node class, we need to access the parent of this geometry node's "combined matrix" variable. The parent of this node WILL have a combined matrix variable, but the BASE class does not.

    Like so:

    (Parent Node)
    Code:
    class CDOFNode : public CSceneNode
    {
    public:
    
    	CDOFNode(float m[4][4]) 
    	{
    		.....
    	}
    
    	~CDOFNode() { }
    
    	void Update()
    	{
    		.....
    	}
    
    	void Initialize( float m[4][4] )
    	{
    		.....
    	}
    
    private:
    	float LocalMatrix[4][4];
    	float CombinedMatrix[4][4];
    };
    See, this guy will be the parent of the geometry node, the geometry node will be in turn a parent to another DOF node..

    Here is the Geometry Node:

    Code:
    class CGeometryNode : public CSceneNode
    {
    public:
    
    	CGeometryNode(boost::weak_ptr<MS3DModel> Resource_Observer) 
    	{ 
    		.....
    	}
    
    	~CGeometryNode() { }
    
    	void Update()
    	{
    		..... // need to access parent->Combined matrix here!!!!!
    	}
    
    
    private:
    	boost::weak_ptr<MS3DModel> Geometry;
    	float CombinedMatrix[4][4];
    };
    Now you would think this is work, the DOF node DID create the geometry node, he IS the parent, but...

    The base SceneNode class does not have a combined matrix, and he shouldn't either!

    Code:
    class CSceneNode
    {
    public:
    	CSceneNode() { }
    
    	virtual ~CSceneNode() { ..... }
    
    	// deletes this node
    	void Release() { ...... }
    
    	// call update on all children
    	virtual void Update()
    	{
    		......
    	}
    
    	// recursively destroy all children and self
    	void Destroy()
    	{
    		.....
    	}
    
    	// add a child
    	void AddChild( CSceneNode* pNode )
    	{
    		.....
    	}
    
    	// Set the parent of the child
    	void SetParentNode(CSceneNode* Parent)
    	{
    		....
    	}
    
    protected:
    
    	// list of children
    	std::list<CSceneNode*> m_lstChildren;
    
    	// pointer to parent
    	CSceneNode * ParentNode;
    };
    So obviously, this spawns an error, CombinedMatrix is not a member of CSceneNode, this error is true, but in ALL cases, the DOF node will be a parent of a geometry node, thus this problem will never happen during run time!!

    What can I do?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    65
    You may create an object that is-a scene node and therefore has children, but does not have a combined matrix, so your logic fails in thinking that "in ALL cases, the DOF node will be a parent of a geometry node."

    Would mind elaborating on your design a little bit? From what you posted in the other thread I gathered that only a geometry node needs to have child nodes. Isn't that the case?

    Your problem arises from the fact that you cannot be sure that every object in the scene tree has a "combined matrix." The reason why you cannot be sure is because you haven't defined a way to access the combined matrix in the base class, CSceneNode. I think you should either declare a "combined matrix" in CSceneNode (not necessarily as a member, possibly as a virtual "get" function) or make CGeometryNode the base class.

    Did you have a look at the composite pattern like I suggested?

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Blehhh, I don't think the base class should have anything to do with matrices at all..

    Only the DOF..

    I know I could make this work pretty easily, but I can't seem to do it in a logical Manner....
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    65
    What is DOF?

    Usuallly in object oriented programming one designs the class model with some detail before starting to code so that problems like this wouldn't occur.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP flu
    By Hussain Hani in forum General Discussions
    Replies: 15
    Last Post: 06-27-2009, 02:02 AM
  2. Should OOP be any new language priority??
    By Hussain Hani in forum General Discussions
    Replies: 80
    Last Post: 06-13-2009, 10:56 AM
  3. Data Mapping and Moving Relationships
    By Mario F. in forum Tech Board
    Replies: 7
    Last Post: 12-14-2006, 09:32 AM
  4. recommendation for a good OOP book
    By Mario F. in forum C++ Programming
    Replies: 2
    Last Post: 06-15-2006, 04:28 PM
  5. OOP Theory Question
    By Zeusbwr in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2005, 07:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21