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

            麒麟子

            ~~

            導航

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            統計

            常用鏈接

            留言簿(12)

            隨筆分類

            隨筆檔案

            Friends

            WebSites

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            #

            三維向量叉乘推導

            一直以來,我都記不住向量叉乘的結果,每次都要查詢。其根本原因在于,我沒有去研究過叉乘是如何推導出來的。于是,這次想徹底解決一下。首先要感謝維基百科,它已經把所有問題都描述清楚了。

            http://en.wikipedia.org/wiki/Cross_product

             

            而下面的文字,只是我的讀書筆記,以加深自己的印象。

             

            首先我們知道 ,對于向量u和v, u x v的結果,是得到一個既垂直于u又垂直于v的向量,假設記作n.

            則有下面公式

            n = u x v;

            而n的方向,是由右手法則決定的。 即伸出右手,四個手指方向從u繞到v. 此時,大姆指的方向,就是n的方向。 我們通常叫做右向量。

            引用一下維基百科的圖來說明問題,有興趣的兄弟可以照圖比劃一下。 (注:圖中向量是用的a x b來表示)

            image

             

            有了上面的知識,我們繼續向下看。

            我們假設向量 u,v,n分別用三個標量來表示。即

            u = (Xu,Yu,Zu)

            v = (Xv,Yv,Zv)

            n = (Xn,Yn,Zn)

            則,它們的關系為

            Xn = Yu*Zv – Zu*Yv;

            Yn = Zu*Xv – Xu*Zv;

            Zn = Xu*Yv – Yu*Xv;

            即 n = (Yu*Zv – Zu*Yv,Zu*Xv – Xu*Zv,Xu*Yv – Yu*Xv);

            而為了驗證n與u和v的垂直性,可以使用點乘進行

            點乘法則比這個簡單多了, u*v = (Xu*Xv + Yu*Yv + Zu*Zv) = dotUV;

            如果兩個向量垂直,則dotUV = 0;

            代入驗證一把

            u*n = (Xu*(Yu*Zv – Zu*Yv) + Yu*(Zu*Xv – Xu*Zv) + Zu*(Xu*Yv – Yu*Xv));

                  = Xu*Yu*Zv – Xu*Zu*Yv + Yu*Zu*Xv – Yu*Xu*Zv + Zu*Xu*Yv – Zu*Yu*Xv;

            把正負號的因式仔細比對一下,發現剛好可以低消。 結果為0.

            v*n 同理可證。

            于是,也驗證了n與u,v垂直的特性。

             

             

            如果只是為了應用的話,走到這一步就可以停下了。后面的知識,只是為了滿足一下好奇心。

            那我們就來看看,這個結論是怎么來的呢? 我們接著來推導。

            為了更好地推導,我們需要加入三個軸對齊的單位向量。

            i,j,k.

            i,j,k滿足以下特點

            i = j x k; j = k x i; k = i x j;

            k x j = –i; i x k = –j; j x i = –k;

            i x i = j x j = k x k = 0; (0是指0向量)

            由此可知,i,j,k是三個相互垂直的向量。它們剛好可以構成一個坐標系。

            這三個向量的特例就是 i = (1,0,0) j = (0,1,0) k = (0,0,1)。

             

            好,那對于處于i,j,k構成的坐標系中的向量u,v我們可以如下表示

            u = Xu*i + Yu*j + Zu*k;

            v = Xv*i + Yv*j + Zv*k;

             

            那么 u x v = (Xu*i + Yu*j + Zu*k) x (Xv*i + Yv*j + Zv*k)

                           = Xu*Xv*(ixi) + Xu*Yv*(i x j) + Xu*Zv*(i x k) + Yu*Xv*(j x i) + Yu*Yv*(j x j) + Yu*Zv*(j x k) + Zu*Xv*( k x i ) + Zu*Yv(k x j) + Zu*Zv(k x k)

            由于上面的i,j,k三個向量的特點,所以,最后的結果可以簡化為

            u x v = (Yu*Zv – Zu*Yv)*i + (Zu*Xv – Xu*Zv)j + (Xu*Yv – Yu*Xv)k;

            于是,在i,j,k構成的坐標系中。集就是上面的結果。

            當i = (1,0,0) j = (0,1,0) k = (0,0,1)時,我們通常省略i,j,k的寫法。最終也就得到了我們的右向量。

             

            叉乘的意義

              叉乘表示垂直于uxv的右向量。

            使用的地方

              可以通過叉乘,修正向量關系,從而構建坐標系。 常見的有 攝相機矩陣和TBN空間轉換矩陣的構建。

             

             

            叉乘的矩陣表示法。

             

            很多書上,包括 3D游戲大師編程技巧 上面,都是用的矩陣表示法來說明叉乘。

            如下。

            image

            它對應的矩陣表示法為

            image

            求其代數余子式,可以表示為如下

            image

            有了這個,那我們合并公因式i,j,k,則可以得到矩陣表示法

            image

             

            到此,叉乘的內容基本OK了。 值得說明的是,如果對方程組表示成矩陣不熟悉,就會感到不習慣,但是如果多多練習,我想應該是會習慣成自然吧。。。

            posted @ 2013-05-09 00:50 麒麟子 閱讀(8448) | 評論 (1)編輯 收藏

            開源模式

            開放源碼軟件《open-source》是一個新名詞,它被定義為描述其源碼可以被公眾使用的軟件,并且此軟件的使用,修改和分發也不受許可證的限制。開放源碼軟件通常是有copyright的,它的許可證可能包含這樣一些限制: 著意的保護它的開放源碼狀態,著者身份的公告,或者開發的控制。“開放源碼”正在被公眾利益軟件組織注冊為認證標記,這也是創立正式的開放源碼定義的一種手段。
            “開源軟件”可以進行商業化運作,“商業軟件”同樣也可以選擇“開源”。“開源”的目的是方便知識共享,而商業化運作則是為了將停留在“知識”層面上的軟件代碼與文檔轉變為適應商品社會需求的“軟件商品”,從而使知識盡快轉化為現實生產力。但從美國到歐洲再到中國,開源商業化卻明顯不同。
            在中國,開源軟件的最大意義是自主可控,保障信息安全,其次才是多供應商、成本低等等方面的考慮。開源軟件的“開源”特性在中國比在歐洲更為重視。
            美國是商業利益。在美國,是風險投資驅動開源軟件業務的發展。美國已有一個很大的、成功的私有軟件業務,美國的目標是建立下一代的軟件公司。
            雙許可證商業模式
              在美國,基于雙許可證的商業模式(或是在一個商業許可證下再許可開源代碼,或是銷售一個基于開源軟件上的增值商業版本)已是很普遍的。
            開源商業模式
              美國公司不愿意做服務商業模式,因為人力資本很貴。它們關注于提供產品,如提供私有的增值產品或在提供開源軟件版的同時提供企業版。
              在歐洲,訂購服務和支持模式是主要的,而在美國,認為服務模式不可擴展,應是產品模式。
              在中國,開源商業模式主要是服務,但是也有廠商銷售基于開源軟件開發的“自主版權”軟件,采取產品模式。當然,也有二者混合的模式。

            posted @ 2013-04-27 23:50 麒麟子 閱讀(332) | 評論 (0)編輯 收藏

            魔獸世界客戶端數據研究(四):M2文件頭分析

            終于決定,還是通過wow model viewer起手,研究一下WOW的數據類型,從另一個角度,體驗一把這個唯一讓我充過值的游戲。

            這將是一系列隨筆,即在讀代碼的時候,順便記錄,以理清思路和加深映象。 其中會有很多讓人費解的地方,如果有幸被某位兄弟看見

            ,請勿見笑。

            這都是第四篇關于M2文件格式的文章了,但是,對MD2文件格式的理解卻還是九牛一毛,冰山一角。 仔細思考了一下,發現是不是自己一

            開始走的路不對,因為是從半腰上分析的。 今天決定把文件頭補上。 因為文件頭可以大概看出一個文件是如何組織數據,以及包含哪些

            數據的。

            在此,給出WotLK的頭文件定義
                char id[4];
                uint8 version[4];
                uint32 nameLength;
                uint32 nameOfs;
                uint32 GlobalModelFlags; // 1: tilt x, 2: tilt y, 4:, 8: add another field in header, 16: ; (no other flags as

            of 3.1.1);

                uint32 nGlobalSequences; // AnimationRelated
                uint32 ofsGlobalSequences; // A list of timestamps.
                uint32 nAnimations; // AnimationRelated
                uint32 ofsAnimations; // Information about the animations in the model.
                uint32 nAnimationLookup; // AnimationRelated
                uint32 ofsAnimationLookup; // Mapping of global IDs to the entries in the Animation sequences block.
                //uint32 nD;
                //uint32 ofsD;
                uint32 nBones; // BonesAndLookups
                uint32 ofsBones; // Information about the bones in this model.
                uint32 nKeyBoneLookup; // BonesAndLookups
                uint32 ofsKeyBoneLookup; // Lookup table for key skeletal bones.

                uint32 nVertices; // GeometryAndRendering
                uint32 ofsVertices; // Vertices of the model.
                uint32 nViews; // GeometryAndRendering
                //uint32 ofsViews; // Views (LOD) are now in .skins.

                uint32 nColors; // ColorsAndTransparency
                uint32 ofsColors; // Color definitions.

                uint32 nTextures; // TextureAndTheifAnimation
                uint32 ofsTextures; // Textures of this model.

                uint32 nTransparency; // H,  ColorsAndTransparency
                uint32 ofsTransparency; // Transparency of textures.
                //uint32 nI;   // always unused ?
                //uint32 ofsI;
                uint32 nTexAnims;    // J, TextureAndTheifAnimation
                uint32 ofsTexAnims;
                uint32 nTexReplace; // TextureAndTheifAnimation
                uint32 ofsTexReplace; // Replaceable Textures.

                uint32 nTexFlags; // Render Flags
                uint32 ofsTexFlags; // Blending modes / render flags.
                uint32 nBoneLookup; // BonesAndLookups
                uint32 ofsBoneLookup; // A bone lookup table.

                uint32 nTexLookup; // TextureAndTheifAnimation
                uint32 ofsTexLookup; // The same for textures.

                uint32 nTexUnitLookup;        // L, TextureAndTheifAnimation, seems gone after Cataclysm
                uint32 ofsTexUnitLookup; // And texture units. Somewhere they have to be too.
                uint32 nTransparencyLookup; // M, ColorsAndTransparency
                uint32 ofsTransparencyLookup; // Everything needs its lookup. Here are the transparencies.
                uint32 nTexAnimLookup; // TextureAndTheifAnimation
                uint32 ofsTexAnimLookup; // Wait. Do we have animated Textures? Wasn't ofsTexAnims deleted? oO

                Sphere collisionSphere;
                Sphere boundSphere;

                uint32 nBoundingTriangles; // Miscellaneous
                uint32 ofsBoundingTriangles;
                uint32 nBoundingVertices; // Miscellaneous
                uint32 ofsBoundingVertices;
                uint32 nBoundingNormals; // Miscellaneous
                uint32 ofsBoundingNormals;

                uint32 nAttachments; // O, Miscellaneous
                uint32 ofsAttachments; // Attachments are for weapons etc.
                uint32 nAttachLookup; // P, Miscellaneous
                uint32 ofsAttachLookup; // Of course with a lookup.
                uint32 nEvents; //
                uint32 ofsEvents; // Used for playing sounds when dying and a lot else.
                uint32 nLights; // R
                uint32 ofsLights; // Lights are mainly used in loginscreens but in wands and some doodads too.
                uint32 nCameras; // S, Miscellaneous
                uint32 ofsCameras; // The cameras are present in most models for having a model in the Character-Tab.
                uint32 nCameraLookup; // Miscellaneous
                uint32 ofsCameraLookup; // And lookup-time again, unit16
                uint32 nRibbonEmitters; // U, Effects
                uint32 ofsRibbonEmitters; // Things swirling around. See the CoT-entrance for light-trails.
                uint32 nParticleEmitters; // V, Effects
                uint32 ofsParticleEmitters; // Spells and weapons, doodads and loginscreens use them. Blood dripping of a blade?

            Particles.
            };

            在說明之前,有幾個約定需要講解一下,以便簡單。 結構體中的 nXXXXX表示,有多少個這樣的數據單元
            而ofsXXXXXX表示,在哪里讀取這個數據。  而每一個數據單元具體的大小和信息,則需要由額外的地方來定義。
            在解釋的時候,就不對nXXXXX和ofsXXXX多作解釋了。

            下面逐一說明各變量的作用的含意
            id:  必然是 'M' 'D' '2' '0'
            version:  用來檢查文件版本的。 可以是以下值
                 // 10 1 0 0 = WoW 5.0 models (as of 15464)
                // 10 1 0 0 = WoW 4.0.0.12319 models
                // 9 1 0 0 = WoW 4.0 models
                // 8 1 0 0 = WoW 3.0 models
                // 4 1 0 0 = WoW 2.0 models
                // 0 1 0 0 = WoW 1.0 models
            nameLength和nameOfs 在WMV中,除了看到拿來檢測數據合法性外,沒有看到拿來讀取數據的地方

            GlobalModelFlags 模型的全局標志位,在WMV中除了看到用于輸出外,沒有看到有其它地方使用

            nGlobalSequences和ofsGlobalSequences 一個全局數據序列,數據單元類型為UINT32

            nAnimations和ofsAnimations 動畫數據信息,數據單元類型由ModelAnimation定義,此定義在WMV中如下。
            struct ModelAnimation
            {
                uint32 animID; // AnimationDataDB.ID
                uint32 timeStart;
                uint32 timeEnd;

                float moveSpeed;

                uint32 flags;
                uint16 probability;
                uint16 unused;
                uint32 d1;
                uint32 d2;
                uint32 playSpeed;  // note: this can't be play speed because it's 0 for some models

                Sphere boundSphere;

                int16 NextAnimation;
                int16 Index;
            };
            它主要是定義一個動畫的相關參數,比如ID,開始結束時間等等。

            nAnimationLookup,動畫數據查看表,主要是給外部提供一個查詢的便利性,數據單元類型為UINT16

            nBones,ofsBones 骨骼數據,數據單元類型為ModelBoneDef 其定義大致如下

            struct ModelBoneDef {
                int32 keyboneid; // Back-reference to the key bone lookup table. -1 if this is no key bone.
                int32 flags; // Only known flags: 8 - billboarded and 512 - transformed
                int16 parent; // parent bone index
                int16 geoid; // A geoset for this bone.
                int32 unknown; // new int added to the bone definitions.  Added in WoW 2.0
                AnimationBlock translation; // (Vec3D)
                AnimationBlock rotation; // (QuatS)
                AnimationBlock scaling; // (Vec3D)
                Vec3D pivot;
            };
            可以看出,每個骨頭都有一個ID,以及一些標志位,同時記錄了其父骨骼的索引。 而骨骼本身,則有平移,旋轉,縮放和錨點等數據。

            nKeyBoneLookup也是一個提供快速查詢的數據。 M2中很多對應的信息,都提供了這樣的LOOK UP TABLE。 典型的以空間換時間的做法。

            nVertices,ofsVertices 頂點信息,其數據單元定義如下
            struct ModelVertex
            {
                Vec3D pos;
                uint8 weights[4];
                uint8 bones[4];
                Vec3D normal;
                Vec2D texcoords;
                int unk1, unk2; // always 0,0 so this is probably unused
            };
            每一個頂點數據,有一個位置信息,4個骨骼索引和對應的權重 (其實貌似權重存3個就可以了。) 法線(法線貌似也只存兩個FLOAT就

            可以了。) 紋理坐標 以及兩個沒有摸索出用途的INT。  值得注意的是,WOW中的坐標用的是Z向上,Y向里的坐標。 如果要將WOW中的坐

            標轉換到左手坐標系(D3D默認)中。  則 X0,Y0,Z0 = X,Z,Y  若轉換成右手坐標系(OPENGL默認) 則 X0,Y0,Z0 = X,Z,-Y.  這個在

            前面分析數據的時候有說過。  因為在WMV中,就有轉換坐標系相關的操作。

            nViews, 此值表示模型有多少個LOD數據。 在WotLK版本以后,LOD數據全部被放入了 *.skin文件中。 不再在M2文件中讀取。
            假設一個模型為 ooxx.m2  那其對應的LOD文件信息可以為 ooxx00.skin  ooxx01.skin ooxx02.skin ooxx03.skin,而此M2模型的具體子

            模型劃分等細節,都在skin文件中了。

            nColors,ofsColors 此模型用到的顏色序列,用于實現模型動態變色效果 其數據單元定義為

            struct ModelColorDef {
                AnimationBlock color; // (Vec3D) Three floats. One for each color.
                AnimationBlock opacity; // (UInt16) 0 - transparent, 0x7FFF - opaque.
            };

            struct AnimationBlock {
                int16 type;        // interpolation type (0=none, 1=linear, 2=hermite)
                int16 seq;        // global sequence id or -1
                uint32 nRanges;
                uint32 ofsRanges;
                uint32 nTimes;
                uint32 ofsTimes;
                uint32 nKeys;
                uint32 ofsKeys;
            };

            nTextures,ofsTextures定義了此模型用到的紋理序列,其結構定義如下
            #define    TEXTURE_MAX    32
            struct ModelTextureDef
            {
                uint32 type;
                uint32 flags;
                uint32 nameLen;
                uint32 nameOfs;
            };
            關于紋理相關的內容,得專門有一篇文章講解一下才行。這個內容有點多,但是思路卻很清楚清晰

            nTransparency,ofsTransparency用于實現透明變化效果,其讀取結構定義如下
            struct ModelTransDef
            {
                AnimationBlock trans; // (UInt16)
            };
            AnimationBlock的定義上面已經給出

            nTexAnims 紋理動畫,結構體定義如下
            struct ModelTexAnimDef {
                AnimationBlock trans; // (Vec3D)
                AnimationBlock rot; // (QuatS)
                AnimationBlock scale; // (Vec3D)
            };
            這個表示在不同的情況下,紋理矩陣作用的效果,一些爆布,火盆上的火焰或者流動的巖漿就是通過這個實現的。

            nTexReplace 字面上是可替換的紋理,在WMV中沒有發現具體的用法。

            nTexFlags 紋理標記位,在WMV中沒有發現具體用法

            nBoneLookup 骨骼查詢表,在WMV中,除了拿來顯示以外,沒有看到特別的作用。

            nTexLookup 紋理查詢表,用于快速定位一個nTextures中讀出來的紋理。

            nTexUnitLookup 紋理單元查詢表,和上面的功能類似,貌似CTM版本就沒有使用到了。

            nTransparencyLookup 透明信息查詢表

            nTexAnimLookup 紋理信息查詢表

            collisionSphere 碰撞球

            boundSphere 包圍球

            nBoundingTriangles 構成包圍網格的三角形數據 每個數據單元是UINT16

            nBoundingVertices 構成包圍網格的頂點數據 每個數據單元是Vec3D,即三個FLOAT

            nBoundingNormals 構成包圍網格的法線數據 數據同上

            nAttachments掛接點的信息  每個掛接點的信息定義如下
            struct ModelAttachmentDef
            {
                uint32 id; // Just an id. Is referenced in the enum POSITION_SLOTS.
                uint32 bone; // Somewhere it has to be attached.
                Vec3D pos; // Relative to that bone of course.
                AnimationBlock unk; // (Int32) Its an integer in the data. It has been 1 on all models I saw. Whatever.
            };

            nAttachLookup 掛接點查詢表,用于快速定位某個掛接點

            nEvents 動畫播放時的事件觸發,用于完成一些特殊的,比如音效的播放,攻擊方與受擊方的動畫吻合等。 定義如下
            struct ModelEventDef
            {
                char id[4]; // This is a (actually 3 character) name for the event with a $ in front.
                int32 dbid; // This data is passed when the event is fired.
                int32 bone; // Somewhere it has to be attached.
                Vec3D pos; // Relative to that bone of course.
                int16 type; // This is some fake-AnimationBlock.
                int16 seq; // Built up like a real one but without timestamps(?). What the fuck?
                uint32 nTimes; // See the documentation on AnimationBlocks at this topic.
                uint32 ofsTimes; // This points to a list of timestamps for each animation given.
            };

            關于ID的值,WMV中列出了一些摸索到的。
            /*
            There are a lot more of them. I did not list all up to now.
            ID     Data     Description
            DEST         exploding ballista, that one has a really fucked up block. Oo
            POIN     unk     something alliance gunship related (flying in icecrown)
            WHEE     601+     Used on wheels at vehicles.
            $tsp         p is {0 to 3} (position); t is {W, S, B, F (feet) or R} (type); s is {R or L} (right or left); this is

            used when running through snow for example.
            $AHx         UnitCombat_C, x is {0 to 3}
            $BRT         Plays some sound.
            $BTH         Used for bubbles or breath. ("In front of head")
            $BWP         UnitCombat_C
            $BWR         Something with bow and rifle. Used in AttackRifle, AttackBow etc. "shoot now"?
            $CAH         UnitCombat_C
            $Cxx         UnitCombat_C, x is {P or S}
            $CSD    SoundEntries.dbc     Emote sounds?
            $CVS    SoundEntriesAdvanced.dbc     Sound
            $DSE       
            $DSL    SoundEntries.dbc     Sound with something special. Use another one if you always want to have it playing..
            $DSO    SoundEntries.dbc     Sound
            $DTH         UnitCombat_C, death, this plays death sounds and more.
            $EMV         MapLoad.cpp
            $ESD         Plays some emote sound.
            $EWT         MapLoad.cpp
            $FDx         x is {1 to 5}. Calls some function in the Object VMT. Also plays some sound.
            $FDx         x is {6 to 9}. Calls some function in the Object VMT.
            $FDX         Should do nothing. But is existant.
            $FSD         Plays some sound.
            $GCx         Play gameobject custom sound referenced in GameObjectDisplayInfo.dbc. x can be from {0 to 3}: {Custom0,

            Custom1, Custom2, Custom3}
            $GOx         Play gameobject sound referenced in GameObjectDisplayInfo.dbc. x can be from {0 to 5}: {Stand, Open,

            Loop, Close, Destroy, Opened}
            $HIT         Get hit?
            $KVS         MapLoad.cpp
            $SCD         Plays some sound.
            $SHK    SpellEffectCameraShakes.dbc     Add a camera shake
            $SHx         x is {L or R}, fired on Sheath and SheathHip. "Left/right shoulder" was in the old list.
            $SMD         Plays some sound.
            $SMG         Plays some sound.
            $SND    SoundEntries.dbc     Sound
            $TRD         Does something with a spell, a sound and a spellvisual.
            $VGx         UnitVehicle_C, x is {0 to 8}
            $VTx         UnitVehicle_C, x is {0 to 8}
            $WxG         x is {W or N}. Calls some function in the Object VMT.
            -------     ----------------------------------     - Old documentation (?) ----------------------------------------------
            $CSx         x is {L or R} ("Left/right hand") (?)
            $CFM       
            $CHD         ("Head") (?)
            $CCH         ("Bust") (?)
            $TRD         ("Crotch") (?)
            $CCH         ("Bust") (?)
            $BWR         ("Right hand") (?)
            $CAH       
            $CST
            */

            nLights 光照信息,標記了,模型的哪個骨骼上,掛接了燈光。 結構定義如下
            struct ModelLightDef {
                int16 type; // 0: Directional, 1: Point light
                int16 bone; // If its attached to a bone, this is the bone. Else here is a nice -1.
                Vec3D pos; // Position, Where is this light?
                AnimationBlock ambientColor; // (Vec3D) The ambient color. Three floats for RGB.
                AnimationBlock ambientIntensity; // (Float) A float for the intensity.
                AnimationBlock diffuseColor; // (Vec3D) The diffuse color. Three floats for RGB.
                AnimationBlock diffuseIntensity; // (Float) A float for the intensity again.
                AnimationBlock attenuationStart; // (Float) This defines, where the light starts to be.
                AnimationBlock attenuationEnd; // (Float) And where it stops.
                AnimationBlock useAttenuation; // (Uint32) Its an integer and usually 1.
            };

            nCameras 真的不是太懂這個。 結構體定義如下

            struct ModelCameraDef {
                int32 id; // 0 is potrait camera, 1 characterinfo camera; -1 if none; referenced in CamLookup_Table
                float fov; // No radians, no degrees. Multiply by 35 to get degrees.
                float farclip; // Where it stops to be drawn.
                float nearclip; // Far and near. Both of them.
                AnimationBlock transPos; // (Vec3D) How the cameras position moves. Should be 3*3 floats. (? WoW parses 36 bytes

            = 3*3*sizeof(float))
                Vec3D pos; // float, Where the camera is located.
                AnimationBlock transTarget; // (Vec3D) How the target moves. Should be 3*3 floats. (?)
                Vec3D target; // float, Where the camera points to.
                AnimationBlock rot; // (Quat) The camera can have some roll-effect. Its 0 to 2*Pi.
            };

            nCameraLookup 攝相機信息查詢表

            nRibbonEmitters 此模型身上的多邊形軌跡(緞帶)效果數目。 結構體定義如下
            struct ModelRibbonEmitterDef {
                int32 id;
                int32 bone;
                Vec3D pos;
                int32 nTextures;
                int32 ofsTextures;
                int32 nUnknown;
                int32 ofsUnknown;
                AnimationBlock color; // (Vec3D)
                AnimationBlock opacity; // (UInt16) And an alpha value in a short, where: 0 - transparent, 0x7FFF - opaque.
                AnimationBlock above; // (Float) The height above.
                AnimationBlock below; // (Float) The height below. Do not set these to the same!
                float res; // This defines how smooth the ribbon is. A low value may produce a lot of edges.
                float length; // The length aka Lifespan.
                float Emissionangle; // use arcsin(val) to get the angle in degree
                int16 s1, s2;
                AnimationBlock unk1; // (short)
                AnimationBlock unk2; // (boolean)
                int32 unknown; // This looks much like just some Padding to the fill up the 0x10 Bytes, always 0
            };

            最后一個值unknown是WotLK版本后新增的,不知道拿來干什么。 但可以肯定,WLK版本,加強了這個效果類型的表現力。

            nParticleEmitters 粒子系統,結構體定義如下。
            struct ModelParticleEmitterDefV10
            {
                int32 id;
                int32 flags;
                Vec3D pos; // The position. Relative to the following bone.
                int16 bone; // The bone its attached to.
                int16 texture; // And the texture that is used.
                int32 nModelFileName;
                int32 ofsModelFileName;
                int32 nParticleFileName;
                int32 ofsParticleFileName; // TODO
                int8 blend;
                int8 EmitterType; // EmitterType     1 - Plane (rectangle), 2 - Sphere, 3 - Spline? (can't be bothered to find one)
                int16 ParticleColor; // This one is used so you can assign a color to specific particles. They loop over all
                                     // particles and compare +0x2A to 11, 12 and 13. If that matches, the colors from the dbc get applied.
                int8 ParticleType; // 0 "normal" particle,
                                   // 1 large quad from the particle's origin to its position (used in Moonwell water effects)
                                   // 2 seems to be the same as 0 (found some in the Deeprun Tram blinky-lights-sign thing)
                int8 HeaderTail; // 0 - Head, 1 - Tail, 2 - Both
                int16 TextureTileRotation; // TODO, Rotation for the texture tile. (Values: -1,0,1)
                int16 cols; // How many different frames are on that texture? People should learn what rows and cols are.
                int16 rows; // (2, 2) means slice texture to 2*2 pieces
                AnimationBlock EmissionSpeed; // (Float) All of the following blocks should be floats.
                AnimationBlock SpeedVariation; // (Float) Variation in the flying-speed. (range: 0 to 1)
                AnimationBlock VerticalRange; // (Float) Drifting away vertically. (range: 0 to pi)
                AnimationBlock HorizontalRange; // (Float) They can do it horizontally too! (range: 0 to 2*pi)
                AnimationBlock Gravity; // (Float) Fall down, apple!
                AnimationBlock Lifespan; // (Float) Everyone has to die.
                int32 unknown;
                AnimationBlock EmissionRate; // (Float) Stread your particles, emitter.
                int32 unknown2;
                AnimationBlock EmissionAreaLength; // (Float) Well, you can do that in this area.
                AnimationBlock EmissionAreaWidth; // (Float)
                AnimationBlock Gravity2; // (Float) A second gravity? Its strong.
                ModelParticleParams p;
                AnimationBlock en; // (UInt16), seems unused in cataclysm
                int32 unknown3; // 12319, cataclysm
                int32 unknown4; // 12319, cataclysm
                int32 unknown5; // 12319, cataclysm
                int32 unknown6; // 12319, cataclysm
            };

            可見WOW在粒子這塊的處理還是比較用心的,畢竟很多裝備上都是這種效果,特別是武器,肩膀,頭盔,盾牌等裝備上的效果。
            后面CTM中新增的4個INT,可能是為了加強效果用的。 說明WOW還在繼續增強粒子系統的表現力。 也就是說,WOW中裝備的表現力還是將會通過粒子系統來實現。

            哇靠,又一點了。 發貼睡覺。。。。。

            posted @ 2013-04-27 01:03 麒麟子 閱讀(860) | 評論 (0)編輯 收藏

            魔獸世界客戶端數據研究(三)

            終于決定,還是通過wow model viewer起手,研究一下WOW的數據類型,從另一個角度,體驗一把這個唯一讓我充過值的游戲。

            這將是一系列隨筆,即在讀代碼的時候,順便記錄,以理清思路和加深映象。 其中會有很多讓人費解的地方,如果有幸被某位兄弟看見

            ,請勿見笑。

             

            今天來說一下M2中的LOD的數據

            WOW中,為了降低遠處模型的渲染開銷,為模型做了LOD,即遠處的模型,使用更少的頂點,更粗略的材質。 比如遠處的模型在渲染的時

            候,面片數量減少,關閉光照,不渲染掛接的特效等等。

            因此,不用證明也知道,M2中,材質是存在每一個LOD信息中的。
            哎,也就寫這幾句的時候順手些,其實不用分析,也是這個結果。因為我們自己的引擎就是這樣做的,何況是WOW這種大師級的作品呢。

            從WMV的解析代碼下手,看看它是如何解析的吧。
            首先,它使用了這樣一行代碼
            int16 *transLookup = (int16*)(f.getBuffer() + header.ofsTransparencyLookup);
            讀取了一串用于透明值的查找數組。 不過暫時沒有使用,后面材質構建的地方才會用到。
            接下來,就是讀取相關數據了。 在WLK以后,所有的這些數據,被分離到了.skin文件里面,不知道是咱想的,以后再來作討論。 但是在

            WLK之前,這個數據還是被放在了一起的。

            通過模型的名字我們組合上.skin,就是當前所要的渲染數據了。
            這個組合是這樣的。
            假如我們一個模型是 humanmale.m2
            那么它的四個LOD數據分別就是 humanmale01.skin humanmale02.skin humanmale03.skin humanmale04.skin

            當我們得到了這個數據后,就可以通過MPQFile加載想要的數據了。

            OK,假設上面的過程,我們已經完全搞定了,此時,我們就得到了一個skin的數據。有了這個數據,我們就可以為所欲為了,嘿嘿。有點

            夸張了。 在這個數據的最前面,肯定是數據頭了。 數據頭在WMV中本來一直是以xxxxHeader來定義的,不過在這里,它一改風格,定義

            了一個叫ModelView的東西。

            我們來看看這貨的定義
            struct ModelView
            {
            #ifdef WotLK
                char id[4]; //巫妖王版本新增的一個標記位,必須是 'S' 'K' 'I' 'N'
            #endif
                uint32 nIndex; //這個表示此LOD有多少個INDEX
                uint32 ofsIndex; //這個表示此LOD的INDEX從模型的哪里開始數
                uint32 nTris; //這個表示此LOD有多少個構建成三角形的索引
                uint32 ofsTris;     //三角形個數
                uint32 nProps; //額外的頂點屬性
                uint32 ofsProps; //頂點屬性讀取
                uint32 nSub; //有多少個子部件 后面定義的ModelGeoset表示一個子部件,其包括了MESH數據,材質,渲染狀態等內容
                uint32 ofsSub;     //
                uint32 nTex;  //紋理
                uint32 ofsTex;     // ModelTexUnit, material properties/textures
                int32 lod;                 // LOD bias?  WMV作者也打了問號。
            };

            有了這個數據頭以后,我們就可以無腦的先讀取上面的數據,然后再進行構建。

            索引數據
            uint16 *indexLookup = (uint16*)(g.getBuffer() + view->ofsIndex);
            構成三角形的頂點索引序列
            uint16 *triangles = (uint16*)(g.getBuffer() + view->ofsTris);

            當前模型在渲染時候的索引數目
            nIndices = view->nTris;
            重新分配索引
            wxDELETEA(indices);
            indices = new uint16[nIndices];

            將本地索引轉換成全局索引
            for (size_t i = 0; i<nIndices; i++)
            {
                    indices[i] = indexLookup[triangles[i]];
            }

            索引數據總算是完了,下面就得準備子模型和材質相關的事情。
            大家都知道,在渲染管線中,一次渲染提交只能提交具有相同渲染狀態和紋理的模型。 于是,我們的模型如果具有不同的材質,就需要

            先做分割處理。 這是所有WOW這樣的3D MMORPG引擎都需要處理的問題。

            在WMV中,模型渲染狀態相關的數據,使用了ModelGeoset來表示,紋理相關的,使用了ModelTexUnit來表示
            先看看ModelGeoset的定義
            /// Lod part, One material + render operation
            struct ModelGeoset
            {
                uint32 id;        // mesh part id?
                uint16 vstart;    // first vertex, Starting vertex number.
                uint16 vcount;    // num vertices, Number of vertices.
                uint16 istart;    // first index, Starting triangle index (that's 3* the number of triangles drawn so far).
                uint16 icount;    // num indices, Number of triangle indices.
                uint16 nSkinnedBones;    // number of bone indices, Number of elements in the bone lookup table.
                uint16 StartBones;        // ? always 1 to 4, Starting index in the bone lookup table.
                uint16 rootBone;        // root bone?
                uint16 nBones;        //
                Vec3D BoundingBox[2];
                float radius;
            };

            由上可知,它定義了渲染相關的頂點,以及骨骼,和包圍盒信息,最后一個是作為構建包圍球用的。

            /// Lod part, A texture unit (sub of material)
            struct ModelTexUnit
            {
                // probably the texture units
                // size always >=number of materials it seems
                uint16 flags;        // Usually 16 for static textures, and 0 for animated textures.
                uint16 shading;        // If set to 0x8000: shaders. Used in skyboxes to ditch the need for depth buffering.

            See below.
                uint16 op;            // Material this texture is part of (index into mat)
                uint16 op2;            // Always same as above?
                int16 colorIndex;    // A Color out of the Colors-Block or -1 if none.
                uint16 flagsIndex;    // RenderFlags (index into render flags, TexFlags)
                uint16 texunit;        // Index into the texture unit lookup table.
                uint16 mode;        // See below.
                uint16 textureid;    // Index into Texture lookup table
                uint16 texunit2;    // copy of texture unit value?
                uint16 transid;        // Index into transparency lookup table.
                uint16 texanimid;    // Index into uvanimation lookup table.
            };
            而上面這個結構,是紋理相關的信息。

            上面的信息,都是一些索引和ID值,真正的數據是放在全局信息中的。

            讀取完上面的數據后,LOD信息基本上就大功造成了。 而這些索引是如何使用的,只有下一次再研究了。今天又很晚了。

            由此可知,WOW中的數據組織和一般的引擎沒有太多區別。 即HEADER信息用于分割數據區域。
            整個模型要使用的數據,放在了最上層,然后,不同的LOD和子MESH要使用數據的時候,只需要保存一些索引值,再到全局數據里去查詢就可以了。

            暫時到此吧,下次繼續。。。。

            posted @ 2013-04-26 01:11 麒麟子 閱讀(2061) | 評論 (2)編輯 收藏

            魔獸世界客戶端數據研究(二)

            終于決定,還是通過wow model viewer起手,研究一下WOW的數據類型,從另一個角度,體驗一把這

            個唯一讓我充過值的游戲。

            這將是一系列隨筆,即在讀代碼的時候,順便記錄,以理清思路和加深映象。 其中會有很多讓人費

            解的地方,如果有幸被某位兄弟看見,請勿見笑。

             

            上次弄到nAttachLookup就不行了,這次繼續弄。
            最近四川地震了,所以弄得比較慢。

            好吧,我們接著nAttachLookup說。
            讀完掛接數據后,我們接著讀了堆nAttachLookup個的uint16數據。這串數據最后被存了下來。在

            WMV中用了一個uint16的數組來存儲,叫attLookup
            經過多方面分析,這個attLookup正如其名字一樣,是用來查詢掛接點的。
            而attLookup的值可以是以下枚舉成員

            enum POSITION_SLOTS
            { // wxString Attach_Names[]
                ATT_LEFT_WRIST = 0, // Mountpoint
                ATT_RIGHT_PALM,
                ATT_LEFT_PALM,
                ATT_RIGHT_ELBOW,
                ATT_LEFT_ELBOW,
                ATT_RIGHT_SHOULDER, // 5
                ATT_LEFT_SHOULDER,
                ATT_RIGHT_KNEE,
                ATT_LEFT_KNEE,
                ATT_RIGHT_HIP,
                ATT_LEFT_HIP, // 10
                ATT_HELMET,
                ATT_BACK,
                ATT_RIGHT_SHOULDER_HORIZONTAL,
                ATT_LEFT_SHOULDER_HORIZONTAL,
                ATT_BUST, // 15
                ATT_BUST2,
                ATT_FACE,
                ATT_ABOVE_CHARACTER,
                ATT_GROUND,
                ATT_TOP_OF_HEAD, // 20
                ATT_LEFT_PALM2,
                ATT_RIGHT_PALM2,
                ATT_PRE_CAST_2L,
                ATT_PRE_CAST_2R,
                ATT_PRE_CAST_3, // 25
                ATT_RIGHT_BACK_SHEATH,
                ATT_LEFT_BACK_SHEATH,
                ATT_MIDDLE_BACK_SHEATH,
                ATT_BELLY,
                ATT_LEFT_BACK, // 30
                ATT_RIGHT_BACK,
                ATT_LEFT_HIP_SHEATH,
                ATT_RIGHT_HIP_SHEATH,
                ATT_BUST3, // Spell Impact
                ATT_PALM3, // 35
                ATT_RIGHT_PALM_UNK2,
                ATT_DEMOLISHERVEHICLE,
                ATT_DEMOLISHERVEHICLE2,
                ATT_VEHICLE_SEAT1,
                ATT_VEHICLE_SEAT2, // 40
                ATT_VEHICLE_SEAT3,
                ATT_VEHICLE_SEAT4
            };

            上面這個枚舉成員,定義了WOW中一個帶動畫的模型可以掛接物體的位置。又可以說,是骨頭ID。在

            先前我們的ModelAttachment或者ModelAttachmentDef結構體中定義的id,就正好是上面的枚舉值中

            的一個。

            讀完掛接信息以后,就是顏色和透明度數據了,WOW的模型中,一個模型可以持有由若干顏色和透明

            度組成的序列,在每幀渲染的時候,動態插值計算出當前的值。 即可以實現顏色閃爍和透明度變化

            的效果。 幽靈虎和鳳凰什么的,就是用到了這個。

            //這是顏色結構體的定義,可以看出,它定義了一個顏色值,和一個16位的透明度值
            struct ModelColorDef {
                AnimationBlock color; // (Vec3D) Three floats. One for each color.
                AnimationBlock opacity; // (UInt16) 0 - transparent, 0x7FFF - opaque.
            };

            //這是透明度結構體的定義,也是一個16位的透明度值。
            struct ModelTransDef {
                AnimationBlock trans; // (UInt16)
            };

            這兩個定義,導致了模型透明度的重復。 而在WMV中的代碼,也確實是這樣寫的。先將顏色進行了

            插值,而后又用透明隊列的值對顏色中的ALPHA通道進行修改。

            讀取完了上面的數據后,接下來的,就是模型的LOD數據。 LOD中則包含了對應的材質數據。 在WMV

            中,只讀取了LOD0的模型。

            讀取完LOD后,WMV對模型的頂點數據建立了一個索引。

                if (nIndices) {
                    IndiceToVerts = new size_t[nIndices+2];
                    for (size_t i=0;i<nIndices;i++){
                        size_t a = indices[i];
                        for (size_t j=0;j<header.nVertices;j++){
                            if (a < header.nVertices && origVertices[a].pos == origVertices[j].pos){
                                IndiceToVerts[i] = j;
                                break;
                            }
                        }
                    }
                }

            今天暫時寫到這里,改天繼續。。。

            posted @ 2013-04-24 00:47 麒麟子 閱讀(512) | 評論 (0)編輯 收藏

            僅列出標題
            共38頁: 1 2 3 4 5 6 7 8 9 Last 
            久久人人爽人人爽人人爽| 国产高潮久久免费观看| 久久国产亚洲精品| 久久精品国产亚洲AV忘忧草18| 2021国产精品久久精品| 久久人人爽爽爽人久久久| 97超级碰碰碰碰久久久久| 久久人妻少妇嫩草AV蜜桃| 蜜臀久久99精品久久久久久小说| 久久99久久99小草精品免视看| 国产精品内射久久久久欢欢| 午夜精品久久久久久久久| 国产成人精品久久亚洲| 亚洲αv久久久噜噜噜噜噜| 国内精品久久人妻互换| 日韩久久无码免费毛片软件| 国产精品久久永久免费| 久久亚洲sm情趣捆绑调教| 欧美日韩中文字幕久久伊人| 伊人久久大香线蕉综合影院首页 | 久久久精品无码专区不卡| 亚洲精品无码成人片久久| 久久播电影网| 久久九九有精品国产23百花影院| 99久久夜色精品国产网站| 武侠古典久久婷婷狼人伊人| 色综合久久久久网| 久久久久久久99精品免费观看| 狠狠综合久久AV一区二区三区| 久久婷婷五月综合色99啪ak| 国产精品成人精品久久久| 精品久久久久久综合日本| 色婷婷综合久久久中文字幕| 久久久久亚洲AV片无码下载蜜桃| 青青热久久国产久精品 | 久久精品成人免费看| 亚洲成色WWW久久网站| 亚洲精品国精品久久99热一| 热99RE久久精品这里都是精品免费 | 99久久香蕉国产线看观香| 亚洲国产精品成人久久蜜臀 |