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. imx6 u-boot.bin 和 u-boot.imx

    有些MFG TOOL烧录工具使用了u-boot.imx,而不是原来的u-boot.bin文件进行烧录. 这两个镜像的区别是,u-boot.bin文件编译后,会在u-boot.bin的开头添加一个大小为 ...

  2. django GET POST

    django需要读取客户端get和post请求的值.读取处理方法和异常记录于此. 参考链接: http://stackoverflow.com/questions/12518517/request-p ...

  3. 我的工具箱之MySql Front 5.3

    下载地址:http://pan.baidu.com/s/1i4sJpNB 这款软件用来连接MySql,作为前端使用. 它功能全面,方便快捷,如果说有缺点的话,sql窗口中不能执行选择的部分有遗憾. 2 ...

  4. LeetCode Intersection of Two Linked Lists

    原题链接在这里:https://leetcode.com/problems/intersection-of-two-linked-lists/ 思路:1. 找到距离各自tail 相同距离的起始List ...

  5. CentOS6.5Minimal安装Gitlab7.5

    文章出处:http://www.restran.net/2015/04/09/gilab-centos-installation-note/ 在 CentOS 6.5 Minimal 系统环境下,用源 ...

  6. js 自动下载函数

    function downloadFile(fileName, content){ var aLink = document.createElement('a'); var blob = new Bl ...

  7. 压测 502 日志报错 upstream timed out (110: Connection timed out)

    环境介绍 服务器:centos6.5服务:nginx proxy 问题描述: 压测 开发同事 的开发环境项目没事,但是 线上机器 命中%50 ,大量502 php的某些页面打不开,页面提示gatewa ...

  8. iOS UICollectionView之二(垂直滚动)

    #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...

  9. AngularJS form表单验证(非常全面)

    构建一个ng表单 novalidate=”novalidate” 2.form中不能有action属性.提交交由ng-submit处理 3.每个input一定要有ng-model,最好有一个name方 ...

  10. subprocess使用

    1. Popen使用 test = subprocess.Popen('ls /tmpa', shell=True, stdout = subprocess.PIPE, stderr=subproce ...