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

天行健 君子當(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>
            亚洲欧美精品在线观看| 亚洲大片一区二区三区| 欧美日韩精品免费看| 欧美不卡三区| 国产精品v欧美精品v日本精品动漫 | 国产一区二区三区在线观看视频| 国语自产偷拍精品视频偷| 亚洲第一福利在线观看| 女人香蕉久久**毛片精品| 亚洲精品乱码久久久久久| 99精品久久久| 欧美一区二区视频在线观看2020| 裸体一区二区三区| 亚洲视频axxx| 欧美黄色影院| 在线成人激情黄色| 欧美一二区视频| 亚洲国产激情| 欧美一区二区视频观看视频| 欧美激情综合网| 在线视频国产日韩| 亚洲精品日日夜夜| 麻豆精品视频在线| 国产日产高清欧美一区二区三区| 一区二区三区免费在线观看| 欧美黄色aa电影| 校园激情久久| 国产麻豆精品视频| 亚洲午夜一区二区三区| 亚洲高清色综合| 国产精品日韩| 欧美一级片久久久久久久| 久久国产精品久久精品国产| 国产精品乱码一区二区三区| 亚洲欧美日韩精品久久久久| 99精品99| 欧美日韩一区二区三区四区在线观看| 亚洲精品久久久久久久久久久久| 免费成人毛片| 你懂的亚洲视频| 亚洲精品视频一区二区三区| 午夜精品久久久久久久99水蜜桃 | 免费成人av| 欧美一区二区三区免费大片| 欧美乱妇高清无乱码| 亚洲图片在区色| 一区二区三区回区在观看免费视频| 欧美另类一区| 欧美高清视频| 欧美日韩一区二区欧美激情| 欧美激情视频网站| 精品成人在线观看| 亚洲精品美女在线观看| 黄网动漫久久久| 午夜欧美大片免费观看| 亚洲综合国产精品| 欧美在线视频二区| 亚洲激情网站免费观看| 91久久综合| 国产精品成人播放| 久久国产手机看片| 老牛国产精品一区的观看方式| 日韩视频在线一区| 美女成人午夜| 亚洲第一中文字幕在线观看| 激情自拍一区| 久久激五月天综合精品| 久久久久国产精品一区| 欧美好骚综合网| 亚洲高清一区二区三区| 亚洲精品久久7777| 欧美美女视频| 99视频超级精品| 亚洲一区二区三区777| 欧美午夜欧美| 亚洲欧美影音先锋| 久久国产精品亚洲77777| 国产亚洲欧洲997久久综合| 午夜精品视频在线| 久久久久综合| 欧美日韩在线看| 99国产精品自拍| 欧美一区二区三区免费视| 国产欧美一区二区白浆黑人| 欧美在线播放一区二区| 免费影视亚洲| 亚洲欧洲在线播放| 亚洲无毛电影| 一区二区三区高清在线| 国产精品久久久久久亚洲毛片| 亚洲欧美中文日韩v在线观看| 久久精品国产欧美亚洲人人爽| 精品二区视频| 欧美精品一区视频| 午夜精品福利在线| 欧美高清在线观看| 亚洲制服av| 在线国产日韩| 欧美日韩亚洲高清| 久久精品国产免费看久久精品| 91久久久久久久久| 欧美制服丝袜第一页| 欧美日韩一区二区在线观看视频 | 日韩午夜在线观看视频| 亚洲第一网站免费视频| 欧美/亚洲一区| 亚洲综合大片69999| 欧美激情一区二区三区在线视频| 亚洲在线视频免费观看| 在线观看欧美亚洲| 欧美三级精品| 亚洲视频www| 欧美国产激情二区三区| 西西裸体人体做爰大胆久久久| 亚洲国产精品久久久久秋霞不卡| 久久综合色播五月| 亚洲欧美区自拍先锋| 亚洲精品国精品久久99热| 久久免费观看视频| 小黄鸭精品aⅴ导航网站入口| 亚洲精品乱码久久久久| 国产午夜精品在线| 欧美一区二区在线| 亚洲最快最全在线视频| 亚洲国产日韩在线| 99re8这里有精品热视频免费 | 女女同性精品视频| 性欧美暴力猛交69hd| 亚洲视频一起| 日韩一区二区免费看| 亚洲国产成人久久| 鲁大师影院一区二区三区| 久久精品成人| 欧美一区二区三区播放老司机| 亚洲婷婷在线| 亚洲午夜成aⅴ人片| 日韩午夜精品| 亚洲精品一区中文| 国产精品你懂的在线欣赏| 欧美精品免费在线| 欧美二区乱c少妇| 麻豆成人av| 另类亚洲自拍| 欧美顶级大胆免费视频| 麻豆精品传媒视频| 欧美.www| 欧美精品九九| 欧美性生交xxxxx久久久| 欧美精品免费在线观看| 欧美伦理影院| 欧美天天综合网| 国产精品久久久91| 国产精品一区二区久久国产| 国产欧美韩国高清| 国产在线观看精品一区二区三区| 欧美大片在线观看| 欧美精品在线一区二区| 欧美日韩美女| 国产精品一区二区久久| 国产一区二区三区自拍| 海角社区69精品视频| 亚洲国产黄色片| 亚洲作爱视频| 伊人春色精品| 最新日韩在线视频| 亚洲一二三区精品| 久久久久国产成人精品亚洲午夜| 鲁鲁狠狠狠7777一区二区| 亚洲国产精品999| 一区二区三区国产| 欧美在线日韩在线| 欧美极品一区二区三区| 国产精品av免费在线观看| 国产一区二区主播在线| 亚洲国产一区视频| 亚洲天堂久久| 美女网站在线免费欧美精品| 亚洲精品乱码视频| 亚洲欧美在线另类| 欧美成人精品高清在线播放| 国产精品视频在线观看| 在线免费日韩片| 亚洲欧美一区二区视频| 亚洲性人人天天夜夜摸| 久久久久久国产精品mv| 亚洲精品三级| 久久久久国产免费免费| 午夜精品久久久久99热蜜桃导演| 狂野欧美一区| 国产精品尤物福利片在线观看| 91久久国产自产拍夜夜嗨| 午夜精品久久久久久| 欧美激情一区三区| 亚洲欧美在线看| 欧美日韩在线免费| 亚洲国产婷婷| 久久免费黄色| 亚洲综合国产| 欧美先锋影音| 99视频精品|