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 ...
随机推荐
- zoj1027 Human Gene Functions
一道动态规划,两个串进行匹配,不同字母匹配的值不一样,也可以和空格匹配(空格不能与空格匹配),求最大的匹配值. 数据很弱,每个串都在100以内. 定义dp[i][j]为第一个串前i个数和第二个串前j个 ...
- 【11.2noip冲刺赛】 循环整数 (分段打表)
[问题描述]moreD在学习完循环小数之后发现循环是个很美好的性质.自己只需要记住短短的循环节以及循环次数(次数大于1,且是整数)就可以记住整个数字了.因为背诵数字变得方便了,moreD决定背诵[L, ...
- Sublime_调试PHP编译系统设置.
工具->编译系统->新建编译系统 { "cmd": ["C:\\wampserver\\bin\\php\\php5.3.13\\php.ex ...
- Python学习笔记(二)Python的数据类型和变量
Python的字符串 Python使用''和""将字符串括起来,与ruby类似,特殊之处是Python可以使用r''表示''内部的字符串默认不转义,如: print(r'\\\t\ ...
- wifi 攻破
链接1 wifi 加密方式 1,wep加密 2.WPA/WPA2-PSK加密 WPA2 的破解方式: 1 爆力破解 2,pin 破解 1) 先破解 pin 码 2)再用 minidwep-gtk 破解
- 一维树状数组(HD1166)
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<string.h> using namespace st ...
- python sys.exit()函数说明
sys.exit()函数是通过抛出异常的方式来终止进程的,也就是说如果它抛出来的异常被捕捉到了的话程序就不会退出了. #!/usr/bin/python #!coding:utf-8 import s ...
- Android Studio安装使用图文教程
原文 http://jingyan.baidu.com/article/1876c852a25cb4890b1376fa.html Google I/O开发者大会上宣布,Android Studio ...
- css案例学习之class执行的顺序
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Unity3d 打包时报错 CommandInvokationFailure: Unable to convert classes into dex format. See the Console for details.
今天打包带有Android插件的unity3d 项目是,报错CommandInvokationFailure: Unable to convert classes into dex format. S ...