3D项目处理点选操作步骤
#ifdef _DEBUG
#pragma comment(lib,"osgGAd.lib")
#pragma comment(lib,"osgViewerd.lib")
#pragma comment(lib,"osgDBd.lib")
#pragma comment(lib,"OpenThreadsd.lib")
#pragma comment(lib,"osgd.lib")
#pragma comment(lib,"osgWidgetd.lib")
#pragma comment(lib,"osgTextd.lib")
#pragma comment(lib,"osgManipulatord.lib")
#pragma comment(lib,"osgUtild.lib")
#pragma comment(lib,"osgParticled.lib")
#else
#pragma comment(lib,"osgGA.lib")
#pragma comment(lib,"osgViewer.lib")
#pragma comment(lib,"osgDB.lib")
#pragma comment(lib,"OpenThreads.lib")
#pragma comment(lib,"osg.lib")
#pragma comment(lib,"osgWidget.lib")
#pragma comment(lib,"osgText.lib")
#pragma comment(lib,"osgManipulator.lib")
#pragma comment(lib,"osgUtil.lib")
#pragma comment(lib,"osgParticle.lib")
#endif
#include <osgViewer/Viewer>
#include <osgGA/GUIEventHandler>
#include <osg/Group>
#include <osg/MatrixTransform>
#include <osg/Material>
#include <osgDB/ReadFile>
#include <osgUtil/LineSegmentIntersector>
#include <osg/ShapeDrawable>
#include <osgText/Text>
#include <vector>
osg::ref_ptr<osg::Node> cow;
class CPickHandler : public osgGA::GUIEventHandler{
osgViewer::Viewer * mViewer;
osg::Group * mGroup;
osg::Node * lastSelect;
public:
CPickHandler(osgViewer::Viewer * viewer, osg::Group *group) :mViewer(viewer),mGroup(group),lastSelect(){}
virtual bool handle(const osgGA::GUIEventAdapter & ea, osgGA::GUIActionAdapter & aa){
switch(ea.getEventType()){
case(osgGA::GUIEventAdapter::PUSH):{
if(lastSelect){
//osg::StateSet * state = lastSelect->getOrCreateStateSet();
//state->setMode(GL_BLEND, osg::StateAttribute::ON);
/*osg::ref_ptr<osg::Material> material = new osg::Material();
material->setTransparency(osg::Material::FRONT_AND_BACK, 1.0);
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0,0.0,0.0,1.0));
alarmSphere->getOrCreateStateSet()->setAttributeAndModes(material,osg::StateAttribute::ON);*/
//osg::Material * mtrl = dynamic_cast<osg::Material *>(state->getAttribute(osg::StateAttribute::MATERIAL));
//mtrl->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0, 1.0, 1.0, 1.0));
//state->setAttributeAndModes(mtrl, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
//state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
lastSelect = ;
}
Pick(ea.getX(),ea.getY()); //获得单击的鼠标坐标
}
return true;
}
return false;
}
protected:
void Pick(float x, float y){ 在pick函数中写触发函数
osgUtil::LineSegmentIntersector::Intersections intersections;
if(mViewer->computeIntersections(x, y, intersections)){
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin(); hitr!= intersections.end(); ++hitr){
if(!hitr->nodePath.empty() && !(hitr->nodePath.back()->getName().empty())){
const osg::NodePath& np = hitr->nodePath;
for(int i = np.size() - ; i >= ; --i){
osg::Node* nd = dynamic_cast<osg::Node *> (np[i]);
if(nd){
//std::cout<< "************"<<std::endl;
std::cout << nd->getName() <<std::endl;
std::cout << np.size() <<std::endl;
if(nd->getName()=="Mesh12 Group4 Group1 Model"||nd->getName() == "Mesh18 Group6 Group1 Model"||nd->getName() == "Mesh6 Group2 Group1 Model"||nd->getName() == "Mesh16 Group6 Group1 Model"||nd->getName() == "Mesh10 Group4 Group1 Model"||nd->getName() == "Mesh4 Group2 Group1 Model"){
//osg::StateSet * state = nd->getOrCreateStateSet();
//state->setMode(GL_BLEND, osg::StateAttribute::ON);
//osg::Material *mtrl = dynamic_cast<osg::Material *>(state->getAttribute(osg::StateAttribute::MATERIAL));
//if(!mtrl){
//mtrl = new osg::Material;
//}
//osg::ref_ptr<osg::Material> material = new osg::Material();
//material->setTransparency(osg::Material::FRONT_AND_BACK, 0.5);
//material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0,0.0,0.0,1.0));
//alarmSphere->getOrCreateStateSet()->setAttributeAndModes(material,osg::StateAttribute::ON);
////nd->setNodeMask(false);
//mtrl->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0, 0.0, 0.0, 1.0));
//state->setAttributeAndModes(mtrl, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
//state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
osg::Vec3 eye, center, up; //改变视角代码段
center = cow->computeBound()._center;
eye = center;
eye[] += cow->computeBound()._radius * ;
up.set( .f, .f, .f );
osg::Matrix mt;
mt.makeLookAt( eye, center, up );
mViewer->getCameraManipulator()->setByInverseMatrix( mt );
lastSelect = nd;
}
return ;
}
}
}
}
}
return ;
}
};
void main(){
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Group> root = new osg::Group();
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
cow = osgDB::readNodeFile("D:\\information of buaa\\LAST CHANCE\\lab\\NewModels\\toUse\\pipelineTeam_3_boiler2\\pipelineTeam1.ive");
//osg::ref_ptr<osg::Node> cow = osgDB::readNodeFile("cow.osg");
cow->setName("officeBuilding");
mt->addChild(cow);
mt->setName("officeBuilding");
root->addChild(mt);
//root->getChild(0);
//std::cout<< root->getChild(2)->getName() << std::endl;
/*osg::ref_ptr<osg::MatrixTransform> mtRobot = new osg::MatrixTransform;
osg::ref_ptr<osg::Node> robot = osgDB::readNodeFile("robot.osg");
mtRobot->setMatrix(osg::Matrix::translate(20,0,0));
robot->setName("robot");
mtRobot->addChild(robot);
root->addChild(mtRobot);*/
//std::cout << root->getChild(0)->getName() << std::endl;
//osg::ref_ptr<osg::Plane> Plane (new osg::Plane());
/*osg::ShapeDrawable *shapeBall=new osg::ShapeDrawable(new osg::Box(mt->computeBound()._center, mt->computeBound()._radius/3, mt->computeBound()._radius/10, mt->computeBound()._radius/3));
osg::ref_ptr<osg::Material> material = new osg::Material();
material->setTransparency(osg::Material::FRONT_AND_BACK, 1.0);
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0,0.0,0.0,1.0));
alarmSphere->getOrCreateStateSet()->setAttributeAndModes(material,osg::StateAttribute::ON);
alarmSphere->getOrCreateStateSet()->setMode(GL_BLEND,osg::StateAttribute::ON);
alarmSphere->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
alarmSphere->addDrawable(shapeBall);
root->addChild(alarmSphere);
*/
viewer.setSceneData(root.get());
viewer.addEventHandler(new CPickHandler(&viewer, root));
viewer.realize();
viewer.run();
return ;
}
3D项目处理点选操作步骤的更多相关文章
- oa项目环境搭建的操作步骤详解
dto:多表关联查询用单独建一个类,把查询数据放dto即可 vo:是view的缩写.单独定义一个类
- 将项目Demo上传到Github上的操作步骤
之前我有很多代码直接上传到了CSDN上,主要是因为操作方便,今天我就说说将源码Demo上传到Github上的操作步骤. 首先,你要先确定自己在Github上有自己的账户名,账户邮箱和密码.如果没有可以 ...
- Windows2008 R2上完全卸载Oracle操作步骤
Windows2008 R2上完全卸载Oracle操作步骤 1.关闭Oracle所有的服务,按[win+R]运行[services.msc]找到所有Oracle开头的服务,点击停止. 2.使用Orac ...
- Windows7上完全卸载Oracle 12c操作步骤
注:本文来源于:< Windows7上完全卸载Oracle 12c操作步骤 > 1.关闭Oracle所有的服务,按[win+R]运行[services.msc]找到所有Oracle开头的 ...
- MFC绘图基础——上机操作步骤
一.上机之前的介绍 软件环境:VC++6.0 目的:熟悉基本的MFC框架搭建和了解界面 二.MFC上机操作步骤 1,在Windows桌面上运行VC++6.0. 2,新建项目工程文件. 3,在MFC 应 ...
- Windows2008 R2上完全卸载Oracle操作步骤(转)
最近现场项目,碰到了好几次oracle数据库被损坏,而且无法恢复的问题,没办法,只好卸载重装了.oracle卸载确实麻烦,都是从网上查的方法, 为了方便以后查询,在此就做一下记录. Windows20 ...
- 《Asp.Net Core3 + Vue3入坑教程》-Net Core项目搭建与Swagger配置步骤
简介 <Asp.Net Core3 + Vue3入坑教程> 此教程仅适合新手入门或者前后端分离尝试者.可以根据图文一步一步进操作编码也可以选择直接查看源码.每一篇文章都有对应的源码 教程后 ...
- 物理机连接虚拟机中的数据库及Windows添加防火墙允许端口详细操作步骤
公司项目中因为会使用到SQL server数据库,但是自己电脑无论安装2008R2或者2014版本都不成功,我想可能是和之前安装的一些Windows的软件存在冲突. 于是便单独创建了一台虚拟机,在虚拟 ...
- ABP创建数据库操作步骤
1 ABP创建数据库操作步骤 1.1 SimpleTaskSystem.Web项目中的Web.config文件修改数据库配置. <add name="Default" pro ...
随机推荐
- 反射消除String类对象的不可变特性
大家都知道,在JAVA中字符串一旦声明就不可改变,如果尝试修改字符串的内容,将会重新实例化一个新的字符串对象,这也是为了安全性和效率. 由于字符串在程序之中被大量使用,所以JAVA引入了一个字符串常量 ...
- 消息机制JMS
消息机制JMS http://wenku.baidu.com/link?url=5FiNu_HP3lUFKhePmfCUPE09DV_f9-tsQ4NpWtKxHYphxAglzsjg3XSM8Sz6 ...
- c++11: <thread>学习
<thread>头文件中包含thread类与this_thread命名空间,下面逐一介绍. thread类 1. 构造函数 (1)默认构造函数 thread() noexcept; 默认构 ...
- Python 自带IDLE中调试程序
在vs2013下调试过Python,今天试了下使用自带IDLE调试,相比而言后者效果不好. 记录一下 http://q.cnblogs.com/q/35869/ 在“Python Shell”窗口中单 ...
- Python成长之路第一篇(2)-初识列表和元组
可以将列表和元组当成普通的“数组”,他能保存任意数量任意类型的Python对象,和数组一样都是通过数字0索引访问元素,列表和元组可以存储不同类型的对象,列表和元组有几处重要区别.列表元素用([])包括 ...
- 用python开发简单ftp程序
根据alex老师视频开发的简单ftp程序,只能实现简单的get功能 ftp客户端程序: #!/usr/bin/env python #_*_ coding:utf-8 _*_ import socke ...
- leetcode算法刷题(四)——动态规划(二)
又到了晚上,动态规划,开刷! 第121题 Best Time to Buy and Sell Stock 题目的意思:给予一个数组price,表示特定股票在某天的股价,里面第i个数表示第i天的价格.只 ...
- OpenCV2.4.9+VS2012安装与配置
需要下载并安装Visual Studio 2012 然后在OpenCV官网下载安装OpenCV2.4.9 for Windows,网址为http://opencv.org/downloads.html ...
- CSS自学笔记(11):CSS3背景和边框
CSS3 背景 在CSS3中新增了多个关于背景的属性,可以让我们对背景有了更多更好的操作,减少用第三方工具对背景图片进行修改美化. CSS3中主要是通过定义backgrounp中的各个属性来控制背景( ...
- 为WPF项目创建单元测试
原文作者: 周银辉 来源: 博客园 原文地址:http://www.cnblogs.com/zhouyinhui/archive/2007/09/30/911522.html 可能你已发现一个问题, ...