osgGA::KeySwitchMatrixManipulator 跟随
#ifdef _WIN32
#include <Windows.h>
#endif // _WIN32 #include <osg/Group>
#include <osg/Camera>
#include <osgDB/ReadFile>
#include <osg/Node> #include <osg/Geometry>
#include <osg/Image>
#include <osg/ShapeDrawable>
#include <osg/Texture2D> #include <osg/MatrixTransform>
#include <osg/AnimationPath> #include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers> #include <osgGA/DriveManipulator>
#include <osgGA/GUIEventHandler>
#include <osgGA/GUIEventAdapter>
#include <osgGA/GUIActionAdapter> #include <osgGA/AnimationPathManipulator>
#include <osgGA/KeySwitchMatrixManipulator> #include <osgUtil/LineSegmentIntersector> #include <iostream>
using namespace std; class Follow:public osgGA::KeySwitchMatrixManipulator
{
public:
Follow(osgViewer::Viewer *viewerParam)
{
m_vPosition = osg::Vec3(0.0, -200.0, -70.0);
m_vRotation = osg::Vec3(osg::PI_2, 0.0f, 0.0f);
m_fMoveSpeed = 2.0;
m_fAnglg = 2.5;
viewer1 = viewerParam;
} virtual void setByMatrix()
{ } virtual void setByInverseMatrix()
{ } virtual osg::Matrixd getMatrix() const
{
osg::Matrixd mat1;
mat1.makeRotate(m_vRotation.x(), osg::Vec3(1.0, 0.0, 0.0), m_vRotation.y(), osg::Vec3(0.0, 1.0, 0.0), m_vRotation.z(), osg::Vec3(0.0, 0.0, 1.0));
return mat1*osg::Matrixd::translate(m_vPosition);
} virtual osg::Matrixd getInverseMatrix() const
{
osg::Matrixd mat1;
mat1.makeRotate(m_vRotation.x(), osg::Vec3(1.0, 0.0, 0.0), m_vRotation.y(), osg::Vec3(0.0, 1.0, 0.0), m_vRotation.z(), osg::Vec3(0.0, 0.0, 1.0));
return osg::Matrixd::inverse(mat1*osg::Matrixd::translate(m_vPosition));
} virtual float getFusionDistanceValue() const {
//return _current->getFusionDistanceValue();
return viewer1->getFusionDistanceValue();
} virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const
{ return viewer1->getFusionDistanceMode();
} void changePosition(osg::Vec3 delta)
{
m_vPosition += delta;
} bool handle(const osgGA::GUIEventAdapter& gea,osgGA::GUIActionAdapter& gaa)
{
//
switch (gea.getEventType())
{
case osgGA::GUIEventAdapter::DOUBLECLICK:
std::cout << "-double click--" << std::endl;
break; case osgGA::GUIEventAdapter::KEYDOWN:
//std::cout << "-ket down--" << std::endl;
if (gea.getKey()==)
{
changePosition(osg::Vec3(m_fMoveSpeed*cosf(osg::PI_2 + m_vRotation[]), m_fMoveSpeed*sinf(osg::PI_2 + m_vRotation[]), ));
}
else if (gea.getKey()==)
{
changePosition(osg::Vec3(-m_fMoveSpeed*cosf(osg::PI_2 + m_vRotation[]), -m_fMoveSpeed*sinf(osg::PI_2 + m_vRotation[]), ));
}
else if (gea.getKey()== 0xFF53)
{
m_vRotation._v[] -= osg::DegreesToRadians(m_fAnglg);
}
else if (gea.getKey()==0xFF51)
{
m_vRotation._v[] += osg::DegreesToRadians(m_fAnglg);
}
else
{ } break; default:
break;
} return false;
} private:
osg::Vec3 m_vPosition;
osg::Vec3 m_vRotation;
float m_fMoveSpeed;
float m_fAnglg;
osgUtil::SceneView::FusionDistanceMode model1;
osgViewer::Viewer *viewer1;
}; int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer;
osg::ref_ptr<osg::Group> group1 = new osg::Group;
osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:\\参考手册\\BIM\\osg\\四合院2019.osgb"); group1->addChild(node1.get());
viewer1->setSceneData(group1);
viewer1->setUpViewInWindow(, , , , );
viewer1->setCameraManipulator(new Follow(viewer1)); //viewer1->addEventHandler(new osgViewer::WindowSizeHandler);
viewer1->realize(); return viewer1->run();
}


