青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

3D中的方位和角位移的C++實現(3)

新建網頁 1

 
cRotationMatrix類的目的就是處理非常特殊的(也是極其常用的)物體和慣性坐標空間之間的旋轉。這個矩陣類不是一般的變換類,我們假定這個類只包含旋轉,因此,它是正交的。換句話說,該矩陣表達的是方位,而不是角位移。當你創建這樣的矩陣時,不必指定變換的方向(物體坐標空間到慣性坐標空間或是慣性坐標空間到物體坐標空間)。變換的方向在實際執行變換時指定,每個方向對應一個函數。

RotationMatrix.h:

    #ifndef ROTATION_MATRIX_H
   
#define ROTATION_MATRIX_H
   
   
class cVector3;
   
class cEulerAngles;
   
class cQuaternion;
   
   
//---------------------------------------------------------------------------
    // Implement a simple 3x3 matrix that is used for ROTATION ONLY.  The
    // matrix is assumed to be orthogonal.  The direction of transformation
    // is specified at the time of transformation.
    //---------------------------------------------------------------------------
   
class cRotationMatrix
    {
   
public:
        
float    m11, m12, m13;
        
float    m21, m22, m23;
        
float    m31, m32, m33;    
   
   
public:
        
void identity();
   
        
// setup the matrix with a specified orientation
   
    void setup(const cEulerAngles& orientation);
   
        
// setup the matrix from a quaternion, assuming the quaternion performs the
        // rotation in the specified direction of transformation.
   
    void from_inertial_to_object_quat(const cQuaternion& q);
        
void from_object_to_inertial_quat(const cQuaternion& q);
   
        
// perform rotations
   
    cVector3 inertial_to_object(const cVector3& v) const;
        cVector3 object_to_inertial(
const cVector3& v) const;
    };
   
   
#endif

因為cRotationMatrix類很簡單,因此也非常容易使用。首先,用歐拉角或四元數設置矩陣。如果使用四元數,還必須指明該四元數代表哪種角位移。一旦創建了矩陣,就能用inertial_to_object()object_to_inertial()函數執行旋轉。

cRotationMatrix.cpp

    #include "vector3.h"
    #include "RotationMatrix.h"
    #include "MathUtil.h"
    #include "Quaternion.h"
    #include "EulerAngles.h"
   
   
/////////////////////////////////////////////////////////////////////////////
   
//
    // MATRIX ORGANIZATION
    //
    // A user of this class should rarely care how the matrix is organized.
    // However, it is of course important that internally we keep everything
    // straight.
    //
    // The matrix is assumed to be a rotation matrix only, and therefore
    // orthoganal.  The "forward" direction of transformation (if that really
    // even applies in this case) will be from inertial to object space.
    // To perform an object->inertial rotation, we will multiply by the
    // transpose.
    //
    // In other words:
    //
    // Inertial to object:
    //
    //                  | m11 m12 m13 |
    //     [ ix iy iz ] | m21 m22 m23 | = [ ox oy oz ]
    //                  | m31 m32 m33 |
    //
    // Object to inertial:
    //
    //                  | m11 m21 m31 |
    //     [ ox oy oz ] | m12 m22 m32 | = [ ix iy iz ]
    //                  | m13 m23 m33 |
    //
    // Or, using column vector notation:
    //
    // Inertial to object:
    //
    //     | m11 m21 m31 | | ix |    | ox |
    //     | m12 m22 m32 | | iy | = | oy |
    //     | m13 m23 m33 | | iz |    | oz |
    //
    // Object to inertial:
    //
    //     | m11 m12 m13 | | ox |    | ix |
    //     | m21 m22 m23 | | oy | = | iy |
    //     | m31 m32 m33 | | oz |    | iz |
    //
   
/////////////////////////////////////////////////////////////////////////////
   

   
//---------------------------------------------------------------------------
    // Set the matrix to the identity matrix
    //---------------------------------------------------------------------------
   
