开始迁移到托管DirectX SlimDX框架的,例如,MDX应用的帕特里克Murrisa地形的浏览器。

在托管DirectX代码所示,到新的代码,与SlimDX评论的形式。

MDX迁移项目中SlimDX

图书馆设置SlimDX“

下载并安装“ 2010年2月SlimDX SDK(微星)。 “。 
添加一个引用到项目中。NET库“C:\ Program Files文件\ SlimDX SDK(2010年2月)\ BIN \ X86 \ SlimDX.dll。 如果你添加了一个链接的添加引用对话框中,不通过标签“。NET”和一个“浏览”,然后选择“链接属性复制到本机 - >真实而具体的版本 - >真实的。

     / /使用Microsoft.DirectX.Direct3D;
/ /使用Microsoft.DirectX的;
/ /使用Microsoft.DirectX.DirectInput; 使用SlimDX;
使用SlimDX.Direct3D9;
使用键= SlimDX.DirectInput.Key;
使用KeyboardState = SlimDX.DirectInput.KeyboardState;
使用键盘时,SlimDX.DirectInput.Keyboard;
采用的DirectInput = SlimDX.DirectInput.DirectInput;

为什么不直接使用使用SlimDX.DirectInput,? 可以,但随后会发生冲突,有一流的设备,这是在两个命名空间。

使用类SlimDX.Direct3D9

     / /私有Microsoft.DirectX.Direct3D.Device _device;
/ /私有Microsoft.DirectX.DirectInput.Device _Keyboard,;
/ /的私人Microsoft.DirectX.Direct3D.Font _font; 专用设备_device;
私人的Direct3D _direct3d;
私人FilterCaps _textureFilterCaps;
私人DirectInput的_directInput;
私人键盘_keyb;
私人SlimDX.Direct3D9.Font _font;

创建SlimDX.Direct3D9.Device

只显示需要转换的代码。

     / /创建设备
PresentParameters presentParams =的新PresentParameters(); / / PresentParams.AutoDepthStencilFormat的= DepthFormat.D16;
/ /设备新设备(0,DeviceType.Hardware,的,CreateFlags.HardwareVertexProcessing,presentParams); presentParams.AutoDepthStencilFormat = Format.D16;
_direct3d新的Direct3D();
_device新的设备(_direct3d,0,DeviceType.Hardware,this.Handle,CreateFlags.HardwareVertexProcessing,presentParams);

设备事件

     / / Device.DeviceReset的+ =的EventHandler(OnDeviceReset)的;
/ / Device.DeviceResizing的+ =:新CancelEventHandler(OnDeviceResizing);

类似物目前尚未发现 

参数设置渲染设备

简单类型:

     / /渲染设置
/ / Device.RenderState.ZBufferEnable的= TRUE;
/ / Device.RenderState.Ambient的ambientColor;
/ / Device.RenderState.FogStart的mapWidth == 0? 60:(浮动)mapWidth“/ 8; device.SetRenderState(RenderState.ZEnable,TRUE); / / BOOL
device.SetRenderState(RenderState.Ambient,ambientColor.ToArgb()); / / int(COLOR4类型数据)
device.SetRenderState(RenderState.FogStart,mapWidth == 0×60:(浮动)mapWidth / 8); / / INT

等等

类型的参数:

     / / Device.RenderState.FillMode的FillMode.Solid;
/ / Device.RenderState.CullMode的Cull.CounterClockwise;
/ / Device.RenderState.SourceBlend的Blend.SourceAlpha;
/ / Device.RenderState.FogTableMode的FogMode.Linear; device.SetRenderState (RenderState.FillMode,FillMode.Solid);
device.SetRenderState (RenderState.CullMode,Cull.Counterclockwise); device.SetRenderState (RenderState.SourceBlend,Blend.SourceAlpha); device.SetRenderState (RenderState.FogTableMode,FogMode.Linear);

其他参数的移动设备

     / /纹理过滤
