Hi Robert,

No problems. Files attached. Let me know if there are any issues.

Cheers,

Paul 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Robert Osfield
> Sent: Saturday, 1 November 2008 9:31 PM
> To: OpenSceneGraph Submissions
> Subject: Re: 
> [osg-submissions]Dragger::setupCustomGeometry(osg::MatrixTrans
> form* customxform)
> 
> Hi Paul,
> 
> Could you post whole changed files, copy and paste in a email 
> is not appropriate form as it's very prone to errors.
> 
> Thanks,
> Robeert.
> 
> On Sat, Nov 1, 2008 at 11:14 AM, Paul McIntosh 
> <[EMAIL PROTECTED]> wrote:
> > Hi All,
> >
> > This is my first submission so hopefully it will make sense...
> >
> > This is a very simple but powerful change to the osgManipulator 
> > "Dragger" class, it allows you to specify your own custom 
> geometry for 
> > a dragger when you create it. The actual osg changes are 
> very simple, 
> > but I have also included an example of how to use it 
> (because that is 
> > the hardest bit). I think the how to use comments should be 
> added to 
> > the Dragger code somewhere (Dragger.cpp?).
> >
> >
> > "Dragger"
> >
> > /** Setup custom geometry for dragger. */ void 
> > setupCustomGeometry(osg::MatrixTransform* customxform);
> >
> >
> > "Dragger.cpp"
> >
> > /** Setup custom geometry for dragger. */ void 
> > Dragger::setupCustomGeometry(osg::MatrixTransform* customxform) {
> >        addChild(customxform);
> > }
> >
> > "How to use"
> >
> > /* Here is an example of using setupCustomGeometry // As 
> before create 
> > the type of dragger that you need dragger = new 
> > osgManipulator::Translate2DDragger();
> >
> > // however instead of calling "dragger->setupDefaultGeometry();"
> > // create your own geometry to suit your task (refer to
> > setupDefaultGeometry() for hints)
> > // an example of a "box" dragger looks like...
> > osg::ref_ptr<osg::MatrixTransform> customDraggerxform = new 
> > osg::MatrixTransform; osg::ref_ptr<osg::Geode> customDraggerGeode
= 
> > new osg::Geode; osg::ref_ptr<osg::Box> box = new osg::Box 
> > (osg::Vec3(0.0f,0.0f,0.0f), 400.0f, 2.0f, 400.0f); 
> > osg::ref_ptr<osg::Drawable> drawable = new 
> > osg::ShapeDrawable(box.get()); 
> > //osgManipulator::setDrawableToAlwaysCull(*drawable); // 
> you can make 
> > draggers invisible too
> > customDraggerGeode->addDrawable(drawable.get());
> > customDraggerxform->addChild(customDraggerGeode.get());
> >
> > // once you have your geometry, pass it to the dragger to 
> use as the 
> > pick geometry
> > dragger->setupCustomGeometry(customDraggerxform.get());
> > */
> >
> > Cheers,
> >
> > Paul
> > --
> > Paul McIntosh
> > www.internetscooter.com
> >
> > _______________________________________________
> > osg-submissions mailing list
> > [email protected]
> > 
>
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscene
> > graph.org
> >
> _______________________________________________
> osg-submissions mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-o
> penscenegraph.org
> 

Attachment: Dragger
Description: Binary data

/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.

#include <osgManipulator/Dragger>
#include <osg/Material>

using namespace osgManipulator;

PointerInfo::PointerInfo():
    _nearPoint(osg::Vec3()),
    _farPoint(osg::Vec3()),
    _eyeDir(osg::Vec3(0,0,1))
{
    _hitIter = _hitList.begin();
}

bool PointerInfo::contains(const osg::Node* node) const
{
    if (node && _hitIter!=_hitList.end()) return 
std::find((*_hitIter).first.begin(), (*_hitIter).first.end(), node) != 
(*_hitIter).first.end();
    else return false;
}

bool PointerInfo::projectWindowXYIntoObject(const osg::Vec2& windowCoord, 
osg::Vec3& nearPoint, osg::Vec3& farPoint) const
{
    nearPoint = osg::Vec3(windowCoord.x(),windowCoord.y(),0.0f)*_inverseMVPW;
    farPoint = osg::Vec3(windowCoord.x(),windowCoord.y(),1.0f)*_inverseMVPW;

    return true;
}

Dragger::Dragger() : _commandManager(0)
{
    _parentDragger = this;
    getOrCreateStateSet()->setDataVariance(osg::Object::DYNAMIC);
}

