XNA-3D-绘制立方体
来源:互联网 发布:api函数与c语言 编辑:程序博客网 时间:2024/05/05 21:43
一.要点
绘制立方体(或其他3D图形)的方法与绘制三角形的方法类似,任何一个3D图形的轮廓都有一系列三角形构成.为减少数据冗余,在绘制复杂3D图形时,应使用
GraphicsDevice.DrawIndexedPrimitives()方法,而不是绘制三角形时所使用的GraphicsDevice.DrawUserPrimitives()。
二.实现代码
1.为Game类添加成员变量:
1: VertexPositionColor[] vertexList;2: VertexBuffer vertexBuffer;3: ushort[] indexList;
4: IndexBuffer indexBuffer;
2.在LoadContent()方法中定义立方体六个顶点的坐标
1: vertexList = new VertexPositionColor[]
2: {3: new VertexPositionColor(new Vector3(1f,1f,-1f),Color.Red),
4: new VertexPositionColor(new Vector3(1f,-1f,-1f),Color.Red),5: new VertexPositionColor(new Vector3(-1f,-1f,-1f),Color.Red),
6: new VertexPositionColor(new Vector3(-1f,1f,-1f),Color.Red),7: new VertexPositionColor(new Vector3(1f,1f,1f),Color.Red),
8: new VertexPositionColor(new Vector3(1f,-1f,1f),Color.Red),9: new VertexPositionColor(new Vector3(-1f,-1f,1f),Color.Red),
10: new VertexPositionColor(new Vector3(-1f,1f,1f),Color.Red)11: };12: vertexBuffer = new VertexBuffer(
13: GraphicsDevice,14: typeof(VertexPositionColor),
15: vertexList.Length,16: BufferUsage.None);17: vertexBuffer.SetData<VertexPositionColor>(vertexList);
3.定义顶点索引数组:
1: indexList = new ushort[]2: {3: 0,1,2,0,2,3,4: 7,4,5,7,5,6,5: 0,1,5,0,5,4,6: 7,3,2,7,2,6,7: 0,4,7,0,7,3,8: 2,1,5,2,5,69: };10: indexBuffer = new IndexBuffer(11: GraphicsDevice,12: typeof(ushort),13: indexList.Length,14: BufferUsage.None);15: indexBuffer.SetData<ushort>(indexList);
4.在Draw()方法中添加绘制代码:
1: GraphicsDevice.SetVertexBuffer(vertexBuffer);2: GraphicsDevice.Indices = indexBuffer;3:4: int primitiveCount = indexList.Length / 3;
5: foreach (var pass in basicEffect.CurrentTechnique.Passes)
6: {7: pass.Apply();8: GraphicsDevice.DrawIndexedPrimitives(9: PrimitiveType.TriangleList,10: 0,11: 0,12: vertexList.Length,13: 0,14: primitiveCount);15: }
- XNA-3D-绘制立方体
- 如何实现3D效果(绘制长方体/立方体)
- 详解用CSS绘制3D旋转立方体
- 3D游戏编程入门(十六)索引缓存绘制立方体
- XNA 3D文字
- 3D 旋转立方体
- 3D立方体(代码)
- XNA-顯示3D模型
- 3D立方体及光照
- Android opengl 3D立方体
- wpf 3D立方体旋转
- 3D旋转立方体演示
- 3D动画立方体实现
- h5 3D旋转立方体
- css3之3D立方体
- CSS3 3D旋转立方体
- 3D图形学编程基础-基于Direct3D11-学习记录(一)初始化DX设备,实现立方体绘制
- XNA学习(二) 载入3D模型
- busybox文件系统的启动顺序
- POJ2151-Check the difficulty of problems
- 佛罗里达更新及搜索引擎的沙盒期效应
- 网站分析基础概念之退出页
- 配置实现快速程序开发
- XNA-3D-绘制立方体
- [易飞]ERP的展BOM程序
- c语言之猜数字游戏
- 社会化媒体上的用户行为分析
- python文件读写
- 设想Apple的七大未来产品
- Min Max Roads Lightoj 1162
- poj 3519 Minimal Backgammon
- 修改进度条ProgressBar颜色