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

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

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

新建網(wǎng)頁 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>
            国产在线高清精品| 欧美国产三区| 欧美日韩999| 美女日韩欧美| 国产亚洲成人一区| 亚洲一区二区三区影院| 日韩一区二区精品在线观看| 久久久精品tv| 久久久水蜜桃| 国产欧美一区二区三区国产幕精品 | 国产精品乱人伦中文| 亚洲国产精品国自产拍av秋霞| 国产日本欧洲亚洲| 亚洲欧美乱综合| 先锋资源久久| 国产精品影音先锋| 亚洲欧美资源在线| 久久高清一区| 国产一区二区三区在线观看网站 | 亚洲毛片av| 欧美激情精品久久久久久变态| 欧美jizz19hd性欧美| 在线观看不卡av| 久久亚洲一区二区| 亚洲第一网站| 一本色道久久88亚洲综合88| 欧美精品 日韩| 亚洲激情第一区| 9i看片成人免费高清| 欧美精品性视频| 99精品国产在热久久下载| 在线视频精品一| 国产精品久久久久久影院8一贰佰| 一区二区三区国产精品| 新片速递亚洲合集欧美合集| 国产麻豆午夜三级精品| 久久国产免费看| 欧美电影在线观看| 一区二区三区日韩欧美| 国产精品国产三级国产aⅴ无密码 国产精品国产三级国产aⅴ入口 | 亚洲免费在线观看| 久久久亚洲午夜电影| 亚洲第一精品影视| 欧美日韩国产一中文字不卡| 亚洲夜间福利| 老司机精品导航| 亚洲美女福利视频网站| 国产精品欧美一区喷水| 久久激情五月激情| 最新日韩在线视频| 欧美夜福利tv在线| 狠狠色综合网| 欧美片第一页| 久久av红桃一区二区小说| 亚洲丰满在线| 欧美与欧洲交xxxx免费观看 | 亚洲区在线播放| 国产精品国产自产拍高清av王其| 欧美一区影院| 亚洲精品一二三| 久久婷婷综合激情| 在线视频精品| 在线播放中文一区| 国产精品区免费视频| 欧美18av| 欧美在线观看你懂的| 亚洲卡通欧美制服中文| 久久久久成人精品免费播放动漫| 亚洲人精品午夜| 国产亚洲欧美激情| 欧美日韩三级一区二区| 久久久久久久久久久成人| 99视频日韩| 亚洲国产欧美一区二区三区久久| 欧美一区二区三区在线播放| 99视频国产精品免费观看| 国内视频一区| 国产精品有限公司| 欧美日韩成人综合| 蜜臀av一级做a爰片久久| 欧美影视一区| 亚洲一区二区成人| 日韩午夜免费| 亚洲国产精品一区二区第一页| 久久精品欧美日韩| 亚洲一区视频| 宅男噜噜噜66一区二区66| 亚洲第一网站免费视频| 国产性色一区二区| 国产精品视频免费在线观看| 欧美日韩精品在线播放| 欧美www视频在线观看| 久久久久久久91| 久久se精品一区精品二区| 午夜精品久久久久久久男人的天堂| 99精品欧美一区二区三区| 最新国产成人av网站网址麻豆| 欧美成人精品在线播放| 久久亚洲精品一区二区| 久久久久九九九| 久久九九久精品国产免费直播| 欧美在线一区二区三区| 亚洲欧洲99久久| 午夜电影亚洲| 欧美一区免费视频| 欧美一区二区三区四区在线观看地址 | 一区二区三区波多野结衣在线观看| 亚洲国产精品久久久久秋霞不卡| 一区在线电影| 在线精品亚洲一区二区| 亚洲国产精品成人一区二区| 亚洲电影激情视频网站| 亚洲激情电影在线| 亚洲精品久久嫩草网站秘色| 亚洲日本一区二区| 日韩一级网站| 亚洲欧美视频在线观看| 欧美在线视频日韩| 久久综合图片| 亚洲国产精品va在线看黑人| 亚洲国产视频一区| 日韩一级网站| 午夜欧美理论片| 久久蜜臀精品av| 欧美黑人多人双交| 国产精品国产三级欧美二区| 国产精品一区二区三区成人| 国产一区在线视频| 亚洲高清久久网| 中日韩视频在线观看| 欧美亚洲一区| 欧美成人69| 亚洲视频免费观看| 久久激情一区| 欧美日韩国产精品一区| 国产精品揄拍500视频| 在线观看精品| 亚洲一区精品电影| 久久亚洲不卡| 日韩天堂在线视频| 欧美在线1区| 欧美日韩国产色综合一二三四| 国产老女人精品毛片久久| 亚洲国产日韩一级| 西西人体一区二区| 亚洲第一福利视频| 亚洲欧美综合国产精品一区| 男同欧美伦乱| 国产精品羞羞答答| 亚洲日本欧美天堂| 久久久精品动漫| 亚洲精品四区| 久久女同精品一区二区| 国产精品男人爽免费视频1| 国产毛片精品国产一区二区三区| 亚洲激情视频在线观看| 久久se精品一区精品二区| 亚洲日本成人网| 久久久精品一区| 国产麻豆午夜三级精品| 99在线观看免费视频精品观看| 久久先锋资源| 亚洲女女女同性video| 欧美日韩999| 亚洲精品国产品国语在线app| 久久精品亚洲一区二区| 一区二区欧美亚洲| 欧美激情 亚洲a∨综合| 伊人久久男人天堂| 久久精品欧洲| 亚洲尤物视频在线| 欧美视频国产精品| 99精品视频免费全部在线| 欧美成人免费在线视频| 久久精品99无色码中文字幕| 国产免费成人在线视频| 亚洲视频视频在线| 亚洲伦理中文字幕| 欧美激情aaaa| 亚洲精品视频免费| 亚洲国产欧美日韩另类综合| 六月丁香综合| 亚洲国产另类久久精品| 美女视频网站黄色亚洲| 久久国产88| 一区国产精品| 欧美α欧美αv大片| 久久久午夜视频| 在线观看成人av| 欧美成人小视频| 免费视频久久| 日韩视频一区二区三区在线播放免费观看| 欧美14一18处毛片| 免费在线观看精品| 99国产精品| 亚洲手机成人高清视频| 国产精品自在在线| 久久久夜精品| 久久综合狠狠综合久久激情| 亚洲国产精品一区二区第一页|