锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久久人妻一区精品色,99久久精品免费观看国产,亚洲а∨天堂久久精品9966http://www.shnenglu.com/mzty/category/1502.html<br/> <br/> <a href = "http://www.shnenglu.com/mzty/archive/2007/03/02/19109.html"><font size = 5 color ="#00FFFF">{C++ 鍩虹}<font/></a> <a href = "http://www.shnenglu.com/mzty/archive/2007/08/13/29922.html"><font size = 5 color ="#00FFFF">{C++ 楂樼駭}<font/></a> <a href = "http://www.shnenglu.com/mzty/archive/2007/04/16/22064.html"><font size = 5 color ="#00FFFF">{C#鐣岄潰錛孋++鏍稿績綆楁硶}<font/></a> <a href = "http://www.shnenglu.com/mzty/archive/2007/03/04/19163.html"><font size = 5 color ="#00FFFF">{璁捐妯″紡}<font/></a> <a href = " http://www.shnenglu.com/mzty/archive/2007/03/04/19167.html"><font size = 5 color ="#FF0000">{C#鍩虹}<font/></a> zh-cnTue, 20 May 2008 15:11:49 GMTTue, 20 May 2008 15:11:49 GMT60綰圭悊+VertexElement錛堜簩錛?/title><link>http://www.shnenglu.com/mzty/archive/2007/11/09/36236.html</link><dc:creator>姊﹀湪澶╂動</dc:creator><author>姊﹀湪澶╂動</author><pubDate>Fri, 09 Nov 2007 10:01:00 GMT</pubDate><guid>http://www.shnenglu.com/mzty/archive/2007/11/09/36236.html</guid><wfw:comment>http://www.shnenglu.com/mzty/comments/36236.html</wfw:comment><comments>http://www.shnenglu.com/mzty/archive/2007/11/09/36236.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/mzty/comments/commentRss/36236.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/mzty/services/trackbacks/36236.html</trackback:ping><description><![CDATA[     鎽樿: 浠g爜錛?//------------------------------------------------------------------------------//           Name: dx9cs_multiple_vertex_buffers.cs//&n...  <a href='http://www.shnenglu.com/mzty/archive/2007/11/09/36236.html'>闃呰鍏ㄦ枃</a><img src ="http://www.shnenglu.com/mzty/aggbug/36236.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/mzty/" target="_blank">姊﹀湪澶╂動</a> 2007-11-09 18:01 <a href="http://www.shnenglu.com/mzty/archive/2007/11/09/36236.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Manged Direct3d鍩烘湰妗嗘灦+Mesh鐨勪嬌鐢紙涓錛?/title><link>http://www.shnenglu.com/mzty/archive/2007/11/09/36234.html</link><dc:creator>姊﹀湪澶╂動</dc:creator><author>姊﹀湪澶╂動</author><pubDate>Fri, 09 Nov 2007 09:34:00 GMT</pubDate><guid>http://www.shnenglu.com/mzty/archive/2007/11/09/36234.html</guid><wfw:comment>http://www.shnenglu.com/mzty/comments/36234.html</wfw:comment><comments>http://www.shnenglu.com/mzty/archive/2007/11/09/36234.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/mzty/comments/commentRss/36234.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/mzty/services/trackbacks/36234.html</trackback:ping><description><![CDATA[     鎽樿: 浠g爜錛?using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;us...  <a href='http://www.shnenglu.com/mzty/archive/2007/11/09/36234.html'>闃呰鍏ㄦ枃</a><img src ="http://www.shnenglu.com/mzty/aggbug/36234.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/mzty/" target="_blank">姊﹀湪澶╂動</a> 2007-11-09 17:34 <a href="http://www.shnenglu.com/mzty/archive/2007/11/09/36234.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>涓虹▼搴忓鍔犵畝鍗曠殑澹伴煶鎻愮ず(.net灝佽API --PlaySound())http://www.shnenglu.com/mzty/archive/2006/07/06/9490.html姊﹀湪澶╂動姊﹀湪澶╂動Thu, 06 Jul 2006 08:40:00 GMThttp://www.shnenglu.com/mzty/archive/2006/07/06/9490.htmlhttp://www.shnenglu.com/mzty/comments/9490.htmlhttp://www.shnenglu.com/mzty/archive/2006/07/06/9490.html#Feedback0http://www.shnenglu.com/mzty/comments/commentRss/9490.htmlhttp://www.shnenglu.com/mzty/services/trackbacks/9490.html
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽
using 聽System;
using 聽System.Runtime.InteropServices;

namespace 聽tonysound聽
{
聽聽聽聽
public class 聽Sound聽
聽聽聽聽
{
聽聽聽聽聽聽聽聽
public static void 聽Play(聽 string 聽strFileName,聽PlaySoundFlags聽soundFlags)聽
聽聽聽聽聽聽聽聽
{
聽聽聽聽聽聽聽聽聽聽聽聽PlaySound(聽strFileName,聽IntPtr.Zero,聽soundFlags);
聽聽聽聽聽聽聽聽聽聽聽聽
// 聽passes聽to聽Playsound聽the聽filename聽and聽a聽pointer
聽聽聽聽聽聽聽聽聽聽聽聽
// 聽to聽the聽Flag
聽聽聽聽聽聽聽聽}


聽聽聽聽聽聽聽聽[DllImport(
" winmm.dll " )]聽 // inports聽the聽winmm.dll聽used聽for聽sound
聽聽聽聽聽聽聽聽 private static extern bool 聽PlaySound(聽 string 聽szSound,聽IntPtr聽hMod,聽PlaySoundFlags聽flags聽);
聽聽聽聽}


聽聽聽聽[Flags]聽
// enumeration聽treated聽as聽a聽bit聽field聽or聽set聽of聽flags
聽聽聽聽 public enum 聽PlaySoundFlags:聽 int
聽聽聽聽
{

聽聽聽聽聽聽聽聽SND_SYNC聽
= 0x0000 ,聽 /* 聽play聽synchronously聽(default)聽 */
聽聽聽聽聽聽聽聽SND_ASYNC聽
= 0x0001 ,聽 /* 聽play聽asynchronously聽 */
聽聽聽聽聽聽聽聽SND_NODEFAULT聽
= 0x0002 ,聽 /* 聽silence聽(!default)聽if聽sound聽notfound聽 */
聽聽聽聽聽聽聽聽SND_LOOP聽
= 0x0008 ,聽 /* 聽loop聽the聽sound聽until聽nextsndPlaySound聽 */
聽聽聽聽聽聽聽聽SND_NOSTOP聽
= 0x0010 ,聽 /* 聽don't聽stop聽any聽currently聽playingsound聽 */
聽聽聽聽聽聽聽聽SND_NOWAIT聽
= 0x00002000 ,聽 /* 聽don't聽wait聽if聽the聽driver聽is聽busy聽 */
聽聽聽聽聽聽聽聽SND_FILENAME聽
= 0x00020000 ,聽 /* 聽name聽is聽file聽name聽 */
聽聽聽聽聽聽聽聽SND_RESOURCE聽
= 0x00040004 /* 聽name聽is聽resource聽name聽or聽atom聽 */
聽聽聽聽}

}


鐗圭偣灝辨槸綆鍗曞皬宸?鍙兘鍦╳indows涓婄敤鍟?

姊﹀湪澶╂動 2006-07-06 16:40 鍙戣〃璇勮
]]>
Managed directx 媯鏌ョ‖浠舵敮鎸佸拰瀹炵幇鍏ㄥ睆鏄劇ずhttp://www.shnenglu.com/mzty/archive/2006/06/22/8839.html姊﹀湪澶╂動姊﹀湪澶╂動Thu, 22 Jun 2006 08:08:00 GMThttp://www.shnenglu.com/mzty/archive/2006/06/22/8839.htmlhttp://www.shnenglu.com/mzty/comments/8839.htmlhttp://www.shnenglu.com/mzty/archive/2006/06/22/8839.html#Feedback0http://www.shnenglu.com/mzty/comments/commentRss/8839.htmlhttp://www.shnenglu.com/mzty/services/trackbacks/8839.html闃呰鍏ㄦ枃

姊﹀湪澶╂動 2006-06-22 16:08 鍙戣〃璇勮
]]>
managed directx 瀹炵幇澶槼緋葷殑妯℃嫙http://www.shnenglu.com/mzty/archive/2006/06/22/8837.html姊﹀湪澶╂動姊﹀湪澶╂動Thu, 22 Jun 2006 07:39:00 GMThttp://www.shnenglu.com/mzty/archive/2006/06/22/8837.htmlhttp://www.shnenglu.com/mzty/comments/8837.htmlhttp://www.shnenglu.com/mzty/archive/2006/06/22/8837.html#Feedback1http://www.shnenglu.com/mzty/comments/commentRss/8837.htmlhttp://www.shnenglu.com/mzty/services/trackbacks/8837.html闃呰鍏ㄦ枃

姊﹀湪澶╂動 2006-06-22 15:39 鍙戣〃璇勮
]]>
鎶曞獎鍙樻崲http://www.shnenglu.com/mzty/archive/2006/06/13/8495.html姊﹀湪澶╂動姊﹀湪澶╂動Tue, 13 Jun 2006 06:33:00 GMThttp://www.shnenglu.com/mzty/archive/2006/06/13/8495.htmlhttp://www.shnenglu.com/mzty/comments/8495.htmlhttp://www.shnenglu.com/mzty/archive/2006/06/13/8495.html#Feedback0http://www.shnenglu.com/mzty/comments/commentRss/8495.htmlhttp://www.shnenglu.com/mzty/services/trackbacks/8495.html鎶曞獎鍙樻崲鍒嗙被

聽聽聽 鎶婁笁緇寸墿浣撳彉涓轟簩緇村浘褰㈣〃紺虹殑榪囩▼縐頒負鎶曞獎鍙樻崲銆?/p>

鎶曞獎鍙樻崲鐨勫垎綾繪儏鍐靛涓嬭〃鎵紺猴細




涓栫晫鍧愭爣涓庤瀵熷潗鏍?/font>

聽聽聽 鐗╀綋鍦ㄧ┖闂寸殑琛ㄧず鏄敤涓栫晫鍧愭爣鏉ヨ〃紺猴紝浣嗘槸褰撲漢浠幓瑙傚療鐗╀綋鏃訛紝鍧愭爣緋誨氨杞寲涓鴻瀵熷潗鏍囩郴銆傝繖灝遍渶瑕佸湪涓や釜鍧愭爣緋諱箣闂磋繘琛岃漿鎹紝鍙互閫氳繃騫崇Щ銆佹棆杞疄鐜頒粠涓栫晫鍧愭爣鍒拌瀵熷潗鏍囩殑鍙樻崲銆?/p>

騫崇Щ鍚庯紝鐢ㄥ崟浣嶇煝閲忔硶寰楀埌鏃嬭漿鐭╅樀錛?/p>

  1. 鍙?/font> Zv 杞村悜涓鴻瀵熷鉤闈㈢殑娉曞悜 VPN錛屽叾鍗曚綅鐭㈤噺n=VPN/|VPN|=(nx,ny,nz)

  2. 鍙?/font> Xv 杞村悜涓鴻瀵熸柟鍚?/font>PREF錛屽叾鍗曚綅鐭㈤噺u=PREF/|PREF|=(ux,uy,uz)

  3. 鍙?font face="Times New Roman">Yv杞村悜鐨勫崟浣嶇煝閲?/font>v=un=錛?/font>vx錛?/font>vy錛?/font>vz錛?/font>

鍥犳涓栫晫鍧愭爣鍒拌瀵熷潗鏍囧埌鍙樻崲鐭╅樀涓猴細


姝e鉤琛屾姇褰憋紙涓夎鍥撅級

聽聽聽 鎶曞獎鏂瑰悜鍨傜洿浜庢姇褰卞鉤闈㈢殑鎶曞獎縐頒負姝e鉤琛屾姇褰?/a>錛屾垜浠氬父鎵璇寸殑涓夎鍥懼潎灞炰簬姝e鉤琛屾姇褰便備笁瑙嗗浘鐨勭敓鎴愬氨鏄妸 x 銆?/font> y 銆?/font> z 鍧愭爣緋葷殑褰綋鎶曞獎鍒?/font> z =0鐨勫鉤闈紝鍙樻崲鍒?/font> u 銆?/font> v 銆?/font> w 鍧愭爣緋匯備竴鑸繕闇灝嗕笁涓鍥懼湪涓涓鉤闈笂鐢誨嚭錛岃繖鏃跺氨寰楀埌涓嬮潰鐨勫彉鎹㈠叕寮忥紝鍏朵腑( a 錛?/font> b )涓?/font> u 銆?/font> v 鍧愭爣緋諱笅鐨勫鹼紝 tx 銆?/font> ty 銆?/font> tz 鍧囧鍥句腑鎵紺恒?br />聽聽 1錛変富瑙嗗浘

聽聽 2錛変刊瑙嗗浘

聽聽 3錛変晶瑙嗗浘

涓夎鍥?br />
鏂滃鉤琛屾姇褰?/font>

聽聽聽 鎶曞獎鏂瑰悜涓嶅瀭鐩翠簬鎶曞獎騫抽潰鐨勫鉤琛屾姇褰辮縐頒負鏂滃鉤琛屾姇褰?/font>錛岀幇鍦ㄨ鎴戜滑鏉ユ帹瀵兼枩騫寵鎶曞獎鐨勫彉鎹㈢煩闃點備笅鍥句腑鐨刏=0鐨勫潗鏍囧鉤闈負瑙傚療騫抽潰錛岀偣錛?/font> x 錛?/font> y 錛変負鐐癸紙 x 錛?/font> y 錛?/font> z 錛夊湪瑙傚療騫抽潰涓婄殑姝e鉤琛屾姇褰卞潗鏍囷紝鐐癸紙 x 錛?/font> y 錛変負鏂滄姇褰卞潗鏍囥傦紙 x 錛?/font> y 錛変笌錛?/font> x 錛?/font> y 錛夌殑璺濈涓?/font> L 銆?



