OSG学习:自动对齐节点示例
/**********************************************************
*Write by FlySky
*zzuxp@163.com http://www.OsgChina.org
**********************************************************/ #include <osgViewer/Viewer> #include <osg/Node>
#include <osg/Geometry>
#include <osg/Geode>
#include <osg/Group>
#include <osg/AutoTransform> #include <osgDB/ReadFile>
#include <osgDB/WriteFile> #include <osgText/Text> #include <osgUtil/Optimizer> #include <iostream> //创建自动变换节点
osg::ref_ptr<osg::Node> createAutoTransform(osg::Vec3& position, float size, std::string& label,
osg::AutoTransform::AutoRotateMode autoMode, osgText::Text::AxisAlignment axisAlignment)
{
osg::ref_ptr<osg::Geode> geode = new osg::Geode(); //字体
std::string font("fonts/cour.ttf"); //创建Text对象
osg::ref_ptr<osgText::Text> text = new osgText::Text();
geode->addDrawable(text.get()); //设置字体
text->setFont(font);
//设置字体的分辨率,默认为32*32
text->setFontResolution(128.0f, 128.0f);
//设置字体的大小
text->setCharacterSize(size);
//设置对齐方式
text->setAlignment(osgText::Text::CENTER_CENTER);
//设置方向
text->setAxisAlignment(axisAlignment);
//设置文字
text->setText(label); //关闭光照
geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); //创建自动变换节点
osg::ref_ptr<osg::AutoTransform> at = new osg::AutoTransform();
//添加子节点
at->addChild(geode.get()); //设置自动变换方式
at->setAutoRotateMode(autoMode);
//根据屏幕大小来缩放节点,默认为false,设置为true时,节点无法缩放
at->setAutoScaleToScreen(false);
//at->setAutoScaleToScreen(true) ;
//设置缩放的最大和最小比例
at->setMinimumScale(0.0f);
at->setMaximumScale(5.0f);
//设置位置
at->setPosition(position); return at.get();
}
int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer(); osg::ref_ptr<osg::Group> root = new osg::Group(); std::string text("Fly To Sky"); /*
三种变换模式:
ROTATE_TO_SCREEN 自动朝向屏幕
ROTATE_TO_CAMERA 自动朝向相机
NO_ROTATION 无
*/
//添加ROTATE_TO_SCEREEN模式变换节点
root->addChild(createAutoTransform(osg::Vec3(0.0f, 0.0f, 0.0f), 60.0f, text,
osg::AutoTransform::ROTATE_TO_SCREEN, osgText::Text::XY_PLANE)); //添加NO_ROTATION模式变换节点
root->addChild(createAutoTransform(osg::Vec3(0.0f, 0.0f, 0.0f), 60.0f, text,
osg::AutoTransform::NO_ROTATION, osgText::Text::YZ_PLANE)); //添加ROTATE_TO_CAMERA模式变换节点
//root->addChild(createAutoTransform(osg::Vec3(0.0f,0.0f,0.0f),60.0f,text,
// osg::AutoTransform::ROTATE_TO_CAMERA,osgText::Text::XY_PLANE)) ; //优化场景数据
osgUtil::Optimizer optimizer;
optimizer.optimize(root.get()); viewer->setSceneData(root.get()); viewer->realize(); viewer->run(); return 0;
}
OSG学习:自动对齐节点示例的更多相关文章
- OSG学习:矩阵变换节点示例
#include<osgViewer\Viewer> #include<osg\Node> #include<osg\Geode> #include<osg\ ...
- osg学习示例之遇到问题四骨骼动画编译osgCal
osg学习示例之遇到问题四骨骼动画编译osgCal 转自:http://blog.csdn.net/wuwangrun/article/details/8239451 今天学到书<OpenSce ...
- 【原创】SpringBoot & SpringCloud 快速入门学习笔记(完整示例)
[原创]SpringBoot & SpringCloud 快速入门学习笔记(完整示例) 1月前在系统的学习SpringBoot和SpringCloud,同时整理了快速入门示例,方便能针对每个知 ...
- OSG学习:位置变换节点示例
osg::PositionAttitudeTransform节点. #include <osgViewer\Viewer> #include <osg\Node> #inclu ...
- OSG学习:阴影代码示例
效果图: 代码示例: #include <osgViewer/Viewer> #include <osg/Node> #include <osg/Geode> #i ...
- OSG学习:响应键盘鼠标示例
示例功能:示例里面有两个模型,一个是牛,另一个是飞机.鼠标右键时牛和飞机都隐藏,鼠标左键双击时牛和飞机都显示,按键盘上面的LEFT键,显示牛,按键盘上面的RIGHT键显示飞机.其中显示与隐藏节点使用的 ...
- OSG学习:转动的小汽车示例
由于只是简单的示例,所以小汽车的模型也比较简单,是由简单的几何体组成. 代码如下: #include <osg\ShapeDrawable> #include <osg\Animat ...
- OSG学习:使用已有回调示例
回调的类型有很多种,一般很容易就想到的是UpdateCallBack,或者EventCallBack,回调的意思就是说,你可以规定在某件事情发生时启动一个函数,这个函数可能做一些事情.这个函数就叫做回 ...
- OSG学习:基本几何体绘制示例
绘制并渲染几何体主要有如下3大步骤: 1.创建各种向量数据,如顶点.纹理坐标.颜色和法线等.需要注意的是,添加顶点数据时主要按照逆时针顺序添加, 以确保背面剔除的正确. 2.实例化一个几何体对象(os ...
随机推荐
- 『Python基础-3』变量、定义变量、变量类型、关键字Python基础-3』变量、定义变量、变量类型、关键字
『Python基础-3』变量.定义变量.变量类型.关键字 目录: 1.Python变量.变量的命名 2.变量的类型(Python数据类型) 3.Python关键字 1. Python 变量.变量的命名 ...
- flask日志
日志功能的实现 Python 自身提供了一个用于记录日志的标准库模块:logging. logging 模块 logging 模块定义的函数和类为应用程序和库的开发实现了一个灵活的事件日志系统 log ...
- gp与 pg 查询进程
select now()-query_start as cost_time,* from pg_stat_activity where current_query not in ( '<IDLE ...
- .Net 面试题 汇总(六)
一.填空题 1.面向对象的语言具有(继承)性.(多态)性.(封装)性. 2.能用foreach遍历访问的对象需要实现 (IEnumberable)接口或声明(GetEnumberator)方法的类型. ...
- 通过c#操作word文档的其他方式
如果不嫌麻烦可以选择MS的word组件,因为过于庞大复杂.一般都是在无法满足要求的情况下才采用此种方式 参考链接:http://blog.csdn.net/lu930124/article/detai ...
- [python]安装wxpython的时候遇到问题记录
一.安装wxpython的时候报错 “no installation of python 2.7 found in registy” 解决方案: win7上,已经安装python27,但是在安装wxp ...
- Ruby 基础教程1-3
1.命令行参数ARGV[] 2.文件读取 file=File.open(filename) text=file.read print text file.close 一次读取所有内容耗内存,耗 ...
- Centos 7 快速安装 Docker
摘要: 安装 Docker [root@localhost~]# yum install docker 启动 docker 服务 [root@localhost~]# systemctl start ...
- Siki_Unity_2-1_API常用方法和类详细讲解(上)
Unity 2-1 API常用方法和类详细讲解(上) 任务1&2:课程前言.学习方法 && 开发环境.查API文档 API: Application Programming I ...
- 只写Python一遍代码,就可以同时生成安卓及IOS的APP,真优秀
前言: 用Python写安卓APP肯定不是最好的选择,但是肯定是一个很偷懒的选择 我们使用kivy开发安卓APP,Kivy是一套专门用于跨平台快速应用开发的开源框架,使用Python和Cython编写 ...