Dragger::~Dragger()
{
}


bool CompositeDragger::handle(const PointerInfo& pi, const 
osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
    // Check if the dragger node is in the nodepath.
    if (!pi.contains(this))
        return false;

    for (DraggerList::iterator itr=_draggerList.begin(); 
itr!=_draggerList.end(); ++itr)
    {
        if ((*itr)->handle(pi, ea, aa))
            return true;
    }
    return false;
}

bool CompositeDragger::containsDragger( const Dragger* dragger ) const
{
    for (DraggerList::const_iterator itr = _draggerList.begin(); itr != 
_draggerList.end(); ++itr)
    {
        if (itr->get() == dragger) return true;
    }
    return false;
}

CompositeDragger::DraggerList::iterator CompositeDragger::findDragger( const 
Dragger* dragger )
{
    for (DraggerList::iterator itr = _draggerList.begin(); itr != 
_draggerList.end(); ++itr)
    {
        if (itr->get() == dragger) return itr;
    }
    return _draggerList.end();
}

bool CompositeDragger::addDragger(Dragger *dragger)
{
    if (dragger && !containsDragger(dragger))
    {
        _draggerList.push_back(dragger);
        return true;
    }
    else return false;

}

bool CompositeDragger::removeDragger(Dragger *dragger)
{
    DraggerList::iterator itr = findDragger(dragger);
    if (itr != _draggerList.end())
    {
        _draggerList.erase(itr);
        return true;
    }
    else return false;

}
void CompositeDragger::setCommandManager(CommandManager* cm)
{
    for (DraggerList::iterator itr = _draggerList.begin(); itr != 
_draggerList.end(); ++itr)
    {
        (*itr)->setCommandManager(cm);
    }
    Dragger::setCommandManager(cm);
}

void CompositeDragger::setParentDragger(Dragger* dragger)
{
    for (DraggerList::iterator itr = _draggerList.begin(); itr != 
_draggerList.end(); ++itr)
    {
        (*itr)->setParentDragger(dragger);
    }
    Dragger::setParentDragger(dragger);
}

class ForceCullCallback : public osg::Drawable::CullCallback
{
    public:
        virtual bool cull(osg::NodeVisitor*, osg::Drawable*, osg::State*) const
        {
            return true;
        }
};

void osgManipulator::setDrawableToAlwaysCull(osg::Drawable& drawable)
{
    ForceCullCallback* cullCB = new ForceCullCallback;
    drawable.setCullCallback (cullCB);    
}

void osgManipulator::setMaterialColor(const osg::Vec4& color, osg::Node& node)
{
    osg::Material* mat = 
dynamic_cast<osg::Material*>(node.getOrCreateStateSet()->getAttribute(osg::StateAttribute::MATERIAL));
    if (! mat)
    {
        mat = new osg::Material;
        mat->setDataVariance(osg::Object::DYNAMIC);
        node.getOrCreateStateSet()->setAttribute(mat);
    }
    mat->setDiffuse(osg::Material::FRONT_AND_BACK, color);
}


void Dragger::setupCustomGeometry(osg::MatrixTransform* customxform)
{
        addChild(customxform);

        /* Here is an example of using setupCustomGeometry 
        // As before create the type of dragger that you need dragger = new 
osgManipulator::Translate2DDragger();

        // however instead of calling "dragger->setupDefaultGeometry();" 
        // create your own geometry to suit your task (refer to 
setupDefaultGeometry() for hints) 
        // an example of a "box" dragger looks like...
        osg::ref_ptr<osg::MatrixTransform> customDraggerxform = new 
osg::MatrixTransform; 
        osg::ref_ptr<osg::Geode> customDraggerGeode = new osg::Geode; 
        osg::ref_ptr<osg::Box> box = new osg::Box (osg::Vec3(0.0f,0.0f,0.0f), 
400.0f, 2.0f, 400.0f); 
        osg::ref_ptr<osg::Drawable> drawable = new 
osg::ShapeDrawable(box.get()); 
        //osgManipulator::setDrawableToAlwaysCull(*drawable); // you can make 
draggers invisible too
        customDraggerGeode->addDrawable(drawable.get());
        customDraggerxform->addChild(customDraggerGeode.get());

        // once you have your geometry, pass it to the dragger to use as the 
pick geometry
        dragger->setupCustomGeometry(customDraggerxform.get());
        */

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

Reply via email to