閫忚鎶曞獎

聽聽聽 閫忚鎶曞獎鐨勮綰匡紙鎶曞獎綰匡級鏄粠瑙嗙偣錛堣瀵熺偣錛夊嚭鍙戯紝瑙嗙嚎鏄笉騫寵鐨勩備笉騫寵浜庢姇褰卞鉤闈㈢殑瑙嗙嚎姹囪仛鐨勪竴鐐圭О涓虹伃鐐癸紝鍦ㄥ潗鏍囪醬涓婄殑鐏偣鍙仛涓葷伃鐐廣備富鐏偣鏁板拰鎶曞獎騫抽潰鍒囧壊鍧愭爣杞寸殑鏁伴噺鐩稿搴斻傛寜鐓т富鐏偣鐨勪釜鏁幫紝閫忚鎶曞獎鍙垎涓轟竴鐐歸忚銆佷簩鐐歸忚鍜屼笁鐐歸忚銆?



涓嬮潰鎴戜滑鏉ユ帹瀵肩畝鍗曠殑涓鐐歸忚鐨勬姇褰卞叕寮忋?/p>

浠庝笂鍥?/font>

P 鐐瑰湪瑙傚療騫抽潰涓婄殑鎶曞獎鎴戜滑鍙互寰楀埌鎻忚堪 P 鐐圭殑鍙傛暟鏂圭▼錛?/font>

鐢ㄩ綈嬈″潗鏍囪〃紺轟負錛?/p>




http://jpkc.swjtu.edu.cn/C15/imagination/jisuanjituxing/Chapter6/CG_Txt_6_018.htm



]]>
涓夌淮鍑犱綍鍙樻崲http://www.shnenglu.com/mzty/archive/2006/06/13/8494.html姊﹀湪澶╂動姊﹀湪澶╂動Tue, 13 Jun 2006 06:11:00 GMThttp://www.shnenglu.com/mzty/archive/2006/06/13/8494.htmlhttp://www.shnenglu.com/mzty/comments/8494.htmlhttp://www.shnenglu.com/mzty/archive/2006/06/13/8494.html#Feedback0http://www.shnenglu.com/mzty/comments/commentRss/8494.htmlhttp://www.shnenglu.com/mzty/services/trackbacks/8494.html 涓夌淮鍑犱綍鍙樻崲
  1. 鐢變簬鐢ㄩ綈嬈″潗鏍囪〃紺猴紝涓夌淮鍑犱綍鍙樻崲鐨勭煩闃墊槸涓涓?闃舵柟闃碉紝鍏跺艦寮忓涓嬶細


聽聽聽聽 1錛夊鉤縐誨彉鎹?br />
聽聽聽聽 鍙傜収浜岀淮鐨勫鉤縐誨彉鎹紝鎴戜滑寰堝鏄撳緱鍒頒笁緇村鉤縐誨彉鎹㈢煩闃碉細

聽聽聽聽

聽聽聽聽 2錛夌緝鏀懼彉鎹?br />聽聽聽 鐩存帴鑰冭檻鐩稿浜庡弬鑰冪偣

錛?/font> xf 錛?/font> yf 錛?/font> zf 錛?/font> 鐨勭緝鏀懼彉鎹紝鍏舵楠や負錛?/font>

聽聽聽聽 A. 灝嗗鉤縐誨埌鍧愭爣鍘熺偣澶勶紱
聽聽聽聽 B. 榪涜緙╂斁鍙樻崲錛?br />聽聽聽聽 C. 灝嗗弬鑰冪偣

錛?/font> xf 錛?/font> yf 錛?/font> zf 錛?/font> 縐誨洖鍘熸潵浣嶇疆
聽聽聽聽聽聽 鍒欏彉鎹㈢煩闃典負錛?br />聽聽聽聽聽
聽聽聽 3錛夌粫鍧愭爣杞寸殑鏃嬭漿鍙樻崲
聽聽聽聽涓夌淮絀洪棿鐨勬棆杞浉瀵硅澶嶆潅浜涳紝鑰冭檻鍙蟲墜鍧愭爣緋諱笅鐩稿鍧愭爣鍘熺偣緇曞潗鏍囪醬鏃嬭漿
q 瑙掔殑鍙樻崲錛?/font>

聽聽聽聽 A.緇?/font> x 杞存棆杞?br />
聽聽聽

聽聽聽聽 B.緇?/font> y 杞存棆杞?br />
聽聽聽

聽聽聽聽 C.緇?/font> z 杞存棆杞?br />
聽聽聽

聽聽聽聽
聽聽聽聽

涓夌淮絀洪棿鐨勫鉤縐匯佹棆杞強緙╂斁紺烘剰鍥?/font>

聽聽 4錛夌粫浠繪剰杞寸殑鏃嬭漿鍙樻崲
聽聽 璁炬棆杞醬 AB 鐢變換鎰忎竴鐐?/font> A 錛?/font> xa 錛?/font> ya 錛?/font> za 錛夊強鍏舵柟鍚戞暟( a 錛?/font> b 錛?/font> c )瀹氫箟錛?img height="29" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_288.gif" width="400" border="0" />

聽聽聽聽聽

聽聽 鍙互閫氳繃涓嬪垪姝ラ鏉ュ疄鐜?/font> P 鐐圭殑鏃嬭漿錛?/font>

聽聽聽聽 A. 灝?/font> A 鐐圭Щ鍒板潗鏍囧師鐐廣?/font>

聽聽聽聽 B. 浣?/p> AB 鍒嗗埆緇?/font> X 杞淬?/font> Y 杞存棆杞傚綋瑙掑害涓?/font> Z 杞撮噸鍚堛?/font>

聽聽聽聽

聽聽聽聽 D.浣滀笂榪板彉鎹㈢殑閫嗘搷浣滐紝浣?/font> AB 鍥炲埌鍘熸潵浣嶇疆銆?/font>

鏄?/font> AB 鍦?/font> YOZ 騫抽潰涓?/font> XOZ 騫抽潰鐨勬姇褰變笌 Z 杞寸殑澶硅銆?br />

