转自:http://gis4all.ru/zh-CN/net/managed-directx/

开始迁移到托管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); / / BOOLdevice.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 / / MDXdescription.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);
 

转载于:https://www.cnblogs.com/yuxiuting/archive/2013/03/21/2972963.html

托管DirectX,从MDX到SlimDX的转换(转)相关推荐

  1. [转]托管DirectX,从MDX到SlimDX的转换

    开始迁移到托管DirectX SlimDX框架的,例如,MDX应用的帕特里克Murrisa地形的浏览器. 在托管DirectX代码所示,到新的代码,与SlimDX评论的形式. MDX迁移项目中Slim ...

  2. [原创]Managed DirectX 基础使用教程(零)

    hangtao_me@yahoo.com.cn 由于下学期的毕业设计,最近开始研究起了.NET平台下的DirectX.本来是不打算用DirectX的,因为我不会DirectX - -||.但是DEMO ...

  3. .NET Framework 中新托管 Direct3D 图形 API 的简介

    .NET Framework 中新托管 Direct3D 图形 API 的简介 发布日期: 12/6/2004 | 更新日期: 12/6/2004 Yahya H. Mirza 和 Henry da ...

  4. 开源2D图形库/图形框架

    记下一些关于2d方面的图形库资料,以便以后项目需要. skia图形框架(c/c++): google项目地址:http://code.google.com/p/skia/ 这里可以在线浏览skia源码 ...

  5. C#与C/C++的交互

    warensoft 工作室博客园首页 Warensoft 工作室:承接.NET应用项目开发,游戏开发   博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅  :: 管理 ...

  6. MLIR与Code Generation

    MLIR与Code Generation MLIR多级中间表示 MLIR 项目是一种构建可重用和可扩展编译器基础架构的新方法.MLIR 旨在解决软件碎片问题,改进异构硬件的编译,显着降低构建特定领域编 ...

  7. Machine Learning for Encrypted Malware Traffic Classification

    Machine Learning for Encrypted Malware Traffic Classification: Accounting for Noisy Labels and Non-S ...

  8. 经典技术文章翻译(1):COM+集成:.NET Enterprise Services 如何帮你建立分布式应用(2)

    实现客户端       当一个基于CLR 组件服务类被编译和部署,你就需要在客户端调用它.长远来看,组件服务类没什么特别之处;事实是使用COM+ 运行时服务是不相关的. 这个代码展示了简单类早期的定义 ...

  9. 《XNA高级编程:Xbox 360和Windows》1-2

    1.2免费获取XNA Game Studio Express 要开始编写代码,您必须确保已经安装了一些工具,其中IDE是您快速开始的一个非常重要的工具.如果您已经安装并配置了XNA Game Stud ...

最新文章

  1. 微信小程序开发-入门基础
  2. 2020年6月学术会议变动汇总
  3. Java双等号,Equals(),HashCode()小结
  4. mysql 分词搜索_实战 | canal 实现Mysql到Elasticsearch实时增量同步
  5. php数字取反,[转+自]关于PHP7的新特性(涉及取反和disabled_functions绕过)
  6. svg defs 进行定义 引用
  7. Mybatis源码笔记之浅析ParameterHandler
  8. Java JDBC------------------ODBC(SQLServer)链接
  9. linux批量分区,Linux磁盘批量分区格式化和挂载脚本
  10. Java如何连接数据库
  11. 人工智能 —— 自然演绎推理
  12. js 手机虚拟键盘控制
  13. mysql中标识列是什么意思_数据库标识列是什么意思
  14. 管理学-“三个和尚”
  15. MarkDown编辑器----小书匠
  16. 分享|数智化转型咨询赋能白皮书2021(附PDF)
  17. java指令重排,为什么重排?
  18. 多御安全浏览器更新隐私锁,个人隐私有救了
  19. Oracle中新建数据表的两种方法
  20. 2017谷歌I/O大会时间正式公布;微软发布利用实感技术的无人机模拟器│IoT黑板报...

热门文章

  1. Mysql INSERT加入WHERE条件
  2. npm run eject报错:This git repository has untracked files or uncommitted changes:...
  3. CocoaPods使用笔记
  4. ADSP-21489的图形化编程详解(7:延时、增益、分频、反馈、响度)
  5. PI调节器与无差拍电流预测控制器性能对比
  6. Mmap fs可能让大索引访问变得缓慢
  7. 既要科技、又要潮牌,千元realme重走OPPO路才是最好选择?
  8. 动态刷新mapper看过来
  9. pandas向已经拥有数据的Excel文件中添加新数据
  10. [转]WordPress主题开发:主题初始化