Hi Mukund,
im pretty new to OSG. Well i tried inheriting Geode and MatrixTransform into a
class(RotatePyramid) as follows:
Code:
class RotatePyramid : public osg::Geode, public osg::MatrixTransform {
};
osg::ref_ptr<RotatePyramid> pyramidGeode = new RotatePyramid;
int main()
{
osg::ref_ptr<osg::Group> root = new osg::Group;
... // code here
root->addChild(pyramidGeode); // error here
}
Error: 'argument' : ambiguous conversions from 'RotatePyramid *' to 'osg::Node
*'
Can anyone please suggest how i can rectify this?
This is a C++ question. Since Geode and MatrixTransform both inherit
(indirectly for MatrixTransform) from Node, your derived class has
Node's members 2 times. In C++, if you *really* want to do this, you can
do it (I forget if it's with private/protected inheritance or virtual
inheritance). But I don't recommend you do this. In any case, it
wouldn't have had the effect you were likely trying to do, which I think
is that you want a Geode that you can transform. To do this you would
have had to (at very least) parent the Geode part to the MatrixTransform
part of your class. And things just get more confusing from there.
In your case, why don't you just make your RotatePyramid class inherit
MatrixTransform, and have a Geode member whose important methods you'd
give access to (with simple forwarding members), something like:
class RotatePyramid : public osg::MatrixTransform
{
public:
RotatePyramid(...) : m_geode(new osg::Geode)
{ this->addChild(m_geode); }
void addDrawable(osg::Drawable* drawable)
{ m_geode->addDrawable(drawable); }
unsigned int getNumDrawables() const
{ return m_geode->getNumDrawables(); }
// etc ...
protected:
// Note: No need to store this in a ref_ptr since it will be ref
// counted by the MatrixTransform's children list.
osg::Geode* m_geode;
};
The only drawback I can see with this approach is that you won't be able
to pass RotatePyramid to functions that take an osg::Geode explicitly.
But in that case, you can have an asGeode() method in RotatePyramid that
will return m_geode, and then use that in those cases.
It all comes down to preference and code readability IMHO. If you can do
the same thing without using less-known features of the language, I
would personally prefer that route. Unless there are very compelling
advantages, but in this case I don't see any.
Hope this helps,
J-S
--
______________________________________________________
Jean-Sebastien Guay [email protected]
http://www.cm-labs.com/
http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org