osgGA::KeySwitchMatrixManipulator 跟随的更多相关文章
- OSG 实现跟随节点的相机(转)
本章教程将继续使用回调和节点路径(NodePath)来检索节点的世界坐标. 本章目标: 在一个典型的仿真过程中,用户可能需要从场景中的各种车辆和人物里选择一个进行跟随.本章将介绍一种将摄像机“依附 ...
- OSG开源教程(转)
例:geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); 来指定要利用这些数据生成一个怎么样的形状. ...
- OSGMFC
在OSG的Demo中找到MFC_OSG类文件. #pragma once #include <osgViewer/Viewer> #include <osgViewer/Viewer ...
- [osg][osgEarth][原]基于OE自定义自由飞行漫游器(初级版)
由于受够了OE的漫游器,想搞个可以在全球飞行的漫游器,所以就做了一个: 请无视我的起名规则······ 类头文件:EarthWalkManipulator.h #pragma once //南水之源 ...
- [原][osgEarth]在osgearth中添加相机路径动画
在osg中添加相机动画路径请参考:http://www.cnblogs.com/lyggqm/p/8075277.html 这里的代码是在osgearth中添加相机动画路径漫游器: #include ...
- osg for android学习之一:windows下编译(亲测通过)【转】
1. 首先需要一个OSG for android的环境 (1)NDK 现在Eclipse 对NDK已经相当友好了,已经不需要另外cygwin的参与,具体可以参考 Android NDK开发篇(一):新 ...
- osg编译日志-release
1>------ 已启动生成: 项目: ZERO_CHECK, 配置: Release x64 ------1> Checking Build System1> CMake does ...
- osg 加载 fbx文件
#ifdef _WIN32 #include <Windows.h> #endif // _WIN32 #include <osg/Group> #include <os ...
- osg 添加 fbx插件 osg中编译fbx
使用osg加载fbx模型,需要自己编译fbx插件,编译流程与插件使用案例如下 代码地址:https://github.com/shelltdf/osgFBX CMake Error: The foll ...
随机推荐
- mybatis遍历map
mytabis是可以遍历map的,试过很多其他的方法都不行,最终使用如下方法是可以的: 1.mapper.java如下(注意要加@Param注解,否则不行,我就在这里折腾了不少时间): int upd ...
- GIS 基础知识简介
前言 前一段时间,在公司进行了分析 GIS 基础信息的介绍.之所以会有这个介绍以及为什么是我?这个个中缘由说下. 公司不是一个GIS方面的公司,但是由于业务的需要,经常需要用到地图(要和地图打交道), ...
- Unity Platform Differernces
https://docs.unity3d.com/560/Documentation/Manual/SL-PlatformDifferences.html
- 怎么才能零基础彻底学会Java
21世纪进入信息时代,信息科技给人类的生产和生活方式带来了深刻的变革,信息产业已成为推动国家经济发展的主导产业之一,Java编程语言作为含金量极高的一门IT技术,很多人希望从事这个行业,那么想学好Ja ...
- vue 项目总结 知识点补充
1.页面加载后自动执行函数 2.向后端请求数据方法 2-1 :axios 的安装使用 2-2 在组件中使用 2-3 发送请求 2-4 接收数据后渲染 2-5 后端数据渲染 2-6 解决跨域问题 任务 ...
- 什么是 restful 规范?
一种软件架构风格.设计风格,而不是标准,只是提供了一组设计原则和约束条件. 一.协议 API与用户的通信协议,总是使用HTTPs协议. 什么是https协议 二.域名 应该尽量将API部署在专用域名之 ...
- Elasticsearch 使用:创建、插入、查询、更新、删除
Elasticsearch 是一个开源的搜索引擎,建立在一个全文搜索引擎库 Apache Lucene™ 基础之上. Lucene 可能是目前存在的,不论开源还是私有的,拥有最先进,高性能和全功能搜索 ...
- 页面打开excel
1. File => Stream / MemoryStream FileStream stream = new FileStream(path, FileMode.Open, FileAcce ...
- Android工程的合并
http://www.xuanyusong.com/archives/3395 1.游戏包名( 类似 com.xx.xxx ) Android应用程序只能有一个包名,如果两个游戏包名一样,那么后者安装 ...
- 使用开源软件 jumpserver 搭造自己的堡垒机
使用开源软件 jumpserver 搭造自己的堡垒机 开软地址:https://github.com/jumpserver/jumpserver 目前版本:1.5.2 测试的时候有少许BUG,但功能却 ...