资源简介
本程序可以实现三维的显示,放大,缩小,翻转等操作,并且还可自行添加贴图,只需将其中的图片路径修改一下。

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsFormsApplication14
{
public partial class Form1 : Form
{
public Vector3 CamPostion = new Vector3(0 100 100);//定义摄像机位置
public Vector3 CamTarget = new Vector3(125 30 125);//定义摄像机目标位置
private Device device = null;//定义绘图设备
private float angleY = 0.01f;//定义绕Y轴旋转变量
private int mouseLastX mouseLastY;//记录鼠标按下时的坐标位置
private bool isRotateByMouse = false;//记录是否由鼠标控制旋转
private bool isMoveByMouse = false;//记录是否由鼠标控制移动
private CustomVertex.PositionTextured[] vertices;//定义顶点变量
private Texture texture;//定义贴图变量
private Material material;//定义材质变量
private VertexBuffer vertexBuffer;//定义顶点缓冲变量
private IndexBuffer indexBuffer;//定义索引缓冲变量
private int[] indices;//定义索引号变量
private int xCount = 5 yCount = 4;//定义横向和纵向网格数目
private float cellHeight = 1f cellWidth = 1f;//定义单元的宽度和长度
public string texturePath = @“D:\1.bmp“;//定义贴图路径
public string heightMapPath = @“D:\1.bmp“;//定义高度图路径
public Form1()
{
//InitializeComponent();
this.ClientSize = new Size(800 600);//指定窗体尺寸
this.Text = “三维显示“;//指定窗体标题
}
public bool InitializeDirect3D()
{
try
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true; //指定以Windows窗体形式显示
presentParams.SwapEffect = SwapEffect.Discard; //当前屏幕绘制后它将自动从内存中删除
presentParams.AutoDepthStencilFormat = DepthFormat.D16;
presentParams.EnableAutoDepthStencil = true;
presentParams.PresentationInterval = PresentInterval.Immediate;
device = new Device(0 DeviceType.Hardware this CreateFlags.SoftwareVertexProcessing presentParams); //实例化device对象
Matrix viewMatrix = Matrix.LookAtLH(CamPostion CamTarget new Vector3(0 1 0));
device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4 this.Width / this.Height 0.1f 1000f);
device.Transform.View = viewMatrix;
//lastCamPosAndTarg.Add(device.Transform.View);//记录这次摄像机的位置
VertexDeclaration();//定义顶点
IndicesDeclaration();//定义索引缓冲
LoadTexturesAndMaterials();//导入贴图和材质
return true;
}
catch (DirectXException e)
{
MessageBox.Show(e.ToString() “Error“); //处理异常
return false;
}
}
private void VertexDeclaration()//定义顶点
{
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 917 2013-03-01 17:08 WindowsFormsApplication14\WindowsFormsApplication14.sln
..A..H. 22016 2013-03-18 10:10 WindowsFormsApplication14\WindowsFormsApplication14.suo
文件 14068 2013-03-02 20:00 WindowsFormsApplication14\WindowsFormsApplication14\Form1.cs
文件 1175 2013-03-01 17:08 WindowsFormsApplication14\WindowsFormsApplication14\Form1.Designer.cs
文件 1178 2013-03-01 17:20 WindowsFormsApplication14\WindowsFormsApplication14\Program.cs
文件 3645 2013-03-01 17:18 WindowsFormsApplication14\WindowsFormsApplication14\WindowsFormsApplication14.csproj
文件 6508 2013-03-02 20:00 WindowsFormsApplication14\WindowsFormsApplication14\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 180 2013-03-02 16:08 WindowsFormsApplication14\WindowsFormsApplication14\obj\x86\Debug\WindowsFormsApplication14.Properties.Resources.resources
文件 8388 2013-03-02 16:08 WindowsFormsApplication14\WindowsFormsApplication14\obj\x86\Debug\GenerateResource-ResGen.read.1.tlog
文件 1022 2013-03-02 16:08 WindowsFormsApplication14\WindowsFormsApplication14\obj\x86\Debug\GenerateResource-ResGen.write.1.tlog
文件 36352 2013-03-02 20:00 WindowsFormsApplication14\WindowsFormsApplication14\obj\x86\Debug\WindowsFormsApplication14.pdb
文件 14336 2013-03-02 20:00 WindowsFormsApplication14\WindowsFormsApplication14\obj\x86\Debug\WindowsFormsApplication14.exe
文件 2058 2013-03-18 10:07 WindowsFormsApplication14\WindowsFormsApplication14\obj\x86\Debug\WindowsFormsApplication14.csproj.FileListAbsolute.txt
文件 3413 2013-03-01 17:55 WindowsFormsApplication14\WindowsFormsApplication14\obj\x86\Debug\ResolveAssemblyReference.cache
文件 490 2010-03-17 22:39 WindowsFormsApplication14\WindowsFormsApplication14\bin\Debug\WindowsFormsApplication14.vshost.exe.manifest
文件 11608 2013-03-18 10:07 WindowsFormsApplication14\WindowsFormsApplication14\bin\Debug\WindowsFormsApplication14.vshost.exe
文件 14336 2013-03-02 20:00 WindowsFormsApplication14\WindowsFormsApplication14\bin\Debug\WindowsFormsApplication14.exe
文件 36352 2013-03-02 20:00 WindowsFormsApplication14\WindowsFormsApplication14\bin\Debug\WindowsFormsApplication14.pdb
文件 1406 2013-03-01 17:08 WindowsFormsApplication14\WindowsFormsApplication14\Properties\AssemblyInfo.cs
文件 5612 2013-03-01 17:08 WindowsFormsApplication14\WindowsFormsApplication14\Properties\Resources.resx
文件 2900 2013-03-01 17:08 WindowsFormsApplication14\WindowsFormsApplication14\Properties\Resources.Designer.cs
文件 249 2013-03-01 17:08 WindowsFormsApplication14\WindowsFormsApplication14\Properties\Settings.settings
文件 1110 2013-03-01 17:08 WindowsFormsApplication14\WindowsFormsApplication14\Properties\Settings.Designer.cs
目录 0 2013-03-01 17:24 WindowsFormsApplication14\WindowsFormsApplication14\obj\x86\Debug\TempPE
目录 0 2013-03-01 17:24 WindowsFormsApplication14\WindowsFormsApplication14\obj\x86\Debug
目录 0 2013-03-01 17:24 WindowsFormsApplication14\WindowsFormsApplication14\obj\x86
目录 0 2013-03-01 17:24 WindowsFormsApplication14\WindowsFormsApplication14\bin\Debug
目录 0 2013-03-01 17:24 WindowsFormsApplication14\WindowsFormsApplication14\obj
目录 0 2013-03-01 17:24 WindowsFormsApplication14\WindowsFormsApplication14\bin
目录 0 2013-03-01 17:24 WindowsFormsApplication14\WindowsFormsApplication14\Properties
............此处省略5个文件信息
- 上一篇:c#拼图游戏可换图,选难度,计时,统计步数
- 下一篇:ASP图书管理系统
相关资源
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
- 基于c#的实验室设备管理系统621530
- C# 使用ListView控件实现图片浏览器(源
- C#简单窗体聊天程序
评论
共有 条评论