/ / Device.SamplerState [0]。MinFilter = TextureFilter.Anisotropic;
/ / Device.SamplerState [0]。(MagFilter = TextureFilter.Linear);
/ / Device.SamplerState [0]。AddressU = TextureAddress.Clamp;
/ / Device.SamplerState [0]。AddressV = TextureAddress.Clamp; device.SetSamplerState(0,SamplerState.MinFilter,TextureFilter.Anisotropic);
device.SetSamplerState(0,SamplerState.MagFilter,TextureFilter.Linear);
device.SetSamplerState(0,SamplerState.AddressU,TextureAddress.Clamp);
device.SetSamplerState(0,SamplerState.AddressV,TextureAddress.Clamp); / /纹理阶段状态。
/ / Device.TextureState的[0]。ColorArgument2 = TextureArgument.Diffuse;
/ / Device.TextureState的[0]。AlphaArgument1 = TextureArgument.TextureColor;
/ / Device.TextureState的[0]。ColorOperation = TextureOperation.Modulate;
/ / Device.TextureState的[0]。AlphaOperation = TextureOperation.SelectArg1; ·device.SetTextureStageState(0,TextureStage.ColorArg2的,TextureArgument.Diffuse);
device.SetTextureStageState(0,TextureStage.AlphaArg1,TextureArgument.Texture);
device.SetTextureStageState(0,TextureStage.ColorOperation,TextureOperation.Modulate);
device.SetTextureStageState(0,TextureStage.AlphaOperation型,TextureOperation.SelectArg1);

device.DeviceCaps

所有类型的检查:

     / /检查硬件顶点处理和纯设备。
/ /如果(device.DeviceCaps.TextureFilterCaps.SupportsMinifyAnisotropic的)...
/ /如果(device.DeviceCaps.TextureFilterCaps.SupportsMinifyLinear的)...
/ /如果(device.DeviceCaps.TextureFilterCaps.SupportsMagnifyAnisotropic的)...
/ /如果(device.DeviceCaps.TextureFilterCaps.SupportsMagnifyLinear的)...

切换到这样的设计:

    的能力deviceCaps = _direct3d.GetDeviceCaps(0,DeviceType.Hardware);
FilterCaps textureFilterCaps deviceCaps.TextureFilterCaps; 如果((textureFilterCaps FilterCaps.MinAnisotropic)= 0)...
如果((textureFilterCaps FilterCaps.MinLinear)= 0)...
如果((textureFilterCaps FilterCaps.MagAnisotropic)= 0)...
如果((textureFilterCaps FilterCaps.MagLinear)= 0)...

简单类型

    颜色 - > SlimDX.Color4

     / / Material.SpecularSharpness = 30.0f; / /薄亮点(小=大)

     material.Power = 30.0f; / /薄亮点(小=大)

向量

     / /三维向量射线Vector3.Empty;

    三维向量射线Vector3.Zero;

向量。 Vector3.Unproject(...)

    三维向量p1的=新的三维向量(的x,y,的MinZ);
... / / P1.Unproject(device.Viewport,device.Transform.Projection,device.Transform.View,device.Transform.World);

这条线的设计:

    漂浮的MinZ = device.Viewport.MinZ;
浮动maxZ = device.Viewport.MaxZ;
宽度= device.Viewport.Width;
高度= device.Viewport.Height;
VX = device.Viewport.X;
诠释VY = device.Viewport.Y; 矩阵worldViewProjection:= device.GetTransform(TransformState.Projection)* device.GetTransform(TransformState.View)* device.GetTransform(TransformState.World); P1 = Vector3.Unproject(P1,VX,VY,宽度,高度的MinZ,maxZ,worldViewProjection);

向量。 Vector3.Scale(浮动)

     / / Ray.Scale的((浮动)U);

    射线Vector3.Multiply(射线,(浮动)U);

向量。 矩阵转换

    三维向量POS =新的三维向量();
和矩阵lightTrans = Matrix.Identity;
... / / Pos.TransformCoordinate的(lightTrans); POS = Vector3.TransformCoordinate(POS,lightTrans);

灯光设置

     / /灯光设置
私人无效LightSetup()
{
/ /使用白色,定向光
/ / Device.Lights [0]。漫= Color.White;
/ / Device.Lights [0]。镜面= Color.FromArgb(0X80,0X80,0X80)/ /软亮点
/ / Device.Lights [0]。类型= LightType.Directional; 灯光灯();
light.Diffuse新Color4(Color.White);
light.Specular =的新Color4(0.5F,0.5F,0.5F); / /软亮点
light.Type = LightType.Directional; / / Device.SetLight的(0,光); / /(*** 1) / /计算光线的方向(三维向量名次)
... / / Device.Lights的[0]。方向=-轴位置;
/ / Device.Lights [0]。更新(); / /不是,更新,使用EnableLight()
/ / Device.Lights的[0]。启用= TRUE; light.Direction =-POS;
device.SetLight(0亮); / /搬到了这里(*** 1)
device.EnableLight(0,TRUE); ...
}