http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Txt_6_012.htm



]]>
浜岀淮鍥懼艦鐨勫嚑浣曞彉鎹?/title><link>http://www.shnenglu.com/mzty/archive/2006/06/13/8493.html</link><dc:creator>姊﹀湪澶╂動</dc:creator><author>姊﹀湪澶╂動</author><pubDate>Tue, 13 Jun 2006 06:10:00 GMT</pubDate><guid>http://www.shnenglu.com/mzty/archive/2006/06/13/8493.html</guid><wfw:comment>http://www.shnenglu.com/mzty/comments/8493.html</wfw:comment><comments>http://www.shnenglu.com/mzty/archive/2006/06/13/8493.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/mzty/comments/commentRss/8493.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/mzty/services/trackbacks/8493.html</trackback:ping><description><![CDATA[ <a name="2"> <font face="榛戜綋" color="#0000ff">浜岀淮鍥懼艦鐨勫嚑浣曞彉鎹?/font> </a> <p style="LINE-HEIGHT: 200%"> <font face="瀹嬩綋" size="3">聽聽聽 姝e鎴戜滑鍦ㄩ檮褰曚腑鎻愬埌鐨勯偅鏍鳳紝鐢ㄩ綈嬈″潗鏍囪〃紺虹偣鐨勫彉鎹㈠皢闈炲父鏂逛究錛屽洜姝ゅ湪鏈妭涓墍鏈夌殑鍑犱綍鍙樻崲閮藉皢閲囩敤榻愭鍧愭爣榪涜榪愮畻銆備簩緇撮綈嬈″潗鏍囧彉鎹㈢殑鐭╅樀鐨勫艦寮忔槸錛?<br /><img height="71" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_256.gif" width="91" border="0" /> 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <br />榪欎釜鐭╅樀姣忎竴涓厓绱犻兘鏄湁鐗規畩鍚箟鐨勩?br /><img height="41" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter5/CG_Gif_5_209.gif" width="535" border="0" /></font> <font face="瀹嬩綋" size="3">褰㈣繘琛屽鉤縐誨彉鎹紱[</font> <font face="Times New Roman" size="3"> <i>g</i> </font> <font face="瀹嬩綋" size="3"> </font> <font face="Times New Roman" size="3"> <i>h</i> </font> <font face="瀹嬩綋" size="3">]鏄鍥懼艦浣滄姇褰卞彉鎹紱[</font> <font face="Times New Roman" size="3"> <i>i</i> </font> <font face="瀹嬩綋" size="3">]鍒欐槸瀵瑰浘褰㈡暣浣撹繘琛岀緝鏀懼彉鎹€?br />1錛夊鉤縐誨彉鎹?<br /><img height="81" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_253.gif" width="359" border="0" /><br /><br />2錛夌緝鏀懼彉鎹?<br /><img height="81" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_254.gif" width="369" border="0" /><br /><br />3錛夋棆杞彉鎹?img height="28" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_291.gif" width="502" border="0" /><br /><img height="66" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_255.gif" width="421" border="0" /><br /><br /><img height="28" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_292.gif" width="336" border="0" /><br />4錛夊縐板彉鎹?br /></font> <i> <font size="3"> <img src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_222.gif" border="0" /> </font> </i> </p> <p> <font face="瀹嬩綋" size="3">瀵圭О鍙樻崲鍏跺疄鍙槸</font> <font size="3"> <font face="Times New Roman"> <i>a</i> </font> <font face="瀹嬩綋">銆?/font> <font face="Times New Roman"> <i>b</i> </font> <font face="瀹嬩綋">銆?/font> <font face="Times New Roman"> <i>d</i> </font> <font face="瀹嬩綋">銆?/font> <font face="Times New Roman"> <i>e</i> </font> <font face="瀹嬩綋">鍙?/font>0<font face="瀹嬩綋">銆?/font>1<font face="瀹嬩綋">絳夌壒孌婂間駭鐢熺殑涓浜涚壒孌婃晥鏋溿備緥濡傦細</font></font> </p> <ol type="A"> <li> <p style="LINE-HEIGHT: 200%"> <font face="瀹嬩綋" size="3">褰?/font> <font face="Times New Roman" size="3"> <i>b</i> </font> <font face="瀹嬩綋" size="3">=</font> <font face="Times New Roman" size="3"> <i>d</i> </font> <font face="瀹嬩綋" size="3">=0錛?/font> <font face="Times New Roman" size="3"> <i>a</i> </font> <font face="瀹嬩綋" size="3">=-1錛?/font> <font face="Times New Roman" size="3"> <i>e</i> </font> <font face="瀹嬩綋" size="3">=1鏃舵湁</font> <font size="3"> <font face="Times New Roman"> <i>x</i> </font> <sup>麓</sup>=-<font face="Times New Roman"><i>x</i></font><font face="瀹嬩綋">錛?/font><font face="Times New Roman"><i>y</i></font><sup>麓</sup>=<font face="Times New Roman"><i>y</i></font><font face="瀹嬩綋">錛屼駭鐢熶笌</font><font face="Times New Roman"><i>y</i></font><font face="瀹嬩綋">杞村縐扮殑鍥懼艦</font><i>銆?/i></font> </p> </li> <li> <p style="LINE-HEIGHT: 200%"> <font face="瀹嬩綋">褰?/font> <font face="Times New Roman" size="3"> <i>b</i> </font> <font face="瀹嬩綋" size="3">=</font> <font face="Times New Roman" size="3"> <i>d</i> </font> <font face="瀹嬩綋" size="3">=0錛?/font> <font face="Times New Roman" size="3"> <i>a</i> </font> <font face="瀹嬩綋" size="3">=-1錛?/font> <font face="Times New Roman" size="3"> <i>e</i> </font> <font face="瀹嬩綋">=-1鏃舵湁</font> <font face="Times New Roman"> <i>x</i> </font> <sup>麓</sup>=<font face="Times New Roman"><i>x</i></font><font face="瀹嬩綋">錛?/font><font face="Times New Roman"><i>y</i></font><sup>麓</sup>=-<font face="Times New Roman"><i>y</i></font><font face="瀹嬩綋">錛屼駭鐢熶笌</font><font face="Times New Roman"><i>x</i></font><font face="瀹嬩綋">杞村縐扮殑鍥懼艦銆?/font></p> </li> <li> <p style="LINE-HEIGHT: 200%"> <font face="瀹嬩綋" size="3">褰?/font> <font size="3"> <font face="Times New Roman" size="3"> <i>b</i> </font> <font face="瀹嬩綋" size="3">=</font> <font face="Times New Roman" size="3"> <i>d</i> </font> </font> <font face="瀹嬩綋" size="3">=0錛?/font> <font face="Times New Roman" size="3"> <i>a</i> </font> <font face="瀹嬩綋" size="3">=</font> <font face="Times New Roman" size="3"> <i>e</i> </font> <font face="瀹嬩綋" size="3">=-1鏃舵湁</font> <font size="3"> <font face="Times New Roman"> <i>x</i> </font> <sup>麓</sup>=-<font face="Times New Roman"><i>x</i></font><font face="瀹嬩綋">錛?/font><font face="Times New Roman"><i>y</i></font><sup>麓</sup>=-<font face="Times New Roman"><i>y</i></font><font face="瀹嬩綋">錛屼駭鐢熶笌鍘熺偣瀵圭О鐨勫浘褰€?/font></font> </p> </li> <li> <p style="LINE-HEIGHT: 200%"> <font face="瀹嬩綋">褰?/font> <font face="Times New Roman" size="3"> <i>b</i> </font> <font face="瀹嬩綋" size="3">=</font> <font face="Times New Roman" size="3"> <i>d</i> </font> <font face="瀹嬩綋" size="3"> </font> <font face="瀹嬩綋">=1錛?/font> <font face="Times New Roman" size="3"> <i>a</i> </font> <font face="瀹嬩綋" size="3">=</font> <font face="Times New Roman" size="3"> <i>e</i> </font> <font face="瀹嬩綋">=0鏃舵湁</font> <font face="Times New Roman"> <i>x</i> </font> <sup>麓</sup>=<font face="Times New Roman"><i>y</i></font><font face="瀹嬩綋">錛?/font><font face="Times New Roman"><i>y</i></font><sup>麓</sup>=<font face="Times New Roman"><i>x</i></font><font face="瀹嬩綋">錛屼駭鐢熶笌鐩寸嚎</font>y=x<font face="瀹嬩綋">瀵圭О鐨勫浘褰€?/font></p> </li> <li> <p style="LINE-HEIGHT: 200%"> <font face="瀹嬩綋">褰?/font> <font face="Times New Roman" size="3"> <i>b</i> </font> <font face="瀹嬩綋" size="3">=</font> <font face="Times New Roman" size="3"> <i>d</i> </font> <font face="瀹嬩綋" size="3"> </font> <font face="瀹嬩綋">=-1錛?/font> <font face="Times New Roman" size="3"> <i>a</i> </font> <font face="瀹嬩綋" size="3">=</font> <font face="Times New Roman" size="3"> <i>e</i> </font> <font face="瀹嬩綋">=0鏃舵湁</font> <font face="Times New Roman"> <i>x</i> </font> <sup>麓</sup>=-<font face="Times New Roman" size="3"><i>y</i></font><font face="瀹嬩綋">錛?/font><font face="Times New Roman"><i>y</i></font><sup>麓</sup>=-<font face="Times New Roman" size="3"><i>x</i></font><font face="瀹嬩綋">錛屼駭鐢熶笌鐩寸嚎</font><font face="Times New Roman"><i>y</i></font>=-<font face="Times New Roman"><i>x</i></font><font face="瀹嬩綋">瀵圭О鐨勫浘褰€?/font></p> </li> </ol> <p> <font face="瀹嬩綋" size="3">5錛夐敊鍒囧彉鎹?br /><br /></font> <img height="70" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_223.gif" width="236" border="0" /> <font size="3"> <ol type="A"> <li> <p style="LINE-HEIGHT: 200%"> <font face="瀹嬩綋">褰?/font> <font face="Times New Roman"> <i>d</i> </font>=0<font face="瀹嬩綋">鏃訛紝</font><font face="Times New Roman"><i>x</i></font><sup>麓</sup>=<font face="Times New Roman"><i>x</i></font><font face="瀹嬩綋">+</font><font face="Times New Roman"><i>by</i></font><font face="瀹嬩綋">錛?/font><font face="Times New Roman"><i>y</i></font><sup>麓</sup>=<font face="Times New Roman"><i>y</i></font><font face="瀹嬩綋">錛屾鏃訛紝鍥懼艦鐨?/font><font face="Times New Roman"><i>y</i></font><font face="瀹嬩綋">鍧愭爣涓嶅彉錛?/font><font face="Times New Roman"><i>x</i></font><font face="瀹嬩綋">鍧愭爣闅忓垵鍊悸?錛?/font><font face="Times New Roman"><i>x</i></font><font face="瀹嬩綋">錛?/font><font face="Times New Roman"><i>y</i></font><font face="瀹嬩綋">錛夊強鍙樻崲緋繪暟</font><font face="Times New Roman"><i>b</i></font><font face="瀹嬩綋">浣滅嚎鎬у彉鍖栥?/font></p> </li> <li> <p style="LINE-HEIGHT: 200%"> <font face="瀹嬩綋">褰?/font> <font face="Times New Roman"> <i>b</i> </font>=0<font face="瀹嬩綋">鏃訛紝</font><font face="Times New Roman"><i>x</i></font><sup>麓</sup>=<font face="Times New Roman"><i>x</i></font><font face="瀹嬩綋">錛?/font><font face="Times New Roman"><i>y</i></font><sup>麓</sup>=<font face="Times New Roman"><i>dx</i></font>+<font face="Times New Roman"><i>y</i></font><font face="瀹嬩綋">錛屾鏃訛紝鍥懼艦鐨?/font><font face="Times New Roman" size="3"><i>x</i></font><font face="瀹嬩綋">鍧愭爣涓嶅彉錛?/font><font face="Times New Roman"><i>y</i></font><font face="瀹嬩綋">鍧愭爣闅忓垵鍊悸?錛?/font><font face="Times New Roman"><i>x</i></font><font face="瀹嬩綋">錛?/font><font face="Times New Roman"><i>y</i></font><font face="瀹嬩綋">錛夊強鍙樻崲緋繪暟</font><font face="Times New Roman"><i>d</i></font><font face="瀹嬩綋">浣滅嚎鎬у彉鍖栥?/font></p> </li> </ol> <font face="瀹嬩綋"> <blockquote> <p align="center"> <img height="189" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_005.gif" width="239" /> <img height="175" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_006.gif" width="221" /> <br /> <img height="169" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_007.gif" width="230" /> <img height="178" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_008.gif" width="223" /> <br /> <img height="181" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_009.gif" width="222" /> <img height="210" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_010.gif" width="217" /> </p> </blockquote> <p>6錛夊鍚堝彉鎹?/p> </font> </font> </p> <blockquote> <p style="LINE-HEIGHT: 200%" align="justify"> <font face="瀹嬩綋" size="3">濡傛灉鍥懼艦瑕佸仛涓嬈′互涓婄殑鍑犱綍鍙樻崲錛岄偅涔堝彲浠ュ皢鍚勪釜鍙樻崲鐭╅樀緇煎悎璧鋒潵榪涜涓姝ュ埌浣嶇殑鍙樻崲銆傚鍚堝彉鎹㈡湁濡備笅鐨勬ц川錛?/font> </p> </blockquote> <ol type="A"> <font face="瀹嬩綋" size="3"> <li>澶嶅悎騫崇Щ <p style="LINE-HEIGHT: 250%" align="justify">瀵瑰悓涓鍥懼艦鍋氫袱嬈″鉤縐葷浉褰撲簬灝嗕袱嬈$殑騫崇Щ涓ゅ姞璧鋒潵錛?img height="63" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_224.gif" width="516" border="0" /><br /></p></li> <li>澶嶅悎緙╂斁 <p style="LINE-HEIGHT: 200%" align="justify">涓ゆ榪炵畫鐨勭緝鏀劇浉褰撲簬灝嗙緝鏀炬搷浣滅浉涔橈細</p><p style="LINE-HEIGHT: 200%" align="justify"><img height="158" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_282.gif" width="424" border="0" /></p></li> </font> <font face="瀹嬩綋" size="3"> <li>澶嶅悎鏃嬭漿 <p style="LINE-HEIGHT: 200%" align="justify">涓ゆ榪炵畫鐨勬棆杞浉褰撲簬灝嗕袱嬈$殑鏃嬭漿瑙掑害鐩稿姞錛?img height="50" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_283.gif" width="509" border="0" /></p></li> </font> <font face="瀹嬩綋" size="3">緙╂斁銆佹棆杞彉鎹㈤兘涓庡弬鑰冪偣鏈夊叧錛屼笂闈㈣繘琛岀殑鍚勭鍙樻崲閮芥槸浠ュ師鐐逛負鍙傝冪偣鐨勩傚鏋滅浉瀵規煇涓竴鑸殑鍙傝冪偣錛?/font> <font size="3"> <font face="Times New Roman"> <i>x<sub>f</sub></i> </font> <font face="瀹嬩綋">錛?/font> <font face="Times New Roman"> <i>y<sub>f</sub></i> </font> <font face="瀹嬩綋">錛変綔緙╂斁銆佹棆杞彉鎹紝鐩稿綋浜庡皢璇ョ偣縐誨埌鍧愭爣鍘熺偣澶勶紝鐒跺悗榪涜緙╂斁銆佹棆杞彉鎹紝鏈鍚庡皢錛?/font> <font face="Times New Roman"> <i>x<sub>f</sub></i> </font> <font face="瀹嬩綋"> </font> <font face="瀹嬩綋">錛?/font> <font face="瀹嬩綋"> </font> <font face="Times New Roman"> <i>y<sub>f</sub></i> </font> <font face="瀹嬩綋"> </font> <font face="瀹嬩綋">錛夌偣縐誨洖鍘熸潵鐨勪綅緗傚垏璁板鍚堝彉鎹㈡椂錛屽厛浣滅敤鐨勫彉鎹㈢煩闃靛湪鍙崇錛屽悗浣滅敤鐨勫彉鎹㈢煩闃靛湪宸︾銆?</font> <li> <font face="瀹嬩綋">鍏充簬錛?/font> <font face="Times New Roman"> <i>x<sub>f</sub></i> </font> <font face="瀹嬩綋"> </font> <font face="瀹嬩綋">錛?/font> <font face="Times New Roman"> <i>y<sub>f</sub></i> </font> <font face="瀹嬩綋"> </font> <font face="瀹嬩綋">錛夌偣鐨勭緝鏀懼彉鎹? <p align="justify"><img height="25" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_225.gif" width="301" border="0" /></p></font> <p align="justify"> <img height="141" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_226.gif" width="277" border="0" /> </p> </li> </font> <font size="3"> <li> <font face="瀹嬩綋">緇曪紙</font> <i>x<sub>f</sub></i> <font face="瀹嬩綋">錛?/font> <i>y<sub>f</sub></i> <font face="瀹嬩綋"> </font> <font face="瀹嬩綋">錛夌偣鐨勬棆杞彉鎹? <p align="justify"><img height="168" src="http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Gif_6_227.gif" width="338" border="0" /></p></font> <p align="justify"> <a >http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Txt_6_011.htm</a>銆</p> </li> </font> </ol> <img src ="http://www.shnenglu.com/mzty/aggbug/8493.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/mzty/" target="_blank">姊﹀湪澶╂動</a> 2006-06-13 14:10 <a href="http://www.shnenglu.com/mzty/archive/2006/06/13/8493.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>紿楀彛鍖哄埌瑙嗗浘鍖虹殑鍧愭爣鍙樻崲 http://www.shnenglu.com/mzty/archive/2006/06/13/8492.html姊﹀湪澶╂動姊﹀湪澶╂動Tue, 13 Jun 2006 06:05:00 GMThttp://www.shnenglu.com/mzty/archive/2006/06/13/8492.htmlhttp://www.shnenglu.com/mzty/comments/8492.htmlhttp://www.shnenglu.com/mzty/archive/2006/06/13/8492.html#Feedback0http://www.shnenglu.com/mzty/comments/commentRss/8492.htmlhttp://www.shnenglu.com/mzty/services/trackbacks/8492.html 紿楀彛鍖哄埌瑙嗗浘鍖虹殑鍧愭爣鍙樻崲

聽聽聽 瀹為檯鐨勭獥鍙e尯涓庤鍥懼尯寰寰涓嶄竴鏍峰ぇ灝忥紝瑕佸湪瑙嗗浘鍖烘紜湴鏄劇ず褰綋鐨勶紝蹇呴』灝嗗叾浠庣獥鍙e尯鍙樻崲鍒拌鍥懼尯銆?/font>


姣斾緥鍏崇郴錛屼袱鑰呯殑鍙樻崲鍏紡涓猴細

聽聽

鍙互綆鍗曞湴灝嗕袱鑰呯殑鍏崇郴琛ㄧず涓猴細



http://necweb.neu.edu.cn/ncourse//tuxingxue/Chapter6/CG_Txt_6_010.htm



]]>
managed directx瀹炵幇璇誨啓buffer (Read and Write VertexBuffer and IndexBuffer Data)http://www.shnenglu.com/mzty/archive/2006/06/09/8343.html姊﹀湪澶╂動姊﹀湪澶╂動Fri, 09 Jun 2006 08:39:00 GMThttp://www.shnenglu.com/mzty/archive/2006/06/09/8343.htmlhttp://www.shnenglu.com/mzty/comments/8343.htmlhttp://www.shnenglu.com/mzty/archive/2006/06/09/8343.html#Feedback1http://www.shnenglu.com/mzty/comments/commentRss/8343.htmlhttp://www.shnenglu.com/mzty/services/trackbacks/8343.htmlRead and Write VertexBuffer and IndexBuffer Data With GraphicsStreams
using  System;
using  Microsoft.DirectX;
using  Microsoft.DirectX.Direct3D;

public   struct  PositionNormalTexVertex
{
    
public  Vector3 Position;
    
public  Vector3 Normal;
    
public    float  Tu0, Tv0;
    
public   static   readonly  VertexFormats FVF  =  VertexFormats.Position  |  VertexFormats.Texture1;
}

