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

天行健 君子當(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類很簡單,因此也非常容易使用。首先,用歐拉角或四元數(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 閱讀(506) 評論(0)  編輯 收藏 引用

公告

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

隨筆分類(178)

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

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲欧洲中文日韩久久av乱码| 校园激情久久| 久久久亚洲高清| 久久精视频免费在线久久完整在线看| 久久久久五月天| 亚洲黄色视屏| 99av国产精品欲麻豆| 99国产精品久久久久久久| 欧美三级乱人伦电影| 亚洲在线观看视频网站| 久久免费99精品久久久久久| 久久国产精彩视频| 国产精品成人av性教育| 亚洲欧美视频在线观看| 日韩视频免费观看高清完整版| 一区二区三区国产在线观看| 亚洲欧美国产三级| 亚洲免费中文字幕| 久久久久高清| 一区二区三区久久网| 久久久久久黄| 欧美高潮视频| 欧美在线看片| 欧美日本中文| 久久免费精品视频| 欧美日韩性视频在线| 久久女同互慰一区二区三区| 欧美日韩国产高清| 久久野战av| 一本久久青青| 亚洲国产一区二区在线| 亚洲男人的天堂在线aⅴ视频| 欧美国产另类| 久久久国产精品一区| 亚洲女同精品视频| 久久精品国产一区二区三| 欧美精品1区2区| 亚洲成色777777在线观看影院| 久久国产乱子精品免费女| 免费日本视频一区| 久久久久久久999| 欧美日韩一区二区国产| 宅男精品导航| 久久婷婷久久| 久久久亚洲成人| 国产麻豆精品久久一二三| 日韩午夜高潮| 亚洲国产精品一区二区www| 亚洲午夜视频| 另类激情亚洲| 免费欧美在线| 久久人体大胆视频| 久久久国际精品| 国产女人18毛片水18精品| 一区二区三区日韩在线观看| 国产精品女人网站| 99精品视频免费观看视频| 亚洲乱码一区二区| 欧美bbbxxxxx| 久久av在线看| 久久尤物视频| 亚洲欧美日韩第一区| 中国日韩欧美久久久久久久久| 亚洲一区二区三区在线看| 中文欧美日韩| 欧美视频导航| 亚洲一本大道在线| 先锋影音久久| 国产亚洲一区二区精品| 亚洲激情精品| 中国成人黄色视屏| 欧美少妇一区二区| 亚洲一区精品在线| 久久精品欧美| 伊人成年综合电影网| 久久夜色精品国产欧美乱极品| 欧美视频第二页| 亚洲伊人网站| 久久亚洲高清| 亚洲人www| 亚洲图片欧美日产| 久久成人免费日本黄色| 欧美一区二区高清| 性视频1819p久久| 久久九九全国免费精品观看| 亚洲成色精品| 午夜在线一区二区| 久久综合久久综合九色| 亚洲免费福利视频| 国产精品国产三级国产| 亚洲国产精品美女| 亚洲主播在线播放| 国内精品久久久久久影视8| 免费成人av资源网| 一区二区三区国产盗摄| 麻豆精品在线视频| 一区二区精品国产| 国产尤物精品| 亚洲香蕉成视频在线观看| 久久精品国产亚洲高清剧情介绍| 欧美日韩在线播| 欧美一级视频一区二区| 亚洲国产日韩欧美一区二区三区| 精品av久久久久电影| 亚洲欧美激情视频| 欧美成人资源网| 午夜精品久久久久久久99水蜜桃| 欧美精品九九99久久| 亚洲欧美激情视频| 性欧美xxxx视频在线观看| 欧美日韩情趣电影| 久久久无码精品亚洲日韩按摩| 老司机成人在线视频| 亚洲精品一区二区三| 国产亚洲激情| 欧美特黄一区| 欧美阿v一级看视频| 欧美一区永久视频免费观看| 一本久久知道综合久久| 欧美激情在线播放| 久久久久久亚洲精品不卡4k岛国| 国产精品久久久久一区| 一区二区三区四区国产精品| 欧美xart系列高清| 亚洲黄色av一区| 国产一区成人| 国产精品视频一区二区三区| 欧美日本一道本| 欧美激情视频免费观看| 免费看黄裸体一级大秀欧美| 欧美在线视频一区二区三区| 美日韩在线观看| 久久久久99| 亚洲欧洲精品一区二区精品久久久 | 亚洲麻豆国产自偷在线| 欧美成人黑人xx视频免费观看| 91久久夜色精品国产网站| 国产一区二区三区电影在线观看 | 午夜在线不卡| 亚洲一区二区少妇| 一本色道久久综合狠狠躁篇的优点| 午夜欧美理论片| 久久久精品999| 亚洲专区在线| 午夜亚洲福利在线老司机| 在线视频亚洲欧美| 亚洲香蕉在线观看| 亚洲综合成人在线| 性欧美暴力猛交69hd| 久久9热精品视频| 国产欧美日韩在线播放| 国产欧美亚洲视频| 国产主播精品在线| 亚洲大胆人体视频| 欧美系列亚洲系列| 国产精品久久久久久久久搜平片| 久久久久久久一区二区三区| 久久九九热re6这里有精品| 久久亚洲一区二区三区四区| 欧美成年人视频| 国产精品播放| 国模一区二区三区| 亚洲欧洲视频| 亚洲综合不卡| 麻豆久久久9性大片| 亚洲国产精品久久久久| 99在线热播精品免费99热| 中文无字幕一区二区三区| 欧美在线观看网站| 牛牛影视久久网| 久久成人精品| 欧美成年人在线观看| 欧美午夜激情在线| 好看的亚洲午夜视频在线| 亚洲肉体裸体xxxx137| 午夜精品视频在线| 99re6热只有精品免费观看| 亚洲免费在线电影| 另类图片国产| 亚洲视频免费观看| 老司机免费视频一区二区| 国产精品成人观看视频国产奇米| 欧美jizzhd精品欧美巨大免费| 国产伦精品一区二区三区| 欧美韩日亚洲| 国产中文一区| 亚洲欧美日本国产专区一区| 欧美电影在线观看完整版| 亚洲一级一区| 欧美人与性动交cc0o| 精品成人在线视频| 亚洲欧美精品suv| 在线视频亚洲欧美| 欧美不卡高清| 午夜影视日本亚洲欧洲精品| 欧美日韩在线精品| 欧美三区在线视频| 亚洲国产清纯| 美女精品国产| 性欧美暴力猛交另类hd|