• <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)而不息

            Using Key?Framed Skeletal Animation(2)

            Working with the Four Key Types

            Currently, there are four types of keys you can use in your animation sets, each signified by a value ranging from 0 to 4 that is listed in the .X file following the frame reference inside an AnimationKey template. These four keys and their respective values are:

            Rotational keys (type 0). These are quaternion rotational values, stored using four components: w,x, y, and z.

            Scaling keys (type 1). You can also use this type of key to animate scaling values. A scale key uses three components that represent the x, y, and z scaling values to use.
             
            Translation keys (type 2). These keys specify a position in 3D space using three components that represent the x, y, and z coordinates. You can easily store these three values as a vector.

            Transformation matrix keys (type 4). You can use this key to compound all transformations into matrices. This key uses 16 floats that represent a homogenous 4x4 transformation matrix that transforms a bone.

            So getting back to the previous Animation data objects, you can see that the very first AnimationKey object (which affects the Bip01 bone) defines a transformation matrix key (represented by the value 4), as shown here:

            {Bip01}
            AnimationKey {
            4;
            3;
            0; 16; 1.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 1.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 1.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 1.00000;;,
            1000; 16; 1.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 1.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 1.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 1.00000;;,
            2000; 16; 1.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 1.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 1.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 1.00000;;;
            }

            As for the second AnimationKey object (which affects the Bip01_LeftArm bone), there are three keys in use: translation (value 2), scaling (value 1), and rotation (value 0).

            {Bip01_LeftArm}
            AnimationKey {
            0;
            1;
            0; 4; 1.00000, 0.000000, 0.00000, 0.000000;;;
            }
            AnimationKey {
            1;
            1;
            0; 4; 1.000000, 1.00000, 1.000000;;;
            }
            AnimationKey {
            2;
            1;
            0; 3; 0.000000, 0.00000, 0.000000;;;
            }

            As you may have surmised by now, you can have any number of AnimationKey objects per Animation object, with each AnimationKey object using one specific key type. Following the key's type value (0=rotational, 1=scaling, 2=position, 4=matrix) is the number of keys to use in the animation sequence for that specific bone. In the first bone's set (Bip01) there are three matrix type keys defined, whereas the remaining AnimationKey objects (that affect the Bip01_LeftArm bone) use only one key for each of the remaining transformation types (rotation, scaling, and position).

            Next comes the key data. The first value for each key is the time value, which is specified using an arbitrary value that you choose (such as seconds, milliseconds, frames, or any other form of measurement you wish to use). In my examples, I always specify time as milliseconds. A number that defines how many key values are to follow comes after the time value. Take the following key data, for example:

            AnimationKey {
              2; // Key type
              1; // # of keys
              0; // Key time
              3; // # of values to follow for key's data
              10.00000, 20.00000, 30.00000;;; // key's data
            }

            The first value, 2, means the key is used to contain translation animation keys. The 1 means there is one key to follow. The first and only key is located at time 0. The value 3 follows the time, which means that three more values (10, 20, and 30) are to follow. The three values represent the coordinates to use for that time in the animation.

            Going back to the earlier example, you can see that the first animation key (the transformation matrix key) has three matrices that are used at times 0, 1000, and 2000. At those exact times during the animation, you will set the transformation matrix for the Bip01 bone.

            For the time values between keys, you need to interpolate the matrices to come up with the correct transformations. In fact, you can interpolate all key types to get the correct values to use between keys. The easiest way to interpolate is to use the transformation matrix, scaling, translation, or rotation values from the animation keys, divide by the time between two keys, and multiply the result based on the time into the key. You saw me use linear interpolation for a transformation matrix in the previous section. Before long, I'll show you how to interpolate translation, scaling, and rotation values as well.

            That's basically it for the AnimationKey! You just need to read in each key contained within your AnimationKey data objects and apply it to the proper bone transformations using the interpolated matrices over time.

            Okay, enough of the animation templates, data objects, keys, and interpolation for now; we'll get back to that stuff in a bit. For now, let's get your hands into some real code and see how to load the animation data into your game. Then I'll get back to showing you how to work with the actual data.

             

            Reading Animation Data from .X Files

            You learned how to load meshes and frame hierarchies from an .X file, as well as how to use frame hierarchies to deform (modify) the mesh while rendering. This chapter's purpose is to teach you how to read in the animation data contained in an .X file so you can play back key−framed animations.

            The first step to reading in the animation data is to look at the templates you'll be using and build a couple classes to contain the data from those templates' data objects. First, here are the templates that you'll be working with, along with their declarations:

            template AnimationKey {
            <10DD46A8−775B−11cf−8F52−0040333594A3>
            DWORD keyType;
            DWORD nKeys;
            array TimedFloatKeys keys[nKeys];
            }
            template Animation {
            <3D82AB4F−62DA−11cf−AB39−0020AF71E433>
            [AnimationKey]
            [AnimationOptions]
            [...]
            }
            template AnimationSet {
            <3D82AB50−62DA−11cf−AB39−0020AF71E433>
            [Animation]
            }

            At the top of the list you have AnimationKey, which stores the type of animation key data, the number of key values to follow, and the key data itself, which is stored in an array of TimedFloatKey objects that store the time and an array of floating−point values in the form Time:NumValues:Values.

            Data objects of the Animation template class type can store an AnimationKey object and an AnimationOptions object. Notice that the Animation template is left open because it needs a frame data object reference to match the animation key to a bone.

            Last, there's the AnimationSet template, which only contains Animation objects. You can store any number of animations within an animation set; typically, you'll have one animation for each bone.

            Note The AnimationOptions template, is highly useful if you want your artists to specify playback options. Inside the AnimationOptions
            template, you'll find two variablesopenclosed and positionquality.If openclosed is set to 0, then the animation in which the object is embedded doesn't loop; a value of 1 means the animation loops. As for positionquality, setting it to a value of 0 means to use spline positions, whereas a value of 1 means to use linear positions. Typically, you'd set positionquality to 1.

            You'll want to use some custom classes to store your animation data; those classes will pretty much mirror the Animation templates' data exactly. First, you want a class that contains the values of the various key types: scaling, translation, rotation, and transformation. The first two types, scaling and translation, both use a vector, so one class will suffice.

            class cAnimationVectorKey
            {
            public:
              float m_Time;
              D3DXVECTOR3 m_vecKey;
            };

            Rotation keys use a quaternion (a four−dimensional vector).

            class cAnimationQuaternionKey
            {
            public:
              float m_Time;
              D3DXQUATERNION m_quatKey;
            };

            Last, the transformation key uses a 4x4 homogenous matrix.

            class cAnimationMatrixKey
            {
            public:
              float m_Time;
              D3DXMATRIX m_matKey;
            };

            So far, so good. Remember that each bone in your animation has its own list of keys to use, which is the purpose of the Animation template. For each bone in your hierarchy, there is a matching Animation data object. Your matching animation class will therefore contain the name of the bone to which it is connected, the number of keys for each type (translation, scaling, rotation, and transformation), a linked list data pointer, and a pointer to the bone (or frame) structure you're using in your hierarchy. Also, you need to include a constructor and destructor that clear out the class's data.

            class cAnimation
            {
            public:
            char *m_Name; // Bone's name
            D3DXFRAME *m_Bone; // Pointer to bone
            cAnimation *m_Next; // Next animation object in list
            	// # each key type and array of each type's keys
            	DWORD m_NumTranslationKeys;
            cAnimationVectorKey *m_TranslationKeys;
            	DWORD m_NumScaleKeys;
            cAnimationVectorKey *m_ScaleKeys;
            	DWORD m_NumRotationKeys;
            cAnimationQuaternionKey *m_RotationKeys;
            	DWORD m_NumMatrixKeys;
            cAnimationMatrixKey *m_MatrixKeys;
            public:
            cAnimation();
            ~cAnimation();
            };

            Finally, the AnimationSet template contains the Animation objects for an entire bone hierarchy. At this point, all your animation set class needs to do is track an array of cAnimation classes (remember that each bone in the hierarchy has a matching cAnimation class), as well as the length of the complete animation.

            class cAnimationSet
            {
            public:
            char *m_Name; // Name of animation
            DWORD m_Length; // Length of animation
            cAnimationSet *m_Next; // Next set in linked list
            DWORD m_NumAnimations;
            cAnimation *m_Animations;
            public:
            cAnimationSet();
            ~cAnimationSet();
            }

            posted on 2008-04-24 18:50 lovedday 閱讀(480) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            公告

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            隨筆分類(178)

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

            搜索

            最新評論

            久久精品视频一| 久久精品国产欧美日韩99热| 欧美一区二区三区久久综| 欧美激情一区二区久久久| 亚洲女久久久噜噜噜熟女| 国产精品久久久久久影院| 国产精品亚洲综合专区片高清久久久 | 久久99国产精品一区二区| 久久久青草久久久青草| 久久人搡人人玩人妻精品首页| 国产精品成人久久久| 久久青青草原综合伊人| 亚洲精品无码久久不卡| 日本三级久久网| 久久99热这里只有精品国产| 99久久久精品| 亚洲欧美成人综合久久久| 精品综合久久久久久88小说| 亚洲精品无码久久久影院相关影片| 国产精品18久久久久久vr| 久久久久亚洲av成人网人人软件 | 久久精品天天中文字幕人妻| 久久精品成人欧美大片| 国内精品久久久久久99蜜桃 | 国产精品久久久久天天影视| 久久久亚洲欧洲日产国码是AV | 久久久久亚洲av毛片大| 久久精品国产免费一区| 久久久久久亚洲Av无码精品专口| 中文成人无码精品久久久不卡| 91精品国产综合久久香蕉| 久久人人爽人人爽人人片av高请 | 99久久精品国产免看国产一区| 亚洲狠狠婷婷综合久久蜜芽| 亚洲Av无码国产情品久久| 精品久久久久久无码人妻蜜桃| 999久久久国产精品| 久久亚洲综合色一区二区三区| 久久国产乱子精品免费女| 国产精品久久网| 久久综合久久综合九色|