void cRotationMatrix::identity()
    {
        m11 = 1.0f;    m12 = 0.0f; m13 = 0.0f;
        m21 = 0.0f;    m22 = 1.0f; m23 = 0.0f;
        m31 = 0.0f;    m32 = 0.0f; m33 = 1.0f;
    }
   
   
//-----------------------------------------------------------------------------------------------------
    // Setup the matrix with the specified orientation
    //
    //     | cosh * cosb + sinh * sinp * sinb      -cosh * sinb + sinh * sinp * cosb         sinh * cosp |
    // M = | sinb * cosp                            cosb * cosp                                 -sinp         |
    //       | -sinh * cosb + cosh * sinp * sinb        sinb * sinh + cosh * sinp * cosb        cosh * cosp  |
    //-----------------------------------------------------------------------------------------------------
   
void cRotationMatrix::setup(const cEulerAngles& orientation)
    {
        
// Fetch sine and cosine of angles
   

        
float sh,ch, sp,cp, sb,cb;
   
        sin_cos(&sh, &ch, orientation.heading);
        sin_cos(&sp, &cp, orientation.pitch);
        sin_cos(&sb, &cb, orientation.bank);
   
        
// Fill in the matrix elements
   

        m11 = ch * cb + sh * sp * sb;
        m12 = -ch * sb + sh * sp * cb;
        m13 = sh * cp;
   
        m21 = sb * cp;
        m22 = cb * cp;
        m23 = -sp;
   
        m31 = -sh * cb + ch * sp * sb;
        m32 = sb * sh + ch * sp * cb;
        m33 = ch * cp; 
    }
   
   
//-----------------------------------------------------------------------------------------
    // Setup the matrix, given a quaternion that performs an inertial->object rotation.
    //
    //         | 1 - 2(y^2 + z^2)        2(xy + wz)            2(xz - wy)         |
    // M = | 2(xy - wz)                1 - 2(x^2 + z^2)    2(yz + wx)         |
    //         | 2(xz + wy)                2(yz - wx)            1 - 2(x^2 + y^2) |
    //-----------------------------------------------------------------------------------------
   
void cRotationMatrix::from_inertial_to_object_quat(const cQuaternion& q)
    {
        
// Fill in the matrix elements.  This could possibly be optimized since there are 
        // many common subexpressions. We'll leave that up to the compiler
   

        m11 = 1.0f - 2.0f * (q.y * q.y + q.z * q.z);
        m12 = 2.0f * (q.x * q.y + q.w * q.z);
        m13 = 2.0f * (q.x * q.z - q.w * q.y);
   
        m21 = 2.0f * (q.x * q.y - q.w * q.z);
        m22 = 1.0f - 2.0f * (q.x * q.x + q.z * q.z);
        m23 = 2.0f * (q.y * q.z + q.w * q.x);
   
        m31 = 2.0f * (q.x * q.z + q.w * q.y);
        m32 = 2.0f * (q.y * q.z - q.w * q.x);
        m33 = 1.0f - 2.0f * (q.x * q.x + q.y * q.y);
    }
   
   
//-----------------------------------------------------------------------------------------
    // Setup the matrix, given a quaternion that performs an object->inertial rotation.
    //
    //         | 1 - 2(y^2 + z^2)        2(xy - wz)            2(xz + wy)         |
    // M = | 2(xy + wz)                1 - 2(x^2 + z^2)    2(yz - wx)         |
    //         | 2(xz - wy)                2(yz + wx)            1 - 2(x^2 + y^2) |
    //-----------------------------------------------------------------------------------------
   
void cRotationMatrix::from_object_to_inertial_quat(const cQuaternion& q)
    {
        
// Fill in the matrix elements.  This could possibly be optimized since there are 
        // many common subexpressions. We'll leave that up to the compiler
   

        m11 = 1.0f - 2.0f * (q.y * q.y + q.z * q.z);
        m12 = 2.0f * (q.x * q.y - q.w * q.z);
        m13 = 2.0f * (q.x * q.z + q.w * q.y);
   
        m21 = 2.0f * (q.x * q.y + q.w * q.z);
        m22 = 1.0f - 2.0f * (q.x * q.x + q.z * q.z);
        m23 = 2.0f * (q.y * q.z - q.w * q.x);
   
        m31 = 2.0f * (q.x * q.z - q.w * q.y);
        m32 = 2.0f * (q.y * q.z + q.w * q.x);
        m33 = 1.0f - 2.0f * (q.x * q.x + q.y * q.y);
    }
   
   
