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

天行健 君子當自強而不息

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>
            亚洲私人影院| 亚洲国产91色在线| 亚洲视频免费观看| 欧美视频在线视频| 亚洲一区三区在线观看| 一本久道久久久| 国产精品久久波多野结衣| 午夜精品福利电影| 亚洲一级电影| 在线观看视频免费一区二区三区| 老鸭窝毛片一区二区三区| 久久久噜噜噜久久中文字免| 亚洲人成绝费网站色www| 91久久久在线| 国产精品美女| 麻豆9191精品国产| 欧美激情综合五月色丁香| 这里是久久伊人| 亚洲欧美在线x视频| 国产日韩欧美精品一区| 免费日韩成人| 欧美四级在线观看| 久久精品一区二区国产| 亚洲欧美日韩在线观看a三区| 亚洲视频一二三| 狠久久av成人天堂| 亚洲精品欧美| 国产在线乱码一区二区三区| 亚洲成人资源| 欧美一区2区三区4区公司二百 | 99热免费精品在线观看| 国产日韩亚洲欧美精品| 亚洲成人自拍视频| 国产精品专区h在线观看| 裸体女人亚洲精品一区| 欧美午夜视频在线| 久热精品视频在线观看一区| 欧美日韩亚洲视频| 久久久国产成人精品| 欧美日本国产一区| 快射av在线播放一区| 欧美日韩在线观看一区二区| 理论片一区二区在线| 欧美视频一区二区三区四区| 欧美高清视频一区二区三区在线观看 | 欧美激情第10页| 国产精品亚洲不卡a| 亚洲第一精品福利| 国产麻豆日韩| 国产精品99久久久久久宅男| 亚洲国产精品传媒在线观看| 欧美一区二区视频观看视频| 亚洲一区二区三区精品在线 | 亚洲天堂av在线免费观看| 亚洲大片免费看| 午夜老司机精品| 性8sex亚洲区入口| 欧美精品手机在线| 欧美高清视频www夜色资源网| 国内精品久久久久影院色| 国产精品99久久久久久久久久久久| 亚洲毛片av| 欧美国产国产综合| 欧美福利影院| 亚洲电影第三页| 久久综合狠狠综合久久激情| 欧美www视频在线观看| 狠狠狠色丁香婷婷综合激情| 欧美在线你懂的| 久久综合久久美利坚合众国| 激情久久中文字幕| 久久精品国产99国产精品澳门| 久久精品盗摄| 激情国产一区| 免费在线成人av| 亚洲国产成人av好男人在线观看| 最新国产成人av网站网址麻豆 | 欧美国产高潮xxxx1819| 亚洲成在人线av| 亚洲精品乱码久久久久久黑人| 欧美大片91| 99精品热6080yy久久| 亚洲在线观看免费| 国产精品一区二区三区四区 | 亚洲精品视频一区二区三区| 亚洲视频中文字幕| 国产精品私拍pans大尺度在线 | 亚洲少妇最新在线视频| 欧美亚洲视频在线观看| 国内自拍亚洲| 欧美国产三区| 亚洲无亚洲人成网站77777| 欧美亚洲自偷自偷| 亚洲高清在线观看| 欧美久久精品午夜青青大伊人| 亚洲天堂av电影| 久热精品视频在线观看一区| 99国产精品久久久| 国产精品欧美日韩一区| 欧美在线视频全部完| 亚洲第一黄色网| 午夜精品久久久久久99热| 激情综合五月天| 欧美日韩一区二区高清| 久久国产黑丝| 亚洲靠逼com| 久久青草久久| 一区二区三区免费在线观看| 精品1区2区| 国产精品高潮粉嫩av| 久久免费高清| 亚洲自拍偷拍福利| 亚洲福利一区| 久久精品在线播放| 夜夜嗨av一区二区三区四季av| 国产综合在线看| 欧美日韩视频一区二区| 久久久福利视频| 亚洲欧美精品中文字幕在线| 亚洲人成免费| 久久影院午夜论| 香蕉国产精品偷在线观看不卡| 99视频+国产日韩欧美| 激情欧美一区| 国产欧美日韩在线观看| 欧美色视频日本高清在线观看| 男男成人高潮片免费网站| 欧美一级久久| 亚洲欧美日韩天堂一区二区| 日韩视频在线一区二区三区| 亚洲国产黄色片| 久久综合九色综合久99| 久久精品日产第一区二区三区 | 亚洲黄色在线| 韩日在线一区| 国产亚洲精品高潮| 国产精品美女久久| 欧美日韩精品免费观看| 欧美成人午夜激情在线| 快射av在线播放一区| 欧美在线视频一区二区| 午夜精品久久久久久久99热浪潮| 亚洲视频第一页| 亚洲综合色噜噜狠狠| 中国女人久久久| 中文av字幕一区| aa日韩免费精品视频一| 99精品国产在热久久| 日韩一二三区视频| 一本色道久久精品| 日韩网站在线观看| 99视频有精品| 亚洲欧美中文另类| 亚洲欧美综合网| 欧美一区二区精品在线| 午夜精品免费| 久久青青草原一区二区| 免费亚洲电影在线观看| 欧美激情亚洲精品| 欧美日韩网址| 国产精品毛片| 伊甸园精品99久久久久久| 伊人成人网在线看| 亚洲国产色一区| 中文一区在线| 久久精品亚洲一区二区| 麻豆成人小视频| 91久久夜色精品国产九色| 亚洲精品影院| 欧美一级黄色网| 欧美国产综合| 国产精品综合av一区二区国产馆| 伊大人香蕉综合8在线视| 亚洲精品视频在线观看免费| 亚洲尤物在线| 欧美成熟视频| 亚洲深夜福利在线| 久久精品人人做人人爽电影蜜月| 暖暖成人免费视频| 国产精品久久久久aaaa樱花| 韩国成人理伦片免费播放| 日韩视频在线免费| 欧美在线亚洲| 亚洲人成免费| 久久精品卡一| 国产精品久久久久久久久久直播| 一区二区三区中文在线观看| 亚洲一区二区三区精品视频| 男人的天堂亚洲| 午夜精品久久久久久久99热浪潮| 免费在线欧美黄色| 国产热re99久久6国产精品| 亚洲精品乱码久久久久久黑人 | 亚洲欧美久久久久一区二区三区| 老色批av在线精品| 一区二区三区**美女毛片 | 亚洲免费视频一区二区| 女女同性精品视频| 国产日韩欧美在线| 亚洲视频精品|