转自:http://blog.163.com/dj_zone/blog/static/4908931320098294047820/

osg::Quat

To set the attitude of a node or group of nodes, we use a new object, the osg::Quat. An osg::Quat is used to instantiate a quaternion, which we use to rotate objects. The two functions that we will use to apply rotation transformations to a PAT node are:

void setAttitude(const Quat& quat);
const Quat& getAttitude() const;

We simply construct a new osg::Quat whenever we want to rotate a PAT. The two declarations for an osg::Quat are:

osg::Quat(value_type angle, const Vec3d &axis)
osg::Quat(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3)

The first constructor creates a osg::Quat with a facing of angle in radians around one or more axes defined within the osg::Vec3d. For example:

osg::Quat(1.2, osg::Vec3d(1.0, 0.0, 1.0));

This will create a quaternion that has the properties of rotating 1.2 radians around the x and z axis. For the axis, a value of 1.0 will represent a rotation around that axis, with a value of 0.0 producing no rotation. Also note that because there is but a single angle of rotation, all the axes will be rotated by the same amount if they are flagged for rotation. That is, with this constructor, I cannot rotate 3.0 radians around the x axis and 4.0 radians around the y axis. That requires a more complicated system where there is an individual angle for each axis. For example:

osg::Quat(
    1.0, osg::Vec3d(1.0, 0.0, 0.0),
    2.0, osg::Vec3d(0.0, 1.0, 0.0),
    0.0, osg::Vec3d(0.0, 0.0, 1.0)
);

This constructor is used when the angle of rotation around more than one axis should not be equal. In the above example, we rotate 1.0 radians around the x axis, 2.0 around the y, and 0.0 around the z.

I find it easier to use degrees rather than radians, and OSG helps with degree usage by offering the following function to convert degrees into radians:

osg::DegreesToRadians(<some_degree_value>);

The osg::DegreesToRadians function returns a double. Note that, like translations, rotation angles are offsets from initial values, so unless we keep increasing or changing the rotational angle, the object will not rotate. Setting the attitude of a PAT with the Quat of (5.0, (1.0, 0.0, 0.0)) will NOT rotate the object 5 units per iteration around the x axis. Instead it will rotate the object 5 radians around the x axis on first call, and it will stay that way until the angle is changed.

转载:OSG::Quat(四元数)用法的更多相关文章

  1. 【转载】ssh-keygen 基本用法

    [转载]ssh-keygen 基本用法 原文地址:https://www.liaohuqiu.net/cn/posts/ssh-keygen-abc/ ssh 公钥认证是ssh认证的方式之一.通过公钥 ...

  2. 【转载】 mysql explain用法

    转载链接:  mysql explain用法 官网说明:     http://dev.mysql.com/doc/refman/5.7/en/explain-output.html 参数:  htt ...

  3. [转载] extern "C"的用法解析

    本文转载自: http://www.cnblogs.com/rollenholt/archive/2012/03/20/2409046.html   1.引言 C++语言的创建初衷是“a better ...

  4. (转载)C# 枚举 FlagsAttribute用法

    这是读过几篇文章后发现整理的最完整的一篇文章 转载地址:枚举特性FlagsAttribute的用法 先看官方的解释:指示可以将枚举作为位域(即一组标志)处理. 看起来并不好理解,到底什么是作为位域处理 ...

  5. 【转载】Java DecimalFormat 用法

    转载只供个人学习参考,以下查看请前往原出处:http://blog.csdn.net/wangchangshuai0010/article/details/8577982 我们经常要将数字进行格式化, ...

  6. 转载:python argparse用法总结

    https://www.jianshu.com/p/fef2d215b91d 1. argparse介绍 是python的一个命令行解析包,非常编写可读性非常好的程序 2. 基本用法 prog.py是 ...

  7. 【转载】CreateProcess的用法

    第一.第二个参数的用法: 例子: 使用ie打开指定的网页. 注意第二个参数是 可执行文件+命令行参数 #include "stdafx.h" #include <window ...

  8. (转载)delphi checklistbox用法

    delphi checklistbox用法 在Delphi中checklistbox中高亮选中(不论是否Checked)能够进行操作么?删除,上下移动等等 删除:CheckListBox.Delete ...

  9. (转载)MySQL BETWEEN 用法

    (转载)http://www.5idev.com/p-php_mysql_between.shtml MySQL BETWEEN 语法 BETWEEN 运算符用于 WHERE 表达式中,选取介于两个值 ...

随机推荐

  1. Centos下PPTP环境部署记录

    PPTP(点到点隧道协议)是一种用于让远程用户拨号连接到本地的ISP,通过因特网安全远程访问公司资源的新型技术.它能将PPP(点到点协议)帧封装成IP数据包,以便能够在基于IP的互联网上进行传输.PP ...

  2. Python_装饰器_29

    # 装饰器形成的过程 : 最简单的装饰器 有返回值的 有一个参数 万能参数 # 装饰器的作用 # 原则 :开放封闭原则 # 语法糖 :@ # 装饰器的固定模式 import time # print( ...

  3. 个人作业——final

    一 . 对M1M2的一个总结 我特别感谢我们组的PM.以前我觉得女生学计算机这个专业,跟男生比差太远了.总觉得我们女生就是上上课写写作业考考试还行,但是一到开发什么项目啊,实战之类的,总觉得自己的能力 ...

  4. 201303014001 张敏 计科高职13-1 github使用心得

    Github:https://github.com/zhangmin131/text 个人心得体会: Git是一种良好的.支持分支管理的代码管理方式,能很好地解决团队之间协作的问题.每个工程师在自己本 ...

  5. 小学四则运算APP 第二次冲刺-第二天

    团队成员:陈淑筠.杨家安.陈曦 团队选题:小学四则运算APP 第二次冲刺阶段时间:11.29~12.09 本次发布的判断题功能界面的设置: activity_panduan_set.xml: < ...

  6. Java与JavaScript之间关于JSON的是非恩怨

    http://blog.csdn.net/joyhen/article/details/43271569 js 单引号替换成双引号,双引号替换成单引号 操作 解决问题的场景: Java端生成了JSON ...

  7. Java singleton 一例

    org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of ...

  8. mysql 备份数据库 mysqldump

    @echo off for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE ...

  9. 请求与响应编码及jsp基本原理

    1.请求转发和请求包含 (1)请求转发: this.getServletContext().getRequestDispatcher("").forward(request,res ...

  10. delphi有关获取其他程序的窗口及对窗口内控件的操作

    1.获取当前所有窗口 procedure TForm1.Button1Click(Sender: TObject);var szText: array[0..254] of char; hCurren ...