• <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 the .X File Format(2)

            Defining Templates

            Since an .X file's open−ended design is so, well, open−ended, you must predefine each template that you intend to use for DirectX to understand how to access the template's data. Typically templates are defined inside an .X file, although you can define them from within your program (as I mentioned earlier).

            You define a template (contained in an .X file) by assigning it a unique class name preceded by the word template, as I have done in the following line of text. (Notice the opening bracket, which signifies the start of the template's definition.)

            template ContactEntry {

            Cool−now you've started the declaration of a template that you will use to store a person's contact information. We're calling the template class ContactEntry, as you can see from the code. Even though you have assigned your template a unique class name, you need to go one step further and also assign it a unique identification number−a GUID.

            When you get around to reading an .X file into your program, you'll only have access to the GUIDs of each template, not the class names. The class names are important only to your .X file data objects; you want your program to differentiate those data objects by their template GUIDs.

            To define a GUID for your template, fire up the guidgen.exe program that comes with your Microsoft Visual C/C++ compiler installation (located in the \Common\Tools directory of your MSVC installation). After you've found and executed the guidgen.exe file, you'll be presented with a small dialog box, shown in Figure 3.1.

            Figure 3.1: The guidgen.exe's Create GUID dialog box allows you to create a unique identification number in various formats.

            As you can see in Figure 3.1, the Create GUID dialog box allows you to choose the format of the GUID you want to create. In this case you'll use format #2, DEFINE_GUID(). Select the option and click the Copy button.

            Now a completely unique identification number is on the Clipboard, waiting for you to paste it into your code. Go back to the .X file you are creating and paste the contents of the Clipboard into your template declaration.

            template ContactEntry {
            // {4C9D055B−C64D−4bfe−A7D9−981F507E45FF}
            DEFINE_GUID(<<name>>,
            0x4c9d055b, 0xc64d, 0x4bfe, 0xa7, 0xd9, 0x98, 0x1f, 0x50, 0x7e, 0x45, 0xff);

            Whoops! That's a little too much text for the template, so you need to cut out the DEFINE_GUID macro stuff and paste that into your project's source code. Yes, that's right−every template you define requires a matching GUID definition (via the DEFINE_GUID macro, for example) inside your code. This means you need to include the initguid.h file in your code and use DEFINE_GUID, as I have done here.

            #include "initguid.h"

            // At beginning of source code file − add DEFINE_GUIDs
            DEFINE_GUID(ContactEntry, 0x4c9d055b, 0xc64d, 0x4bfe, 0xa7, 0xd9, 0x98,  0x1f, 0x50, 0x7e, 0x45, 0xff);

            Notice that in the DEFINE_GUID macro, I've replaced the <<name>> text with the actual class name of the template I am defining. In this case, I am using ContactEntry as a macro name. From this point on, the ContactEntry macro will contain a pointer to my template's GUID (which must match the template's GUID in the .X file).

            Getting back to the ContactEntry template, you also need to remove the comment tag from the pasted text and change the GUID's brackets to angle brackets, as I have done here:

            template ContactEntry {
            <4C9D055B−C64D−4bfe−A7D9−981F507E45FF>

            Now you're ready to move on and define the template's data. Templates are much like C structures and classes; they contain variables and pointers to other templates, as well as access restrictions. The types of variables you can use are much like the ones you use in C. Table 3.1 shows you the data types at your disposal for defining templates, as well as matching C/C++ data types.

            Much like C/C++ variable declarations, you follow the data type keyword with an instance name and finish with a semicolon (signifying the end of the variable declaration).

            DWORD Value;

            In Table 3.1, you'll notice the array keyword, which defines an array of data types. To define an array, you specify the array keyword followed by the data type, instance name, and array size (enclosed in square brackets). For example, to declare an array of 20 STRING data types, you could use:

            array STRING Text[20];

            Note The cool thing about arrays is that you can use another data type to define the array size, as I have done here:

            DWORD ArraySize;

            array STRING Names[ArraySize];

            Now you need to go back to the ContactEntry template and define a person's name, phone number, and age. The three variables−two strings (name and phone number) and one numerical value (age)−can be defined in the ContactEntry template as follows.

            template ContactEntry {
              <4C9D055B−C64D−4bfe−A7D9−981F507E45FF>
              STRING Name; // The contact's name
              STRING PhoneNumber; // The contact's phone number
              DWORD Age; // The contact's age
            }

            Cool! You finish your template definition with a closing bracket, and you're ready to go.

             

            Creating Data Objects from Templates

            After you have defined a template, you can begin creating data objects and defining their data. Data objects are defined by their respective template class types and an optional instance name. You can use this instance name to later reference the data object inside the .X file or from within your project (a feature you'll read about later in this chapter).

            Moving on with the example, take the ContactEntry template and create a data object from it. This data object will contain a person's name, phone number, and age.

            ContactEntry JimsEntry {
              "Jim Adams";
              "(800) 555−1212";
              30;
            }

            Notice that I've declared the data object's instance name as JimsEntry. From now on, I can reference this data object by using the name enclosed in brackets, like this:

            {JimsEntry}

            Referencing a data object in this manner is called data referencing, or referencing (as if you couldn't guess!), and it allows you to point one data object to another. For example, an animation sequence template (AnimationSet) requires you to reference a Frame data object for the sequence's embedded objects.

            You can also use referencing to duplicate an object's data without having to retype it. This is useful when you are creating a few identical Mesh data objects in an .X file, with each Mesh object being oriented differently inside various Frame objects.


            posted on 2008-04-16 19:16 lovedday 閱讀(402) 評(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)論

            久久超碰97人人做人人爱| 亚洲va久久久噜噜噜久久男同| 午夜精品久久久久久中宇| 伊人久久大香线蕉综合Av| 久久久精品2019免费观看| 国产精品禁18久久久夂久| 噜噜噜色噜噜噜久久| 久久久久国产精品熟女影院 | 久久亚洲高清综合| 久久精品天天中文字幕人妻| 91精品无码久久久久久五月天| 亚洲国产高清精品线久久| 99久久久精品| AV狠狠色丁香婷婷综合久久| 久久国产精品免费一区二区三区 | 亚洲精品tv久久久久| 精品久久久久香蕉网| 久久综合久久综合亚洲| a级毛片无码兔费真人久久| 久久精品一区二区三区不卡| 国产福利电影一区二区三区久久久久成人精品综合 | 色综合久久中文色婷婷| 久久综合88熟人妻| 亚洲精品乱码久久久久久蜜桃不卡 | 亚洲欧美国产精品专区久久 | 色婷婷久久综合中文久久一本| 精品国产91久久久久久久a| 久久国产精品成人片免费| 久久久久久国产精品无码下载| 久久天天躁夜夜躁狠狠躁2022 | 亚洲精品国精品久久99热| 美女写真久久影院| 久久久久久久99精品免费观看| 69久久夜色精品国产69| 日韩精品久久久肉伦网站| 天天躁日日躁狠狠久久| 久久久精品人妻一区二区三区四| 久久国产高潮流白浆免费观看| 久久国产免费观看精品3| 99久久精品午夜一区二区| 国产精品无码久久综合 |