public   class  Example
{
    
public   unsafe   void   GraphicsStreamReadWrite()
    
{
        
// Create a vertex buffer in the managed pool
        VertexBuffer vb  =   new  VertexBuffer( typeof (PositionNormalTexVertex),  100 , device, Usage.None, PositionNormalTexVertex.FVF, Pool.Managed);

        
// First, fill an array of PositionNormalTexVertex elements with data.
        PositionNormalTexVertex[] vertices  =   new  PositionNormalTexVertex[ 50 ];
        
for ( int  i = 0 ; i < 50 ; i ++ )
        
{
            
// fill the vertices with some data
            vertices[i].Position  =   new  Vector3(3f,4f,5f);
        }


        
// The size of the verticies are 32-bytes each (float3 (12) + float3 (12) + float(4) + float(4))
        
// To lock 50 verticies, the size of the lock would be 1600 (32 * 50)
        GraphicsStream vbData  =   vb.Lock( 0 , 1600 , LockFlags.None);

        
// copy the vertex data into the vertex buffer
        vbData.Write(vertices);

        
// Unlock the VB
        vb.Unlock();


        
// This time, lock the entire VertexBuffer
        vbData  =   vb.Lock( 0 3200 , LockFlags.None);

        
// Cast the InternalDataPointer (a void pointer) to an array of verticies
        PositionNormalTexVertex *  vbArray  =  (PositionNormalTexVertex * ) vbData.InternalDataPointer;

        
for ( int  i = 0 ; i < 100 ; i ++ )
        
{
            
// perform some operations on the data
            vbArray[i].Tu0  =  i;
            vbArray[i].Tv0 
=  vbArray[i].Tu0  *   2 ;

            Console.WriteLine(vbArray[i].Tv0.ToString());
        }


        
// Unlock the buffer
        vb.Unlock();
        vb.Dispose();
    }

}

Read and Write VertexBuffer Data With Arrays

 

using System;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

public struct PositionNormalTexVertex
{
    
public Vector3 Position;
    
public Vector3 Normal;
    
public float Tu0, Tv0;
    
public static readonly VertexFormats FVF = VertexFormats.Position | VertexFormats.Texture1;
}


public class Example
{
    
public void ArrayBasedReadWrite()
    
{
        
//Create a vertex buffer in the managed pool
        VertexBuffer vb = new VertexBuffer(typeof(PositionNormalTexVertex), 100, device,                 Usage.None, PositionNormalTex1Vertex.FVF, Pool.Managed);

        
//Fill an array of the appropriate type with the VB data using Lock()
        PositionNormalTexVertex[] vbData = (PositionNormalTexVertex[]) vb.Lock(0,                    typeof(PositionNormalTexVertex), LockFlags.None, 50);
        
for(int i=0; i<50; i++)
        
{
            
//set your vertices to something
            vbData[i].Position = new Vector3(2f,2f,2f);  
            vbData[i].Normal 
= new Vector3(1f,0f,0f);
            vbData[i].Tu0 
= i;
            vbData[i].Tv0 
= i;
        }

        
//Unlock the vb before you can use it elsewhere
        vb.Unlock();

        
//This lock overload simply locks the entire VB -- setting ReadOnly                     //can improve perf when reading a vertexbuffer
        vbData = (PositionNormalTexVertex[]) vb.Lock(0, LockFlags.ReadOnly);
        
for(int i=0; i<100; i++)
        
{
            
//read some vertex data
            Console.WriteLine("Vertex " + i + "Tu: " +  vbData[i].Tu0 + " , Tv: " + vbData[i].Tv0);
        }


        
//Unlock the buffer
        vb.Unlock();


        vb.Dispose();
    }

}



]]>
Managed directx -----the different of transformed vertex and untransformed vertexhttp://www.shnenglu.com/mzty/archive/2006/06/09/8341.html姊﹀湪澶╂動姊﹀湪澶╂動Fri, 09 Jun 2006 08:33:00 GMThttp://www.shnenglu.com/mzty/archive/2006/06/09/8341.htmlhttp://www.shnenglu.com/mzty/comments/8341.htmlhttp://www.shnenglu.com/mzty/archive/2006/06/09/8341.html#Feedback1http://www.shnenglu.com/mzty/comments/commentRss/8341.htmlhttp://www.shnenglu.com/mzty/services/trackbacks/8341.html
publicvoid聽OnCreateVertexBuffer(object聽sender,聽EventArgs聽e)
聽聽聽聽聽聽聽聽
{
聽聽聽聽聽聽聽聽聽聽聽聽VertexBuffer聽vb聽
=聽(VertexBuffer)sender;
聽聽聽聽聽聽聽聽聽聽聽聽GraphicsStream聽stm聽
=聽vb.Lock(0,聽0,聽0);
聽聽聽聽聽聽聽聽聽聽聽聽CustomVertex.TransformedColored[]聽verts聽
=new聽CustomVertex.TransformedColored[3];

聽聽聽聽聽聽聽聽聽聽聽聽verts[
0].X=150;verts[0].Y=50;verts[0].Z=0.5f;聽verts[0].Rhw=5;聽verts[0].Color聽=聽System.Drawing.Color.Red.ToArgb();
聽聽聽聽聽聽聽聽聽聽聽聽verts[
1].X=250;verts[1].Y=250;verts[1].Z=0.5f;聽verts[1].Rhw=5;聽verts[1].Color聽=聽System.Drawing.Color.Yellow.ToArgb();
聽聽聽聽聽聽聽聽聽聽聽聽verts[
2].X=50;verts[2].Y=250;verts[2].Z=0.5f;聽verts[2].Rhw=5;聽verts[2].Color聽=聽System.Drawing.Color.SkyBlue.ToArgb();
聽聽聽聽聽聽聽聽聽聽聽聽stm.Write(verts);
聽聽聽聽聽聽聽聽聽聽聽聽vb.Unlock();
聽聽聽聽聽聽聽聽}

聽聽聽聽聽聽聽聽
privatevoid聽Render()
聽聽聽聽聽聽聽聽
{
聽聽聽聽聽聽聽聽聽聽聽聽
if聽(device聽==null)聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
return;

聽聽聽聽聽聽聽聽聽聽聽聽
//Clear聽the聽backbuffer聽to聽a聽blue聽color聽(ARGB聽=聽000000ff)
聽聽聽聽聽聽聽聽聽聽聽聽device.Clear(ClearFlags.Target,聽System.Drawing.Color.Blue,聽1.0f,聽0);
聽聽聽聽聽聽聽聽聽聽聽聽
//Begin聽the聽scene
聽聽聽聽聽聽聽聽聽聽聽聽device.BeginScene();
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽device.SetStreamSource(聽
0,聽vertexBuffer,聽0);
聽聽聽聽聽聽聽聽聽聽聽聽device.VertexFormat聽
=聽CustomVertex.TransformedColored.Format;
聽聽聽聽聽聽聽聽聽聽聽聽device.DrawPrimitives(PrimitiveType.TriangleList,聽
0,聽1);
聽聽聽聽聽聽聽聽聽聽聽聽
//End聽the聽scene
聽聽聽聽聽聽聽聽聽聽聽聽device.EndScene();
聽聽聽聽聽聽聽聽聽聽聽聽device.Present();
聽聽聽聽聽聽聽聽}


untransformed vertex : 蹇呴』鐨刴anual寤虹珛camare鍘繪樉紺?br />
publicvoid聽OnCreateVertexBuffer(object聽sender,聽EventArgs聽e)
聽聽聽聽聽聽聽聽
{
聽聽聽聽聽聽聽聽聽聽聽聽VertexBuffer聽vb聽
=聽(VertexBuffer)sender;
聽聽聽聽聽聽聽聽聽聽聽聽CustomVertex.PositionColored[]聽verts聽
=聽(CustomVertex.PositionColored[])vb.Lock(0,0);
聽聽聽聽聽聽聽聽聽聽聽聽verts[
0].X=-1.0f;聽verts[0].Y=-1.0f;聽verts[0].Z=0.0f;聽verts[0].Color聽=聽System.Drawing.Color.DarkGoldenrod.ToArgb();
聽聽聽聽聽聽聽聽聽聽聽聽verts[
1].X=1.0f;聽verts[1].Y=-1.0f聽;verts[1].Z=0.0f;聽verts[1].Color聽=聽System.Drawing.Color.MediumOrchid.ToArgb();
聽聽聽聽聽聽聽聽聽聽聽聽verts[
2].X=0.0f;聽verts[2].Y=1.0f;聽verts[2].Z聽=0.0f;聽verts[2].Color聽=聽System.Drawing.Color.Cornsilk.ToArgb();
聽聽聽聽聽聽聽聽聽聽聽聽vb.Unlock();
聽聽聽聽聽聽聽聽}


聽聽聽聽聽聽聽聽
privatevoid聽Render()
聽聽聽聽聽聽聽聽
{
聽聽聽聽聽聽聽聽聽聽聽聽
if聽(device聽==null)聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
return;

聽聽聽聽聽聽聽聽聽聽聽聽
if聽(pause)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
return;

聽聽聽聽聽聽聽聽聽聽聽聽
//Clear聽the聽backbuffer聽to聽a聽blue聽color聽
聽聽聽聽聽聽聽聽聽聽聽聽device.Clear(ClearFlags.Target,聽System.Drawing.Color.Blue,聽1.0f,聽0);
聽聽聽聽聽聽聽聽聽聽聽聽
//Begin聽the聽scene
聽聽聽聽聽聽聽聽聽聽聽聽device.BeginScene();
聽聽聽聽聽聽聽聽聽聽聽聽
//聽Setup聽the聽world,聽view,聽and聽projection聽matrices
聽聽聽聽聽聽聽聽聽聽聽聽SetupMatrices();
聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽device.SetStreamSource(
0,聽vertexBuffer,聽0);
聽聽聽聽聽聽聽聽聽聽聽聽device.VertexFormat聽
=聽CustomVertex.PositionColored.Format;
聽聽聽聽聽聽聽聽聽聽聽聽device.DrawPrimitives(PrimitiveType.TriangleList,聽
0,聽1);
聽聽聽聽聽聽聽聽聽聽聽聽
//End聽the聽scene
聽聽聽聽聽聽聽聽聽聽聽聽device.EndScene();
聽聽聽聽聽聽聽聽聽聽聽聽device.Present();
聽聽聽聽聽聽聽聽}


聽聽聽聽聽聽聽聽
privatevoid聽SetupMatrices()
聽聽聽聽聽聽聽聽
{
聽聽聽聽聽聽聽聽聽聽聽聽
//聽For聽our聽world聽matrix,聽we聽will聽just聽rotate聽the聽object聽about聽the聽y-axis.

聽聽聽聽聽聽聽聽聽聽聽聽
//聽Set聽up聽the聽rotation聽matrix聽to聽generate聽1聽full聽rotation聽(2*PI聽radians)聽
聽聽聽聽聽聽聽聽聽聽聽聽
//聽every聽1000聽ms.聽To聽avoid聽the聽loss聽of聽precision聽inherent聽in聽very聽high聽
聽聽聽聽聽聽聽聽聽聽聽聽
//聽floating聽point聽numbers,聽the聽system聽time聽is聽modulated聽by聽the聽rotation聽
聽聽聽聽聽聽聽聽聽聽聽聽
//聽period聽before聽conversion聽to聽a聽radian聽angle.
聽聽聽聽聽聽聽聽聽聽聽聽int聽聽iTime聽聽=聽Environment.TickCount聽%1000;
聽聽聽聽聽聽聽聽聽聽聽聽
float聽fAngle聽=聽iTime聽*聽(2.0f*聽(float)Math.PI)聽/1000.0f;
聽聽聽聽聽聽聽聽聽聽聽聽device.Transform.World聽
=聽Matrix.RotationY(聽fAngle聽);

聽聽聽聽聽聽聽聽聽聽聽聽
//聽Set聽up聽our聽view聽matrix.聽A聽view聽matrix聽can聽be聽defined聽given聽an聽eye聽point,
聽聽聽聽聽聽聽聽聽聽聽聽
//聽a聽point聽to聽lookat,聽and聽a聽direction聽for聽which聽way聽is聽up.聽Here,聽we聽set聽the
聽聽聽聽聽聽聽聽聽聽聽聽
//聽eye聽five聽units聽back聽along聽the聽z-axis聽and聽up聽three聽units,聽look聽at聽the
聽聽聽聽聽聽聽聽聽聽聽聽
//聽origin,聽and聽define聽"up"聽to聽be聽in聽the聽y-direction.
聽聽聽聽聽聽聽聽聽聽聽聽device.Transform.View聽=聽Matrix.LookAtLH(聽new聽Vector3(聽0.0f,聽3.0f,-5.0f聽),聽new聽Vector3(聽0.0f,聽0.0f,聽0.0f聽),聽new聽Vector3(聽0.0f,聽1.0f,聽0.0f聽)聽);

聽聽聽聽聽聽聽聽聽聽聽聽
//聽For聽the聽projection聽matrix,聽we聽set聽up聽a聽perspective聽transform聽(which
聽聽聽聽聽聽聽聽聽聽聽聽
//聽transforms聽geometry聽from聽3D聽view聽space聽to聽2D聽viewport聽space,聽with
聽聽聽聽聽聽聽聽聽聽聽聽
//聽a聽perspective聽divide聽making聽objects聽smaller聽in聽the聽distance).聽To聽build
聽聽聽聽聽聽聽聽聽聽聽聽
//聽a聽perpsective聽transform,聽we聽need聽the聽field聽of聽view聽(1/4聽pi聽is聽common),
聽聽聽聽聽聽聽聽聽聽聽聽
//聽the聽aspect聽ratio,聽and聽the聽near聽and聽far聽clipping聽planes聽(which聽define聽at
聽聽聽聽聽聽聽聽聽聽聽聽
//聽what聽distances聽geometry聽should聽be聽no聽longer聽be聽rendered).
聽聽聽聽聽聽聽聽聽聽聽聽device.Transform.Projection聽=聽Matrix.PerspectiveFovLH(聽(float)Math.PI聽/4,聽1.0f,聽1.0f,聽100.0f聽);
聽聽聽聽聽聽聽聽}
鐪嬪ソ鎷?澶氫簡涓涓緩绔媘atrix鐨刦unction: 濂圭殑浣滅敤鐪嬩唬鐮佸柦!!!~~~~~~~~~~~~~~

]]>
Managed Directx ---world matrix , projection matrix , view matrixhttp://www.shnenglu.com/mzty/archive/2006/06/09/8338.html姊﹀湪澶╂動姊﹀湪澶╂動Fri, 09 Jun 2006 07:07:00 GMThttp://www.shnenglu.com/mzty/archive/2006/06/09/8338.htmlhttp://www.shnenglu.com/mzty/comments/8338.htmlhttp://www.shnenglu.com/mzty/archive/2006/06/09/8338.html#Feedback0http://www.shnenglu.com/mzty/comments/commentRss/8338.htmlhttp://www.shnenglu.com/mzty/services/trackbacks/8338.html Set Up a View Matrix

