⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3d游戏编程入门经典.txt

📁 3D游戏编程入门经典.教你三天回3D、、3D游戏编程入门经典
💻 TXT
📖 第 1 页 / 共 5 页
字号:

 private static void enumeratedevicecombos(enumadapterinformation 

             adapterinfo,

 enumdeviceinformation deviceinfo, arraylist adapterformatlist)

 {

 // find out which adapter formats are supported by this device

 for each(format adapterformat in adapterformatlist)

 {

 for(int i = 0; i < backbufferformatsarray.length; i++)

 {

 // go through each windowed mode

 bool windowed = false;

 do

 {

 if((!windowed)&&(adapterinfo.displaymodelist.count== 0))

 continue; // nothing here

 if(!manager.checkdevicetype((int)adapterinfo. 

                                  adapterordinal,

 deviceinfo.devicetype, adapterformat,

 backbufferformatsarray[i], windowed))

 continue; // unsupported

 // do we require post pixel shader blending?

 if (ispostpixelshaderblendingrequired)

 {

 if (!manager.checkdeviceformat(

 (int)adapterinfo.adapterordinal,

 deviceinfo.devicetype, adapterformat,

 usage.querypostpixelshaderblending,

 resourcetype.textures, backbuffer 

 formatsarray[i]))

 continue; // unsupported

 }

 // if an application callback function has been provided,

 // make sure this device is acceptable to the app.

 if (devicecreationinterface != null)

 {

 if

 (!devicecreationinterface.isdeviceacceptable(deviceinfo.caps,

 adapterformat, backbufferformatsarray[i], 

                              windowed))

 continue; // application doesn’t like this device

 }

 // at this point,we have an adapter/device/adapterformat/

 // backbufferformat/iswindowed devicecombo that is 

 // supported by the system and acceptable to the app. 

 // we still need to find one or more suitable depth/ 

 // stencil buffer format,multisample type, and present 

 // interval.

 enumdevicesettingscombo devicecombo = new

 enumdevicesettingscombo();

 // store the information

 devicecombo.adapterordinal=adapterinfo. adapterordinal;

 devicecombo.devicetype = deviceinfo.devicetype;

 devicecombo.adapterformat = adapterformat;

 devicecombo.backbufferformat=backbufferformatsarray[i];

 devicecombo.iswindowed = windowed;

 // build the depth stencil format and multisample type list

 builddepthstencilformatlist(devicecombo);

 buildmultisampletypelist(devicecombo);

 if (devicecombo.multisampletypelist.count == 0)

 {

 // nothing to do

 continue;

 }

 // build the conflict and present lists

 buildconflictlist(devicecombo);

 buildpresentintervallist(deviceinfo, devicecombo);

 devicecombo.adapterinformation = adapterinfo;

 devicecombo.deviceinformation = deviceinfo;

 // add the combo to the list of devices

 deviceinfo.devicesettingslist.add(devicecombo);

 // flip value so it loops

 windowed = !windowed;

 }

 while (windowed);

 }

 }

 }

 该方法类似前面的方法,它遍历了一个列表(关于格式的列表)并创建了一个新的关于有效数据的列表。该方法调用了isdeviceacceptable方法。注意,如果isdeviceacceptable方法返回false,则该设备组合将被忽略。

  

         
   在本章中,您开始了第一个游戏项目,并接触了样本框架。您浏览了大量的代码,这些代码枚举了系统可能支持的设备组合。对于您将编写的任何游戏来说,样本框架是一个起点。在第4章中,您将创建设备,并开始绘制一些图像。

  

         
   到目前为止,您编写的代码还不能令人兴奋。在第3章“理解样本框架”中,介绍了一些样本框架代码。尽管这些代码非常重要,但是当您看到在屏幕上创建的内容时并不会像看到游戏的图形部分那么兴奋。

 第3章中的框架代码正引导您生成奇妙的3d图形,因此请您做好准备。您即将编写第一个3d绘图代码。

 在本章中,您将学习到:

 ●       如何创建direct3d设备

 ●       如何在屏幕上绘图

 ●       如何加载网格(mesh)

 ●       如何创建照相机

 4.1  创建设备  对于该游戏的剩余部分来说,您仍然需要处理第3章中开始的项目。现在您最希望做的是建立项目,以实际处理样本框架。在第3章创建的main方法中,加入程序清单4.1中的代码,该段代码位于创建gameengine类之后。

 程序清单4.1  钩接事件和回调

 // set the callback functions. these functions allow the sample framework

 // to notify the application about device changes,user input,and windows

 // messages. the callbacks are optional so you need only set callbacks 

 // for events you’re interested in. however, if you don’t handle the 

 // device reset/lost callbacks, then the sample framework won’t be able 

 // to reset your device since the application must first release all 

 // device resources before resetting. likewise, if you don’t handle 

 // the device created/destroyed callbacks, then the sample framework

 // won’t be able to re-create your device resources.

 sampleframework.disposing += new eventhandler(blockersengine.

 ondestroydevice);

 sampleframework.devicelost += new eventhandler(blockersengine.

  onlostdevice);

 sampleframework.devicecreated +=

 new deviceeventhandler(blockersengine.oncreatedevice);

 sampleframework.devicereset +=

 new deviceeventhandler(blockersengine.onresetdevice);

 sampleframework.setkeyboardcallback(new keyboardcallback(

 blockersengine.onkeyevent));

 // catch mouse move events

 sampleframework.isnotifiedonmousemove = true;

 sampleframework.setmousecallback(new mousecallback(blockersengine. 

                                        onmouseevent));

 sampleframework.setcallbackinterface(blockersengine);

 这一小段代码中发生了大量的事情。总共有4个事件钩接,用来告诉您绘图设备何时创建、丢失、重置和销毁。接着,您需要添加程序清单4.2中的这些处理程序的实现。然后,您将注意到挂钩了两个回调,它们是样本框架为用户输入所提供的方式分别是鼠标和键盘(如程序清单4.3所示)。最后,您调用了传入游戏引擎实例的setcallbackinterface方法。然而,您可能注意到,该实例没有实现正确的接口。因此您需要做出修改。

 程序清单4.2  框架事件处理程序

 ///  

 /// this event will be fired immediately after the direct3d device has 

 /// been created, which will happen during application initialization 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -