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

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

Using the .X File Format(11)

Loading Frame Hierarchies from .X

Skeletal animation systems require a frame hierarchy (which represents the bone structure) to orient each bone during rendering. The .X file format defines a frame−of−reference data template that you can use to define your bone hierarchy. This template, Frame, is merely a placeholder of sorts. It allows any type of data object to be embedded in it so you can reference the instanced Frame object by its assigned instance name and allow all contained objects to be addressed as well.

Building a frame hierarchy involves parsing an .X file, in which you link each Frame object to another. The relationship is very important−a Frame object can either be a sibling or a child to another Frame object, and it can have an unlimited number of siblings and/or child objects linked to it.

In DirectX 9, you have access to a special DirectX structure called D3DXFRAME to contain each frame in your hierarchy. In this section, you'll use D3DXFRAME to contain a frame hierarchy.

The exact way you parse and build your Frame objects is really up to you. You can use the D3DX library to help, or you can parse/build the hierarchy yourself using your custom .X parser. Which is better for you? Whereas the D3DX library is great to use, I find the methods of using the library to load a frame hierarchy overly complicated, with no less than two interfaces to use and an entire memory−handling class of your own to be written. Why bother when you can load a frame hierarchy using one small .X parser class you created?

Instead, load up your trusty .X parser (which you developed earlier in this chapter, in the "Constructing an .X Parser Class" section) and derive a version that scans for Frame data objects. I'll start you off by showing you the derived class you can use.

class cXFrameParser : public cXParser
{
public:
// declare an extended version of D3DXFRAME
// that contains a constructor and destructor
struct D3DXFRAME_EX : public D3DXFRAME
{
D3DXFRAME_EX()
{
Name = NULL;
pFrameSibling = NULL; pFrameFirstChild = NULL;
}
		~D3DXFRAME_EX()
{
delete [] Name;
delete pFrameFirstChild;
delete pFrameSibling;
}
} D3DXFRAME_EX;
	// Instance the root frame of the hierarchy
D3DXFRAME_EX *m_RootFrame;
public:
cXFrameParser() { m_RootFrame = NULL; }
~cXFrameParser() { delete m_RootFrame; }
	BOOL BeginParse(void **Data)
{
// Clear hierarchy
delete m_RootFrame; m_RootFrame = NULL;
}
	BOOL ParseObject(IDirectXFileData *pDataObj, 
IDirectXFileData *pParentDataObj,
DWORD Depth,
void **Data,
BOOL Reference)
{
// Skip reference frames
if(Reference == TRUE)
return TRUE;
		// Make sure template being parsed is a frame
if(*GetObjectGUID(pDataObj) == TID_D3DRMFrame)
{
// Allocate a frame structure
D3DXFRAME_EX *Frame = new D3DXFRAME_EX();
			// Get frame name (assign one if none found)
if((Frame−>Name = GetObjectName(pDataObj)) == NULL)
Frame−>Name = strdup("No Name");
			// Link frame structure into list
if(Data == NULL)
{
// Link as sibling of root
Frame−>pFrameSibling = m_RootFrame;
m_RootFrame = Frame;
Data = (void**)&m_RootFrame;
}
else
{
// Link as child of supplied frame
D3DXFRAME_EX *FramePtr = (D3DXFAME_EX*)*Data;
Frame−>pFrameSibling = FramePtr−>pFrameFirstChild;
FramePtr−>pFrameFirstChild = Frame;
Data = (void**)&Frame;
}
}
		return ParseChildObjects(pDataObj,Depth,Data,Reference);
}
};
cXFrameParser Parser;
Parser.Parse("frames.x");
// Parser.m_RootFrame now points to root frame of hierarchy

There you have it. Once the cXFrameParser::Parse function is complete, you'll have a self−contained frame hierarchy ready to use in your project. The ParseFrame demo loads an .X file of your choice and displays the frame hierarchy inside a list box.

 

ParseFrame Demo

This demo uses the information on loading a frame hierarchy from an .X file. As shown in Figure 3.2, the ParseFrame demo has a button labeled Select .X File. Click that button, locate an .X file to load, and click Open.

Figure 3.2: The ParseFrame demo's dialog box contains two controls−a button you click to load an .X file and a list box that displays the frame hierarchy.

