zoukankan      html  css  js  c++  java
  • osg fbx模型点击节点,对应节点染色

    class CPickHandler :public osgGA::GUIEventHandler
    {
    public:
        CPickHandler(osgViewer::Viewer *viewer) :mViewer(viewer) {}
        virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
        {
            switch (ea.getEventType())
            {
            //case osgGA::GUIEventAdapter::PUSH:
            case osgGA::GUIEventAdapter::DOUBLECLICK:
                if (ea.getButton() == 1)
                {
                    Pick(ea.getX(), ea.getY());//可通过事件ea获得鼠标点击的坐标  
                }
                return true;
            }
            return false;
        }
    protected:
        void Pick(float x, float y)
        {
            osgUtil::LineSegmentIntersector::Intersections intersections;//声明一个相交测试的结果集  
            if (mViewer->computeIntersections(x, y, intersections))//利用view的computerIntersection函数来测试屏幕与场景相交结果存入到结果集中  
            {
                osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
                for (; hitr != intersections.end(); hitr++)
                {
                    if (!hitr->nodePath.empty() && !(hitr->nodePath.back()->getName().empty()))
                    {
                        
                        const osg::NodePath& np = hitr->nodePath;
                        //for (int i = np.size() - 1; i >= 0; --i)
                        //{
                            osg::Node *sc = hitr->nodePath.at(np.size() - 1);
                            //将场景中的模型动态转换为Scribe类型,如果场景的模型中有Scribe节点则返回的是实际的模型Scribe对象  
                            //osgFX::Scribe *sc = dynamic_cast<osgFX::Scribe*>(np[i]);
                            //osg::Node *sc = dynamic_cast<osg::Node*>(np[i]);
                            if (sc != NULL)//如果找到相应的sc,则隐藏起来  
                            {
                                //if (sc->getNodeMask() != 0)
                                //{
                                //    sc->setNodeMask(0);
                                //}
                                setNodeStateset(sc);
                            }
                        //}
                    }
                }
            }
        }
        osgViewer::Viewer *mViewer;
    };

  • 相关阅读:
    Linux下的文件权限
    启动memcached服务器并检查memcached是否启动,关闭memcached
    MySQL的mysqldump工具的基本用法
    MemAdmin
    不同服务器数据库之间的数据操作
    公用js
    AspNetPager分页控件的使用
    平台帮助
    触发器、游标
    jQuery增删改查
  • 原文地址:https://www.cnblogs.com/herd/p/11148008.html
Copyright © 2011-2022 走看看