纹理

纹理加载

     / /纹理质地TextureLoader.FromFile(设备,文件名);

    质感纹理Texture.FromFile(设备,文件名);
质感纹理Texture.FromStream(设备,流); 但这种方法相对应的,直到我找到(创建纹理位图):
/ /纹理T =的纹理(设备,B,0,Pool.Managed);

使用键盘

初始化

     / /键盘KEYB新Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
/ / Keyb.SetCooperativeLevel(这一点,CooperativeLevelFlags.Background CooperativeLevelFlags.NonExclusive);
/ / Keyb.Acquire的(); _directInput =新SlimDX.DirectInput.DirectInput();
_keyb =新键盘(_directInput)的; _keyb.SetCooperativeLevel(这一点,SlimDX.DirectInput.CooperativeLevel.Background | SlimDX.DirectInput.CooperativeLevel.Nonexclusive);
_keyb.Acquire();

阅读

     / / KeyboardState的的键= keyb.GetCurrentKeyboardState();
/ / BOOL转变的=键[Key.LeftShift] | |键[Key.RightShift];
/ / BOOL CTRL =键[Key.LeftControl] | |键[Key.RightControl];

     / /如果Ctrl键(键[Key.L] &&!移&&!)

     (keys.IsPressed(Key.L)&&!转变&&!CTRL)

安装摄像机

     / / _device.Transform.Projection的Matrix.PerspectiveFovLH(FOV的aspectRatio,mapWidth == 0?15F:(浮动)(mapWidth / 30F),mapWidth == 0?5000F:(浮动)(mapWidth * 3));
/ / _device.Transform.View的= Matrix.LookAtLH(新的三维向量(0,0区),新的三维向量(0,0,0),新的三维向量(1,0,0)); 矩阵perspectiveFovLH Matrix.PerspectiveFovLH(FOV的aspectRatio,mapWidth == 0?15楼:(浮动)(mapWidth / 30F),mapWidth == 0?5000F:(浮动)(mapWidth * 3));
和矩阵lookAtLH = Matrix.LookAtLH(新三维向量(0,0区),新的三维向量(0,0,0),新的三维向量(1,0,0)); _device.SetTransform(TransformState.Projection,perspectiveFovLH);
_device.SetTransform(TransformState.View,lookAtLH);

网格

     / /网目网(numFaces,numVertices,MeshFlags.Managed,CustomVertex.PositionNormalTextured.Format,设备);

    网目=新的网(的设备,numFaces,numVertices,MeshFlags.Managed,CustomVertex.PositionNormalTextured.Format);

mesh.VertexBuffer

非常重要的区别。 在SlimDX,我们使用线程,和MDX的System.Array。

     / / INT []行列=新的int [1]; / /行列[0] = mesh.NumberVertices / /行列[0] = mesh.VertexCount / / System.Array中ARR = mesh.VertexBuffer.Lock(0, ,LockFlags.None typeof运算(CustomVertex.PositionNormalTextured),职级); / /(Y = startY,Y <=恩迪,Y + +)/ / {/ /(诠释x = STARTX; X <= endX; X + +)/ / {/ / CustomVertex.PositionNormalTextured PNT新CustomVertex.PositionNormalTextured(); / / ...  / / Arr.SetValue的(PNT,vertIndex + +)/ /} / /} / / mesh.VertexBuffer.Unlock(); / /尺寸= sizeof(CustomVertex.PositionNormalTextured)的mesh.VertexCount使用(数据流流= mesh.VertexBuffer。锁(0,mesh.VertexBuffer.Description.SizeInBytes,LockFlags.None)){CustomVertex.PositionNormalTextured [] ARR =新CustomVertex.PositionNormalTextured [mesh.VertexCount](诠释y = startY; <= ENDY; Y + +){ (X = startx时,X <= endX,X + +){CustomVertex.PositionNormalTextured PNT =的新CustomVertex.PositionNormalTextured();“...  arr.SetValue(PNT,vertIndex + +);}} stream.WriteRange   (ARR)的mesh.VertexBuffer.Unlock();} 

CUSTOMVERTEX

类是在CUSTOMVERTEX MDX,但不,在SlimDX,由于在DirectX缺乏直接对应的。 这里不存在一个独特的解决方案,所以我共享的最终版本。 你只需要创建一个定义良好的结构形式,但是创建一个类CUSTOMVERTEX的 - 你的情况,我创建的代码兼容MDX。 内部的内容也可以实现的结构,以不同的方式,载体,或简单的数据类型。

    使用系统;
