• <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>

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

            頂點(diǎn)坐標(biāo)變換(2)

            矩陣類型及其操作

            在Direct3D中,頂點(diǎn)坐標(biāo)變換通常是借助于矩陣實(shí)現(xiàn)的,因此下面首先介紹在Direct3D中提供的各種矩陣類型和相關(guān)的矩陣運(yùn)算函數(shù)。

             

            1、D3DMATRIX矩陣類型

            D3DMATRIX是Direct3D中最簡(jiǎn)單的矩陣類型,其定義如下:

            typedef struct _D3DMATRIX {
            union {
            struct {
            float _11, _12, _13, _14;
            float _21, _22, _23, _24;
            float _31, _32, _33, _34;
            float _41, _42, _43, _44;
                    };
            float m[4][4];
            };
            } D3DMATRIX;

            顯然,D3DMATIX中存放的是一個(gè)4x4的二維浮點(diǎn)數(shù)組,可以通過_ij的格式訪問該數(shù)組中的每個(gè)元素,i表示該元素的行數(shù),j表示該元素的列數(shù)。例如,_34表示第三行、第四列的元素。

             

            2、D3DXMATRIX矩陣類型

            該類型矩陣定義如下:

            #ifdef __cplusplus
            typedef struct D3DXMATRIX : public D3DMATRIX
            {
            public:
            D3DXMATRIX() {};
            D3DXMATRIX( CONST FLOAT * );
            D3DXMATRIX( CONST D3DMATRIX& );
            D3DXMATRIX( CONST D3DXFLOAT16 * );
            D3DXMATRIX( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
            FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
            FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
            FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 );
                // access grants
            FLOAT& operator () ( UINT Row, UINT Col );
            FLOAT operator () ( UINT Row, UINT Col ) const;
                // casting operators
            operator FLOAT* ();
            operator CONST FLOAT* () const;
                // assignment operators
            D3DXMATRIX& operator *= ( CONST D3DXMATRIX& );
            D3DXMATRIX& operator += ( CONST D3DXMATRIX& );
            D3DXMATRIX& operator -= ( CONST D3DXMATRIX& );
            D3DXMATRIX& operator *= ( FLOAT );
            D3DXMATRIX& operator /= ( FLOAT );
                // unary operators
            D3DXMATRIX operator + () const;
            D3DXMATRIX operator - () const;
                // binary operators
            D3DXMATRIX operator * ( CONST D3DXMATRIX& ) const;
            D3DXMATRIX operator + ( CONST D3DXMATRIX& ) const;
            D3DXMATRIX operator - ( CONST D3DXMATRIX& ) const;
            D3DXMATRIX operator * ( FLOAT ) const;
            D3DXMATRIX operator / ( FLOAT ) const;
                friend D3DXMATRIX operator * ( FLOAT, CONST D3DXMATRIX& );
                BOOL operator == ( CONST D3DXMATRIX& ) const;
            BOOL operator != ( CONST D3DXMATRIX& ) const;
            } D3DXMATRIX, *LPD3DXMATRIX;
            #else //!__cplusplus
            typedef struct _D3DMATRIX D3DXMATRIX, *LPD3DXMATRIX;
            #endif //!__cplusplus

             

            3、D3DXMATRIXA16矩陣類型

            D3DXMATRIXA16稱為16字節(jié)對(duì)齊矩陣(16-byte aligned matrix),它是從矩陣D3DXMATRIX中繼承而來(lái)的,其定義如下:

            typedef D3DX_ALIGN16 _D3DXMATRIXA16 D3DXMATRIXA16, *LPD3DXMATRIXA16;

            //---------------------------------------------------------------------------
            // Aligned Matrices
            //
            // This class helps keep matrices 16-byte aligned as preferred by P4 cpus.
            // It aligns matrices on the stack and on the heap or in global scope.
            // It does this using __declspec(align(16)) which works on VC7 and on VC 6
            // with the processor pack. Unfortunately there is no way to detect the
            // latter so this is turned on only on VC7. On other compilers this is the
            // the same as D3DXMATRIX.
            //
            // Using this class on a compiler that does not actually do the alignment
            // can be dangerous since it will not expose bugs that ignore alignment.
            // E.g if an object of this class in inside a struct or class, and some code
            // memcopys data in it assuming tight packing. This could break on a compiler
            // that eventually start aligning the matrix.
            //---------------------------------------------------------------------------
            #ifdef __cplusplus
            typedef struct _D3DXMATRIXA16 : public D3DXMATRIX
            {
            _D3DXMATRIXA16() {}
            _D3DXMATRIXA16( CONST FLOAT * );
            _D3DXMATRIXA16( CONST D3DMATRIX& );
            _D3DXMATRIXA16( CONST D3DXFLOAT16 * );
            _D3DXMATRIXA16( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
            FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
            FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
            FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 );
                // new operators
            void* operator new ( size_t );
            void* operator new[] ( size_t );
                // delete operators
            void operator delete ( void* ); // These are NOT virtual; Do not
            void operator delete[] ( void* ); // cast to D3DXMATRIX and delete.
                // assignment operators
            _D3DXMATRIXA16& operator = ( CONST D3DXMATRIX& );
            } _D3DXMATRIXA16;
            #else //!__cplusplus
            typedef D3DXMATRIX _D3DXMATRIXA16;
            #endif //!__cplusplus

            當(dāng)使用了Intel Pentium 4運(yùn)行一個(gè)D3DX數(shù)學(xué)函數(shù)時(shí),16字節(jié)對(duì)齊矩陣D3DXMATRIXA16為完成相應(yīng)操作進(jìn)行了優(yōu)化。當(dāng)使用VC++.net或使用安裝了processor pack的VC6++時(shí),將開啟字節(jié)對(duì)齊功能。但不幸的是,編譯器無(wú)法探測(cè)到是否安裝了processor pack,所以字節(jié)對(duì)齊僅僅只對(duì)VC++.net默認(rèn)開啟。對(duì)于其他編譯器,16字節(jié)對(duì)齊矩陣D3DXMATRIXA16將被當(dāng)作D3DXMATRIX進(jìn)行操作。

            經(jīng)過擴(kuò)展后的結(jié)構(gòu)體D3DXMATRIX和D3DXMATRIXA16對(duì)許多運(yùn)算符進(jìn)行了重載,所以可以直接進(jìn)行轉(zhuǎn)換運(yùn)算、賦值運(yùn)算以及多種一元、二元運(yùn)算,大大方便了矩陣類型變量的運(yùn)算。

             

            4、常見的矩陣運(yùn)算函數(shù)

            因?yàn)榫仃嚨倪\(yùn)算相對(duì)比較復(fù)雜,所以Direct3D提供了一組矩陣運(yùn)算函數(shù),例如,通過函數(shù)D3DXMatrixTranslation()構(gòu)造一個(gè)平移矩陣;通過函數(shù)D3DXMatrixRotationX()、D3DXMatrixRotationY()和D3DXMatrixRotationZ()構(gòu)造繞x、y和z軸轉(zhuǎn)動(dòng)一定角度的矩陣;通過函數(shù)D3DXMatrixScaling()構(gòu)造一個(gè)縮放矩陣;通過函數(shù)D3DXMatrxiIdentity()將一個(gè)矩陣單位化;通過函數(shù)D3DXMatrixMultiply()計(jì)算兩個(gè)矩陣的積;通過函數(shù)D3DXMatrixInverse()求原矩陣的逆矩陣;通過函數(shù)D3DXMatrixTranspose()計(jì)算原矩陣的轉(zhuǎn)置矩陣。


            posted on 2008-05-02 10:00 lovedday 閱讀(1198) 評(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)論

            99久久免费国产精品热| 久久亚洲精品无码观看不卡| 国内精品人妻无码久久久影院导航| 青青草原综合久久大伊人| 久久精品国产亚洲av麻豆图片| 久久婷婷五月综合国产尤物app| 狠色狠色狠狠色综合久久| 伊人精品久久久久7777| 国产一区二区三区久久| 精品国产乱码久久久久软件| 99久久精品国产麻豆| 久久婷婷人人澡人人爽人人爱| 精品久久久久久| 久久亚洲精品无码VA大香大香| 亚洲狠狠综合久久| 久久久久亚洲AV无码专区体验| 久久久久久极精品久久久| 国产成人精品免费久久久久| 99久久做夜夜爱天天做精品| 色综合久久天天综合| 久久久久久国产精品免费无码| 日本久久中文字幕| 国产精品99久久不卡| 国产精品久久久久AV福利动漫| 2021最新久久久视精品爱| 久久精品中文字幕有码| 91精品国产91热久久久久福利 | 久久夜色精品国产噜噜噜亚洲AV| 国产成人精品综合久久久| 久久久久久国产精品免费无码| 狠狠综合久久AV一区二区三区| 大香伊人久久精品一区二区 | 久久国产欧美日韩精品| 麻豆av久久av盛宴av| 国内精品久久久久影院老司 | 日日躁夜夜躁狠狠久久AV| 久久久久久久免费视频| 亚洲精品综合久久| 99精品国产免费久久久久久下载| 综合久久精品色| 久久久噜噜噜久久中文字幕色伊伊|