zoukankan      html  css  js  c++  java
  • 转载: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.

  • 相关阅读:
    emacs 编程入门 函数
    boost库介绍
    jquery css attr
    html 相对定位 绝对 定位 css + div
    我常用的grep
    我常用的tar
    C#皮肤的用法(皮肤资源+使用实例下载)
    C#资源文件操作示例 创建资源和读取资源
    黄聪:c#中高效的excel导入sqlserver的方法
    黄聪:Delphi 中的 XMLDocument 类详解(2) 记要
  • 原文地址:https://www.cnblogs.com/cLockey/p/4623083.html
Copyright © 2011-2022 走看看