应用SoRayPickAction类的交互式程序

/*---------------------------------------------------------------------------------------------------------------------------- 
   
FUNCTION: 
            static void event_cb(void * ud, SoEventCallback * n)    事件响应函数
            static SoSeparator *pickedPointsSubGraph(void) 在鼠标点击处画一个点
            Main(int, char **argv);主函数按照场景示意图绘制场景 
     
PURPOSE: 利用线集节点(SoLineSet)绘制两个四边形的剖面。用鼠标在四边形上点击,在点击处画一个点,并在屏幕上输出所点击的点在笛卡尔坐标系下的坐标。
   
HISTORY:       Date:26/11/2007             Author:Shao Yanhong           
Comment: 该程序还有缺陷,就是在初始的绘制图中莫名其妙地多了一个点。目前还没有找到它出现的原因,望看到该程序的有心人可以,帮忙解决一下。当然,在以后的学习中,我也会多摸索,找出该程序的问题所在。
----------------------------------------------------------------------------------------------------------------------------------*/
#include <Inventor/Win/SoWin.h>
#include <Inventor/Win/viewers/SoWinExaminerViewer.h>
#include <Inventor/nodes/SoCoordinate3.h>
#include <Inventor/nodes/SoLineSet.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoVertexProperty.h>
#include <Inventor/SoPickedPoint.h>
#include <Inventor/actions/SoRayPickAction.h>
#include <Inventor/events/SoMouseButtonEvent.h>
#include <Inventor/nodes/SoEventCallback.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#include <Inventor/nodes/SoPickStyle.h>
#include <Inventor/nodes/SoPointSet.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoDrawStyle.h>

static SoCoordinate3 * pickpoints = NULL;                // 储存拾取点信息
static void event_cb(void * ud, SoEventCallback * n)    // 事件响应
{ 
    const SoMouseButtonEvent * mbe = (SoMouseButtonEvent *)n->getEvent();
    
    if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 &&
        mbe->getState() == SoButtonEvent::DOWN) 
    {
        SoWinExaminerViewer * viewer = (SoWinExaminerViewer *)ud;

        
        SoRayPickAction rp(viewer->getViewportRegion());//创建拾取的实例对象

         rp.setPoint(mbe->getPosition());
        
        rp.apply(viewer->getSceneManager()->getSceneGraph());//使用Open Inventor自带的隐含相机

        SoPickedPoint * point = rp.getPickedPoint();//获得拾取物体上的拾取点
        if (point == NULL) 
        {
            (void)fprintf(stderr, "/n** miss! **/n/n");
            return;
        }

        n->setHandled();
        
        //const SbVec3f& SoPickedPoint::getPoint() const [inline]:Returns the intersection point in world space 
        SbVec3f v = point->getPoint();                    // 点的坐标
        (void)fprintf(stdout, "point=<%f, %f, %f>/n",v[0], v[1], v[2]);

        // 在选取点处做个标记
        const int idx = pickpoints->point.getNum();
        //void SoMFVec3f::set1Value(int index, const SbVec3f &newValue ):Sets the index'th value in the 
        //array to newValue. The array will be automatically expanded, if necessary 
        pickpoints->point.set1Value(idx, v);
    }
}

//在鼠标点击处画一个点
//返回的分隔符节点SoSeparator中包括SoPickStyle,SoDrawStyle,SoCoordinate3,SoPointSet
static SoSeparator *pickedPointsSubGraph(void)
{
    SoSeparator * picksep = new SoSeparator;
    SoPickStyle * pickstyle = new SoPickStyle;
    pickstyle->style = SoPickStyle::UNPICKABLE; //使拾取动作对后面画的那个点无效,其默认值为SHAPE
    picksep->addChild(pickstyle);               //SHAPE表示可以对场景图中的形状物体上的点进行拾取。
    
    SoDrawStyle * drawstyle = new SoDrawStyle; //SoDrawStyle 的style 域默认值为FILLED
                                                  //FILLED 区域填充模式(默认值) 
    drawstyle->pointSize = 10;        //::pointSize Radius of points (for POINTS style). 
    picksep->addChild(drawstyle);
    
    pickpoints = new SoCoordinate3;
    picksep->addChild(pickpoints);
    picksep->addChild(new SoPointSet);
    
    return picksep;
}


