D3DXCreateMeshFVF

首先创建一个ID3DXMesh接口。 ID3DXMesh接口的说明可以参数龙书。

这里主要是用代码来讲解:

#define VERTEX_FVF   (D3DFVF_XYZ | D3DFVF_TEX1)

	hr = D3DXCreateMeshFVF(
12,
24,
D3DXMESH_MANAGED,
VERTEX_FVF,
m_pd3dDevice,
&pMesh
); VERTEX vertices[] =
{
//正y面?
{-5.0f, -5.0f, 0.0f, 0,1},
{-5.0f, 5.0f, 0.0f, 0,0},
{5.0f, 5.0f, 0.0f,1,0},
{5.0f, -5.0f, 0.0f, 1,1},
//侧¨¤面?r
{5.0f, -5.0f, 0.0f, 0,1},
{5.0f, 5.0f, 0.0f,0,0},
{5.0f, 5.0f, 10.0f,1,0},
{5.0f, -5.0f, 10.0f, 1,1},
//后¨®面?
{5.0f, -5.0f, 10.0f, 0,1},
{5.0f, 5.0f, 10.0f,0,0},
{-5.0f, 5.0f, 10.0f, 1,0},
{-5.0f, -5.0f, 10.0f, 1,1}, {-5.0f, -5.0f, 10.0f, 0,1},
{-5.0f, 5.0f, 10.0f, 0,0},
{-5.0f, 5.0f, 0.0f, 1,0},
{-5.0f, -5.0f, 0.0f, 1,1}, {-5.0f, 5.0f, 0.0f, 0,1},
{-5.0f, 5.0f, 10.0f, 0,0},
{5.0f, 5.0f, 10.0f, 1,0},
{5.0f, 5.0f, 0.0f, 1,1}, /* {-5.0f, -5.0f, 0.0f, 0,1},
{-5.0f, -5.0f, 10.0f, 0,0},
{5.0f, -5.0f, 10.0f, 1,0},
{5.0f, -5.0f, 0.0f, 1,1}*/ {-5.0f, -5.0f, 0.0f, 0,1},
{5.0f, -5.0f, 0.0f, 0,0},
{5.0f, -5.0f, 10.0f, 1,0},
{-5.0f, -5.0f, 10.0f, 1,1}, //底下的面。需要用逆时针。不然会被剔除
}; 把上面的顶点数据拷贝到 网格里面
void* pBuffer;
pMesh->LockVertexBuffer(0,(void**)&pBuffer);
memcpy(pBuffer,vertices,sizeof(vertices));
pMesh->UnlockVertexBuffer(); 接着创建 索引数据
WORD* i = 0;
pMesh->LockIndexBuffer(0, (void**)&i); // fill in the front face index data
i[0] = 0; i[1] = 1; i[2] = 2;
i[3] = 0; i[4] = 2; i[5] = 3; // fill in the back face index data
i[6] = 4; i[7] = 5; i[8] = 6;
i[9] = 4; i[10] = 6; i[11] = 7; // fill in the top face index data
i[12] = 8; i[13] = 9; i[14] = 10;
i[15] = 8; i[16] = 10; i[17] = 11; // fill in the bottom face index data
i[18] = 12; i[19] = 13; i[20] = 14;
i[21] = 12; i[22] = 14; i[23] = 15; // fill in the left face index data
i[24] = 16; i[25] = 17; i[26] = 18;
i[27] = 16; i[28] = 18; i[29] = 19; // fill in the right face index data
i[30] = 20; i[31] = 21; i[32] = 22;
i[33] = 20; i[34] = 22; i[35] = 23; pMesh->UnlockIndexBuffer(); //下面是创建了6个集合,创建多少个接口。后面就需要绘制几个集合
DWORD* attributeEuffer = 0;
pMesh->LockAttributeBuffer(0,&attributeEuffer);
for ( int a = 0; a < 2; a++)
{
attributeEuffer[a] = 0;
}
for ( int b = 2; b < 4; b++)
{
attributeEuffer[b] = 1;
}
for ( int c = 4; c < 6; c++)
{
attributeEuffer[c] = 2;
} //优化
hr = pMesh->OptimizeInplace(
D3DXMESHOPT_ATTRSORT |
D3DXMESHOPT_COMPACT |
D3DXMESHOPT_VERTEXCACHE,
&adjacencyBuffer[0],
0, 0, 0); for ( int c = 6; c < 8; c++)
{
attributeEuffer[c] = 3;
} for ( int c = 8; c < 10; c++)
{
attributeEuffer[c] = 4;
} for ( int c = 10; c < 12; c++)
{
attributeEuffer[c] = 5;
}
pMesh->UnlockAttributeBuffer(); std::vector<DWORD> adjacencyBuffer(pMesh->GetNumFaces() * 3);
pMesh->GenerateAdjacency(0.0f, &adjacencyBuffer[0]); for(int i = 0; i < 6; i++)
{
pMesh->DrawSubset( i );
}

ID3DXMesh接口 创建自己的立方体网格的更多相关文章

  1. Unity3D 创建动态的立方体图系统

    Unity3D 创建动态的立方体图系统 这一篇主要是利用上一篇的Shader,通过脚本来完成一个动态的立方体图变化系统. 准备工作如下: 创建一个新的场景.一个球体.提供给场景一个平行光,准备2个立方 ...

  2. Android(java)学习笔记66:实现Runnable接口创建线程 和 使用Callable和Future创建线程

    1. 前面说的线程的实现是新写一个子类继承Thread: 是将类声明为 Thread 的子类.该子类应重写 Thread 类的 run 方法.接下来可以分配并启动该子类的实例 2. 这里说的方案2是指 ...

  3. 使用Runnable接口创建线程-3

    实现Runnable接口的类必须使用Thread类的实例才能创建线程.通过Runnable接口创建线程分为两步: 1. 将实现Runnable接口的类实例化. 2. 建立一个Thread对象,并将第一 ...

  4. 使用Callable接口创建线程和使用线程池的方式创建线程

    1.使用Callable接口的方式实现多线程,这是JDK5.0新增的一种创建多线程的方法 package com.baozi.java2; import java.util.concurrent.Ca ...

  5. 实现Runnable接口创建多线程及其优势

    实现Runnable接口创建多线程: 创建一个Runnable接口的实现类RunnableImpl: 主线程中: 其中,链式编程的Thread类的静态方法currentThread方法点getName ...

  6. 使用CommandLineRunner或ApplicationRunner接口创建bean

    在spring boot应用中,我们可以在程序启动之前执行任何任务.为了达到这个目的,我们需要使用CommandLineRunner或ApplicationRunner接口创建bean,spring ...

  7. 使用Runnable接口创建线程

    实现Runnable接口的类必须使用Thread类的实例才能创建线程.通过Runnable接口创建线程分为两步: 1.将实现Runnable接口的类实例化. 2.建立一个Thread对象,并将第一步实 ...

  8. 实现Callable接口创建线程

    创建执行线程有四种方式: 实现implements接口创建线程 继承Thread类创建线程 实现Callable接口,通过FutureTask包装器来创建线程 使用线程池创建线程 下面介绍通过实现Ca ...

  9. Android(java)学习笔记6:实现Runnable接口创建线程 和 使用Callable和Future创建线程

    1. 前面说的线程的实现是新写一个子类继承Thread: 是将类声明为 Thread 的子类.该子类应重写 Thread 类的 run 方法.接下来可以分配并启动该子类的实例 2. 这里说的方案2是指 ...

随机推荐

  1. 通过CSS使文本框中输入的小写字母变大写字母

    在style.css文件中写 .dataField input{text-transform:uppercase;} .dataField textarea {text-transform:upper ...

  2. eclipse for hello world makefile

    1. 工程文件分析 使用eclipse新建一个Hello World工程,假设工程名称是hello,此时eclipse在工程目录下新建了一个名为hello的文件夹: hello/ .cproject ...

  3. HTML5列表、块和布局

    一.列表 <ul> <ol> <li> unorder order list ol: type="1 A a I i" start=" ...

  4. Linux命令行–理解Linux文件权限(转)

    6.1.1 /etc/passwd文件 /etc/passwd:包含系统用户账户列表以及每个用户的基本配置信息 每个条目有七个字段,每个字段用冒号隔开 登录用户名 用户密码 用户账户的UID 用户账户 ...

  5. Buffer too small

    在项目中用到了CString,后来发现在Format的时候会报Buffer too small的错误,在网上查资料发现时这样的 CString output ; int size = m_NicInf ...

  6. Android 动态添加删除ExpandableListView的item的例子

    这个例子可以学习到如下几点: 1.通过自定义Dialog(单独布局的xml文件进行弹出显示) 2.通过menu点击监听添加,删除view中的items 3.点击ExpandableListView中g ...

  7. js 如何清除setinterval

    var id=window.setInterval(function(){ },1000);window.clearInterval(id);

  8. 利用NSUserdefaults来存储自定义的NSObject类及自定义类数组

    利用NSUserdefaults来存储自定义的NSObject类及自定义类数组 1.利用NSUserdefaults来存储自定义的NSObject类 利用NSUserdefaults也可以来存储及获取 ...

  9. RANSAC随机一致性采样算法学习体会

    The RANSAC algorithm is a learning technique to estimate parameters of a model by random sampling of ...

  10. nsstring基本数据类型的包装类

    // //  main.m //  10-基本数据类型的包装类 // //  Created by apple on 14-3-20. //  Copyright (c) 2014年 apple. A ...