//---------------------------------------------------------------------------
    // Rotate a vector from inertial to object space
    //---------------------------------------------------------------------------
   
cVector3 cRotationMatrix::inertial_to_object(const cVector3& v) const
    {
        
// perform the matrix multiplication in the "standard" way
   
    return cVector3(m11 * v.x + m21 * v.y + m31 * v.z,
                        m12 * v.x + m22 * v.y + m32 * v.z,
                        m13 * v.x + m23 * v.y + m33 * v.z);
    }
   
   
//---------------------------------------------------------------------------
    // Rotate a vector from object to inertial space
    //---------------------------------------------------------------------------
   
cVector3 cRotationMatrix::object_to_inertial(const cVector3& v) const
    {
        
// Multiply by the transpose
   
    return cVector3(m11 * v.x + m12 * v.y + m13 * v.z,
                        m21 * v.x + m22 * v.y + m23 * v.z,
                        m31 * v.x + m32 * v.y + m33 * v.z);
    }

posted on 2008-02-19 09:49 lovedday 閱讀(511) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产综合在线视频| 一区二区三区我不卡| 99国产精品99久久久久久| 欧美国产欧美综合| 免费不卡在线视频| 亚洲欧洲午夜| 99pao成人国产永久免费视频| 欧美另类极品videosbest最新版本 | 香蕉久久夜色精品国产使用方法| 一区二区黄色| 国产亚洲综合精品| 欧美激情亚洲国产| 国产精品盗摄久久久| 久久精品成人一区二区三区蜜臀 | 日韩视频免费在线| 国产精品久久久一区二区| 久久激情视频免费观看| 久久欧美肥婆一二区| av成人黄色| 香蕉久久久久久久av网站| 亚洲日本成人| 亚洲一区二区精品在线| 亚洲第一区在线观看| 亚洲伦理在线免费看| 国产在线高清精品| 亚洲人体影院| 国产精品亚洲综合天堂夜夜| 欧美jjzz| 国产精品一区二区久久| 欧美国产三区| 国产日韩av高清| 亚洲欧洲一区二区三区| 国内外成人在线| 一区二区三区精品久久久| 狠狠色狠狠色综合日日91app| 亚洲欧洲午夜| 亚洲高清在线观看| 亚洲欧美日韩一区二区| 一本色道久久综合狠狠躁的推荐| 欧美一区二区三区四区在线观看| 一本久久青青| 欧美不卡视频一区发布| 久久久久久久一区二区三区| 欧美日韩一区二区三区四区五区 | 久久国产欧美精品| 欧美深夜福利| 亚洲国产小视频在线观看| 国产亚洲午夜| 亚洲女爱视频在线| 亚洲素人在线| 欧美日韩黄视频| 亚洲国产成人av| 亚洲福利视频免费观看| 久久精品99国产精品酒店日本| 亚洲欧美日韩国产综合精品二区| 欧美高清视频免费观看| 欧美.日韩.国产.一区.二区| 国外成人免费视频| 久久精品国产第一区二区三区最新章节| 亚洲美女中出| 欧美黄色免费| 亚洲激情第一页| 亚洲精品久久| 欧美黑人一区二区三区| 亚洲日本一区二区| aa国产精品| 欧美日韩在线不卡| 日韩视频免费观看| 亚洲免费中文字幕| 国产精品视频网站| 午夜精品理论片| 久久国产欧美精品| 国产一区二区三区四区| 久久成人免费电影| 免费观看一区| 亚洲人成高清| 欧美另类视频在线| 一区二区三区日韩精品| 午夜精品视频在线观看一区二区| 国产精品伦子伦免费视频| 亚洲欧美在线一区二区| 久久狠狠婷婷| 在线欧美日韩| 欧美日韩www| 午夜精品久久久久99热蜜桃导演| 久久久国产精彩视频美女艺术照福利| 国内精品久久久| 欧美暴力喷水在线| 亚洲一级片在线观看| 久久亚洲精品视频| 99xxxx成人网| 国产亚洲精品资源在线26u| 久久久99爱| 亚洲国产精品欧美一二99| 亚洲亚洲精品在线观看| 国产一区二区精品在线观看| 久久只有精品| 亚洲视频二区| 欧美激情女人20p| 亚洲欧美日韩中文播放| 国语自产精品视频在线看| 欧美激情偷拍| 欧美一级午夜免费电影| 亚洲国产裸拍裸体视频在线观看乱了中文| 亚洲美女毛片| 国内欧美视频一区二区| 欧美精品亚洲精品| 午夜在线a亚洲v天堂网2018| 亚洲福利视频三区| 久久精品人人做人人爽电影蜜月| 亚洲人体一区| 韩国福利一区| 国产精品久久国产精品99gif| 久久九九热免费视频| 一区二区高清在线观看| 欧美大秀在线观看| 久久9热精品视频| 99视频精品免费观看| 一色屋精品视频免费看| 国产精品专区h在线观看| 欧美黑人在线播放| 久久在线播放| 久久不射电影网| 亚洲一区二区精品视频| 亚洲免费成人| 亚洲国产裸拍裸体视频在线观看乱了中文| 欧美在线日韩| 亚欧成人在线| 亚洲综合精品四区| 亚洲四色影视在线观看| 在线视频免费在线观看一区二区| 亚洲国产精品久久久久婷婷老年| 国产婷婷色一区二区三区在线| 欧美日韩在线免费视频| 欧美va日韩va| 欧美大片第1页| 久久永久免费| 久久亚洲精品一区| 久久伊人亚洲| 鲁大师成人一区二区三区| 久久九九99视频| 久久视频免费观看| 久久天天狠狠| 欧美成人精品一区二区| 欧美暴力喷水在线| 欧美a级在线| 欧美承认网站| 欧美人牲a欧美精品| 欧美日本韩国一区二区三区| 欧美日韩a区| 欧美午夜精品久久久| 国产精品99一区| 国产精品人人做人人爽人人添| 欧美性猛交99久久久久99按摩 | 国产欧美精品一区aⅴ影院| 欧美午夜不卡视频| 国产精品美女在线| 国产一区二区精品久久| 精品1区2区3区4区| 亚洲精品综合精品自拍| 一区二区三区波多野结衣在线观看| 中文无字幕一区二区三区| 亚洲一区二区三区乱码aⅴ蜜桃女 亚洲一区二区三区乱码aⅴ | 欧美精品日韩综合在线| 欧美日韩在线一区| 国产伦精品一区二区三区免费迷| 国产视频在线观看一区二区三区| 国产综合久久久久久鬼色| 亚洲电影免费观看高清完整版在线观看 | 亚欧成人在线| 欧美成人精品福利| 国产精品都在这里| 精品福利免费观看| 亚洲香蕉在线观看| 久久蜜臀精品av| 亚洲美女黄色片| 性欧美1819性猛交| 欧美精品在线观看播放| 国产欧美日韩综合一区在线观看 | 久久久国产精彩视频美女艺术照福利| 美女网站在线免费欧美精品| 亚洲另类在线视频| 欧美亚洲免费| 欧美三级日韩三级国产三级| 国产综合香蕉五月婷在线| 亚洲视频电影图片偷拍一区| 久久久久在线| 一区二区三欧美| 欧美大色视频| 黑丝一区二区三区| 亚洲一区一卡| 亚洲国产婷婷| 久久国产精品99精品国产| 欧美日韩一区二区三区视频| 亚洲成色www久久网站| 午夜日韩激情| 亚洲片在线观看| 久久影院午夜论| 狠狠色丁香婷婷综合久久片| 亚洲专区在线|