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

天行健 君子當自強而不息

Working with Maps and Levels(14)

cAutomap::cAutomap and cAutomap::~cAutomap

The constructor and destructor of the cAutomap class ensure that all data is placed
within a known state and that all used resources are released. The constructor does
nothing more than clear some variables and orient a camera to point downward.
You later use that camera to render the map. The destructor calls on the Free
function to release all used resources.

 

cAutomap::create and cAutoMap::free

All right, take a deep breath for this part. The create function is the biggest of the
bunch. It loads an .X file and converts each mesh within into a separate vertex
buffer. Starting with its variable declarations, examine the variable in pieces to
better understand what’s going on:

bool cAutoMap::create(pcstr filename, long color)
{
    free();

    cMesh mesh;
    
if(! mesh.load(filename, ".\\"))
        
return false;

    
// get number of map section, create section visible flag array, vertex buffer array.

    m_num_sections = mesh.get_num_meshes();
    
if(m_num_sections == 0)
    {
        mesh.free();
        
return false;
    }

    m_visible = 
new bool[m_num_sections];
    ZeroMemory(m_visible, m_num_sections);

    m_map_vb = 
new DIRECT3DVERTEXBUFFER9_PTR[m_num_sections];
    
long num  = m_num_sections - 1;

    
// get a bounding radius to scale by
    float radius;
    mesh.get_bounds(NULL, NULL, NULL, NULL, NULL, NULL, &radius);
    m_scale = 128.0f / radius;

    
// go through each mesh in the cMesh object and construct a matching vertex buffer.
    // make sure to start with last section in map to compensate for linked list ordering of mesh in cMesh.
    for(sMeshInfo* mesh_info = mesh.get_root_mesh(); mesh_info != NULL; mesh_info = mesh_info->m_next)
    {
        
static long per_vertex_size = D3DXGetFVFVertexSize(mesh_info->m_d3d_mesh->GetFVF());

        ID3DXMesh* d3d_mesh = mesh_info->m_d3d_mesh;
        
ushort* index_ptr;
        
char*   vert_ptr;

        d3d_mesh->LockIndexBuffer(D3DLOCK_READONLY,  (
void**) &index_ptr);
        d3d_mesh->LockVertexBuffer(D3DLOCK_READONLY, (
void**) &vert_ptr);

        
long num_faces = d3d_mesh->GetNumFaces();
        create_vertex_buffer(&m_map_vb[num], num_faces * 3, 
sizeof(sMapVertex), AUTO_MAP_FVF);

        sMapVertex* map_vb_ptr;
        m_map_vb[num]->Lock(0, 0, (
void**) &map_vb_ptr, 0);

        
// pull out vertices and construct map vertex list, then fill into map vertex buffer.
        for(long i = 0; i < num_faces; i++)
        {
            
for(long j = 0; j < 3; j++)
            {
                
ushort vert_index = *index_ptr;
                index_ptr++;

                sVertex* vert = (sVertex*) &vert_ptr[per_vertex_size * vert_index];

                sMapVertex map_vert;

                map_vert.x = vert->x * m_scale;
                map_vert.y = 0.0f;
                map_vert.z = vert->z * m_scale;
                map_vert.diffuse = color;

                memcpy(map_vb_ptr, &map_vert, 
sizeof(sMapVertex));
                map_vb_ptr++;
            }
        }

        m_map_vb[num]->Unlock();
        d3d_mesh->UnlockVertexBuffer();
        d3d_mesh->UnlockIndexBuffer();

        num--;
    }

    mesh.free();

    
// create a character arrow vertex buffer and fill in it

    sMapVertex arrow_verts[3] = 
    {
        {  0.0f, 0.0f,  10.0f, D3DCOLOR_RGBA(128, 64, 0, 255) },
        {  5.0f, 0.0f, -10.0f, D3DCOLOR_RGBA(128, 64, 0, 255) },
        { -5.0f, 0.0f, -10.0f, D3DCOLOR_RGBA(128, 64, 0, 255) }
    };

    create_vertex_buffer(&m_arrow_vb, 3, 
sizeof(sMapVertex), AUTO_MAP_FVF);
    fill_in_vertex_buffer(m_arrow_vb, 0, 3, arrow_verts);

    
return true;
}

At this point, some variables are declared, a prior auto map is freed (via a call to
free), and some error checking is being performed. Notice that the variable declarations
include the vertex definitions for the pointer vertex buffer.

Now move on, starting with the code that loads the map mesh that is used to create
the vertex buffers.

