转:OSG::Quat(四元数)用法

转自: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.

时间: 2024-09-30 07:28:52

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

OSG 四元数Quat

四元数是通过使用四个数来表达方位,其目的是避免旋转过程中的万向锁问题.所以在3D中,四元数的主要用途即是用于旋转.从数学意义上讲,四元数是扩展了复数系统,它使用三个虚部i,j,k,一个四元数[x, y, z, w]定义了复数w+xi+yj+zk.我们通过OSG中的Quat类来了解四元数的基本操作及应用 1.        数据定义 使用一维数组来保存数据 double _v[4] 2.        基本操作:与向量相同,主要的基本操作都用内联函数来实现 四元数的标题乘除运算 四元数的叉乘: 四

osg四元数设置roll pitch heading角度

roll绕Y轴旋转 pitch绕X轴旋转 heading绕Z轴旋转 单位是弧度,可以使用osg::inDegrees(45)将45角度转换为弧度 定义一个四元数 osg::Quat q( roll,osg::Vec3d(0.0, 1.0, 0.0), pitch,osg::Vec3d(1.0, 0.0, 0.0), heading,osg::Vec3d(0.0, 0.0, 1.0)); //设置旋转 manipulator->setRotation(q);

osg实例介绍

转自:http://blog.csdn.net/yungis/article/list/1 [原]osgmotionblur例子 该例子演示了运动模糊的效果.一下内容是转自网上的:原理:引用内容对于运动画面,将当前帧画面与上一帧画面进行alpha融合,以产生出残影——运动模糊效果.通过使用累积缓存来完成这项工作.OpenGL提供一个累积缓存,可以用来存储当前指定的颜色缓存里面的内容,并进行一定的运算操作.通过函数glAccum可以对累积缓存进行操作. glAccum介绍如下:引用内容void g

OSG世界坐标转屏幕坐标(转载)

OSG世界坐标转屏幕坐标 #define M(row,col) m[col * 4 + row] void Transform_Point(double out[4], const double m[16], const double in[4]){    out[0] = M(0, 0) * in[0] + M(0, 1) * in[1] + M(0, 2) * in[2] + M(0, 3) * in[3];    out[1] = M(1, 0) * in[0] + M(1, 1) * i

OSG开源教程(转)

整理:荣明.王伟 北 京 2008年4月 序 第一次接触OSG是在2001年,当时开源社区刚刚兴起,还没有现在这么火.下载了OSG源码,但是在看了几个Demo之后,感觉没有什么特别之处.时隔七年之后,我再次将目光投向OSG,发现OSG确实有其独到之处,很多3D效果已经不弱于甚至超过商业软件,有感于开源力量的巨大.但是,与当前主流3D商业软件如Vega.VegaPrime.VTree.Performer等相比,开源软件的缺点也很明显,其中文档缺乏可谓其致命弱点之一.开发者只能从浩瀚的源码中,进行编

OSG节点更新与事件回调

OSG中的节点主要使用回调(CallBack)来完成用户临时.需要每帧执行的工作.根据回调功能被调用的时机划分为更新回调(Update CallBack)和人机交互时间回调(Event CallBack).前者在每一帧中系统遍历到当前节点时调用,后者则由交互事件触发,如操作键盘.鼠标.关闭窗口.改变窗口大小等动作.回调类基类是osg::NodeCallBack(),主要函数如下: //虚函数,回调函数主要操作在此函数中,子类应当重写,已完成相应操作 void operator()(Node* n

OSG程序设计之更新回调

更新回调(Update Callback)涉及到一个类:osg::NodeCallback.这个类重载了函数调用操作符.当回调动作发生时,将会执行这一操作符的内容. 如果节点绑定了更新回调函数,那么在每一帧系统遍历到此节点时,回调函数都会被调用. 下面给出一个例子: #include <osg/io_utils> #include <osg/PositionAttitudeTransform> #include <osgDB/ReadFile> #include <

osg 路径 动画 效果

osg 路径 动画 效果 转自:http://blog.csdn.net/zhuyingqingfen/article/details/8248157 #include <osg/Group>#include <osg/ShapeDrawable> #include <osgViewer/ViewerEventHandlers>#include <osgViewer/Viewer> #include <osgDB/ReadFile>#includ

[osg]OSG相机添加动画路径

查看osg坐标系,camare默认姿态:http://www.cnblogs.com/lyggqm/p/8073688.html 首先搞清楚osg的坐标系以及osg::camare的默认姿态 下代码面实现了,在场景里放一只牛.相机使用动画漫游器 在动画中添加三个方向来观察牛.具体三方向姿态请参考代码 #include <iostream> #include <osg/MatrixTransform> #include <osgViewer/Viewer> #includ