Alright, here is the idea.
A child of a parent node needs a combined matrix from the parent node.
A child of a parent node, can also be a parent node.
A parent node, doesn't have anything before it, so it has to create the combined matrix
A child node needs a combined matrix from a parent node, to create a new combined matrix
PROBLEM: The overridden virtual update function needs to take a local matrix, which is combined with the parents combined matrix, to make a new combined matrix. Problem lies within the fact that we now need to send this combined matrix to the child, via the update function, I can't do that! :\.
CODE:
Scene Node base class.
Code:
class CSceneNode
{
public:
CSceneNode() { }
virtual ~CSceneNode() { Destroy(); }
void Release() { delete this; }
virtual void Update()
{
for( std::list<CSceneNode*>::iterator i = m_lstChildren.begin();
i != m_lstChildren.end(); i++ )
{
(*i)->Update();
}
}
void Destroy()
{
for( std::list<CSceneNode*>::iterator i = m_lstChildren.begin();
i != m_lstChildren.end(); i++ )
(*i)->Release();
m_lstChildren.clear();
}
void AddChild( CSceneNode* pNode )
{
m_lstChildren.push_back(pNode);
}
protected:
// list of children
std::list<CSceneNode*> m_lstChildren;
};
Geometry Node Subclass
Code:
class CGeometryNode : public CSceneNode
{
public:
CGeometryNode(boost::weak_ptr<MS3DModel> Resource_Observer, float m[4][4])
{
Resource_Observer = Geometry;
for( int i = 0; i < 4; i++ )
for( int j = 0; j < 4; j++ )
LocalMatrix[i][j] = m[i][j];
}
~CGeometryNode() { }
void Update(float LocalMatrix[4][4])
{
// create combined matrix
// Draw Geometry Here!
CSceneNode::Update(); // need to send a new combined matrix to children to work with!!!
}
private:
float LocalMatrix[4][4];
float CombinedMatrix[4][4];
boost::weak_ptr<MS3DModel> Geometry;
};
Somehow I need to give all children access to the parent node's combine matrix.
Probably more of a design issue...