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

天行健 君子當自強而不息

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) 評論(1)  編輯 收藏 引用

評論

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

好,努力  回復  更多評論   


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            久久久久这里只有精品| 欧美紧缚bdsm在线视频| 亚洲高清在线视频| 亚洲欧洲精品成人久久奇米网| 欧美国产高清| 欧美日韩精选| 午夜精品久久久久久久久久久| 亚洲欧美国产日韩天堂区| 亚洲国产综合在线| 香蕉国产精品偷在线观看不卡| 一区二区欧美日韩| 欧美中文日韩| 亚洲在线网站| 欧美国产日韩一区二区在线观看 | 欧美日本韩国一区二区三区| 久久久www成人免费毛片麻豆| 欧美激情精品| 亚洲永久精品大片| av72成人在线| 欧美岛国激情| 久热精品视频| 国产伦精品一区二区三区照片91| 亚洲精品国精品久久99热一| 亚洲国产高清自拍| 欧美日韩亚洲一区二区三区在线| 性欧美video另类hd性玩具| 免费黄网站欧美| 亚洲福利免费| 国产精品日日摸夜夜添夜夜av| 日韩午夜激情| 99国产精品久久久久老师| 欧美成人综合网站| 先锋亚洲精品| 日韩一级免费| 亚洲国产一区二区三区高清| 亚洲美女电影在线| 欧美精品一区二区高清在线观看| 亚洲欧美日韩综合aⅴ视频| 欧美亚洲尤物久久| 国产日韩亚洲欧美精品| 亚洲欧美激情四射在线日| 欧美韩国在线| 一本久道久久综合婷婷鲸鱼| 在线不卡欧美| 久久综合伊人77777| 老司机亚洲精品| 午夜精品电影| 亚洲视频一区二区在线观看| 国产精品久久久久婷婷| 亚洲综合电影| 99国产精品久久| 亚洲欧美日韩国产综合在线| 国产日韩欧美a| 国产精品福利网站| 性色av香蕉一区二区| 一本色道精品久久一区二区三区 | 亚洲少妇自拍| 欧美一区午夜精品| 国内精品免费午夜毛片| 久久久久久穴| 久久激情网站| 亚洲精品一区二区三区在线观看 | 亚洲国产小视频| 蜜桃久久精品乱码一区二区| 久久精品国产久精国产一老狼 | 91久久精品国产91久久性色| 国产精品video| 欧美一进一出视频| 欧美激情亚洲一区| 久久久久亚洲综合| 艳女tv在线观看国产一区| 亚洲精品久久久久久下一站| 国产精品免费一区二区三区在线观看 | 欧美日韩成人免费| 欧美日韩国产色视频| 欧美成人精品高清在线播放| 欧美成人午夜免费视在线看片| 另类天堂视频在线观看| 蜜桃久久精品一区二区| 亚洲字幕在线观看| 亚洲欧美另类国产| 性久久久久久久| 久久精品亚洲精品| 正在播放欧美一区| 亚洲伊人网站| 欧美专区在线观看| 久久天天狠狠| 亚洲欧美日韩精品综合在线观看| 亚洲欧美日韩直播| 久久免费的精品国产v∧| 欧美成人免费在线观看| 欧美日本亚洲韩国国产| 欧美午夜一区二区福利视频| 国产精品国产一区二区 | 亚洲尤物在线| 久久gogo国模裸体人体| 亚洲视频在线观看三级| 午夜精品网站| 毛片基地黄久久久久久天堂| 亚洲国产女人aaa毛片在线| 亚洲精品综合| 欧美一激情一区二区三区| 美女免费视频一区| 欧美体内谢she精2性欧美| 欧美国产一区二区三区激情无套| 国产精品mv在线观看| 国产自产v一区二区三区c| 亚洲黑丝在线| 亚洲欧美在线免费观看| 欧美α欧美αv大片| 久久久久国产精品午夜一区| 欧美激情视频在线播放| 亚洲欧美国产三级| 欧美成人蜜桃| 国产在线不卡精品| 夜夜爽av福利精品导航| 久久久xxx| 日韩亚洲国产欧美| 久久久亚洲一区| 国产精品久久久久久影视| 亚洲高清在线观看一区| 欧美一区二区三区喷汁尤物| 亚洲电影av| 91久久嫩草影院一区二区| 先锋资源久久| 欧美日韩国产小视频| 影音先锋另类| 欧美一区观看| 一区二区三区精品视频| 免费欧美日韩| 欧美日韩国产一区精品一区| 狠狠色狠狠色综合日日91app| 伊人精品视频| 午夜亚洲影视| 99精品欧美一区二区三区| 麻豆av福利av久久av| 国产一区二区三区久久久| 1204国产成人精品视频| 亚洲国内精品在线| 久久久水蜜桃| 亚洲在线一区二区| 欧美日韩国产精品一区| 91久久精品日日躁夜夜躁欧美| 久久米奇亚洲| 午夜精品久久久| 国产精品久久久久77777| 洋洋av久久久久久久一区| 欧美激情第三页| 久热精品视频在线| 一区二区三区在线免费播放| 亚洲精品欧洲精品| 欧美电影免费观看| 老牛嫩草一区二区三区日本| 国产视频久久久久| 欧美一区二区在线视频| 亚洲摸下面视频| 国产精品久久久免费| 亚洲永久免费| 亚洲无亚洲人成网站77777| 久久精品免费| 今天的高清视频免费播放成人| 久久精品国产精品| 久久国产精品亚洲va麻豆| 国内外成人免费视频| 久久天堂精品| 亚洲视频免费| 国产精品任我爽爆在线播放| 亚洲男女自偷自拍| 亚洲影院污污.| 国产麻豆成人精品| 久久人人97超碰人人澡爱香蕉| 欧美一级片在线播放| 国精品一区二区| 裸体歌舞表演一区二区| 欧美成年人视频网站| 日韩亚洲欧美精品| 一本色道**综合亚洲精品蜜桃冫| 国产精品久久久久久久久动漫| 欧美一区二区三区在| 久久国产精品高清| 亚洲日本va在线观看| 99re66热这里只有精品3直播 | 国产精品乱人伦一区二区| 欧美一区二区三区四区视频| 久久激情视频免费观看| 亚洲欧洲中文日韩久久av乱码| 日韩亚洲在线| 国产日韩欧美视频在线| 欧美大胆成人| 欧美日韩综合视频网址| 久久精品在线| 欧美国产三级| 亚洲欧洲av一区二区| 久久久久久婷| 在线亚洲+欧美+日本专区| 午夜精品亚洲一区二区三区嫩草| 亚洲国产清纯| 亚洲小说欧美另类婷婷| 精品二区视频| 在线一区二区日韩|