ID3DXMesh接口 创建自己的立方体网格
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接口 创建自己的立方体网格的更多相关文章
- Unity3D 创建动态的立方体图系统
Unity3D 创建动态的立方体图系统 这一篇主要是利用上一篇的Shader,通过脚本来完成一个动态的立方体图变化系统. 准备工作如下: 创建一个新的场景.一个球体.提供给场景一个平行光,准备2个立方 ...
- Android(java)学习笔记66:实现Runnable接口创建线程 和 使用Callable和Future创建线程
1. 前面说的线程的实现是新写一个子类继承Thread: 是将类声明为 Thread 的子类.该子类应重写 Thread 类的 run 方法.接下来可以分配并启动该子类的实例 2. 这里说的方案2是指 ...
- 使用Runnable接口创建线程-3
实现Runnable接口的类必须使用Thread类的实例才能创建线程.通过Runnable接口创建线程分为两步: 1. 将实现Runnable接口的类实例化. 2. 建立一个Thread对象,并将第一 ...
- 使用Callable接口创建线程和使用线程池的方式创建线程
1.使用Callable接口的方式实现多线程,这是JDK5.0新增的一种创建多线程的方法 package com.baozi.java2; import java.util.concurrent.Ca ...
- 实现Runnable接口创建多线程及其优势
实现Runnable接口创建多线程: 创建一个Runnable接口的实现类RunnableImpl: 主线程中: 其中,链式编程的Thread类的静态方法currentThread方法点getName ...
- 使用CommandLineRunner或ApplicationRunner接口创建bean
在spring boot应用中,我们可以在程序启动之前执行任何任务.为了达到这个目的,我们需要使用CommandLineRunner或ApplicationRunner接口创建bean,spring ...
- 使用Runnable接口创建线程
实现Runnable接口的类必须使用Thread类的实例才能创建线程.通过Runnable接口创建线程分为两步: 1.将实现Runnable接口的类实例化. 2.建立一个Thread对象,并将第一步实 ...
- 实现Callable接口创建线程
创建执行线程有四种方式: 实现implements接口创建线程 继承Thread类创建线程 实现Callable接口,通过FutureTask包装器来创建线程 使用线程池创建线程 下面介绍通过实现Ca ...
- Android(java)学习笔记6:实现Runnable接口创建线程 和 使用Callable和Future创建线程
1. 前面说的线程的实现是新写一个子类继承Thread: 是将类声明为 Thread 的子类.该子类应重写 Thread 类的 run 方法.接下来可以分配并启动该子类的实例 2. 这里说的方案2是指 ...
随机推荐
- 解决VS2010无法打开,提示无法找到atl100.dll的方法
这个问题是卸载VS2010一些组件造成的误删问题,且从网上下的atl100.dll通常与自己的VS2010不符 解决方法: 从路径:C:\Program Files\Microsoft Visual ...
- http://www.cnblogs.com/peida/archive/2013/04/23/3036035.html
http://www.cnblogs.com/peida/archive/2013/04/23/3036035.html
- 利用Aspose.Word控件实现Word文档的操作
Aspose系列的控件,功能都挺好,之前一直在我的Winform开发框架中用Aspose.Cell来做报表输出,可以实现多样化的报表设计及输出,由于一般输出的内容比较正规化或者多数是表格居多,所以一般 ...
- 蒋鑫:为什么 Git 比 SVN 好
在版本控制系统的选型上,是选择Git还是SVN? 对于开源项目来说这不算问题.使用Git极大地提高了开发效率.扩大了开源项目的参与度. 增强了版本控制系统的安全性,选择Git早已是大势所趋. 但对于企 ...
- Java 使用jaxp添加节点
<?xml version="1.0" encoding="UTF-8"?> <person> <p1> <name& ...
- PAT 解题报告 1050. String Subtraction (20)
1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...
- PostgreSQL Replication之第十二章 与Postgres-XC一起工作(6)
12.6 添加节点 Postgres-XC允许您在那个过程中的任何一个时间点添加新的服务器到计划中.所有您需要做的是按照我们之前演示的设置一个节点,并在 控制器上调用CREATE NODE.然后,该系 ...
- 转:python webdriver API 之控制浏览器滚动条
有时候 web 页面上的元素并非直接可见的,就算把浏览器最大化,我们依然需要拖动滚动条才能看到想要操作的元素, 这个时候就要控制页面滚动条的拖动, 但滚动条并非页面上的元素, 可以借助 JavaScr ...
- codeforces343A A. Rational Resistance
http://http://codeforces.com/problemset/problem/343/A A. Rational Resistance time limit per test 1 s ...
- 数据库 CRUD
1.删除表 drop table +表名 2.修改表 alter table+表名+ add(添加)+列名+ int(类型) alter table+表名+ drop(删除)+column(列) ...