游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1635|回复: 2

问个问题,DX里面怎么在已知一组顶点数据的情况下创建

[复制链接]

5

主题

54

帖子

62

积分

注册会员

Rank: 2

积分
62
发表于 2007-5-9 16:38:00 | 显示全部楼层 |阅读模式
大概意思如题,知道一组顶点数据,现在要把这一组顶点数据变成ID3DXMesh,那位大侠知道怎么做啊》

23

主题

67

帖子

67

积分

注册会员

Rank: 2

积分
67
发表于 2007-5-10 11:02:00 | 显示全部楼层

Re: 问个问题,DX里面怎么在已知一组顶点数据的情况下创

//假设你创建好的vertex指针是vertices,vertex顺序是从上到下,从左到右
        hr = D3DXCreateMeshFVF((map_width - 1)  * (map_height - 1) * 2,//这么多个面
                                                                                                                map_width* map_height,                                                        //一共这么多个顶点
                                                                                                                D3DXMESH_WRITEONLY | D3DXMESH_32BIT,
                                                                                                                D3DFVF_CUSTOMVERTEX,                                                                                                               
                                                                                                                g_pd3dDevice,&m_pMesh);                       
                       

                void* pVertex;
                m_pMesh->LockVertexBuffer(0,(void**)(&pVertex));
                memcpy(pVertex,vertices,sizeof(CUSTOMVERTEX) * numVertices);
                m_pMesh->UnlockVertexBuffer();



        /*create index buffer*/
                //WORD iIndex[(map_height - 1) * (map_width - 1) * 2 * 3];
                WORD* iIndex = new WORD[(map_height - 1) * (map_width - 1) * 2 * 3];
                int n = 0;               
                int count = 0;
                for(y = 0; y < map_height - 1; y ++)
                        for(x = 0; x <map_width - 1; x ++)
                        {
                                int idx= y * map_width * 6 + x * 6 + 0;                       

                                iIndex[y * (map_width - 1) * 6 + x * 6 + 0] =        (WORD)(y* map_width + x);
                                iIndex[y * (map_width - 1) * 6 + x * 6 + 1]        =        (WORD)((y+1)* map_width + x );
                                iIndex[y * (map_width - 1) * 6 + x * 6 + 2] =        (WORD)(y* map_width + x + 1);
                                iIndex[y * (map_width - 1) * 6 + x * 6 + 3] =        (WORD)((y+1)* map_width + x);
                                iIndex[y * (map_width - 1) * 6 + x * 6 + 4] =        (WORD)((y+1)* map_width + x + 1);
                                iIndex[y * (map_width - 1) * 6 + x * 6 + 5] =        (WORD)(y* map_width + x + 1);

                                n += 6;
                                count ++;
                        }
                        void* ppbData;                       
                        m_pMesh->LockIndexBuffer(0,(void**)&ppbData);
                        memcpy(ppbData,iIndex,sizeof(WORD) * n);
                        m_pMesh->UnlockIndexBuffer();

5

主题

54

帖子

62

积分

注册会员

Rank: 2

积分
62
 楼主| 发表于 2007-5-10 14:35:00 | 显示全部楼层

Re:问个问题,DX里面怎么在已知一组顶点数据的情况下创

谢谢!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-26 11:56

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表