The first order of business is to load the actual .X file from disc. The first sMesh
structure is grabbed from the cMesh object (remember from the Graphics Core that
the cMesh class stores meshes in a linked list of sMeshInfo structures).

Next, you calculate the size of the vertex structure used by the .X file and calculate
the scaling factor to alter the meshes being loaded. Finally, you store the number
of map sections in a class variable. Notice that the number of map sections happens
to be the number of meshes in the .X file.

Moving on, you allocate an array of bool variables, with each element in the array
representing whether a map section is visible. Each map section has a matching
element in the array. You also create an array of vertex buffers.
These vertex buffers will be used to store the map sections.

Remember that the meshes are contained with a linked list of structures. Now is
the time to iterate through each structure in the linked list and query each structure
for the pointer to the actual Direct3D ID3DXMesh object that contains the mesh
information for a single map section.

Next, you lock the index and vertex buffers and start pulling out the vertex data.

A vertex buffer is being created to match the number of polygon faces in the source
mesh. The vertex buffer is being locked and a pointer is being retrieved to start storing
the vertices.

Two loops now go through every polygon face in the source mesh, and three vertices
for each face are copied over to the map vertex buffers. Notice that you use only the
X- and Z-coordinates, although the Y-coordinate is set to 0 (again to flatten the map).
Last, you set the diffuse color to the color value provided (used to render the map).

You wrap up the process by unlocking the index and vertex buffers of the source
mesh and then proceeding to the next map section mesh in the linked list of
meshes loaded from the .X file. Notice that the num variable is tracking the vertex
buffer that is being created, and the preceding code decrements it with each mesh
being processed.

You decrement rather than increment the num variable because the meshes in the
cMesh object are stored in reverse order (to make loading faster), so you must compensate
to make sure that each map section is numbered sequentially to match the
order those meshes are stored in the .X file.

The create function finishes up by creating the pointer vertex buffer and copying
over the vertex definition data defined earlier. The source mesh is freed and control
returns to the caller.

In order to free the map sections from memory, you provide a free function that
releases all the allocated resources and prepares the class to load another map class.

posted on 2007-12-10 16:00 lovedday 閱讀(292) 評論(0)  編輯 收藏 引用


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


公告

導(dǎo)航

統(tǒng)計

常用鏈接

