Another slant at this, I've created a transform type to inherit osg::Transform 
that lets me set by matrix and by position, attitude, scale. 


Code:

        class ExtendedTransform : public osg::Transform
        {
                public:

                        ExtendedTransform();

                        ExtendedTransform(const ExtendedTransform& tf,const 
osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
                                osg::Transform(tf,copyop),
                                m_matrixTransform(tf.m_matrixTransform)
                                {
                                }
                    

                        META_Node(osg, ExtendedTransform);

                        inline void setPosition(const osg::Vec3f& pos) 
                        { 
                                m_matrixTransform.setTrans(pos);
                                dirtyBound(); 
                        }
                        inline const osg::Vec3f& getPosition() const 
                        { 
                                return m_matrixTransform.getTrans(); 
                        }

                        inline void setAttitude(const osg::Quat& quat) 
                        { 
                                m_matrixTransform.setRotate(quat);
                                dirtyBound(); 
                        }
                        inline const osg::Quat& getAttitude() const 
                        { 
                                return m_matrixTransform.getRotate(); 
                        }
                
                        inline void setScale(const osg::Vec3f& scale) 
                        { 
                                osg::Vec3d tr = m_matrixTransform.getTrans();
                                osg::Quat rt = m_matrixTransform.getRotate();
                                m_matrixTransform.makeIdentity();
                                m_matrixTransform.preMultTranslate(tr);
                                m_matrixTransform.preMultRotate(rt);
                                m_matrixTransform.preMultScale(scale);
                                dirtyBound(); 
                        }
                        inline const osg::Vec3f& getScale() const 
                        { 
                                return m_matrixTransform.getScale(); 
                        }                       

                        inline const osg::Matrix & getMatrix() const
                        {
                                return m_matrixTransform;
                        }

                        inline void setMatrix(const osg::Matrix & matrix)
                        {
                                m_matrixTransform.set(matrix);
                        }

                        virtual bool computeLocalToWorldMatrix(osg::Matrix& 
matrix, osg::NodeVisitor* nv) const;
                        virtual bool computeWorldToLocalMatrix(osg::Matrix& 
matrix, osg::NodeVisitor* nv) const;


                protected :
                    
                        virtual ~ExtendedTransform() {}

                        osg::Matrixf m_matrixTransform;
        };




As you can see the get/set position, scale, rotation methods are pretty 
inefficient, however I won't actually be calling these very often (Usually from 
a textbox in the UI to directly manipulate the object). 

The implementation of computeLocalToWorldMatrix and computeWorldToLocalMatrix 
is similar to that in MatrixTransform.cpp in the OSG source. 

I also don't store an internal inverse matrix (Its computed on the fly). This 
is to keep the memory requirements for my ExtendedTransform down as I'm using 
these everywhere. 

Any thoughts on the above method to solve my problem? 

thank you for your time, 
Andrew

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=18306#18306





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to