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是指 ...
随机推荐
- imx6 启动 init进程
之前不知道imx6内核是怎么启动文件系统的init进程,查了下资料,记录于此,以后再来补充. kernel/init/main.c static noinline int init_post(void ...
- javascript中创建对象的方式总结
javascript中创建对象的方式总结 具体代码如下: //创建对象的方式: //创建方式一 var person=new Object(); person.name='jack'; person. ...
- AD834+表面声波滤波器调试小结
AD834:带宽较宽,300M无压力,但是输出幅度小,当输入2VPPX2VPP的时候最大输出400mVPP.一个特别要注意的地方是输入走线尽量短,敷铜间距至少满足3倍线宽,不然隔直之后还会耦合信号进去 ...
- QMainWindow的setLayout的问题
因为QMainWindow有自己的layout,所以需要一个QWidget,然后setCentralWidget,给这个QWidget调用setLayout http://stackoverflow. ...
- django工作原理
- Python模块(radom)
radom radom模块提供了随机生成对象的方法 Help on module random: NAME random - Random variable generators. FILE /usr ...
- 第二篇 Integration Services:SSIS数据泵
本篇文章是Integration Services系列的第二篇,详细内容请参考原文. 简介SSIS用于移动数据.数据流任务提供此功能.因为这个原因,当介绍SSIS时我喜欢从数据流任务开始.数据流任务的 ...
- MFC和GDI+一起使用
VS2010,新建MFC项目,在头文件stdafx.h中添加: #include <gdiplus.h> using namespace Gdiplus; #pragma comment ...
- 【杂记】SQL篇
21.事务 22.左联右联 23.大小写转换 24.MySql字符串拼接 25.查询数据库表总数 26.Oracle虚拟表 27.判断是否为空 28.SQL取diff 29.存储过程proc 30.创 ...
- VisualStudio如何以源码文本方式打开rc文件
视图 >> 解决方案资源管理器 >> 右击XXX.rc >> 打开方式 >> 源代码(文本)编辑器