使用System.Runtime.InteropServices;
使用SlimDX;
使用SlimDX.Direct3D9; 命名空间TerrainViewer
{
公共结构CUSTOMVERTEX
{
/ /这句话强制的字节的顺序被存储在GPU的期望数据
[StructLayout(LayoutKind.Sequential)]
的公共结构PositionNormalTextured / / VertexTypePNT
{
公众持股量X; / /位置
公众持股量Y; / /位置
公众持股量Z; / /位置
公众持股量Xn的; / /普通
公众持股量YN / /正常
公众持股量的锌,/ /普通
公众持股量涂; / /质地位置(德克萨斯州)
公众持股量电视,/ /纹理的位置(TY) 公共常量VertexFormat格式= VertexFormat.Position | VertexFormat.Normal | VertexFormat.Texture1; / /选项
/ /公共的三维向量的位置;
/ /公共的三维向量正常;
/ /公共的Vector2 TexturePosition的;
/ /公共的静态诠释SizeBytes的{{返回Marshal.SizeOf(typeof运算(PositionNormalTextured));}}
} / /这句话强制的字节的顺序被存储在GPU的期望数据
[StructLayout(LayoutKind.Sequential)]
公共,结构PositionNormalColored / / VertexTypePNT
{
公众持股量X; / /位置
公众持股量Y; / /位置
公众持股量Z; / /位置
公众持股量Xn的; / /普通
公众持股量YN / /正常
公众持股量的锌,/ /普通
公众诠释的颜色; / /颜色 公共常量VertexFormat格式= VertexFormat.Position | VertexFormat.Normal | VertexFormat.Diffuse; / /选项
/ /公共的三维向量的位置;
/ /公共的三维向量正常;
/ /公共COLOR4颜色/ / MDX
/ /公共的静态诠释SizeBytes的{{返回Marshal.SizeOf(typeof运算(PositionNormalColored));}}
}
}
}

字形

     / / /
/ / /创建一个字体。
/ / /
/ / HTTP :/ / www.gamedev.net/community/forums/topic.asp?topic_id=557531
/ /的公共Microsoft.DirectX.Direct3D.Font的CreateFont(字符串原谅我,浮动emSize,System.Drawing.FontStyle风格)
公共SlimDX.Direct3D9.Font的CreateFont(字符串原谅我,浮动emSize,System.Drawing.FontStyle风格)
{
尝试
{
FontDescription的描述=新的FontDescription的();
description.FaceName familyName;
/ / Description.Height的=(int)的(1.9 * emSize的);
/ / Description.Quality的FontQuality.ClearTypeNatural;
如果(style! = System.Drawing.FontStyle.Regular)
{
/ /如果((风格与System.Drawing.FontStyle.Italic)!= 0)description.IsItalic = TRUE;
((风格与System.Drawing.FontStyle.Italic)!= 0)description.Italic = TRUE; 如果((风格与System.Drawing.FontStyle.Bold)= 0)description.Weight,FontWeight.Heavy; / / Description.Quality的FontQuality.AntiAlias​​ed / / MDX
description.Quality FontQuality.Antialiased;
} / / FONT =新SlimDX.Direct3D9.Font(设备,15,0,FontWeight.Bold,0,假的,
/ / CharacterSet.Default的,Precision.TrueType,FontQuality.ClearTypeNatural,
/ / PitchAndFamily.Default的PitchAndFamily.DontCare,“宋体”); 返回新SlimDX.Direct3D9.Font(INT)(设备,(1.9 * emSize),0,FontWeight.Bold,0,假的,
CharacterSet.Default,Precision.TrueType,FontQuality.Antialiased,
PitchAndFamily.Default PitchAndFamily.DontCare,原谅我); / /返回新Microsoft.DirectX.Direct3D.Font(设备描述); / / MDX
/ / System.Drawing.Font的F =新System.Drawing.Font(新的FontFamily的(原谅我),emSize);
/ /返回新SlimDX.Direct3D9.Font的(设备,F);
}

{
返回null;
}
}

绘制文本

     / / Sprite.Begin(SpriteFlags.None);
/ / Font.DrawText的(雪碧,信息文本,矩形,DrawTextFormat.Left,Color.Black); sprite.Begin(SpriteFlags.AlphaBlend);
font.DrawString(雪碧,信息文本,矩形,DrawTextFormat.Left,Color.Black);
原文链接:http://gis4all.ru/zh-CN/net/managed-directx/

