资源简介
本程序可以实现三维的显示,放大,缩小,翻转等操作,并且还可自行添加贴图,只需将其中的图片路径修改一下。
代码片段和文件信息
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图书管理系统
相关资源
- c#拼图游戏可换图,选难度,计时,统
- C#调用SynoAPIEx.dll接口采集指纹信息+绘
- C#网络摄像头实现实时监控录像
- C# 基于ModBus RTU获取气象站数据
- C#个人日程管理系统_程序设计报告(
- 单张相片后方交会计算程序C#
- C#读取惯导数据的简单
- C# 堆栈 回溯 马踏棋盘演示程序
- C# 数据结构——三元组与十字链表—
- modbus的C#
- C#写的员工管理信息系统,有C#完整项
- C# 标准偏差STDEV与CPK的计算
- C#实时窗口截图
- C#仿360加速球
- C# wpf combobox带treeview的自定义控件
-
C# Updatela
yeredWindow()编写桌面透明 - C# GIS算法演示:道格拉斯压缩、线性
- Rs232串口调试信息传输(C#)
- DirectShowLib,最新的DirectShowLib插件,提
- 布尔莎七参数求解__C#源码
- C#调用灵云TTS
- C#客服端与服务器通讯TcpClient和TcpLi
- C#TCP聊天室
- C# 将一个Treeview的树形结构保存成文件
- C#加载等待控件
- C#文本分割器源码
- C#实现声音录制
-
C#版本和ja
vasc ript版本的DES加密函 - c#写的winform超级记事本
- 处理图片背景色,使用透明C#&图片处
评论
共有 条评论