osg矩阵变换节点-----平移旋转缩放
转自:http://www.cnblogs.com/ylwn817/articles/1973396.html
首先先了解下osg空间方向:

osg方向如左图所示,x轴表示屏幕水平方向,y轴表示和屏幕垂直方向即屏幕里面方向,z轴表示屏幕垂直方向,每个箭头指向表示正方向
下面来学习矩阵变换操作
首先平移:
#include<osgDB/ReadFile>
#include<osgViewer/Viewer>
#include<osg/Node>
#include<osg/MatrixTransform>
void main()
{
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Group> root=new osg::Group();
osg::ref_ptr<osg::Node> osgcool=osgDB::readNodeFile("cow.osg"); osg::ref_ptr<osg::MatrixTransform> trans=new osg::MatrixTransform();
trans->setMatrix(osg::Matrix::translate(,,));
trans->addChild(osgcool.get()); root->addChild(osgcool.get());
root->addChild(trans.get()); viewer.setSceneData(root.get());
viewer.realize();
viewer.run();
}
其中 trans->setMatrix(osg::Matrix::translate(0,0,20));就是用来平移物体,这个表示象Z轴正方向平移也就是屏幕正上方。
缩放操作:
#include<osgDB/ReadFile>
#include<osgViewer/Viewer>
#include<osg/Node>
#include<osg/MatrixTransform>
void main()
{
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Group> root=new osg::Group(); osg::ref_ptr<osg::Node> osgcool=osgDB::readNodeFile("cow.osg"); osg::ref_ptr<osg::MatrixTransform> trans=new osg::MatrixTransform();
trans->setMatrix(osg::Matrix::scale(0.5,0.5,0.5)*osg::Matrix::translate(,-,)); root->addChild(osgcool.get());
root->addChild(trans.get()); viewer.setSceneData(root.get());
viewer.realize();
viewer.run();
osg::Matrix::scale(0.5,0.5,0.5)表示缩放的比例,也就是原来物体的一般大小
旋转:
#include<osgDB/ReadFile>
#include<osgViewer/Viewer>
#include<osg/Node>
#include<osg/MatrixTransform>
void main()
{
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Group> root=new osg::Group(); osg::ref_ptr<osg::Node> osgcool=osgDB::readNodeFile("cow.osg"); osg::ref_ptr<osg::MatrixTransform> trans=new osg::MatrixTransform;
trans->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(90.0),,,));
trans->addChild(osgcool.get()); root->addChild(osgcool.get());
root->addChild(trans.get()); viewer.setSceneData(root.get());
viewer.realize();
viewer.run();
osg::Matrix::rotate(osg::DegreesToRadians(90.0),0,1,0)该方法参数分别表示角度,x,y,z当xyz其中有值是那么物体会绕着物体旋转。当角度为正值的时候,物体绕着x,y,z箭头指向向右旋转,否则物体绕着x,y,z箭头指向向左旋转
旋转可能有理解错误,以实际效果为准
osg矩阵变换节点-----平移旋转缩放的更多相关文章
- osg中使用MatrixTransform来实现模型的平移/旋转/缩放
osg中使用MatrixTransform来实现模型的平移/旋转/缩放 转自:http://www.cnblogs.com/kekec/archive/2011/08/15/2139893.html# ...
- webgl学习笔记三-平移旋转缩放
写在前面 建议先阅读下前面我的两篇文章. webgl学习笔记一-绘图单点 webgl学习笔记二-绘图多点 平移 1.关键点说明 顶点着色器需要加上 uniform vec4 u_Translation ...
- 【Qt官方例程学习笔记】Analog Clock Window Example (画笔的平移/旋转/缩放应用)
这个例子演示了如何使用QPainter的转换和缩放特性来简化绘图. 值得学习的: 定时器事件ID检查: 在定时器事件中检查定时器id是比较好的实践. QPainter抗锯齿: We call QPai ...
- 【安卓】自己定义基于onDraw的随意动画(不不过平移/旋转/缩放/alpha)、!
思路: 1.基于时间的显示映射.如:给定度数,显示圆弧,加上时序,就可以有圆弧动画的效果 2.给定时序. 用于驱动动画的一帧帧绘制 方案一.基于ObjectAnimator.动画运作时会调用degre ...
- 【Qt官方例程学习笔记】Raster Window Example(画笔的平移/旋转/缩放应用)
这个例子显示了如何使用QPainter渲染一个简单的QWindow. 值得学习的内容 <QtGui>头文件 #include <QtGui>就可以使用Qt GUI模块中的所有类 ...
- OSG学习:矩阵变换节点示例
#include<osgViewer\Viewer> #include<osg\Node> #include<osg\Geode> #include<osg\ ...
- View的平移、缩放、旋转以及位置、坐标系
原创 2015年05月12日 13:15:29 标签: Android / Scroll / Scale / Translation / Rotation 24733 Android开发中,经常会接触 ...
- 【C#/WPF】Image图片的Transform变换:平移、缩放、旋转
WPF中图像控件Image的变换属性Transform: 平移 缩放 旋转 即要想实现图片的平移.缩放.旋转,是修改它所在的Image控件的Transform变换属性. 下面在XAML中定义了Imag ...
- ARFoundation - 实现物体旋转, 平移,缩放
ARFoundation - 实现物体旋转, 平移,缩放 本文目的是为了确定在移动端怎样通过单指滑动实现物体的旋转,双指实现平移和缩放. 前提知识: ARFoundation - touch poin ...
随机推荐
- IntersectionObserver API
温馨提示:本文目前仅适用于在 Chrome 51 及以上中浏览. 2016.11.1 追加,Firefox 52 也已经实现. 2016.11.29 追加,Firefox 的人担心目前规范不够稳定,未 ...
- PHP mysql与mysqli事务详解
官方对PHP连接到MySQL数据库服务器的三种主要的API简介如下: http://php.net/manual/zh/mysqli.overview.php PHP mysql与mysqli事务详解 ...
- Alpha版本冲刺总结——曙光初现
No Bug 031402401鲍亮 031402402曹鑫杰 031402403常松 031402412林淋 031402418汪培侨 031402426许秋鑫 项目预期计划 界面设计 androi ...
- struts标签内容截取
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%> <% ...
- parse_str怎么用php
1.需求 了解parse_str的用法 2.作用 parse_str接受2个参数,把第一个参数查询字符串解析到第二个参数数组当中,会覆盖数组中原来的值 parse_str($_SERVER['QUER ...
- MiniProfiler(MiniProfiler.EF6监控调试MVC5和EF6的性能)
git: https://github.com/MiniProfiler 以前开发Webform的时候可以开启trace来跟踪页面事件,这对于诊断程序的性能是有很大的帮助的,起到事半功倍的作用,今天 ...
- MVC学习笔记
7 天玩转 ASP.NET MVC 阅读笔记 1.Web Form的问题 1.响应慢,web控件转化成html需要时间 2.带宽消耗,页面保存web控件的状态(viewstate) 3.由web控件生 ...
- Android错误
1. [2016-09-16 14:25:45 - X_Card] Found 2 versions of android-support-v4.jar in the dependency list, ...
- Dictionary读取键值的快捷方法
对泛型集合Dictionary<T,T> 进行读取键值是经常的操作,一般情况下,都是通过keys 和values进行键值的读取操作: eg: foreach (var item in di ...
- DTD文档模型和HTML基础
html是超文本标记语言,现在常用到的2中文档格式是html5和XHTML 1.0 Transitiona(过渡). <!DOCTYPE html> <!--当前文档为html5-- ...