隨筆分類(178)

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

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美色播在线播放| 国产欧美一区二区三区视频| 在线免费精品视频| 久久一区国产| 毛片基地黄久久久久久天堂| 亚洲国产成人精品久久久国产成人一区 | 亚洲欧美文学| 国产色综合久久| 蜜桃精品久久久久久久免费影院| 久久亚洲春色中文字幕久久久| ●精品国产综合乱码久久久久| 亚洲国产影院| 欧美日本国产一区| 香蕉亚洲视频| 久久免费偷拍视频| 亚洲视频欧美视频| 午夜久久一区| 亚洲国产欧美一区二区三区同亚洲| 亚洲国产精品成人久久综合一区| 欧美激情中文不卡| 欧美一区免费视频| 久久综合九色综合网站| 亚洲色图在线视频| 欧美一区二区视频观看视频| 最新亚洲视频| 亚洲欧美日韩一区二区三区在线观看| 激情成人综合网| 99热这里只有精品8| 伊人春色精品| 亚洲天堂网站在线观看视频| 伊人久久大香线蕉av超碰演员| 日韩视频免费在线| 在线观看一区二区精品视频| 日韩香蕉视频| 亚洲黄色小视频| 亚洲欧美中文日韩在线| 亚洲最新色图| 久久精品成人一区二区三区| 亚洲天堂第二页| 蜜桃av一区| 久久蜜桃精品| 国产精品久久久久免费a∨大胸| 欧美α欧美αv大片| 国产日韩精品视频一区二区三区| 亚洲激情专区| 亚洲国产aⅴ天堂久久| 亚洲欧美在线aaa| 亚洲小视频在线| 女女同性女同一区二区三区91| 久久国产精品久久w女人spa| 欧美日韩另类一区| 亚洲高清免费| 亚洲福利国产| 久久蜜桃资源一区二区老牛 | 最新成人av在线| 久久精品99| 久久久久久尹人网香蕉| 国产精品麻豆va在线播放| 亚洲精品乱码久久久久久| 亚洲国产精品视频| 久久久久九九九| 久久久国产精品一区| 国产精品无人区| 亚洲一区二区在线| 亚洲欧美国产视频| 国产精品国产精品| 亚洲视频网在线直播| 亚洲欧美区自拍先锋| 国产精品你懂的| 亚洲一级二级| 久久国产黑丝| 黄色亚洲精品| 久久亚洲综合色| 亚洲激情欧美激情| 99国产精品久久久久久久久久| 欧美精品一区三区| 99re热这里只有精品免费视频| 亚洲一区二区视频在线| 国产精品久久久久久妇女6080 | 麻豆91精品| 亚洲国产美国国产综合一区二区| 蘑菇福利视频一区播放| 最新日韩中文字幕| 亚洲天堂网站在线观看视频| 国产精品视频一| 久久精品水蜜桃av综合天堂| 欧美国产精品日韩| 一本色道久久综合亚洲精品婷婷| 国产精品毛片在线看| 欧美影院一区| 亚洲国产精品999| 这里只有精品视频在线| 国产精品一二| 久久久视频精品| 亚洲裸体在线观看| 久久国产乱子精品免费女 | 在线免费观看成人网| 欧美不卡视频一区发布| 一本色道**综合亚洲精品蜜桃冫| 久久爱www.| 亚洲乱码国产乱码精品精天堂 | 欧美激情一区二区三级高清视频| 一区二区欧美激情| 免费av成人在线| 亚洲一级在线| 精品粉嫩aⅴ一区二区三区四区| 欧美理论电影网| 久久福利视频导航| 一区二区久久久久久| 久久综合伊人77777| 亚洲一级在线观看| 亚洲黄色有码视频| 国产欧美日韩综合精品二区| 免费永久网站黄欧美| 亚洲欧美日韩一区二区三区在线| 亚洲国产成人精品视频| 亚洲欧美日韩在线观看a三区| 亚洲电影欧美电影有声小说| 国产精品扒开腿做爽爽爽软件 | 看片网站欧美日韩| 亚洲在线免费| 亚洲精品欧美| 久久综合给合久久狠狠狠97色69| 中日韩美女免费视频网址在线观看 | 在线一区二区三区四区| 亚洲电影欧美电影有声小说| 国产精品永久在线| 欧美日韩一区二区三区在线 | 国产精品热久久久久夜色精品三区| 久久资源在线| 欧美一级夜夜爽| 亚洲无线一线二线三线区别av| 亚洲第一页在线| 欧美成人免费一级人片100| 久久精品视频在线| 欧美亚洲视频在线看网址| 中文精品在线| 一卡二卡3卡四卡高清精品视频| 最新日韩在线| 亚洲国产美国国产综合一区二区| 黄色影院成人| 黄色日韩网站视频| 激情av一区| 永久免费精品影视网站| 伊人男人综合视频网| 一区二区三区在线观看视频| 国产午夜久久| 韩国三级在线一区| 伊人男人综合视频网| 在线日本欧美| 亚洲国产老妈| 日韩视频久久| 一本色道久久加勒比精品| 亚洲巨乳在线| 在线亚洲成人| 亚洲欧美日韩在线播放| 欧美一区二区啪啪| 久久久久国产成人精品亚洲午夜| 久久久精品网| 欧美高清在线一区二区| 亚洲大胆美女视频| aa亚洲婷婷| 亚洲欧美一区二区三区久久| 欧美亚洲一区二区在线| 久久嫩草精品久久久久| 欧美大片在线观看| 欧美视频免费| 国产又爽又黄的激情精品视频| 尤妮丝一区二区裸体视频| 亚洲国产精品激情在线观看| 亚洲免费观看高清完整版在线观看熊 | 一区二区av| 久久国产日本精品| 美女精品自拍一二三四| 欧美日韩精品一区二区三区| 国产精品一区二区三区四区五区| 国产主播一区二区三区| 91久久精品国产91久久| 亚洲无吗在线| 久久视频免费观看| 91久久香蕉国产日韩欧美9色| 在线一区观看| 久久综合国产精品台湾中文娱乐网| 欧美电影免费观看高清| 国产精品视频一区二区三区| 狠狠色噜噜狠狠狠狠色吗综合| 亚洲欧洲中文日韩久久av乱码| 亚洲午夜高清视频| 久久综合导航| aa级大片欧美| 蜜臀久久久99精品久久久久久 | 久久在线视频| 国产精品美女久久久久久2018 | 性视频1819p久久| 欧美激情一区二区在线| 亚洲综合导航| 欧美日韩精品高清| 亚洲国产精品福利| 久久国产婷婷国产香蕉| 99精品欧美一区二区三区|