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

天行健 君子當(dāng)自強(qiáng)而不息

3D中的方位和角位移的C++實(shí)現(xiàn)(3)

新建網(wǎng)頁(yè) 1

 
cRotationMatrix類的目的就是處理非常特殊的(也是極其常用的)物體和慣性坐標(biāo)空間之間的旋轉(zhuǎn)。這個(gè)矩陣類不是一般的變換類,我們假定這個(gè)類只包含旋轉(zhuǎn),因此,它是正交的。換句話說,該矩陣表達(dá)的是方位,而不是角位移。當(dāng)你創(chuàng)建這樣的矩陣時(shí),不必指定變換的方向(物體坐標(biāo)空間到慣性坐標(biāo)空間或是慣性坐標(biāo)空間到物體坐標(biāo)空間)。變換的方向在實(shí)際執(zhí)行變換時(shí)指定,每個(gè)方向?qū)?yīng)一個(gè)函數(shù)。

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

因?yàn)?/span>cRotationMatrix類很簡(jiǎn)單,因此也非常容易使用。首先,用歐拉角或四元數(shù)設(shè)置矩陣。如果使用四元數(shù),還必須指明該四元數(shù)代表哪種角位移。一旦創(chuàng)建了矩陣,就能用inertial_to_object()object_to_inertial()函數(shù)執(zhí)行旋轉(zhuǎn)。

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 閱讀(510) 評(píng)論(0)  編輯 收藏 引用


只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

隨筆分類(178)

3D游戲編程相關(guān)鏈接

搜索