int main(int argc, char **argv)
{
    HWND window = SoWin::init(argv[0]);
    
    SoWinExaminerViewer * viewer = new SoWinExaminerViewer(window);
    
    SoSeparator * root = new SoSeparator;
    root->ref();

    root->addChild(pickedPointsSubGraph());

    SoEventCallback * ecb = new SoEventCallback;
    ecb->addEventCallback(SoMouseButtonEvent::getClassTypeId(),event_cb, viewer);
    root->addChild(ecb);

    if (argc!=2) 
    {
        (void)fprintf(stderr, "/nSepecify an Inventor file as argument./n");
        return 1;
    }

    SoInput input;
    if (!input.openFile(argv[1])) {return 1;}

    SoSeparator *r =SoDB::readAll(&input);
    if (r==NULL) {return 1;    }
    root->addChild(r);

    viewer->setSceneGraph(root);
    viewer->setBackgroundColor(SbColor(0.92f, 0.92f, 0.92f));
    viewer->show();
    
    SoWin::show(window);
    SoWin::mainLoop();
    
    delete viewer;
    root->unref();
    return 0;    
}


 


project/settings/debugs/program arguments内填上11.txt
所使用的11.txt文件的内容为:
#Inventor V2.1 ascii

Separator{
    Separator{
         Material{
        diffuseColor 0.0 0.0 1.0
        ambientColor 1.0 0.8 0.8
    }
    Coordinate3{ point [1.0 2.0 1.0, 2.0 2.0 1.0,]}
        LineSet{ }
    }
    Separator{
        Material{
        diffuseColor 0.0 0.0 1.0
        ambientColor 1.0 0.8 0.8
        }
                         
        Coordinate3{ point [2.0 2.0 1.0, 2.0 2.0 2.0,]}
        LineSet{ }
   }
   Separator{
       Material{
        diffuseColor 0.0 0.0 1.0
        ambientColor 1.0 0.8 0.8
    }
        Coordinate3{ point [2.0 2.0 2.0, 1.0 2.0 2.0,]}
        LineSet{ }
}
   Separator{
       Material{
        diffuseColor 0.0 0.0 1.0
        ambientColor 1.0 0.8 0.8
    }
        Coordinate3{ point [1.0 2.0 2.0, 1.0 2.0 1.0,]}
        LineSet{ }
}
   Separator{
        Material{
        diffuseColor 0.0 1.0 1.0
        ambientColor 1.0 0.8 0.8
    }
        Coordinate3{ point [1.0 1.0 1.0, 2.0 1.0 1.0,]}
        LineSet{ }
}
   Separator{
        Material{
        diffuseColor 0.0 1.0 1.0
        ambientColor 1.0 0.8 0.8
    }
        Coordinate3{ point [2.0 1.0 1.0, 2.0 1.0 2.0,]}
        LineSet{ }
}
   Separator{
       Material{
        diffuseColor 0.0 1.0 1.0
        ambientColor 1.0 0.8 0.8
    }
        Coordinate3{ point [2.0 1.0 2.0, 1.0 1.0 2.0,]}
        LineSet{ }
}
   Separator{
       Material{
        diffuseColor 0.0 1.0 1.0
        ambientColor 1.0 0.8 0.8
    }
        Coordinate3{ point [1.0 1.0 2.0, 1.0 1.0 1.0,]}
        LineSet{ }
}

}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
系统根据B/S,即所谓的电脑浏览器/网络服务器方式,运用Java技术性,挑选MySQL作为后台系统。系统主要包含对客服聊天管理、字典表管理、公告信息管理、金融工具管理、金融工具收藏管理、金融工具银行卡管理、借款管理、理财产品管理、理财产品收藏管理、理财产品银行卡管理、理财银行卡信息管理、银行卡管理、存款管理、银行卡记录管理、取款管理、转账管理、用户管理、员工管理等功能模块。 文中重点介绍了银行管理的专业技术发展背景和发展状况,随后遵照软件传统式研发流程,最先挑选适用思维和语言软件开发平台,依据需求分析报告模块和设计数据库结构,再根据系统功能模块的设计制作系统功能模块图、流程表和E-R图。随后设计架构以及编写代码,并实现系统能模块。最终基本完成系统检测和功能测试。结果显示,该系统能够实现所需要的作用,工作状态没有明显缺陷。 系统登录功能是程序必不可少的功能,在登录页面必填的数据有两项,一项就是账号,另一项数据就是密码,当管理员正确填写并提交这二者数据之后,管理员就可以进入系统后台功能操作区。进入银行卡列表,管理员可以进行查看列表、模糊搜索以及相关维护等操作。用户进入系统可以查看公告和模糊搜索公告信息、也可以进行公告维护操作。理财产品管理页面,管理员可以进行查看列表、模糊搜索以及相关维护等操作。产品型管理页面,此页面提供给管理员的功能有:新增产品型,修改产品型,删除产品型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值