(^_^,鍙兘鐪嬪埌projection浠ュ悗媯遍敟涓婁笅鎴潰闂寸殑閮ㄥ垎)
The three input vectors represent the following, respectively:

  1. The eye point: [0, 3, -5].聽聽聽聽 (鐪肩潧)
  2. The camera look-at target: the origin [0, 0, 0]. (鐪肩潧瑕佺湅鐨勪笢涓?
  3. The current world's up-direction: usually [0, 1, 0].聽聽 (鎸囧嚭閭h竟鏄笂闈?

using 聽Microsoft.DirectX.Direct3D;

Device聽device聽
= null ;聽聽 // 聽Create聽rendering聽device.

// 聽Set聽up聽the聽view聽matrix.聽A聽view聽matrix聽can聽be聽defined聽given聽an聽eye聽point,
// 聽聽聽a聽point聽to聽view,聽and聽a聽direction聽for聽which聽way聽is聽up.聽Here,聽you聽set聽
// 聽聽聽the聽eye聽five聽units聽back聽along聽the聽z-axis聽and聽up聽three聽units,聽view聽the
// 聽聽聽origin,聽and聽define聽"up"聽to聽be聽in聽the聽y-direction.

device.Transform.View聽
= 聽Microsoft.DirectX.Matrix.LookAtLH(
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
new 聽Vector3( 0.0f ,聽 3.0f ,聽 - 5.0f ),
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
new 聽Vector3( 0.0f ,聽 0.0f ,聽 0.0f ),
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
new 聽Vector3( 0.0f ,聽 1.0f ,聽 0.0f ));

Set Up a Projection Matrix聽聽

(project浠ュ悗寰楀埌鎴戜滑鑳藉鐪嬪埌鐨勬墍鏈?涓涓1閿ヤ笂涓嬫埅闈㈤棿鐨勯儴鍒?

This example demonstrates how to set up the projection transformation matrix, which transforms 3-D camera or view space coordinates into 2-D screen coordinates.

See the following C# code example, the Projection transformation matrix is set to be equal to the left-handed (LH) PerspectiveFovLH matrix. Input arguments to PerspectiveFovLH are as follows.

  1. Field of view in radians: pi/4. (涓鑸兘涓?/4 pi)
  2. Aspect ratio, or view-space height divided by width: 1, for a square window. (闀垮鐨勬瘮)
  3. Near clipping plane distance: 1 unit.聽聽聽聽 (紱葷溂鐫涜繎鐨勭偣,鍗蟲1閿ョ殑涓婇潰)
  4. Far clipping plane distance: 100 units.聽 (紱葷溂鐫涜繙鐨勭偣,鍗蟲1閿ョ殑涓嬮潰)

using聽Microsoft.DirectX;

Direct3D.Device聽device聽
=null;聽聽//聽Create聽rendering聽device.

//聽For聽the聽projection聽matrix,聽you聽set聽up聽a聽perspective聽transform聽(which
//聽聽聽transforms聽geometry聽from聽3-D聽view聽space聽to聽2-D聽viewport聽space,聽with
//聽聽聽a聽perspective聽divide聽making聽objects聽smaller聽in聽the聽distance).聽To聽build
//聽聽聽a聽perspective聽transform,聽you聽need聽the聽field聽of聽view聽(1/4聽pi聽is聽common),
//聽聽聽the聽aspect聽ratio,聽and聽the聽near聽and聽far聽clipping聽planes聽(which聽define聽
//聽聽聽the聽distances聽at聽which聽geometry聽should聽no聽longer聽be聽rendered).

device.Transform.Projection聽
=聽Matrix.PerspectiveFovLH(
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽(
float)Math.PI聽/4,聽1.0f,聽1.0f,聽100.0f聽);

What Is a World Transformation?

A world transformation changes coordinates from model space, where vertices are defined relative to a model's local origin, to world space, where vertices are defined relative to an origin common to all of the objects in a scene. In essence, the world transformation places a model into the world; hence its name.

Setting Up a World Matrix

As with any other transformation, you create the world transformation by concatenating a series of transformation matrices into a single matrix that contains the sum total of their effects. In the simplest case, when a model is at the world origin and its local coordinate axes are oriented the same as world space, the world matrix is the identity matrix. More commonly, the world matrix is a combination of a translation into world space and possibly one or more rotations to turn the model as needed.

The following C# code example, from a fictitious 3-D model class written in C#, creates a world matrix that includes three rotations to orient a model and a translation to relocate it relative to its position in world space.

publicclass聽ModelClass
{
聽聽聽
privatefloat聽xPos=0;
聽聽聽
privatefloat聽yPos=0;
聽聽聽
privatefloat聽zPos=0;

聽聽聽
privatefloat聽Pitch=0;
聽聽聽
privatefloat聽Yaw=0;
聽聽聽
privatefloat聽Roll=0;

聽聽聽
//Other聽model聽properties聽and聽methods
聽聽聽
聽聽聽
public聽Matrix聽MakeWorldMatrix(Matrix聽worldMatrix)
聽聽聽
{
聽聽聽聽聽聽worldMatrix.Translate(xPos,yPos,zPos);

聽聽聽聽聽聽Matrix聽matRot聽
=聽Matrix.Identity;

聽聽聽聽聽聽matRot.RotateYawPitchRoll(Yaw,Pitch,Roll);
聽聽聽聽聽聽
聽聽聽聽聽聽worldMatrix聽
=聽Matrix.Multiply(matRot,聽worldMatrix);

聽聽聽聽聽聽
return聽worldMatrix;

聽聽聽}

}


Note:Direct3D uses the world and view matrices that you set to configure several internal data structures. Each time you set a new world or view matrix, the system recalculates the associated internal structures. Setting these matrices frequently鈥攆or example, thousands of times per frame鈥攊s computationally time-consuming. You can minimize the number of required calculations by concatenating your world and view matrices into a world-view matrix that you set as the world matrix, and then setting the view matrix to the identity. Keep cached copies of individual world and view matrices so that you can modify, concatenate, and reset the world matrix as needed. For clarity, Direct3D samples in this documentation rarely employ this optimization.


]]>
Managed DirectX ---- Using Matriceshttp://www.shnenglu.com/mzty/archive/2006/05/17/7294.html姊﹀湪澶╂動姊﹀湪澶╂動Wed, 17 May 2006 02:16:00 GMThttp://www.shnenglu.com/mzty/archive/2006/05/17/7294.htmlhttp://www.shnenglu.com/mzty/comments/7294.htmlhttp://www.shnenglu.com/mzty/archive/2006/05/17/7294.html#Feedback0http://www.shnenglu.com/mzty/comments/commentRss/7294.htmlhttp://www.shnenglu.com/mzty/services/trackbacks/7294.html闃呰鍏ㄦ枃

]]>
Managed Directx --rendering vertices (浣跨敤VertexBuffer 榪涜render)http://www.shnenglu.com/mzty/archive/2006/05/12/7007.html姊﹀湪澶╂動姊﹀湪澶╂動Fri, 12 May 2006 05:55:00 GMThttp://www.shnenglu.com/mzty/archive/2006/05/12/7007.htmlhttp://www.shnenglu.com/mzty/comments/7007.htmlhttp://www.shnenglu.com/mzty/archive/2006/05/12/7007.html#Feedback0http://www.shnenglu.com/mzty/comments/commentRss/7007.htmlhttp://www.shnenglu.com/mzty/services/trackbacks/7007.html闃呰鍏ㄦ枃

]]>
Managed DirectX --- create Device http://www.shnenglu.com/mzty/archive/2006/05/09/6830.html姊﹀湪澶╂動姊﹀湪澶╂動Tue, 09 May 2006 10:31:00 GMThttp://www.shnenglu.com/mzty/archive/2006/05/09/6830.htmlhttp://www.shnenglu.com/mzty/comments/6830.htmlhttp://www.shnenglu.com/mzty/archive/2006/05/09/6830.html#Feedback1http://www.shnenglu.com/mzty/comments/commentRss/6830.htmlhttp://www.shnenglu.com/mzty/services/trackbacks/6830.html闃呰鍏ㄦ枃

]]>
Managed DirectX --- Matrix&Transform(Translation and Scaling and Rotation)http://www.shnenglu.com/mzty/archive/2006/05/09/6823.html姊﹀湪澶╂動姊﹀湪澶╂動Tue, 09 May 2006 08:10:00 GMThttp://www.shnenglu.com/mzty/archive/2006/05/09/6823.htmlhttp://www.shnenglu.com/mzty/comments/6823.htmlhttp://www.shnenglu.com/mzty/archive/2006/05/09/6823.html#Feedback0http://www.shnenglu.com/mzty/comments/commentRss/6823.htmlhttp://www.shnenglu.com/mzty/services/trackbacks/6823.html
  • 涓 Translation

  • The following transformation translates the point (x, y, z) to a new point (x', y', z').

    Translate 18

    You can manually create a translation matrix in managed code. The following C# code example shows the source code for a function that creates a matrix to translate vertices.

    						[C#]
    						
    private Matrix TranslateMatrix(float dx, float dy, float dz) { Matrix ret; ret = Matrix.Identity; ret.M41 = dx; ret.M42 = dy; ret.M43 = dz; return ret; }

    For convenience, managed the Microsoft Direct3D supplies the Translation method.

    • 浜?Scaling

    The following transformation scales the point (x, y, z) by arbitrary values in the x-, y-, and z-directions to a new point (x', y', z').

    Matrix scale


    • 涓壜犅?Rotation

    The transformations described here are for left-handed coordinate systems, and so might be different from transformation matrices that you have seen elsewhere. For more information, see 3-D Coordinate Systems.

    The following transformation rotates the point (x, y, z) around the x-axis, producing a new point (x', y', z').

    Matrix x rotation

    The following transformation rotates the point around the y-axis.

    Matrix y rotation

    The following transformation rotates the point around the z-axis.

    Matrix z rotation

    In these example matrices, the Greek letter theta (?) stands for the angle of rotation, in radians. Angles are measured clockwise when looking along the rotation axis toward the origin.

    In a managed application, use the Matrix.RotationX, Matrix.RotationY, and Matrix.RotationZ methods to create rotation matrices. The following C# code example demonstrates how the Matrix.RotationX method performs a rotation.

    				[C#]
    				
    private Matrix MatrixRotationX(float angle) { double sin, cos; sin = Math.Sin(angle); cos = Math.Cos(angle); Matrix ret; ret.M11 = 1.0f; ret.M12 = 0.0f; ret.M13 = 0.0f; ret.M14 = 0.0f; ret.M21 = 0.0f; ret.M22 = (float)cos; ret.M23 = (float)sin; ret.M24 = 0.0f; ret.M31 = 0.0f; ret.M32 = (float)-sin; ret.M33 = (float)cos; ret.M34 = 0.0f; ret.M41 = 0.0f; ret.M42 = 0.0f; ret.M43 = 0.0f; ret.M44 = 1.0f; return ret; }

    • 鍥浡?Matrix Concatenation

    One advantage of using matrices is that you can combine the effects of two or more matrices by multiplying them. This means that, to rotate a model and then translate it to some location, you do not need to apply two matrices. Instead, you multiply the rotation and translation matrices to produce a composite matrix that contains all of their effects. This process, called matrix concatenation, can be written with the following formula.

    Matrix concatination

    In this formula, C is the composite matrix being created, and M1 through Mn are the individual transformations that matrix C contains. In most cases, only two or three matrices are concatenated, but there is no limit.

    Use the Matrix.Multiply method to perform matrix multiplication.

    The order in which the matrix multiplication is performed is crucial. The preceding formula reflects the left-to-right rule of matrix concatenation. That is, the visible effects of the matrices that you use to create a composite matrix occur in left-to-right order. A typical world transformation matrix is shown in the following example. Imagine that you are creating the world transformation matrix for a stereotypical flying saucer. You would probably want to spin the flying saucer around its center - the y-axis of model space - and translate it to some other location in your scene. To accomplish this effect, you first create a rotation matrix, and then multiply it by a translation matrix, as shown in the following formula.

    World Space explanation

    In this formula, Ry is a matrix for rotation about the y-axis, and Tw is a translation to some position in world coordinates.

    The order in which you multiply the matrices is important because, unlike multiplying two scalar values, matrix multiplication is not commutative. Multiplying the matrices in the opposite order has the visual effect of translating the flying saucer to its world space position, and then rotating it around the world origin.

    No matter what type of matrix you are creating, remember the left-to-right rule to ensure that you achieve the expected effects.

    鍒板簳浠涔堟椂鍊欏湪宸﹁竟浠涔堟椂鍊欏湪鍙寵竟?


    鎬葷粨:

    • 浜?3-D Transformations


    In applications that work with 3-D graphics, geometrical transformations can be used to do the following.

    • Express the location of an object relative to another object.
    • Rotate and size objects.
    • Change viewing positions, directions, and perspectives.

    You can transform any point (x,y,z) into another point (x', y', z') using a 4 x 4 matrix.

    Matrix multiply

    Perform the following operations on (x, y, z) and the matrix to produce the point (x', y', z').

    Matrix expanded

    The most common transformations are translation, rotation, and scaling. You can combine the matrices that produce these effects into a single matrix to calculate several transformations at once.



    ]]>
    Managed DirectX start !http://www.shnenglu.com/mzty/archive/2006/04/19/5877.html姊﹀湪澶╂動姊﹀湪澶╂動Wed, 19 Apr 2006 05:56:00 GMThttp://www.shnenglu.com/mzty/archive/2006/04/19/5877.htmlhttp://www.shnenglu.com/mzty/comments/5877.htmlhttp://www.shnenglu.com/mzty/archive/2006/04/19/5877.html#Feedback6http://www.shnenglu.com/mzty/comments/commentRss/5877.htmlhttp://www.shnenglu.com/mzty/services/trackbacks/5877.htmlDirectX 棣栨鍑虹幇鍦?1995 騫達紝褰撴椂縐頒負鈥淕ameSDK鈥濄傚湪鍏跺師濮嬪艦寮忎腑錛岄拡瀵圭殑鐩爣鏄嬌鐢?C 鍜?C++ 鐨勫紑鍙戜漢鍛樸傚彧鏈夊湪 2002 騫?12 鏈堣 API 鐨勭涓涓墭綆$増鏈?(9.0) 鍙戝竷浠ユ潵錛屾墠鍙互浣跨敤 C# 鎴?VB.NET 寮鍙?DirectX錛堝疄闄呬笂錛屽鏋滄偍甯屾湜錛岄偅涔堝彲浠ヤ嬌鐢ㄤ換浣曠鍚?CLR 鐨勮璦錛夈?/p>

    铏界劧涓庨潪鎵樼鐗堟湰鐩告瘮錛屽叧浜庢墭綆?DirectX 鐨勬ц兘浜夎寰堝錛屼絾鍟嗕笟娓告垙宸蹭嬌鐢ㄦ墭綆?DirectX 榪涜鍒涘緩鐨勪簨瀹炲簲璇ヨ兘澶熶粠鏍規湰涓婂鉤鎭繖鏍風殑浜夎銆傝櫧鐒舵煇浜涢渶瑕佹瀬楂樻ц兘鐨勬父鎴忓彲鑳介渶瑕佷嬌鐢ㄩ潪鎵樼浠g爜錛屼絾澶у鏁版父鎴忓彲浠ヤ嬌鐢ㄦ墭綆′唬鐮佹垨鑰呯粨鍚堜嬌鐢ㄦ墭綆″拰闈炴墭綆′唬鐮佽繘琛屽垱寤恒傜紪鍐欐墭綆′唬鐮佷嬌寮鍙戜漢鍛樼殑鏁堢巼鏇撮珮錛屼粠鑰岀紪鍐欏嚭鏇村鐨勪唬鐮侊紝鐢熸垚鏇村畨鍏ㄧ殑浠g爜銆?

    瀹夎 DirectX SDK 涔嬪悗錛屽湪 C:\WINDOWS\Microsoft.NET\Managed DirectX 搴旇鏈変竴涓洰褰曪紝鍦ㄦ満鍣ㄤ笂瀹夎鐨勬瘡涓増鏈殑 SDK 閮芥湁涓涓瓙鐩綍銆傛垜鏈哄櫒涓婁嬌鐢ㄧ殑宸茬粡鏄鍥涚増浜嗭紝鍥犳鎴戞湁鍥涗釜瀛愮洰褰曘傚湪姣忎釜瀛愮洰褰曚腑搴旇鏈変節涓?DLL 鍜屼節涓?XML 鏂囦歡銆傜敱浜庢墭綆$幆澧冧腑鐨?.NET 鍏佽鍚屼竴鍙版満鍣ㄤ笂鐨勫悓涓涓?DLL 鏂囦歡鏈夊涓増鏈紝鑰屼笉浼氬紩璧蜂互鍓嶈縐頒負 DLL Hell 鐨勯棶棰橈紝鎵浠ユ垜浠彲浠ヤ嬌鐢ㄥ鐗堟湰鐨勬墭綆?DirectX 搴撱傝繖灝卞厑璁告偍鍦ㄥ畨瑁呮柊鐗堟湰涔嬪悗杞繪澗鍦板洖婊氬埌浠ュ墠鐨勭増鏈?

    濡傛灉鎮ㄤ互鍓嶆湁鍦?Windows 涓嬪鐞?DLL 鏂囦歡鐨勭粡楠岋紝鎮ㄥ彲鑳戒細鎷呭績鍦ㄥ悓涓鍙拌綆楁満涓婂畨瑁呭悓涓涓枃浠剁殑澶氫釜鐗堟湰浼氫駭鐢熼棶棰樸傝嚜浠?.NET 寮曞叆騫惰鐗堟湰鎺у埗錛岃繖浜涚増鏈帶鍒墮棶棰樺氨涓嶅瀛樺湪浜嗐傝繖鎰忓懗鐫褰撴柊鐗堟湰鐨?SDK 鍙戝竷鏃訛紝鎮ㄥ彲浠ヤ嬌鐢ㄥ涓増鏈潵媯鏌ュ吋瀹規ч棶棰橈紝鑰屼笉蹇呭己榪嚜宸辮繘琛屽崌綰с?/p>

    涔濅釜 DLL 鏂囦歡澶ц嚧瀵瑰簲浜?DirectX 涓殑鍗佷釜鍛藉悕絀洪棿銆傚湪鍒涘緩娓告垙鏃訛紝鎴戜滑浣跨敤鍏朵腑鐨勫ぇ閲忓懡鍚嶇┖闂存潵鎻愪緵瀵硅緭鍏ヨ澶囥佸0闊熾佺綉緇滄挱鏀撅紙褰撶劧榪樻湁 3D 鍥懼艦錛夌殑鏀寔銆?/p>
    鍛藉悕絀洪棿 鎻忚堪

    Microsoft.DirectX

    鍏叡綾誨拰鏁板緇撴瀯

    Microsoft.DirectX.Direct3D

    3D 鍥懼艦鍜屽姪鎵嬪簱

    Microsoft.DirectX.DirectDraw

    Direct Draw 鍥懼艦 API銆傝繖鏄棫寮忓懡鍚嶇┖闂達紝鎮ㄤ笉闇瑕佷嬌鐢ㄥ畠銆?/p>

    Microsoft.DirectX.DirectPlay

    鐢ㄤ簬澶氱帺瀹舵父鎴忕殑緗戠粶 API

    Microsoft.DirectX.DirectSound

    澹伴煶鏀寔

    Microsoft.DirectX.DirectInput

    杈撳叆璁懼鏀寔錛堜緥濡傦紝榧犳爣鍜屾父鎴忔潌錛?/p>

    Microsoft.DirectX.AudioVideoPlayback

    鎾斁瑙嗛鍜岄煶棰戯紙渚嬪錛屽湪 PC 涓婃挱鏀?DVD錛?/p>

    Microsoft.DirectX.Diagnostics

    鐤戦毦瑙g瓟

    Microsoft.DirectX.Security

    璁塊棶瀹夊叏鎬?/p>

    Microsoft.DirectX.Security.Permissions

    璁塊棶瀹夊叏鏉冮檺



    HEL鍜孒AL

    銆銆鍦ㄥ浘5.2涓紝鍙互鐪嬪埌鍦―irectX涓嬫湁涓や釜灞傞潰錛屽垎鍒槸HEL錛堢‖浠舵ā鎷熷眰錛夊拰HAL錛堢‖浠舵娊璞″眰錛夈傝繖鏄竴涓害瀹氾細DirectX鏄竴縐嶉潪甯告湁榪滆鐨勮璁℃濊礬錛屽畠鍋囧畾鍙互閫氳繃紜歡鏉ュ疄鐜伴珮綰фц兘銆備絾鏄紝濡傛灉紜歡騫朵笉鏀寔鏌愪簺鎬ц兘錛岄偅鎬庝箞鍔炲憿錛熻繖灝辨槸HAL鍜孒EL鍙岄噸妯″紡璁捐鎬濊礬鐨勫熀紜銆?br />銆銆HAL錛堢‖浠舵娊璞″眰錛夋槸鎺ヨ繎紜歡鐨勫簳灞傘傚畠鐩存帴鍜岀‖浠朵氦嫻併傝灞傞氬父鏈夎澶囩敓浜у晢鎻愪緵鐨勮澶囬┍鍔ㄧ▼搴忋傚彲浠ラ氳繃甯歌DirectX璋冪敤鐩存帴鍜岀‖浠惰繘琛岃仈緋匯備嬌鐢℉AL瑕佹眰紜歡鑳藉鐩存帴鏀寔鎵瑕佹眰鐨勬ц兘錛岃繖鏃朵嬌鐢℉AL錛屽氨鑳藉鎻愰珮鎬ц兘銆備緥濡傦紝褰撶粯鍒朵竴涓綅鍥炬椂錛屼嬌鐢ㄧ‖浠惰姣旇蔣浠舵洿鑳滀換璇ラ」宸ヤ綔銆?br />銆銆褰撶‖浠朵笉鏀寔鎵瑕佹眰鐨勬ц兘鏃訛紝浣跨敤HEL錛堢‖浠朵豢鐪熷眰錛夈傛垜浠互浣跨敤瑙嗛鍗℃棆杞竴涓綅鍥句負渚嬫潵璇存槑銆傚鏋滅‖浠朵笉鏀寔鏃嬭漿鍔ㄤ綔錛屽垯浣跨敤HEL錛岃蔣浠剁畻娉曞彇浠g‖浠躲傚緢鏄庢樉榪欐牱鍋氶熷害瑕佹參涓浜涳紝浣嗗叧閿槸榪欐牱鍋氳嚦灝戜笉浼氫腑鏂簲鐢ㄧ▼搴忥紝搴旂敤紼嬪簭浠嶇劧鍦ㄨ繍琛岋紝浠呬粎鏄熷害鎱竴浜涜屽凡銆傚彟澶栵紝HAL鍜孒EL涔嬮棿鐨勫垏杞槸閫忔槑鐨勩傚鏋滆姹侱irectX鍋氭煇宸ヤ綔錛岃孒AL鐩存帴澶勭悊璇ュ伐浣滐紝涔熷氨鏄‖浠剁洿鎺ュ鐞嗚欏瑰伐浣溿傚惁鍒欙紝HEL灝嗚皟鐢ㄨ蔣浠朵豢鐪熸潵澶勭悊璇ュ伐浣溿?br />


    Section 1 鈥?Introduction

    Section 1.1 鈥?What is DirectX?

    DirectX is the name given to a series of API for running and displaying multimedia rich applications. Using it, you can have graphics, video, 3D animation, surround sound and so on. The different API鈥檚 available in DirectX are Direct Graphics, Direct Input, Direct Sound, Direct Play and Direct Show.

    Direct Graphics deals with everything related to graphics. With it you can load 3D meshes, render textures, animate 3D models, light your scene, add particle effects and much more. It is concentrated more towards 3D making it ideal for rendering 3D graphics, although it will also work just as well doing 2D graphics too.
    Direct Input is the API that allows you to use many different kinds of input devices such as keyboards, mice, joysticks, joy pads and so on. It gives you much more control than the Win32 API does, and is ideal for games.
    Direct Sound does everything you could ever want to do with audio. You can play midi files and wav files and other types of music. You can add special effects such as an echo or flanging. You can also add 3D surround sound effects by telling Direct Sound to apply special 3D algorithms and so on. Again, this is ideal for games.
    Direct Play is the networking API used mainly in games. If you wish to make a game run over a network then you can use DirectPlay?. There isn鈥檛 much more to say about that really.
    Direct Show can be used for all kinds of multimedia tasks such as video playback. It is ideal for audio or video recording, editing and manipulation.


    Section 1.2 - Assumptions

    Readers should have a basic understanding of the C# language and should have at least enough experience using it to understand the examples. The code examples are fairly simple and don鈥檛 use anything overly complicated, but you should still have a firm grasp of the language nevertheless. If you have any experience with using previous versions of DirectX in other languages then this would certainly help, but isn鈥檛 a requirement. The tutorial assumes you鈥檝e never used DirectX before.
    I will be using the .Net framework version 1.1. Readers using the new .Net 2.0 Framework that comes with Microsoft Visual C# 2005 Express Edition should be able to convert the code without too much trouble. Most of it should be compatibl. I will be using the Microsoft Visual Studio .Net 2003 IDE so any screenshots or descriptions will explain how to perform the task in that IDE. If you are using a different IDE such as Sharp Develop, Borland C# Builder or Microsoft Visual C# 2005 Express Edition, then I assume that you鈥檙e competent enough in it鈥檚 use that you can understand how to do the tasks in your own IDE. You should at least know how to create a new project, add references to your project, add files and code to your project, save it, and build it. Obviously knowing how to do other important things such as use the debugger would be a strong advantage.
    I will use the DirectX Summer Update 2004 SDK. That is: version 1.0.1901.0. There may be some slight incompatibilities with previous versions, but they shouldn鈥檛 be too hard to fix if you鈥檙e using a previous version. I suggest you get the update though if you don鈥檛 already have it.
    Note that I won鈥檛 be using the DirectX wizards or any template files in my project. I鈥檒l be showing you how to do everything yourself so that we can gain a deeper understanding of what鈥檚 actually going on and what we鈥檙e actually writing.



    Section 2 鈥?Creating a New DirectX Project


    Section 2.1 鈥?Creating a New Project

    Start up your IDE. As I mentioned above, I use Microsoft Visual Studio .Net 2003. Start a new project, and save it. Choose either 鈥淲indows Application鈥?or 鈥淐onsole Application鈥?depending on which type of project you wish to make. If you installed DirectX9? properly then you should be able to create a new DirectX project, which has a wizard to guide you through creating a simple application. As I mentioned, I won鈥檛 be using this. I prefer to write the code myself to gain a deeper understanding of what is actually going on in my project.


    Section 2.2 鈥?Adding the DirectX References

    In order to use DirectX in your applications, you must add a reference to the assemblies. To do this in Microsoft Visual Studio .Net 2003 you can click the project menu and click 鈥淎dd Reference鈥? or right click on the 鈥淩eferences鈥?section in the project explorer, and click 鈥淎dd Reference鈥?
    Now you should be presented with the 鈥淎dd Reference鈥?dialog. Make sure the 鈥?Net鈥?tab is selected, and scroll down to 鈥淢icrosoft.DirectX鈥? You will see that there are several entries. At the very least, add 鈥淢icrosoft.DirectX鈥? The other assembly names reflect quite clearly what they contain. For example 鈥淢icrosoft.DirectX.Direct3D鈥?is the 3D graphics API, 鈥淢icrosoft.DirectX.DirectSound鈥?is the Direct Sound API and so on. Go ahead and add whichever ones you require.
    Some of you may notice that you have 2 versions of each assembly with different versions. You will have this if you installed the Summer 2004 Update. I have one set using version 1.0.1901.0 and another set using version 1.0.900.0. I will be adding the assemblies with the newer version: 1.0.1901.0.

    Image


    Adding the DirectX references in Microsoft Visual Studio .Net 2003.


    Section 2.3 鈥?The 鈥渦sing鈥?Directives

    You may wish to add some 鈥渦sing鈥?directives for the namespaces in DirectX. You should know what the 鈥渦sing鈥?directive does. Here are some simple ones for using Direct3D:

    using Microsoft.DirectX;
    using Microsoft.DirectX.Direct3D;


    Section 3 鈥?Direct Graphics Enumeration


    Section 3.1 鈥?Enumerating Adapters and Display Modes

    An adapter is basically a graphics card. Most systems will have just 1 adapter. Systems with multiple monitors may have more than 1 adapter. If you wish to support systems with multiple adapters then you will have to enumerate them, otherwise you can just use the default one. The code to enumerate and choose an adapter is incredibly simple though, so it鈥檚 worth the little bit of extra effort.
    An adapter is described by an AdapterInformation? class located inside the Microsoft.DirectX.Direct3D namespace. This class has some useful properties such as the CurrentDisplayMode? property, which funnily enough, returns the current display mode; the AvailableDisplayModes? property that returns a list of supported display modes, which can be enumerated using a foreach loop; and an Information property, which returns an AdapterDetails? class. This class contains several useful properties which you can use to identify individual cards and so on. One of the most useful properties of this class is the Description property. This gives you a human readable description of the graphics card such as 鈥淣VIDIA GeForce2? MX/MX 400鈥?(My old crappy card). There are many other properties and methods inside the AdapterInformation? class too. Explore the properties and methods using the tooltips and the intellisense (Intellisense is the name given to the lists that pop up in the code editor containing all the accessible members of an object for those of you who don鈥檛 know what that is).
    To actually enumerate an adapter, we use the Manager class located inside the Microsoft.DirectX.Direct3D namespace. You don鈥檛 create a new instance of this class as all of it鈥檚 methods are static. The Manager class contains a static property called 鈥淎dapters鈥?which returns a list of AdapterInformation? classes described above, that you can enumerate using a foreach loop. It really is that simple. If you wish to use the default adapter, or just want to know what it is at least, then you can get that simply by using Manager.Adapters.Default.
    Here鈥檚 an example program showing the main things we鈥檝e learned so far:

    using System;
    using Microsoft.DirectX;
    using Microsoft.DirectX.Direct3D;
    
    
    class AdapterEnumeration
    {
    static void Main(string[] args)
    {
    	foreach(AdapterInformation adapter in Manager.Adapters)
    	{
    	// Check whether or not this is the default adapter
    		if(adapter.Equals(Manager.Adapters.Default))
    		{
    			Console.WriteLine("This is the default adapter\n");
    		}
    		
    		// Write out some information about the adapter
    		Console.WriteLine("" + adapter.Information.ToString() + 
    					"\n\nDisplay Modes:\n");
    			
    		// Write out each display mode
    		foreach(DisplayMode display in adapter.SupportedDisplayModes)
    		{
    			Console.WriteLine("{0}x{1} : {2} @ {3} Hz", 
    					display.Width,
    					display.Height,
    					display.Format,
    					display.RefreshRate);
    		}
    			
    		// Write out the current display mode
    		Console.WriteLine ("\nCurrent Display Mode: {0}x{1} : {2} @ {3} Hz", 
    					adapter.CurrentDisplayMode.Width,
    					adapter.CurrentDisplayMode.Height,
    					adapter.CurrentDisplayMode.Format,
    					adapter.CurrentDisplayMode.RefreshRate);
    			
    		Console.WriteLine("\n\n");
    	}
    
    	Console.ReadLine();
    }
    }




    That鈥檚 extremely simple, I think you鈥檒l agree. The output isn鈥檛 the nicest looking output in the world, but it shows you how to do it. You can make it look pretty quite easily. In a windows application you can add each adapter description to a combo box or some other suitable control. When an adapter in the combo box is selected, you could add information about that adapter to a listview, and add it鈥檚 available display modes to another combo box, selecting the current display mode by default. That鈥檚 how I usually do it, and that鈥檚 an example of the kind of things you can do with the very simple code above.
    As a by the way, you can get a handle to the monitor associated with each adapter using the following code:

    IntPtr MonitorHandle = Manager.GetAdapterMonitor(adapter.Adapter);



    I鈥檓 not quite sure what you could do with that handle, but I鈥檓 sure it鈥檚 useful somewhere, such as with some Win32 API functions that return information about the monitor or something like that. Note that the 鈥淎dapter鈥?property of the AdapterInformation? class is the 鈥渁dapter ordinal鈥?which is just a fancy name for the adapter number. The first one has ordinal 0, the second ordinal 1 and so on. Usually there will be just one default adapter with an adapter ordinal of 0.


    Section 3.2 鈥?Device Capabilities (Caps)

    Device Caps is one of those terms you will hear a lot with DirectX programming. Caps is simply short for Capabilities. The Device Caps are therefore just what the device is and isn鈥檛 capable of doing. There are literally hundreds of things you can check. Retrieving device capabilities is very simple. Again, you use the Manager class to do this. Here is a short snippet of code showing you how to do it:

    AdapterInformation ai = Manager.Adapters.Default;
    Caps caps = Manager.GetDeviceCaps(ai.Adapter, DeviceType.Hardware);



    There鈥檚 nothing hard there, is there? The only thing that might confuse you is the DeviceType?. The 2 main types are 鈥淒eviceType.Hardware鈥?and 鈥淒eviceType.Reference鈥? There is also another device type called a Software Device, but this is very rarely used. I think it鈥檚 something to do with plugging in your own software renderer or something. Using the hardware device type will query the capabilities of the graphics adapter. Using the reference device type will query the capabilities of software emulation, basically. A lot of drivers will be able to make up for lack of hardware features by providing software emulation. A common difference for example, is that the hardware will only usually be able to do a few active lights such as 8 or 16 whereas the reference device may be able to do an unlimited amount. The software device will be able to do pretty much everything, but it鈥檚 much slower than the hardware.
    Anyway, back to the point. You can probably figure out how to use the Caps class by looking at the intellisense again. This is a very powerful way to learn about classes. Most of it should be fairly self explanatory. You can test for all kinds of things. The tooltips will explain what all of the properties mean. For example, if you want to see whether or not textures must be square, you can test that using the following code:

    if(caps.TextureCaps.SupportsSquareOnly)
    {
    	Console.WriteLine("Square textures only are supported");
    }



    As I mentioned, there are literally hundreds of things you can check for. They are all organised into sensible properties. For example, all texture capabilities are stored inside the TextureCaps? property, vertex processing capabilities are inside the VertexProcessingCaps? property and so on. You can explore it using the object browser as well as the intellisense. (Press F2 in Visual Studio .Net 2003 to open the object browser):

    Image
    Exploring the Caps class inside the object browser.

    Section 3.3 鈥?Adapter Formats and BackBuffer? Formats

    There are 3 main questions I will answer in this section: What is a format? What is a backbuffer (format), and what is an adapter format?
    In answer to the first question, the format is just the way that pixel data is encoded. For example, you may have 5 bits to store the amount of red, 6 bits to store the amount of green and another 5 bits to store the amount of blue. This adds up to 16 bits, or 2 bytes per pixel. As a by the way, we give green more bits for 2 reasons. Firstly, to make the pixel data up to 2 bytes without wasting a pixel, and secondly, we chose the green component because our eyes are more sensitive to green and can therefore distinguish between more shades of green than they can red or blue, so it makes sense to give the green component the extra bit. The 2 most common formats are 16 bit and 32 bit. There is a 24 bit format and there are 8 bit formats, but these are rarely used. Some formats have some bits set aside for an 鈥渁lpha鈥?component. This is to do with something called alphablending, which is a type of transparency. You don鈥檛 need to know what that is exactly right now, but just bear in mind that some formats have an extra alpha component. Yet other formats have unused bits, denoted by 鈥淴鈥? For example, there is a 32 bit mode called 鈥淴8R8G8B8鈥?which means that the red, green and blue components are all 8 bits each, and there is an unused 8 bits to round the format up to 4 bytes per pixel. An example of a format with an alpha component is one called 鈥淎8R8G8B8鈥?which has the same as the other format, but instead of having an unused 8 bits, it uses the extra 8 bits for the alpha component.
    Now in order to explain what the backbuffer format is, I suppose I better mention briefly what a backbuffer is. When you draw things on the screen, they aren鈥檛 all drawn at the same time obviously. So you may draw a tree, then draw a bush, then draw another tree, then draw a character, then draw a house for example. They are all drawn one after the other. There is a phenomena called 鈥渁rtifacts鈥?where the screen encounters a vertical resync (a refresh) while you鈥檙e in the middle of drawing your scene on to the screen. This results in flickering graphics where you can briefly see things being drawn on the screen. The way this is fixed is we draw everything offscreen to an area of memory, and only once the scene is finished, we draw this entire area of memory onto the screen at once. This way you don鈥檛 see each individual part being drawn. This area of memory where you do your drawing is called a 鈥渂ackbuffer鈥?and the process of drawing the backbuffer onto the screen is called 鈥渇lipping鈥?or 鈥減resenting鈥? Hopefully the term 鈥渂ackbuffer format鈥?should be quite clear now that I鈥檝e explained what a backbuffer is, and what a format is.
    Now for the adapter format, this is basically just your display mode. The format of the pixels on the main screen. One question may arise from this 鈥?why aren鈥檛 the backbuffer format and the adapter format the exact same? Well the answer to that is in most cases they are. Although there is one difference. In a backbuffer you can have an alpha component, but you can鈥檛 have an alpha component in the adapter format. This is why they may differ.


    Section 3.4 鈥?Device Types

    This is quite a short section. I鈥檝e already mentioned device types before, but here it is again. There are 3 device types: Hardware, Software and Reference. Hardware means use the graphics card where possible, reference means use software emulation. And the software device is rarely used. It鈥檚 something to do with writing your own software renderer I think. Now you may be wondering why you would ever want to use software instead of hardware. Well there is actually a good reason. Because the reference device supports absolutely everything. You would need to fork out a huge amount of money to get a graphics card that can come anywhere near close to being able to do everything. I鈥檓 talking about a top of the range card 鈥?the best you can get. The problem with software is that it鈥檚 painfully slow compared to using hardware. So if you just want to test out some features in your game that your graphics card doesn鈥檛 support, you can switch to software emulated mode and check that it works. Or if you just really want to use some feature not supported by the hardware so much that you鈥檙e willing to slow down everything to a crawl to get it to work then you can use software emulation for that. You probably wouldn鈥檛 want to do that in a game unless you want a frame rate of about 0.5 frames per second. That would be for an application such as a 3D rendering application, where you really want to have some special effect in your scene, and don鈥檛 care if it takes an extra hour to render (These things take hours anyway).


    Section 3.5 鈥?Using Manager.CheckDeviceType

    At this point I鈥檝e explained the following things to you: how to enumerate adapters, how to enumerate display modes, device types and backbuffer and adapter formats. Now you need to begin choosing them. So choose an adapter, a device type, an adapter format (from your list of display modes), a backbuffer format, and a device type. Now you need to choose one more thing: whether or not you want to run this application in a window, or in full screen mode. You will need all of these to create a device (which I鈥檒l explain later. Lets just say for now that it鈥檚 incredibly important). So now you鈥檝e chosen all of these things. Unless you know what you鈥檙e doing or you got pretty lucky, they鈥檙e probably all incompatible with each other and wouldn鈥檛 work. Ideally you want to present a list of adapters to the user. Once they choose an adapter, you would then want to present a list of device types compatible with that adapter to them, and have them choose one of those. Once they鈥檝e chosen an adapter and a device type, you would like them to choose a display mode (the important part being the format, for the adapter format). Once they鈥檝e chosen that, you would then ideally like to present them with a list of backbuffer formats which are compatible with the adapter format to choose from. And finally, you want to present them with the option of fullscreen or windowed mode, if that鈥檚 still there.
    The best way to do this is to check every possibly combination of the following: adapters, device types, available adapter formats, backbuffer formats, whether or not to use windowed or full screen mode. By checking all the combinations of the above, you鈥檒l get a list of all the compatible combinations which you can present to the user whatever way you see fit. The method used to check these is Manager.CheckDeviceType. The following code snippet shows you how you can check all possible combinations. When you get a valid combination, you can add that to your combo boxes or list boxes or your arrays or whatever method of storing the combinations you choose.


    DeviceType[] deviceTypes = new DeviceType[] 
    {DeviceType.Hardware, DeviceType.Software, DeviceType.Reference};
    		
    Format[] backBufferFormats = new Format[] 
    {Format.A8R8G8B8, Format.X8R8G8B8, Format.A2R10G10B10,
    Format.R5G6B5, Format.A1R5G5B5, Format.X1R5G5B5};
    		
    bool[] windowModes = new bool[] {true, false};
    		
    // For each adapter
    foreach (AdapterInformation adapter in Manager.Adapters)
    {
    	ArrayList adapterFormats = new ArrayList();
    			
    	// Build the list of adapter formats
    	foreach (DisplayMode dispMode in adapter.SupportedDisplayModes) {
    		if (!adapterFormats.Contains (dispMode.Format))
    			adapterFormats.Add (dispMode.Format);
    	}
    	
    	foreach (DeviceType deviceType in deviceTypes) {
    		foreach (Format adapterFormat in adapterFormats) {
    			foreach (Format backBufferFormat in backBufferFormats) {
    				foreach (bool windowMode in windowModes) {
    					if (Manager.CheckDeviceType (
    						adapter.Adapter,
    						deviceType,
    						adapterFormat,
    						backBufferFormat,
    						windowMode)) {
    						// *** This combination is valid!
    						}
    				} // windowMode	
    			} // backBufferFormat
    		} // adapterFormat
    	} // deviceType
    } // adapter




    Section 3.6 鈥?Vertex Processing

    The last thing we need before we can create a device (As I said earlier, this will be explained. Just know that it鈥檚 important. This is the main object we use for all our rendering) is a vertex processing type. I assume you鈥檝e used something similar to the above code to enumerate all the possible combinations of adapters, device types, adapter/backbuffer formats and windowed or not and chosen one of each. Now before we can build a device, we need this vertex processing method. Basically the vertex processing method is just telling Direct3D where to do all of the vertex processing. How much should the hardware be involved, and how much should the software be involved, basically. Most cards these days should support hardware vertex processing. Lower end ones will support mixed vertex processing, where the processing is done by both hardware and software. Software only vertex processing will always work, but is slower. We can go through some methods to determine which type of processing is available like this:


    Caps caps = Manager.GetDeviceCaps(Manager.Adapters.Default.Adapter, 
    						DeviceType.Hardware);
    
    	if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
    	{
    		if (caps.DeviceCaps.SupportsPureDevice)
    		{
    			Console.WriteLine ("Pure Device");
    		}
    			
    		Console.WriteLine ("Hardware Vertex Processing");
    		Console.WriteLine ("Mixed Vertex Processing");
    	}
    		
    	Console.WriteLine ("Software Vertex Processing");




    You can see that first we get the device capabilities, as we use them to check the vertex processing available. Then we check if the device supports hardware processing. If it does, we know that at least it supports hardware and mixed processing. If it supports hardware processing, then we check if it supports the 鈥減ure device鈥?which means it also supports resterization and shading as well as just lighting and transformation. We know that software vertex processing will always be available so that鈥檚 a given.
    Now you have everything you need to create a device. You can enumerate and choose an adapter, and a display mode, and a backbuffer format and a device type and finally you can choose whether or not to use windowed mode or full screen mode if it鈥檚 compatible with everything else you鈥檝e chosen.


    Section 3.7 鈥?Enumerating Depth Stencil Formats

    There is one other main thing you will need to be able to enumerate 鈥?depth stencil formats. Don鈥檛 worry about what these actually are, you will learn later. I鈥檓 just putting this in the enumeration section because that鈥檚 where it belongs 鈥?it is afterall enumeration. Just know how to do it. You already know what a format is. This is done quite easily. We first just check the format is valid for the device, then check if it鈥檚 compatible with the backbuffer format. If so, then we can use it (You鈥檒l see what it鈥檚 for later).


    DepthFormat[] depthStencilFormats = new DepthFormat[]
    {
    DepthFormat.D16,
    		DepthFormat.D15S1,
    		DepthFormat.D24X8,
    		DepthFormat.D24S8,
    		DepthFormat.D24X4S4,
    		DepthFormat.D32,
    };
    
    foreach (DepthFormat depthStencilFormat in depthStencilFormats)
    {
    if(Manager.CheckDeviceFormat(adapter, deviceType, adapterFormat, 
    		Usage.DepthStencil, ResourceType.Surface, depthStencilFormat))
    	{
    if (Manager.CheckDepthStencilMatch(adapter, deviceType,
    			adapterFormat, backbufferFormat, depthStencilFormat))
    		{
    			// This depth stencil format is compatible
    		}
    	}
    }




    Section 3.8 鈥?Final Word on Enumeration

    Note that I鈥檝e covered more than enough on enumeration for you to get started. There is plenty more that you can figure out on your own though. Also remember all the stuff in the device capabilities (device caps) classes that can be checked. You check that stuff as you need it though. Unfortunately, enumeration is quite boring. I should have probably told you that at the start. We鈥檒l start doing some more interesting stuff in the next section.


    Section 4 鈥?Rendering Something


    Section 4.1 鈥?Creating the Device

    Finally we get on to this device I鈥檝e mentioned so much in the enumeration section. What is a device? The device is the object we use in almost everything. It鈥檚 a representation of our actual adapter (well, in reality it鈥檚 driver). You will use the device to do all of the rendering (drawing, if I haven鈥檛 mentioned that yet) and lighting and so on. You can鈥檛 do very much without a device. So I think I鈥檝e stressed just how important it is. Now to actually create a device is a little bit trickier than anything we鈥檝e seen yet, but it鈥檚 still fairly trivial. Especially with all our enumeration done above.

    // Assumes you have:
    	// 
    	// AdapterInformation	adapter;
    	// DeviceType		deviceType;
    	// CreateFlags		createFlags;
    	// DisplayMode		displayMode;
    	// Format		backbufferFormat;
    	// bool			windowed;
    		
    	PresentParameters presentation = new PresentParameters();
    		
    	presentation.BackBufferFormat	= backbufferFormat;
    	presentation.BackBufferWidth	= displayMode.Width;
    	presentation.BackBufferHeight	= displayMode.Height;
    	presentation.SwapEffect		= SwapEffect.Flip;
    	presentation.Windowed		= windowed;
    		
    	Device device = new Device(
    			adapter.Adapter, 
    			deviceType, 
    			this,
    			createFlags,
    			presentation);



    So first you need to choose an adapter, a device type, a vertex processing type (this is the createFlags variable) a display mode, a backbuffer format, and whether or not to use windowed mode. All of these are stored in the variables mentioned above. One you鈥檝e chosen these, you then create a new PresentParameters? object. This stores information about the backbuffer, and the display mode, and other important presentation information. You can change things like the number of back buffers to use and so on. We just change the backbuffer format, width and height as appropriate. Then we change the swap effect. The swap effect is just how the backbuffer is presented to the screen. We just tell it to flip the backbuffer and the screen around so that the backbuffer now becomes drawn on the screen, and what was previously on the screen now becomes the backbuffer. Lastly, we set whether or not we want to use windowed mode or not. Now to finally create the device, you pass first the adapter ordinal, then the device type. The next parameter, 鈥渢his鈥? must be a windows forms control! So this won鈥檛 work in console mode obviously. You must write the above code in a windows forms application. Using 鈥渢his鈥?will just draw onto the form. You could also draw onto a picturebox or something else if you pleased. The next parameter is the create flags, or the vertex processing type that I talked about a lot above in the enumeration section. And lastly, you pass the presentation parameters. This should hopefully give us a working device.


    Section 4.2 鈥?Rendering Something

    Now we get to the fun part 鈥?actually rendering! Don鈥檛 get too excited yet though, we鈥檙e only going to clear the window with a color. First we need to know where to actually render though. You could override the OnPaint? event and render everything in there. For a game or something, you will need a loop though. This is usually called 鈥渢he game loop鈥? This game loop usually goes after all the initialization code. Just remember to show your form before entering the loop. So now we know roughly where to put our rendering code, how do we actually write it? Well, we鈥檒l learn 2 new methods of the Device object: Clear and Present. The 鈥淐lear鈥?method simply clears the entire drawing area with your chosen color. The 鈥淧resent鈥?method performs the 鈥渇lip鈥? drawing the backbuffer to the screen. That鈥檚 all we鈥檒l use right now. So here鈥檚 the code for a typical rendering loop:

    while (Running)
    {
    	device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);
    	device.Present();
    	Application.DoEvents();
    }



    Notice that we have a variable, Running. This would be a boolean that you would set to true if your initialization was successful. Then when you want to end the loop, for example when the escape key is pressed, or the form is closing, then you set the Running variable to false. Notice that we also use Application.DoEvents to continue processing messages.


    Section 4.3 鈥?A Complete Sample Application


    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using Microsoft.DirectX;
    using Microsoft.DirectX.Direct3D;
    
    public class MainForm : Form
    {
    	Device device = null;
    
    	/// <summary>
    	///	When the form is clicked, we close it and stop
    	///	the application
    	/// </summary>
    	protected override void OnClick(EventArgs e)
    	{
    		this.Close();
    		base.OnClick (e);
    	}
    
    	
    	/// <summary>
    	///	In the constructor we initialize the device using
    	///	the default adapter and the current display mode
    	/// </summary>
    	public MainForm()
    	{
    		AdapterInformation adapter = Manager.Adapters.Default;
    	
    		PresentParameters presentation = new PresentParameters ();
    		presentation.BackBufferFormat = adapter.CurrentDisplayMode.Format;
    		presentation.BackBufferWidth = adapter.CurrentDisplayMode.Width;
    		presentation.BackBufferHeight = adapter.CurrentDisplayMode.Height;		
    		presentation.SwapEffect	= SwapEffect.Flip;
    		presentation.Windowed = false;
    		
    		// Place it in a try catch block just 
    		//in case it goes wrong for
    		// some reason.
    		try
    		{
    			// To make things simple, we'll just 
    			//use the reference device, and
    			// software vertex processing. 
    			//Although this will be extrelemly slow
    			// it doesn't matter in this case.
    			// It will definetly work on 
    			// all machines, so it saves us doing 
    			//enumeration for now.
    			device = new Device (adapter.Adapter, 
    						DeviceType.Reference,
    						this,
    						CreateFlags.SoftwareVertexProcessing,
    						presentation);
    		}
    		catch (DirectXException e)
    		{
    			MessageBox.Show (e.Message);
    			return;
    		}
    	}
    
    
    	/// <summary>
    	///	Clear the screen with a blue color
    	/// </summary>
    	public void Render()
    	{
    		device.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);
    		device.Present();
    	}
    
    
    	/// <summary>
    	///	The entry point where the main render loop goes
    	/// </summary>
    	static void Main() 
    	{
    		using (MainForm form = new MainForm())
    		{
    			form.Show();
    			
    			while (form.Created)
    			{
    				form.Render();
    				Application.DoEvents();
    			}
    		}
    	}
    }




    As a simple exercise you could try changing the application so that it exits when the escape key is pressed instead of clicked. Also, try changing the color to red. And if you like you can try making the program run in windowed mode by commenting all the backbuffer parameters in the presentation parameters and just change the Windowed property to true.



    ]]>
    久久影院午夜理论片无码| 精品久久久久久国产| 久久久久九九精品影院| 久久影视综合亚洲| 色综合久久中文字幕无码| 99久久夜色精品国产网站| 久久青青草原精品国产不卡| 色偷偷久久一区二区三区| 91精品国产91久久久久久| 精品久久久久久中文字幕大豆网| 青青草原综合久久| 99久久香蕉国产线看观香| 久久亚洲欧美日本精品| 尹人香蕉久久99天天拍| 麻豆精品久久精品色综合| 国内精品九九久久精品| 久久久久国产精品嫩草影院| 狠狠色丁香久久综合五月| 久久婷婷五月综合色奶水99啪| 久久99精品免费一区二区| 91精品国产综合久久婷婷| 热99RE久久精品这里都是精品免费| 久久亚洲欧美日本精品| 国产午夜精品久久久久免费视| 伊人久久一区二区三区无码| 久久国产精品二国产精品| 免费精品99久久国产综合精品| 久久精品天天中文字幕人妻| 99久久做夜夜爱天天做精品| 香蕉久久夜色精品国产尤物| 久久久久久噜噜精品免费直播| av午夜福利一片免费看久久| 色婷婷久久综合中文久久蜜桃av| 亚洲中文字幕伊人久久无码| 亚洲?V乱码久久精品蜜桃| 久久精品国产72国产精福利| 99精品伊人久久久大香线蕉| 国产精品成人99久久久久91gav | 99热热久久这里只有精品68| 996久久国产精品线观看| 久久精品国产精品国产精品污|