最新評(píng)論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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久久久二8 | 亚洲精品乱码| 久久综合狠狠综合久久综合88 | 正在播放日韩| 国产精品亚洲一区| 久久国产精品黑丝| 亚洲成人在线视频播放 | 欧美日韩国产电影| 亚洲视频在线一区| 久久久久久国产精品mv| 亚洲高清不卡在线观看| 欧美精品日韩精品| 亚洲欧美日韩成人| 欧美电影免费| 亚洲自拍三区| 在线免费观看日本一区| 欧美日韩在线观看一区二区| 午夜视频一区二区| 亚洲观看高清完整版在线观看| 亚洲婷婷在线| 在线观看中文字幕亚洲| 欧美日韩一区二区高清| 久久精品国产一区二区电影 | 欧美激情在线狂野欧美精品| 亚洲一二三四区| 一区精品在线播放| 国产精品xvideos88| 久久久噜噜噜久噜久久| 99视频精品免费观看| 久久综合成人精品亚洲另类欧美 | 亚洲一区二区三区中文字幕在线| 老牛国产精品一区的观看方式| 一本大道久久a久久精品综合| 国产在线不卡视频| 国产精品久久77777| 麻豆成人av| 亚洲欧美在线看| 亚洲精品专区| 欧美成人激情在线| 久久久精品999| 亚洲天堂av综合网| 亚洲精品国产精品国自产在线 | 久久不射中文字幕| 亚洲视频欧美视频| 亚洲精品韩国| 欧美福利电影在线观看| 久久国产加勒比精品无码| 亚洲视频免费在线| 亚洲精品中文字| 亚洲第一视频| 激情视频一区| 国模叶桐国产精品一区| 国产精品高潮粉嫩av| 欧美激情精品久久久久久大尺度| 久久蜜桃精品| 久久av红桃一区二区小说| 亚洲综合日韩在线| 一区二区三区欧美日韩| 亚洲日韩欧美视频| 亚洲黄色成人网| 亚洲国产精品va| 欧美国产日韩二区| 欧美成人黄色小视频| 久久中文字幕导航| 久热爱精品视频线路一| 久久综合九色综合欧美就去吻| 久久精品99无色码中文字幕| 欧美一区视频在线| 久久精品一区二区三区不卡牛牛| 欧美亚洲免费高清在线观看| 午夜日韩在线观看| 欧美亚洲自偷自偷| 久久九九精品99国产精品| 久久成人精品| 狂野欧美激情性xxxx欧美| 久久夜色精品国产欧美乱| 麻豆久久久9性大片| 欧美高清视频一区二区| 亚洲国产成人高清精品| 亚洲精品网站在线播放gif| 亚洲伦理在线免费看| 一区二区三区产品免费精品久久75 | 欧美亚洲日本网站| 久久激情婷婷| 蜜桃av一区| 欧美日韩亚洲一区二区三区在线观看| 欧美精品一区二区三区蜜桃| 欧美日韩在线综合| 国产伦精品一区二区三区在线观看| 国产欧美日韩激情| 在线精品一区| 99香蕉国产精品偷在线观看| 亚洲一区二区三区777| 欧美制服第一页| 美女成人午夜| 日韩视频不卡| 亚洲欧美怡红院| 久热爱精品视频线路一| 欧美日韩精品免费观看| 国产精品羞羞答答| 亚洲成人影音| 亚洲一区二区三区777| 欧美资源在线观看| 亚洲国产经典视频| 亚洲一线二线三线久久久| 久久se精品一区二区| 欧美激情一区二区三区四区| 国产精品欧美一区二区三区奶水| 红桃视频亚洲| 在线亚洲电影| 噜噜噜躁狠狠躁狠狠精品视频| 亚洲人在线视频| 久久aⅴ国产紧身牛仔裤| 欧美丰满高潮xxxx喷水动漫| 国产精品丝袜久久久久久app| 亚洲第一视频| 欧美一区二区三区四区高清| 欧美电影免费观看| 亚洲欧美在线免费| 欧美激情1区2区3区| 国产综合色在线视频区| 一区二区电影免费观看| 麻豆精品在线视频| 亚洲性人人天天夜夜摸| 欧美成人精品1314www| 国产午夜精品美女毛片视频| 一本不卡影院| 欧美黄色精品| 久久都是精品| 国产精品一区久久久久| 99在线|亚洲一区二区| 免费日韩精品中文字幕视频在线| 亚洲在线国产日韩欧美| 欧美精品v日韩精品v韩国精品v | 国产一区亚洲一区| 亚洲欧美另类国产| 亚洲精品国产拍免费91在线| 久久久蜜桃精品| 国产一区二区主播在线| 亚洲欧美视频| 亚洲私拍自拍| 欧美网站在线观看| 国产精品99久久久久久www| 亚洲第一视频网站| 久久裸体视频| 一区久久精品| 久久免费视频观看| 久久xxxx精品视频| 国产午夜亚洲精品理论片色戒| 午夜精品影院| 亚洲综合第一| 国产乱码精品1区2区3区| 亚洲宅男天堂在线观看无病毒| 亚洲日本激情| 欧美日韩免费看| 一区二区久久久久久| 91久久黄色| 欧美精品一区二区三区很污很色的| 亚洲人成人一区二区三区| 欧美不卡一卡二卡免费版| 久久免费高清| 亚洲国产成人一区| 欧美激情亚洲激情| 欧美成人有码| 一区二区激情视频| 一本色道久久综合狠狠躁的推荐| 欧美日韩一区国产| 午夜精品一区二区三区电影天堂 | 欧美精品免费在线观看| 一区二区日韩精品| 一区二区三区免费看| 国产精品免费看片| 欧美在线视频日韩| 久久久精品国产一区二区三区| 在线观看一区欧美| 亚洲激情婷婷| 国产精品国产馆在线真实露脸 | 久久精品视频导航| 亚洲国语精品自产拍在线观看| 欧美大香线蕉线伊人久久国产精品| 免费在线日韩av| 在线视频一区观看| 亚洲在线日韩| 在线欧美一区| 99国产精品久久久久久久久久 | 国产精品夜夜夜| 久久综合狠狠综合久久综青草| 免费黄网站欧美| 亚洲一区二区三区精品视频| 午夜免费在线观看精品视频| 精品成人国产| 99精品热视频只有精品10| 国产美女精品一区二区三区| 美女诱惑一区| 国产精品成人在线| 久久综合九色九九| 欧美日韩性视频在线| 久久久久久9999| 欧美日韩免费一区二区三区视频| 久久久国产成人精品|