Original Post
Hi all, just a quick question to wonder if I'm doing this correctly? I have a TerrainQuad class, which is derived from a QuadTreeNode class. The TerrainQuad basically is a quad tree node that includes geometric details, such as vertex positions, normals etc. Now Im trying to call the QuadTree Traverse() function, that accepts QuadTreeNode*s as parameters. However, when I pass in a CTerrainQuad into it, it doesn't in turn use the appropriate CTerrainQuad methods that are used in the traversal, instead uses the CQuadTreeNode's method; so I am having to write a new method in the CTerrainQuad and make the parent virtual so that it does that. Is that right? I mean I can avoid this problem by, as I said, writing new methods, and basically casting everything to a CTerrainQuad... which I get the impression is very wrong? also! Is this a bad thing to do? (same situation) Any rough pointers in the right direction, or useful links on this topic (I'm aware of the basics of inheritance) would be much appreciated. Thanks in advance, Nathan -- edit made class names consistent -- [Edited by - Striken on November 3, 2004 11:30:41 AM]
//,,,,,,,,,,,,,,,,,,,,,,,,
//various header files...
class CQTree{
public:
void Traverse(CQTreeNode* node, ...) {
if(haschildren) {
Traverse(node->child(x), ...);
...
}
if(condition)
GenChildren(node); //this will call CQTreeNode::GenChildren() not CTerrainQuad::GenChildren()
}
}
class CQTreeNode{
public:
virtual void GenChildren(CQTreeNode* parent);
}
class CTerrain:public CQTree{
public:
}
class CTerrainQuad:public CQTreeNode{
public:
virtual void GenChildren(CTerrainQuad* parent); //??
}
//in CTerrainQuad - derived CQuadTreeNode:
//using CQuadTreeNode::Parent()
somevert.x = ((CTerrainQuad*)Parent())->Vertex(0,0);
somevert.x = ((CTerrainQuad*)Parent())->Vertex(0,1);