[转]托管DirectX,从MDX到SlimDX的转换的更多相关文章

  1. 将 Windows 虚拟机从非托管磁盘转换为托管磁盘

    如果有使用非托管磁盘的现有 Windows 虚拟机 (VM),可通过 Azure 托管磁盘服务将 VM 转换为使用托管磁盘. 此过程会同时转换 OS 磁盘和任何附加的数据磁盘. 本文介绍如何使用 Az ...

  2. DotNet 资源大全中文版

    https://blog.csdn.net/fhzh520/article/details/52637545 目录 算法与数据结构(Algorithms and Data structures) 应用 ...

  3. C#学习笔记(一):一些零散但重要的知识点汇总

    集合类型 数组 数组需要注意的就是多维数组和数组的数组之间的区别,如下: using System; namespace Study { class Program { static void Mai ...

  4. 在C++中反射调用.NET(二)

    反射调用返回复杂对象的.NET方法 定义数据接口 上一篇在C++中反射调用.NET(一)中,我们简单的介绍了如何使用C++/CLI并且初步使用了反射调用.NET程序集的简单方法,今天我们看看如何在C+ ...

  5. Azure 和 Linux

    Azure 正在不断集结各种集成的公有云服务,包括分析.虚拟机.数据库.移动.网络.存储和 Web,因此很适合用于托管解决方案. Azure 提供可缩放的计算平台,允许即用即付,而无需投资购买本地硬件 ...

  6. C#编写媒体播放器--Microsoft的Directx提供的DirectShow组件,该组件的程序集QuartzTypeLib.dll.

    使用C#编写媒体播放器时,需要用到Microsoft的Directx提供的DirectShow组件.用该组件前需要先注册程序集QuartzTypeLib.dll. 1.用QuartzTypeLib.d ...

  7. Visual C#使用DirectX实现视频播放

    Visual C#使用DirectX实现视频播放 visual|视频播放 - 很多人第一次接触到DirectX大都是通过游戏,至于安装.升级DirectX的原因无非是满足游戏运行的需要.Direct ...

  8. SlimDX和WPF的合作应用

    1.首先定义一个DX操作类 using System; using SlimDX; using SlimDX.Direct3D9; using System.Windows.Interop; usin ...

  9. Windows 8 DirectX 和Xaml UI 混合处理方案

    原文 http://www.cnblogs.com/chenkai/archive/2012/11/29/2794983.html [如果不想读这么长问题描述和通用的解决方案. 可以直接skip 这段 ...

随机推荐

  1. 思维导图(JavaScript基础)——温习一下下

  2. Unity3D 场景切换加载进度条实现

    需要三个场景,场景A,场景B,场景C: 场景A:一个按钮,点击加载场景B: 场景B:从A切换到C过度场景,加载进度条: 场景C:目标场景: 创建OnProgress.cs脚本: using Syste ...

  3. HDU4418 Time travel(期望dp 高斯消元)

    题意 题目链接 Sol mdzz这题真的太恶心了.. 首先不难看出这就是个高斯消元解方程的板子题 \(f[x] = \sum_{i = 1}^n f[to(x + i)] * p[i] + ave\) ...

  4. Java Web应用开发工具

    java Web应用开发工具详细地址:https://my.oschina.net/gitosc/blog/1538466

  5. 那些年我们对npm 和 cnpm 的误区

    1. npm 和 cnpm 的区别 相信很多人都不太明白 npm 和 cnpm 到底是什么东东, 为啥在国内要用 淘宝镜像使用 cnpm, (1) 两者之间只是 node 中包管理器的不同哟, (2) ...

  6. 转:Jquery如何获取某个元素前(后)的文本内容?

    原文:[解决]Jquery如何获取某个元素前(后)的文本内容? <span> text here... <a id="target_element">百万创 ...

  7. js实现放大镜的效果

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  8. Android上实现视频录制

    首先,我们肯定要用到摄像头,因此需要在Manifest文件中声明使用权限: <uses-permission android:name="android.permission.CAME ...

  9. 3The superclass “javax.servlet.http.HttpServlet" was not found on the Java Build Path 之一

    另外一篇短文里还有第三种解决方案,查看请点击这里 1.异常信息 创建maven web项目时,出现 The superclass “javax.servlet.http.HttpServlet&quo ...

  10. GIT速成

    安装工具与使用工具: GIT工具 :https://www.git-scm.com/download/ WINGDOWS图形界面工具:https://download.tortoisegit.org/ ...