After selecting an .X file to load and clicking Open, you'll be treated to a display of the frame hierarchy contained within the file. To make things easier to understand, the frames are indented by their level in the hierarchy.

Because IDirectXFile interface has been deprecated, I translate this interface into ID3DXFile.

WinMain.cpp:

#include <stdio.h>
#include 
<windows.h>
#include 
<d3d9.h>
#include 
<d3dx9.h>
#include 
<rmxfguid.h>
#include 
"Direct3D.h"
#include 
"XParser.h"
#include 
"resource.h"

#pragma warning(disable : 
4996)

extern unsigned char D3DRM_XTEMPLATES[];

D3DXFRAME_EX
* g_root_frame;

const char g_class_name[] = "ParseFrameClass";
const char g_caption[]      = ".X Frame Parser Demo";

////////////////////////////////////////////////////////////////////////////////////////////////

LRESULT FAR PASCAL window_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

bool do_init(HWND hwnd);
void do_shutdown();
void do_frame();

void add_frames_to_list(D3DXFRAME_EX* frame, DWORD indent, HWND list_handle);

//////////////////////////////////////////////////////////////////////////////////////////////

class cXFrameParser : public cXParser
{
protected:
    D3DXFRAME_EX
* m_root_frame;

protected:
    
virtual bool parse_objects(ID3DXFileData* xfile_data,
                               ID3DXFileData
* parent_xfile_data,
                               DWORD  depth,
                               
void** data,
                               
bool   force_ref)
    {
        GUID type;
        get_object_guid(xfile_data, 
&type);

        
// make sure template being parsed is a mesh (non-referenced)
        if(type == TID_D3DRMFrame && force_ref == false)
        {
            D3DXFRAME_EX
* frame = new D3DXFRAME_EX;

            
// get frame name (assign one if none found)

            frame
->Name = get_object_name(xfile_data);

            
if(frame->Name == NULL)
                frame
->Name = strdup("NoNameFrame");

            
// link frame structure into list

            
if(data == NULL)
            {
                
// link as sibling of root
                frame->pFrameSibling = m_root_frame;
                m_root_frame 
= frame;
                data 
= (void**&m_root_frame;
            }
            
else
            {
                
// link as child of supplied frame
                D3DXFRAME_EX* frame_ptr = (D3DXFRAME_EX*) (*data);
                frame
->pFrameSibling = frame_ptr->pFrameFirstChild;
                frame_ptr
->pFrameFirstChild = frame;
                data 
= (void**&frame_ptr->pFrameFirstChild;
            }

            frame 
= NULL;    // clear frame pointer since it's been assigned
        }

        
return parse_child_objects(xfile_data, depth, data, force_ref);
    }

public:
    
bool load(const char* filename, D3DXFRAME_EX** ret_frame)
    {
        
bool rv = false;
        m_root_frame 
= NULL;

        
if(parse(filename, NULL))
        {
            
*ret_frame = m_root_frame;
            rv 
= true;
        }
        
else
        {
            
*ret_frame = NULL;
        }

        
return rv;
    }
};

//////////////////////////////////////////////////////////////////////////////////////////////

int PASCAL WinMain(HINSTANCE inst, HINSTANCE, LPSTR, int cmd_show)
{      
    CoInitialize(NULL);    
// Initialize the COM system

    
// Create the window class here and register it

    WNDCLASSEX win_class;  

    win_class.cbSize        
= sizeof(win_class);
    win_class.style         
= CS_HREDRAW | CS_VREDRAW;
    win_class.lpfnWndProc   
= window_proc;
    win_class.cbClsExtra    
= 0;
    win_class.cbWndExtra    
= DLGWINDOWEXTRA;
    win_class.hInstance     
= inst;
    win_class.hIcon         
= LoadIcon(NULL, IDI_APPLICATION);
    win_class.hCursor       
= LoadCursor(NULL, IDC_ARROW);
    win_class.hbrBackground 
= (HBRUSH)(COLOR_BTNFACE + 1);
    win_class.lpszMenuName  
= NULL;
    win_class.lpszClassName 
= g_class_name;
    win_class.hIconSm       
= LoadIcon(NULL, IDI_APPLICATION);

    
if(!RegisterClassEx(&win_class))
        
return -1;

    
// create the dialog box window and show it
    HWND hwnd = CreateDialog(inst, MAKEINTRESOURCE(IDD_FRAMEVIEW), 0, NULL);

    ShowWindow(hwnd, cmd_show);
    UpdateWindow(hwnd);

    MSG msg;    
    ZeroMemory(
&msg, sizeof(MSG));

    
// Start message pump, waiting for user to exit
    while(msg.message != WM_QUIT) 
    {
        
if(PeekMessage(&msg, NULL, 00, PM_REMOVE)) 
        {
            TranslateMessage(
&msg);
            DispatchMessage(
&msg);
        }
    }

    UnregisterClass(g_class_name, inst);
    CoUninitialize();

    
return 0;
}

LRESULT FAR PASCAL window_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    OPENFILENAME ofn;
    
char filename[MAX_PATH] = {0};
    
    
// Only handle window destruction messages
    switch(msg) 
    {
    
case WM_COMMAND:
        
switch(LOWORD(wParam))
        {
        
case IDC_SELECT:
            ZeroMemory(
&ofn, sizeof(OPENFILENAME));

            ofn.lStructSize        
= sizeof(OPENFILENAME);
            ofn.nMaxFile        
= MAX_PATH;
            ofn.nMaxFileTitle    
= MAX_PATH;
            ofn.Flags            
= OFN_HIDEREADONLY | OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT;
            ofn.hwndOwner        
= hwnd;
            ofn.lpstrFile        
= filename;
            ofn.lpstrTitle        
= "Load and Parse .x file";
            ofn.lpstrFilter        
= ".X Files (*.x)\0*.x\0All Files (*.*)\0*.*\0\0";
            ofn.lpstrDefExt        
= "x";

            
if(! GetOpenFileName(&ofn))
                
return 0;

            
// get rid of last loaded mesh list
            delete g_root_frame;
            g_root_frame 
= NULL;

            
// parse .x file and display hierarchy

            cXFrameParser mesh_parser;

            
if(mesh_parser.load(filename, &g_root_frame))
            {
                SendMessage(GetDlgItem(hwnd, IDC_FRAMELIST), LB_RESETCONTENT, 
00);
                add_frames_to_list(g_root_frame, 
2, GetDlgItem(hwnd, IDC_FRAMELIST));
            }

            
break;
        }

        
break;
    
    
case WM_DESTROY:
        delete g_root_frame;
        g_root_frame 
= NULL;
        PostQuitMessage(
0);
        
break;

    
case WM_KEYDOWN:
        
if(wParam == VK_ESCAPE)
            DestroyWindow(hwnd);

        
break;
    }

    
return DefWindowProc(hwnd, msg, wParam, lParam);
}

void add_frames_to_list(D3DXFRAME_EX* frame, DWORD indent, HWND list_handle)
{
    
if(frame == NULL)
        
return;

    
// add siblings to list first
    if(frame->pFrameSibling)
        add_frames_to_list((D3DXFRAME_EX
*) frame->pFrameSibling, indent, list_handle);

    
// build text to add to list

    
char text[1024];

    memset(text, 
' ', indent);
    text[indent] 
= '\0';
    strcat(text, frame
->Name);    

    SendMessage(list_handle, LB_ADDSTRING, 
0, (LPARAM) text);

    
// add children to list
    if(frame->pFrameFirstChild)
        add_frames_to_list((D3DXFRAME_EX
*) frame->pFrameFirstChild, indent+4, list_handle);
}
 

download source file


Loading Custom Data from .X

As I've expressed throughout this chapter, the .X file format is completely open−ended; there is no limit to the type of data you can store. With that in mind, you can create any type of data storage you want, and accessing that data will be just as easy as accessing the mesh and frame data we've already covered.

Jump back to your ContactEntry template and see just how to parse an .X file and display every instance of ContactEntry. Again, a single small derived class of cXParser will work perfectly here.

#include "initguid.h"
// First declare the ContactEntry GUID
DEFINE_GUID(ContactEntry, \
0x4c9d055b, 0xc64d, 0x4bfe, 0xa7, 0xd9, 0x98, \
0x1f, 0x50, 0x7e, 0x45, 0xff);
// Now, define the .X parser class
class cXContactParser : public cXParser
{
public:
BOOL ParseObject(IDirectXFileData *pDataObj,
IDirectXFileData *pParentDataObj,
DWORD Depth,
void **Data,
BOOL Reference)
{
// Skip reference objects
if(Reference == TRUE)
return TRUE;
		// Make sure object being parsed is ContactEntry
if(*GetObjectGUID(pDataObj) == CONTACTENTRY)
{
// Get the data pointer and size
DWORD DataSize;
DWORD *DataPtr;
			DataPtr = (DWORD*)GetObjectData(pDataObj, &DataSize);
			// Get name from object data
char *Name = (char*)*DataPtr++;
			// Get phone # from object data
char *PhoneNum = (char*)*DataPtr++;
			// Get age from object data
DWORD Age = *DataPtr++;
			// Display contact information
char Text[1024];
sprintf(Text, "Name: %s\r\nPhone #: %s\r\nAge: %lu", Name, PhoneNum, Age);
MessageBox(NULL, Text, "Contact", MB_OK);
}
		return ParseChildObjects(pDataObj,Depth,Data,Reference);
}
};
cXContactParser Parser;
Parser.Parse("contacts.x");

With a single call to cXContactParser::Parse, you're treated to a list of people's names, phone numbers, and ages−all contained in the contacts.x file! Now wasn't that easy? See, you don't have to be afraid of the .X file format. I personally use .X to store as much custom data as I can.


posted on 2008-04-18 14:35 lovedday 閱讀(919) 評(píng)論(1)  編輯 收藏 引用

評(píng)論

# re: Using the .X File Format(11) 2009-07-07 11:34 blueesoft

好,努力  回復(fù)  更多評(píng)論   


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


公告

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

隨筆分類(178)

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

搜索

最新評(píng)論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲国产精品t66y| 国产午夜精品久久久久久久| 欧美mv日韩mv国产网站| 国产亚洲一区二区三区在线观看| 亚洲视频高清| 一本色道久久综合亚洲精品小说| 欧美激情一区二区三区在线视频| 亚洲高清二区| 亚洲精品乱码久久久久久久久 | 国产精品99久久久久久www| 夜夜嗨一区二区| 欧美日韩黄色一区二区| 亚洲精品久久嫩草网站秘色 | 亚洲国产成人久久综合一区| 久久久久久91香蕉国产| 欧美大成色www永久网站婷| 亚洲国产欧美一区二区三区久久| 欧美一区二区三区四区在线| 久久夜色精品国产欧美乱| 黄色一区二区在线| 欧美va亚洲va日韩∨a综合色| 亚洲国内在线| 亚洲一区二区在线视频| 国产亚洲一区二区三区在线观看| 久久久久久夜| 欧美激情精品久久久久久| 日韩午夜激情电影| 国产精品v日韩精品| 一本一本久久| 久久九九热免费视频| 亚洲二区在线| 欧美日韩综合不卡| 久久国产精品久久久久久| 欧美韩日一区二区| 亚洲一区二区在线免费观看| 国产亚洲精品一区二区| 欧美精品97| 性做久久久久久| 亚洲电影免费观看高清| 亚洲免费视频成人| 亚洲高清中文字幕| 国产精品久久国产愉拍| 久久久久久久久久看片| 日韩一本二本av| 六月丁香综合| 亚洲图片在线观看| 狠狠久久亚洲欧美专区| 欧美日韩在线另类| 久久漫画官网| 亚洲夜间福利| 亚洲福利视频专区| 久久久噜噜噜久久久| 亚洲深夜福利| 亚洲国产精品成人一区二区| 国产精品一区免费在线观看| 男人的天堂亚洲| 欧美一区二区三区视频| 99视频一区| 欧美xart系列高清| 久久精品人人做人人爽电影蜜月| 日韩午夜电影av| 尹人成人综合网| 国产一区二区三区精品欧美日韩一区二区三区 | 欧美大片在线观看一区| 欧美在线播放| 亚洲在线视频免费观看| 日韩手机在线导航| 亚洲电影免费观看高清| 国产亚洲精品久久飘花| 国产精品欧美一区二区三区奶水| 免费成人美女女| 久久国产加勒比精品无码| 亚洲图片在区色| 99国内精品久久久久久久软件| 久热国产精品| 久久久久国产精品厨房| 欧美一区1区三区3区公司| 亚洲综合国产精品| 一本色道综合亚洲| 欧美国产亚洲视频| 美女任你摸久久| 免费在线看成人av| 免播放器亚洲一区| 羞羞漫画18久久大片| 亚洲一区二区高清| 中文在线一区| 亚洲一区二区成人在线观看| 亚洲精品视频在线看| 亚洲国产精品免费| 亚洲欧洲精品天堂一级| 亚洲国产一区在线| 亚洲国产综合在线| 亚洲国语精品自产拍在线观看| 欧美成熟视频| 亚洲高清不卡在线观看| 亚洲精品日韩综合观看成人91| 亚洲国产欧美不卡在线观看| 亚洲人成在线影院| 亚洲理伦电影| 亚洲午夜在线| 午夜亚洲影视| 久久婷婷综合激情| 欧美成人中文| 欧美日韩一区二区免费在线观看| 欧美丝袜一区二区| 影音先锋中文字幕一区| 一区二区三区日韩精品视频| 久久精品电影| 亚洲国产二区| 亚洲欧美视频在线观看| 欧美不卡福利| 国产亚洲欧美在线| 一二三区精品福利视频| 久久久久久久久久码影片| 亚洲激情社区| 欧美在线视频网站| 欧美日韩精品一区| 狠狠狠色丁香婷婷综合激情| 一区二区三区视频观看| 久久最新视频| 亚洲一区二区三区精品在线| 老司机一区二区| 国产欧美综合一区二区三区| 亚洲精品在线二区| 麻豆91精品| 亚洲午夜在线观看| 欧美精品国产精品| 在线观看视频日韩| 欧美专区一区二区三区| 亚洲精品一区在线| 久久久噜久噜久久综合| 国产精品亚洲综合天堂夜夜| 一区二区三区导航| 欧美α欧美αv大片| 欧美一区亚洲一区| 国产精品国产三级国产aⅴ浪潮| 亚洲精品网站在线播放gif| 久久亚洲图片| 性色一区二区三区| 国产精品中文字幕欧美| 亚洲欧美成人在线| 一本久道综合久久精品| 欧美顶级艳妇交换群宴| 亚洲大胆人体在线| 久久婷婷国产麻豆91天堂| 亚洲男人第一网站| 国产精品久久久久毛片软件| 一本久久知道综合久久| 亚洲国产婷婷| 欧美顶级少妇做爰| 亚洲美女精品一区| 亚洲国产成人不卡| 免费看成人av| 亚洲三级免费观看| 亚洲电影免费观看高清完整版在线观看 | 国产欧美一区二区三区久久人妖| 亚洲一区二区久久| 99精品欧美一区二区三区综合在线| 欧美成人国产一区二区| 亚洲第一精品电影| 欧美不卡在线视频| 欧美成人中文字幕在线| 日韩视频精品在线观看| 亚洲国产综合91精品麻豆| 欧美激情第六页| 99综合精品| 在线一区日本视频| 国产模特精品视频久久久久| 久久99在线观看| 久久成年人视频| 亚洲国产成人午夜在线一区| 亚洲国产成人精品女人久久久| 欧美福利视频一区| 亚洲视频在线观看一区| 亚洲一区二区三区精品动漫| 国产午夜精品久久| 免费在线日韩av| 欧美黄色免费网站| 亚洲手机视频| 欧美一区二区三区免费大片| 黄页网站一区| 欧美激情精品久久久| 欧美日韩一区二区高清| 欧美在线视频在线播放完整版免费观看 | 亚洲伊人观看| 欧美亚洲免费高清在线观看| 永久久久久久| 亚洲六月丁香色婷婷综合久久| 欧美视频你懂的| 久久久久久久久岛国免费| 免费短视频成人日韩| 亚洲午夜久久久久久尤物| 欧美亚洲一区二区在线观看| 亚洲电影自拍| 一本一本大道香蕉久在线精品| 国产一区二区三区成人欧美日韩在线观看| 卡一卡二国产精品| 国内精品模特av私拍在线观看| 久久综合久色欧美综合狠狠| 美日韩免费视频|