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

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

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 閱讀(284) 評(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)論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            久久精品夜色噜噜亚洲a∨| 亚洲欧美中文另类| 欧美国产91| 欧美成人午夜视频| 夜夜嗨av一区二区三区中文字幕| 亚洲国产精品免费| 欧美电影美腿模特1979在线看| 99riav1国产精品视频| 亚洲毛片av在线| 国产欧美日韩在线视频| 久久影视精品| 欧美精品一区二区三| 午夜欧美电影在线观看| 久久美女性网| 亚洲一级特黄| 久久精品国产久精国产一老狼| 亚洲成人资源网| 亚洲精品看片| 国产午夜一区二区三区| 亚洲国产日韩欧美在线99| 欧美三级在线| 欧美成人三级在线| 国产精品一区二区久激情瑜伽| 久久在线免费视频| 欧美日韩在线一区二区三区| 欧美伊人精品成人久久综合97| 久久在线播放| 午夜欧美精品久久久久久久| 久久性天堂网| 亚洲欧美另类国产| 欧美99在线视频观看| 欧美一区二区三区免费视频| 欧美久久综合| 老妇喷水一区二区三区| 国产精品ⅴa在线观看h| 欧美二区在线观看| 国产精品一区视频网站| 亚洲激情中文1区| 好吊色欧美一区二区三区四区| 日韩视频精品| 亚洲激情不卡| 欧美中在线观看| 性欧美videos另类喷潮| 欧美精品系列| 欧美成人dvd在线视频| 国产视频观看一区| 欧美午夜宅男影院| 亚洲精品少妇30p| 亚洲啪啪91| 久久久久九九视频| 久久尤物视频| 国产日韩av高清| 亚洲影院色在线观看免费| 亚洲一级高清| 欧美日韩综合久久| 亚洲精品一区二区在线| 亚洲精品欧美日韩专区| 老司机成人网| 欧美国产日本韩| 亚洲国产日韩在线| 蜜臀av在线播放一区二区三区| 另类激情亚洲| 在线免费观看一区二区三区| 欧美中文字幕不卡| 久久久蜜桃精品| 好看不卡的中文字幕| 久久久青草婷婷精品综合日韩| 久久久国产精品一区| 国产欧美一区二区白浆黑人| 亚洲在线网站| 久久久久免费观看| 亚洲成人在线观看视频| 欧美国产成人精品| 亚洲精品你懂的| 夜夜嗨网站十八久久| 欧美三级午夜理伦三级中文幕| 亚洲视频一区在线| 欧美影院视频| 伊人婷婷欧美激情| 欧美劲爆第一页| 一区二区免费在线视频| 欧美在线视频网站| 狠狠色狠狠色综合| 欧美黄色影院| 亚洲午夜视频在线观看| 久久精品观看| 亚洲久久视频| 国产精品一区二区在线观看网站| 欧美亚洲一区| 亚洲国产精品久久久久秋霞不卡| 中文精品视频| 伊人成人开心激情综合网| 欧美电影在线免费观看网站 | 国产日韩欧美日韩大片| 久久天堂成人| 99精品99久久久久久宅男| 羞羞视频在线观看欧美| 最新国产乱人伦偷精品免费网站| 欧美日韩一区二区三区在线 | 韩日在线一区| 欧美日韩国产综合久久| 欧美在线视频一区二区| 亚洲高清在线播放| 亚洲欧美久久| 亚洲免费av网站| 国产偷久久久精品专区| 欧美激情在线有限公司| 9i看片成人免费高清| 国产亚洲欧洲997久久综合| 欧美国产国产综合| 欧美一区二区成人| 日韩视频在线观看一区二区| 久久伊人一区二区| 亚洲欧美久久久久一区二区三区| 亚洲黑丝在线| 国产一区二区三区四区三区四| 欧美日韩成人在线| 免费亚洲视频| 久久久水蜜桃| 久久狠狠婷婷| 亚洲免费在线视频一区 二区| 亚洲精品永久免费| 欧美风情在线观看| 久久久免费精品| 欧美在线播放高清精品| 一本大道久久a久久精二百| 亚洲第一精品影视| 国产亚洲欧美一区在线观看| 国产精品一区二区久久国产| 欧美日韩小视频| 欧美日韩99| 欧美精品一区二区三区一线天视频| 久久艳片www.17c.com| 久久国产精品高清| 性欧美超级视频| 性欧美1819sex性高清| 亚洲欧美不卡| 亚洲伊人网站| 亚洲一区二区在线| 亚洲欧美三级在线| 亚洲欧美综合一区| 欧美一区2区视频在线观看| 午夜在线精品| 久久激情五月激情| 久久久夜夜夜| 老司机亚洲精品| 欧美二区在线观看| 欧美国产日韩一区二区三区| 欧美大片免费看| 欧美日韩直播| 国产欧美日韩一区二区三区| 国产欧美一区二区精品忘忧草| 国产区亚洲区欧美区| 国产午夜精品一区理论片飘花| 合欧美一区二区三区| 亚洲国产欧美日韩精品| 亚洲精品在线免费观看视频| 一本色道久久综合亚洲精品不 | 久久露脸国产精品| 欧美成人精品影院| 亚洲精选久久| 亚洲欧美国产高清va在线播| 欧美一区二区三区在线播放| 久久日韩粉嫩一区二区三区| 欧美mv日韩mv亚洲| 欧美日韩在线精品| 国产日韩欧美精品综合| 亚洲国产精品v| 一区二区三区四区国产精品| 欧美在线视频播放| 欧美成人影音| 一本色道久久综合一区| 一本一本久久| 久久精品亚洲国产奇米99| 欧美黄色日本| 亚洲欧美久久久久一区二区三区| 久久频这里精品99香蕉| 国产精品久久久久久久app| 狠狠色噜噜狠狠色综合久| 亚洲毛片在线看| 亚洲欧美日韩综合| 毛片av中文字幕一区二区| 99国产精品99久久久久久| 久久久久综合一区二区三区| 欧美日韩国产一区二区三区地区| 国产三区精品| 亚洲特色特黄| 欧美高清不卡| 性久久久久久| 欧美日韩一区二区在线| 亚洲国产成人久久| 欧美在线精品一区| 99re66热这里只有精品3直播| 久久九九全国免费精品观看| 国产精品激情偷乱一区二区∴| 91久久精品美女高潮| 久久精品一区二区三区中文字幕 | 模特精品裸拍一区| 亚洲欧美日韩在线播放| 欧美日韩精品二区|