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

天行健 君子當(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福利精品导航| 亚洲国产精品999| 亚洲天堂av图片| 亚洲免费av观看| 欧美性猛交99久久久久99按摩 | 国产一区二区三区黄| 久久久亚洲高清| 久久美女艺术照精彩视频福利播放| 尤物网精品视频| 91久久在线观看| 国产精品红桃| 久久午夜电影| 欧美剧在线免费观看网站| 亚洲欧美另类久久久精品2019| 午夜欧美大尺度福利影院在线看| 在线观看日韩av| 一本色道久久综合亚洲精品高清| 国产日韩欧美在线| 亚洲韩国日本中文字幕| 国产精品久久午夜| 男人插女人欧美| 国产精品久久久久久久久动漫| 欧美中文字幕久久| 欧美激情中文不卡| 欧美主播一区二区三区| 欧美国产日本韩| 欧美主播一区二区三区美女 久久精品人| 欧美一区二区三区在线观看视频| 亚洲高清视频一区| 亚洲在线国产日韩欧美| 亚洲精品国产精品国产自| 亚洲视频在线观看网站| 亚洲视频在线观看视频| 激情校园亚洲| 亚洲一区二区在线免费观看视频| 亚洲国产精品久久久久秋霞蜜臀| 欧美国产日韩在线观看| 欧美精品一区二区视频| 久久九九国产精品| 欧美日韩免费看| 欧美国产亚洲视频| 合欧美一区二区三区| 亚洲视频二区| 国产精品99久久久久久久vr | 欧美一区二区三区在线观看| 在线午夜精品自拍| 免费成年人欧美视频| 久久亚洲春色中文字幕| 国产精品一区二区三区四区五区 | 91久久精品日日躁夜夜躁国产| 国产亚洲精品美女| 亚洲欧美日韩国产| 校园激情久久| 国产精品色婷婷久久58| 99热免费精品在线观看| 日韩视频在线一区二区| 欧美成人免费小视频| 欧美.com| 最近中文字幕日韩精品| 老司机成人网| 欧美成人午夜77777| 精品成人乱色一区二区| 久久精品99国产精品| 久久精品在线视频| 国产日韩精品在线观看| 香蕉成人伊视频在线观看| 亚洲欧美成人精品| 国产精品一区二区黑丝| 香蕉久久一区二区不卡无毒影院 | 久久国产色av| 免费人成精品欧美精品| 在线日韩欧美| 欧美mv日韩mv国产网站app| 亚洲国产精品一区二区尤物区 | 亚洲精品一区中文| 欧美日本高清一区| 亚洲在线成人| 玖玖玖国产精品| 亚洲精品视频在线观看免费| 欧美日韩国产丝袜另类| 99热这里只有精品8| 香蕉亚洲视频| 一区二区三区在线视频播放| 欧美99在线视频观看| 亚洲狼人精品一区二区三区| 亚洲综合精品四区| 国语自产精品视频在线看一大j8| 久久亚洲私人国产精品va媚药| 亚洲高清二区| 小嫩嫩精品导航| 亚洲国产欧洲综合997久久| 欧美日韩精品综合| 欧美一区二区三区的| 欧美凹凸一区二区三区视频| 中文av字幕一区| 国语自产精品视频在线看一大j8 | 欧美—级a级欧美特级ar全黄| 一本久道久久综合狠狠爱| 久久精品女人的天堂av| 亚洲美女在线观看| 国产视频久久| 欧美剧在线免费观看网站| 欧美亚洲一级| 9l视频自拍蝌蚪9l视频成人| 乱码第一页成人| 亚洲先锋成人| 亚洲人妖在线| 国产一区深夜福利| 欧美天天综合网| 久久这里有精品15一区二区三区| 亚洲午夜电影| 亚洲精品久久久久| 免费人成网站在线观看欧美高清| 亚洲女性裸体视频| 亚洲美女黄网| 亚洲国产另类 国产精品国产免费| 国产精品美女主播| 欧美精品18+| 久久只有精品| 久久精品免费电影| 亚洲综合999| 在线亚洲+欧美+日本专区| 亚洲精华国产欧美| 欧美α欧美αv大片| 久久久国产精品一区二区中文| 亚洲永久在线| 亚洲午夜激情在线| 一区二区动漫| 日韩亚洲一区二区| 亚洲精品欧美日韩| 亚洲激情在线观看视频免费| 在线不卡a资源高清| 韩国成人理伦片免费播放| 国产精品专区一| 国产精品尤物福利片在线观看| 欧美色综合天天久久综合精品| 欧美激情一区二区三区在线| 欧美成人精品| 欧美国产日韩xxxxx| 欧美黄色一级视频| 欧美aaa级| 欧美伦理视频网站| 欧美日韩国产一区二区| 欧美日韩国产三级| 国产精品久久波多野结衣| 国产精品国产三级国产专播品爱网| 欧美日韩精品免费在线观看视频| 欧美人在线观看| 国产精品久久久久久av福利软件| 欧美三级电影一区| 国产精品久久婷婷六月丁香| 国产欧美日韩精品专区| 国产一区二区中文| 亚洲大胆人体在线| 99riav1国产精品视频| 在线一区二区三区做爰视频网站| 亚洲系列中文字幕| 久久精品国产久精国产爱| 久久久视频精品| 欧美国产视频一区二区| 亚洲理伦电影| 欧美一区不卡| 男女激情久久| 国产精品蜜臀在线观看| 国产亚洲欧美一级| 亚洲人成网站影音先锋播放| 亚洲神马久久| 久久亚洲精品欧美| 亚洲激情网站| 欧美亚洲在线视频| 欧美福利电影网| 国产精品自拍小视频| 亚洲缚视频在线观看| 亚洲一区二区精品在线观看| 久久久精品欧美丰满| 亚洲国产精品传媒在线观看 | 牛人盗摄一区二区三区视频| 亚洲精品久久久久久久久久久久久| 一区二区三区回区在观看免费视频| 亚洲欧美日韩爽爽影院| 欧美二区在线看| 国产日韩一区二区三区在线播放| 91久久精品一区二区别| 亚洲中字在线| 亚洲福利视频免费观看| 午夜精品久久久久久久99热浪潮 | 欧美日韩午夜激情| 在线观看av不卡| 香蕉久久一区二区不卡无毒影院| 欧美黑人一区二区三区| 亚洲欧美伊人| 欧美日韩另类国产亚洲欧美一级| 激情小说亚洲一区| 午夜久久影院| 亚洲精品网站在线播放gif| 久久精品国产一区二区三区免费看| 欧美日韩在线观看一区二区三区| 1000部国产精品成人观看| 欧美一区日韩一区| 一本一本久久a久久精品综合麻豆 一本一本久久a久久精品牛牛影视 |