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

天行健 君子當(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>
            99视频有精品| 一区二区三区黄色| 久久久亚洲国产天美传媒修理工| 一区二区电影免费观看| 国产精品美女主播在线观看纯欲| 亚洲在线观看免费视频| 亚洲一区三区电影在线观看| 国产伦一区二区三区色一情| 久久影院午夜片一区| 麻豆国产va免费精品高清在线| 亚洲激情偷拍| 一区二区精品国产| 国产日韩专区| 亚洲大胆av| 欧美日韩精品一区二区三区四区| 在线亚洲免费| 久久福利视频导航| 日韩视频中文字幕| 午夜精品网站| 亚洲免费观看高清完整版在线观看熊 | 欧美精品一区二| 亚洲免费视频成人| 久久精品国产清自在天天线| 亚洲精品视频免费在线观看| 一区二区三区精品视频在线观看| 国产日韩一区| 亚洲精品一区二区网址| 国产毛片一区| 亚洲三级电影在线观看 | 久久久久久综合网天天| 日韩亚洲精品视频| 久久av老司机精品网站导航| 亚洲美女在线观看| 久久久国产精品一区二区三区| 一区二区日本视频| 久久亚洲色图| 久久精品伊人| 欧美性做爰毛片| 欧美黄色一区二区| 国户精品久久久久久久久久久不卡| 亚洲国产一区视频| 一区二区在线视频播放| 在线综合欧美| 夜夜嗨av一区二区三区网站四季av | 亚洲永久精品大片| 99re6热在线精品视频播放速度| 性欧美videos另类喷潮| 亚洲天堂av综合网| 欧美国产日韩视频| 欧美成人精品在线| 国产专区欧美精品| 午夜日韩在线| 午夜一区不卡| 国产精品美女黄网| 99国产精品国产精品久久| 亚洲国产日韩欧美在线动漫| 久久久99国产精品免费| 久久激情视频免费观看| 国产精品久久久久久久久久直播 | 亚洲区在线播放| 亚洲国产精品成人精品| 久久久欧美精品| 久热精品视频在线观看一区| 国产婷婷色一区二区三区在线| 亚洲视频视频在线| 亚洲欧美视频一区二区三区| 欧美视频在线观看| 亚洲午夜一区二区| 亚洲欧美制服中文字幕| 国产精品一区久久久| 亚洲欧美日韩高清| 久久精品亚洲| 激情av一区二区| 久久一区二区视频| 亚洲国产高清一区二区三区| 亚洲精品美女| 欧美日韩免费| 亚洲欧美一区二区原创| 久久精品亚洲一区| 亚洲第一页在线| 欧美激情精品久久久| 亚洲精品视频在线看| 亚洲一区二区欧美| 国产精品一区二区在线观看网站| 亚洲欧美综合v| 久久综合五月| 99精品热视频| 国产日韩精品久久久| 久久久美女艺术照精彩视频福利播放 | 国产日韩亚洲欧美| 久久―日本道色综合久久| 亚洲国产成人在线播放| 亚洲综合色视频| 国内外成人免费视频| 欧美jizzhd精品欧美喷水| 日韩特黄影片| 久久精品一区四区| 亚洲精品国产精品久久清纯直播| 欧美视频一区二区在线观看| 性欧美大战久久久久久久久| 亚洲第一色在线| 午夜精彩国产免费不卡不顿大片| 国内精品久久久久久久影视蜜臀 | 一区二区在线观看av| 免费观看成人鲁鲁鲁鲁鲁视频| 日韩视频在线一区| 久久亚洲图片| 亚洲无亚洲人成网站77777 | 久久黄色网页| 亚洲理论电影网| 蜜桃精品久久久久久久免费影院| 一本一本久久| 1024国产精品| 国产乱码精品一区二区三区不卡| 免费观看成人www动漫视频| 亚洲综合视频一区| 91久久夜色精品国产网站| 久久精品毛片| 亚洲高清在线视频| 久久激情五月激情| 亚洲欧美国产一区二区三区| 亚洲日本精品国产第一区| 国内精品写真在线观看| 欧美午夜精品久久久久久人妖| 久久天天躁狠狠躁夜夜av| 亚洲欧美一区二区视频| 一本不卡影院| 亚洲韩国日本中文字幕| 免费高清在线视频一区·| 欧美一区91| 午夜精彩国产免费不卡不顿大片| 日韩午夜在线播放| 亚洲国内高清视频| 在线国产日韩| 在线成人h网| 伊人精品久久久久7777| 国产香蕉久久精品综合网| 国产精品理论片| 欧美日韩在线精品一区二区三区| 欧美大片一区| 欧美激情视频给我| 欧美gay视频激情| 欧美不卡视频一区| 欧美精品久久一区二区| 欧美风情在线| 欧美日本二区| 欧美日韩视频在线第一区| 欧美日韩小视频| 欧美日韩在线综合| 国产精品国产三级国产a| 国产精品日韩在线观看| 国产精品久久久久毛片大屁完整版| 欧美日韩一区在线播放| 国产精品久久久久久久久久久久久 | 欧美日韩一区二区三区| 欧美午夜激情视频| 国产欧美三级| 精品99视频| 亚洲日本成人| 国产精品99久久久久久久女警| 亚洲少妇中出一区| 欧美一级一区| 免费在线欧美黄色| 亚洲黄一区二区| 亚洲午夜一二三区视频| 欧美在线一级va免费观看| 久久久久.com| 欧美激情一区在线观看| 国产精品久久久久国产精品日日| 国产女人水真多18毛片18精品视频| 国产嫩草影院久久久久 | 国产精品欧美久久| 国内精品久久久久久久97牛牛| 在线观看国产欧美| 亚洲天堂av电影| 久久久久久久性| 亚洲精品日韩综合观看成人91| 99这里只有久久精品视频| 性视频1819p久久| 欧美精选一区| 极品av少妇一区二区| 一区二区三区欧美在线| 久久天天综合| 99re热这里只有精品免费视频| 亚洲欧美在线一区| 欧美精品一卡二卡| 国产综合色产在线精品| 99这里只有精品| 快播亚洲色图| 亚洲天堂激情| 欧美破处大片在线视频| 黑人操亚洲美女惩罚| 亚洲一区二区动漫| 欧美激情一二三区| 欧美一级在线播放| 欧美日韩www| 亚洲人精品午夜| 美女啪啪无遮挡免费久久网站| 99国产精品国产精品久久| 久久综合中文字幕|