Professional Documents
Culture Documents
WWW - Kutub.info 1023
WWW - Kutub.info 1023
رس ا
Transformed اـVertexes
اـ-
TransformedColored"! اـ# $%ر-
--------------------
Transformed )( اـ$!*+, #
-) .,/ 0 ا
رس ا-!1
+ (Pixels) 2*3ط ا5,
م7+%/% -,ً أ:-;< =->;
أن-< وأو,GH:3;* اIJJ K!) .;%اد رG; ا$Mت ا:D
اEإ
; آ,ر: اIاوT اKU1ن أH* (Origin Point) I
ا3 اIQ5,
:2W%X 2*Y ا
CustomVertex.TransformedColored[] vertexes ;
:آد
vertexes[0].X = 0;
vertexes[0].Y = 0;
vertexes[0].Color = Color.White .ToArgb();
[1]:I:," اIQ5-ا
:آد
vertexes[1].X = 200;
vertexes[1].Y = 0;
vertexes[1].Color = Color.Blue .ToArgb();
] :2]I"" اIQ5-ا
:آد
vertexes[2].X = 200;
vertexes[2].Y =200;
vertexes[2].Color = Color.Green .ToArgb();
-;1 y وx (:رH;ط ا5-ت ا:D
اE إ,
دE ~ >
أنE[,
:I:+ ا2;M اI<
:آد
-,/ Gآc ;* ,IQ5, يX نH ءQ) إ:Q+, I!;M= اc هIQ%اH
$)
ي
ورةc واTransformedColored عH, (# vertex اـ,
دE
cs/+% I:," وا,:Xن اH! اcs/ وX اIQ5- أن ا:E ,انHا
I !
اI3- # أ,GlsXن اH! اcs/+% I"" وا,زرقXن اH!ا
+ واI#
7+;ان اHع اH- K!) رU+s\ إToArgb()
(red, green, blue).2";
:+د
ي آH* اi3U:
:آد
vertexes[0].X = 0;
vertexes[0].Y = 0;
vertexes[0].Color = Color.White .ToArgb();
vertexes[1].X = 200;
vertexes[1].Y = 0;
vertexes[1].Color = Color.Blue .ToArgb();
vertexes[2].X = 200;
vertexes[2].Y =200;
vertexes[2].Color = Color.Green .ToArgb();
}
;آ !"# K!) 2U- ط5-= اc( ه: 2:ﺹH+ مH5, :I""ة اHQ7ا
:2W%X 2*Y ا
I:!;> مH5-% -, أ-> >3\ اl>3 طHQ7= اc ه2:ﺹH+
\-) -;!* + واOnPaint() ه$%G Iﺹ7 اI وا
ا,$%Gا
.-) حGU-% .;%
رG, vJ أي أن أي,I5 ا
روس ا
.I= ا
اcه
(:+ )( ا
اOnPaint() اـ2s
اiGU+ مH5-% -ه
2*Y دH*ن اH*:% وDrawUserPrimitives, و اـVertexFormat
..اc\ .Y#
:آد
Public OnPaint()
{
.....
.....
VertexFormat();
DrawUserPrimitives();
.....
.....
}
:ن+ هن ا
اIU1 K إ/- نZا
DirectX اـG:7 \, \
w (;* VertexFormat وه اـKوXا
اـ-"# H وه. $%Gاد اG; اVertex ع اـH-
:+ً آ:M#G نH*:%وTransformedColored
:آد
device3d.VertexFormat = CustomVertex.TransformedColored.Format ;
\
د,/ \
w (;* DrawUserPrimitives وه اـI:,"ا
(Parameters) :اتG+:#اG ID[D يH \, أ:E $%G اI5G
طHQ7 ا$% رI:W:
آ2t( أ# :ولXا
2>W-% ;ى )آGsZ IQ5, 2 آ2:ﺹH أيTriangleList I:ﺹs
).ا ا;"لcه
:آد
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX9
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
Device device3d;
CustomVertex.TransformedColored[] vertexes ;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container
components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after
InitializeComponent call
//
}
pp.Windowed = true;
vertexes[0].X = 0;
vertexes[0].Y = 0;
vertexes[0].Color = Color.White .ToArgb();
vertexes[1].X = 200;
vertexes[1].Y = 0;
vertexes[1].Color = Color.Blue .ToArgb();
vertexes[2].X = 200;
vertexes[2].Y =200;
vertexes[2].Color = Color.Green .ToArgb();
device3d.EndScene();
device3d.Present ();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
using (Form1 xx = new Form1 ())
{
xx.ondevice ();
xx.tranvertex ();
Application.Run(xx);
}
}
}
}
F5دH*! Compile 2;)
-)
:2W%X + ا2"# رةH ﺹK!) 2U-%
ا
ه
ااوي
Hasa8384@yahoo.com
:ا
رس ا
PositionColored اـVertexes
اـ-
Cameraاـ-
--------------------
: x = ٠ , y = ٠ , z = ٠و$ ا%&'1ا
: x = ١٠ , y = ٠, z = ٠%<( ا%&'1ا
: x = ٥ , y = ١٠ , z = ٠% ا%&'1ا
;M( En7( ﺱ*فDirectX اـA إhC$4 &ﻁjIا ا2*" ه7
اـE p4ه ا
رس اﺱ1
j7 إﺱ7&*ات اjا
PositionColored. اـE 1 هS
j7ﺱ1ﺱTransformed
:آد
:آد
device.VertexFormat = CustomVertex.PositionColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices);
------------------------------------------------------------------
:"*د آ+ا
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX_Tutorial
public WinForm()
{
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
device.BeginScene();
device.VertexFormat =
CustomVertex.PositionColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);
device.EndScene();
device.Present();
this.Invalidate();
if (disposing)
{
if (components != null)
components.Dispose();
base.Dispose(disposing);
{
our_directx_form.InitializeDevice();
Application.Run(our_directx_form);
}
}
}
}
:7" ا+9 ا1 OSP< ﺱ,hC$*د ا+B run "IC
1C
......................................
Cameraاـ-
"r7
اO(
1C DirectX, اـ%O4 E<W*اIوه أه` ا
:S1 <ء8
ة أC 11 ذهEK( أن1<BC x< اO<I+ اE
:و ه$< ا7BﺡO Aل إ+8$ رﺱ` ا%<BIC `'ﺱ1 :ًأو
'ط1 إﺡ
ا[<ت ا4 "+9` <ﻩ رﺱ` ا7(وLocal Space):
< إ,ﺱﻩM( "+9 ا4 صj اz وy وx *رI اABC(Vectors)
:%<1C أV<W*7 "Mﺱ$4 "+9ا
,'<'ء اKM اA ('" اﺱ` إ%<BIC (وهWorld Space) :
n %nﺱ14 R] وا` واE*Iن اnﺱ4 2yD _<ﺡ
:"Mﺱ$4 "+9 اA إOP( أ,ﺱمF$ا
:آد
PerspectiveFovLH اـ1
j7 ا]ﺡ
ا[<ت وإﺱR2<" هI74 1I إذا
:7 آr<n& اSrW*4 ا]ﺡ
ا[<ت% رؤ%SF *ن+7ﺱ
:آد
device.Transform.Projection = Matrix.PerspectiveFovLH();
:آد
device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI/4,
this.Width/this.Height, -1f, 1f);
' أن (
د4 ,S *رP1I وا,اO<I+ن ا+ (
أن ﺡ
دr4: ًﺱy
%[h[ *ي7 واLookAtLH %
ام ا
اj7{ﺱ4 وذS#*اy
(Parameters).اتO7<را4
World Space( اـeyePoint) اO<I+ اE*
د:ول$ا-
), (forwardDirection)
فS )ا%< إOP1اد اOI اﺱ` ا:(ا-
(upDirection).hC أAا إO<I+ اO :_ا-
:"Mﺱ$4 "+9 اA إOP(أ
د ﻩ1_( وBIول وه* )رﺱ` ا$ ا1 A إEFO1
Vector٣(٠،٠,-٣٠)%<7 ا]ﺡ
ا[<ت ا2yD _<4 eyepoint اـ
%<7 ا]ﺡ
ا[<ت ا2yD _<4 forwardDirection واـ
Vector٣(٠،٠،٠)
Vector٣(٠،١،٠)%<7 ا]ﺡ
ا[<ت ا2yD _<4 upDirection و اـ
: ا]ﺡ
ا[<تEW*7 <W* "+8
:7 آDirectX ة ا]ﺡ
ا[<ت اـ2" هI(
:آد
ام اـj7{ﺱ4 1I
أنr4 *د+ى اO1 ن$ا
وClipping وCullMode وLookAtLH وPerspectiveFovLH
Lighting
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX_Tutorial
public WinForm()
{
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
{
device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, -1f, 1f);
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None ;
device.RenderState.Clipping = true;
vertices[0].Color = Color.Red.ToArgb();
vertices[1].Color = Color.Green.ToArgb();
vertices[2].Color = Color.Yellow.ToArgb();
device.BeginScene();
device.VertexFormat =
CustomVertex.PositionColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);
device.EndScene();
device.Present();
this.Invalidate();
}
protected override void Dispose (bool disposing)
if (disposing)
if (components != null)
components.Dispose();
base.Dispose(disposing);
our_directx_form.InitializeDevice();
Application.Run(our_directx_form);
}
}
}
}
----
إ( AS7درس ا<*م ....و أ ¯4ﺡ< أ*ل D4ن ه2ا ا
رس "IﺡO
ا$ﺱس O x< ...اءﻩ أآO Oة <Oﺱ °ا$ذهن ...
* E (
Cا
رس ا7ﺱ) Eإن 8ء ا)...±
:ا
رس ا
Translation اـ-
Rotation اـ-
--------------------
Translation اـ-
م-. , !ت ا#
ا$%*)ب '& ا% ا: وTranslation اـ
/' ً=> ,م45!ا أو ا7 ا8!)9 :;!
ا/' 0- ا12ه
@A' )!كKIﻉ اI* R @ ا)!فA' B.C ا$D &E FGHا
, ﻩ ا!ىNI@ اA' )!كL @ ا)!فA' @ أو/ﻩ اNIا
7R! إ@ اT* أUVل ر9
أ:/> !E5 اBVD ....ا27وه
:C59
رD)@ اA' ١٢
ارd9 A 7RA أر
' إ*)بU*ن أc اd/
yرD)@ اA' -١٠
ارdEوx ,
(B).7R اN/ اU> /gﻉ
device.Transform.World = Matrix.Translation(-8,2,0)
: أنx$
.R!ت ا7 & 7 اK إD وهdevice : اـ
Udd) اKﻉ9 ف )
ثD D)أي أن اTransform.world:
.م45 اU: :/9 ت#
ا$%ن اD7 نD7 x$
N/' /A7. U وا$زا%> اDCﺹE UوهMatrix.Translation
.='59
, &E ا
رس اU> ﻩ/' /A7. ي2( اxA اK ال )ر2vw/ نcا
@A' و٨-
ارd9 x رD)@ اA' *)ب% اA' ﻩA' و*)
ث
ا
اv
ا9 اAI> اV|9 8 وذ٣-
ارd9 y رD)ا
OnPaint :
:آد
device.Transform.World = Matrix.Translation(-8,-3,0);
:U ا7R ا/gﻉ
ﻉ9 B:0 أ,@/ﻩ اNI أ'= اU> ﻉ
أن آن9 xAن اw9 X$=*
.='59 7R اU> *)ب آ% اA'
:ً=Eد آD7ا
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX_Tutorial
public WinForm()
{
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, -1f, 1f);
device.Transform.View = Matrix.LookAtLH(new Vector3(0,10,-
30), new Vector3(0,0,0), new Vector3(0,1,0));
device.Transform.World =
Matrix.Translation(-8,-3,0);
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None ;
device.RenderState.Clipping = true;
vertices[0].Color = Color.Red.ToArgb();
vertices[1].Color = Color.Green.ToArgb();
vertices[2].Color = Color.Yellow.ToArgb();
device.BeginScene();
device.VertexFormat =
CustomVertex.PositionColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);
device.EndScene();
device.Present();
this.Invalidate();
}
protected override void Dispose (bool disposing)
if (disposing)
if (components != null)
components.Dispose();
base.Dispose(disposing);
}
static void Main()
{
using (WinForm our_directx_form = new WinForm())
{
our_directx_form.InitializeDevice();
Application.Run(our_directx_form);
}
}
}
}
Rotationاـ-
,ت#
ا$%ر اD)E @A' K4
ي:U ا
وران آA' -.
,4 در٣٠ او
ره9 KIا ا2N (Rotation) وأرد* أن *ﻉ
:C59 7R اU> ! آNT>
م ا
ا-.( وRadian) !ادن9 نD7. ت اوا4 در4 :ًiأو
مT* &E D) ا4& أE Geometry.DegreeToRadian ا
(Radian).ت إ@ اـ4ا
ر
:/أ 9ل F9وه Dدا !ة ا
$Dة )وه UاD7. Uن 4
إ
$ا. N.#وي وا ,(
$آ > Uا:C59 7R
!C/ض أ* Uأردت ' دوران 9او ٣٠در gd* &E 4ا 05آ
> Uا
/' ,Ci9 7Rه )/ج إ@ Eﻉ!> ا
$%ا#ت Aـ Xو
اـ Dd* Y ,م l!m &' 829إdط 'DEد& &Eا F, gd/ا5ول
' @Aا)Dر Xوا* @A' Uا)Dر Y,و)ب ه &.ا&gd/
D7.ن آ:U
X = Cosاـ ٣٠و.وي ٠٨٦٧ :
Y = Sinاـ ٣٠و.وي: ٠٥
(أ* !Tإ@ ا).C59 7R
-----------------
أ
/' Eاـ *|> DirectXﻩ Ddم 12N9اﻉ
-|9 Aام Eﺹ>DC
ا
وران(Matrix Rotation).
Eﺹ >DCا
وران D)Aر Xه:U
Eﺹ >DCا
وران D)Aر Yه:U
:U هZ رD)A > ا
ورانDCﺹE
-----------------------
l9 ا
رس اU> الjC* 2vw/ Matrix ﻉ اـ. !ي آ/
@A' 4 در١٨٠ او9 ا
ورانA' ﻩA' l:g*و,xA اDوه
. ا
ورانA'
ﻉ9 xAA
ةIت ا#
ا$%!ى ا/ X, رD)ا
:U
وهd اxAت ا#
ا$إ
:آد
: * اgd/ا
:آد
: اgd/ا
:آد
:آد
device.Transform.World = Matrix.RotationX();
YرD)@ اA' دا ا
وران
:آد
device.Transform.World = Matrix.RotationY();
:آد
device.Transform.World = Matrix.RotationZ();
:آد
device.Transform.World = Matrix.RotationX(Geometry.DegreeToRadian
(180));
:Eد آD7ا
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX_Tutorial
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, -1f, 1f);
device.Transform.World =
Matrix.RotationX (Geometry.DegreeToRadian (180));
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None ;
device.RenderState.Clipping = true;
vertices[0].Color = Color.Red.ToArgb();
vertices[1].Color = Color.Green.ToArgb();
vertices[2].Color = Color.Yellow.ToArgb();
device.BeginScene();
device.VertexFormat =
CustomVertex.PositionColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);
device.EndScene();
device.Present();
this.Invalidate();
angle += 0.05f;
if (disposing)
if (components != null)
components.Dispose();
base.Dispose(disposing);
our_directx_form.InitializeDevice();
Application.Run(our_directx_form);
angle += 0.05f;
:U آangle ء دا ا
وران اـg'إ: ً#
:آد
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX_Tutorial
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
}
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, -1f, 1f);
device.Transform.World =
Matrix.RotationX (angle);
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None ;
device.RenderState.Clipping = true;
vertices[1].Color = Color.Green.ToArgb();
vertices[2].Color = Color.Yellow.ToArgb();
device.BeginScene();
device.VertexFormat =
CustomVertex.PositionColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);
device.EndScene();
device.Present();
this.Invalidate();
angle += 0.05f;
if (disposing)
if (components != null)
components.Dispose();
}
base.Dispose(disposing);
our_directx_form.InitializeDevice();
Application.Run(our_directx_form);
:
ا. d> إ@ اV%9 #=)ور اA ء زواg'ً إH أ8/7
:دD7ا
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX_Tutorial
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
{
device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, -1f, 1f);
device.Transform.World =
Matrix.RotationAxis (new Vector3 (2,2,2),angle);
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None ;
device.RenderState.Clipping = true;
vertices[0].Color = Color.Red.ToArgb();
vertices[1].Color = Color.Green.ToArgb();
vertices[2].Color = Color.Yellow.ToArgb();
device.BeginScene();
device.VertexFormat =
CustomVertex.PositionColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);
device.EndScene();
device.Present();
this.Invalidate();
angle += 0.05f;
if (disposing)
if (components != null)
components.Dispose();
base.Dispose(disposing);
our_directx_form.InitializeDevice();
Application.Run(our_directx_form);
Uاو وهA
ا. ' 4& أE !ىv أd!m ًHك أ/ه
0-
ام ا-إ
milliseconds١٥ N ¤A:. UواTickCount
:آد
Matrix.RotationX((System.Environment.TickCount))
:E79 دD7ا
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX_Tutorial
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, -1f, 1f);
device.Transform.World =
Matrix.RotationX((System.Environment.TickCount / 450.0f));
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None ;
device.RenderState.Clipping = true;
vertices[0].Color = Color.Red.ToArgb();
vertices[1].Color = Color.Green.ToArgb();
vertices[2].Color = Color.Yellow.ToArgb();
device.BeginScene();
device.VertexFormat =
CustomVertex.PositionColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);
device.EndScene();
device.Present();
this.Invalidate();
// angle += 0.05f;
if (disposing)
{
if (components != null)
components.Dispose();
base.Dispose(disposing);
our_directx_form.InitializeDevice();
Application.Run(our_directx_form);
}
}
}
:ا
رس ا
Scalingاـ-
Scaling و اـRotation و اـTranslation ـMatrix اـ-
--------------------
Scalingاـ-
----
E`
ام ا
ا6ﺱpW تq$Hﺡ6\ ا8" ه2W DirectX م اـH>$
OnPaint, " اـ9
اW <\ ا
ا8 هE+rpW مH>L V.ﺡMatrix.Scaling()
TR نH2$ V.ﺡW Scaling اـE$uL <.R v1FL وV#ل ا#k 89:;
z رH اﺡTR و٢ وي-W y رH اﺡTR و١ وي-$ x رHاﺡ
٠ وي-$
:آد
:ًqkد آH2ا
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX_Tutorial
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, -1f, 1f);
device.Transform.World =
Matrix.Scaling (1,2,0);
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None ;
device.RenderState.Clipping = true;
vertices[0].Color = Color.Red.ToArgb();
vertices[1].Color = Color.Green.ToArgb();
vertices[2].Color = Color.Yellow.ToArgb();
device.VertexFormat =
CustomVertex.PositionColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);
device.EndScene();
device.Present();
this.Invalidate();
angle += 0.05f;
if (disposing)
if (components != null)
components.Dispose();
base.Dispose(disposing);
our_directx_form.InitializeDevice();
Application.Run(our_directx_form);
بr و~ح وE.D. آjR ,26; ﺱE.\ ا8 ه,{+ " أjkو
(Matrix)ت+HD0ا
:' اE.W
أ1L
(B):E+HD0( واA) E+HD0ن
ي ا:W ضD;
!
!
:*6ن آH2.{ ﺱWr "ﺡﺹ
----------------------------
----------------------
:آد
:ًqkد آH2ا
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX_Tutorial
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, -1f, 1f);
device.Transform.World =
Matrix.Scaling (2,2,0) * Matrix.RotationX (Geometry.DegreeToRadian
(180))* Matrix.Translation (0,10,1);
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None ;
device.RenderState.Clipping = true;
vertices[0].Color = Color.Red.ToArgb();
vertices[1].SetPosition(new Vector3(10f, 0f, 0f));
vertices[1].Color = Color.Green.ToArgb();
vertices[2].Color = Color.Yellow.ToArgb();
device.BeginScene();
device.VertexFormat =
CustomVertex.PositionColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);
device.EndScene();
device.Present();
this.Invalidate();
angle += 0.05f;
if (disposing)
if (components != null)
components.Dispose();
}
base.Dispose(disposing);
our_directx_form.InitializeDevice();
Application.Run(our_directx_form);
}
:*6" ا2M; ا$
{u.-+ qRGW دH2 RUN "R
;R
( kﺡ.ت ا k1ه *Lااوي اu6Lو *+ Lا
رس ا>دم
: ا
رس ا دي
:16789 12 ا3 إ4+ أ,(ﻩ%>? ت ا:?2 ) واA
دB ت ا:?2 ا,:9 ق6<
:)A
دB اE:! ا:ًDأو
:/ > ل اG? اHIJ<
/&J+اfن إ )!AV 3ا ﺱب ا ,)A.%أي إذا آن ه<ك زاو,:9 )A
ا ?>...,::(%
Vertex Bufferا ـ-
/a )!*<" o% ﺡ3M 1?B& Direct٣d ا ـ/a $دUXU" (Class) )ja /وه
ا ـ,Aor& ):M? 1X أ," stu" 129 ,)^ آت ا/a أوRAM ذاآة ا ـ
.(:M ت:M?B اء اX وإ1"B> ا1:( >ﺱVertex ,
:آد
آت, <?M2& "
< $+J+ي أH ا,2M W9& U وهDevice ا ـ:~ G ا
.)^ ا
---------
>دB ا3 ل إUI
9 CPU ـM ﺱ?ح9 /<B& /> واLock ) ا ـ:M?
هB9 /&J&
Unlock 1?B9 مU!+ ):M?B ا$H>(ء ه+ و<
إVertex, ا ـ,Aor& 1X أ,"VGA
:آد
CustomVertex.PositionColored [] verts =
(CustomVertex.PositionColored [])vb.Lock (0,0);
verts[0].SetPosition(new Vector3(0.0f, 1.0f,
1.0f));
verts[0].Color =
System.Drawing.Color.Aqua.ToArgb();
verts[1].SetPosition(new Vector3(-1.0f, -1.0f,
1.0f));
verts[1].Color =
System.Drawing.Color.Black.ToArgb();
verts[2].SetPosition(new Vector3(1.0f, -1.0f,
1.0f));
verts[2].Color =
System.Drawing.Color.Purple.ToArgb();
vb.Unlock ();
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public Form1()
{
InitializeComponent();
}
public void ondeivce()
{
PresentParameters pp = new PresentParameters
();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16
;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
}
public void camera()
{
device.Transform.Projection =
Matrix.PerspectiveFovLH ((float)Math.PI /4,this.Width /this.Height ,1,50);
device.Transform.View = Matrix.LookAtLH (new
Vector3 (0,0,3),new Vector3 (0,0,0),new Vector3 (0,1,0));
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None;
}
public void position()
{
vb = new
VertexBuffer(typeof(CustomVertex.PositionColored ), 3, device,
Usage.SoftwareProcessing |
Usage.WriteOnly,
CustomVertex.PositionColored.Format, Pool.SystemMemory );
CustomVertex.PositionColored [] verts =
(CustomVertex.PositionColored [])vb.Lock (0,0);
verts[0].SetPosition(new Vector3(0.0f, 1.0f,
1.0f));
verts[0].Color =
System.Drawing.Color.Aqua.ToArgb();
verts[1].SetPosition(new Vector3(-1.0f, -1.0f,
1.0f));
verts[1].Color =
System.Drawing.Color.Black.ToArgb();
verts[2].SetPosition(new Vector3(1.0f, -1.0f,
1.0f));
verts[2].Color =
System.Drawing.Color.Purple.ToArgb();
vb.Unlock ();
}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.Black ,1,1);
device.BeginScene ();
device.VertexFormat =
CustomVertex.PositionColored .Format ;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
device.Transform.World = Matrix.RotationAxis
(new Vector3 (1,2,3),angle);
device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}
while (xx.Created )
{
xx.camera ();
xx.position ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
:/ > ا12 ( < ا4:ﺱa K89 دU2M RUN 1? <
)A>?ار7) إ:M?B9 )ﺹr د واU2 ا," اءoX8 ا$H
ال ه.>7 إ/9 ً|A?< اtو
:ضB ا
:آد
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
--------------------------------------------------------------------
:آد
Application.Run(our_directx_form);
--------------------------------------------------------------------
:آد
this.Invalidate();
:1|a> أ+ /*B& /> وا,/ > ا/9
:آد
Show ();
while (xx.Created )
{
…
…
Application.DoEvents ();
}
---------------
داة3M نU2A ت:_ اﺡ
اWcU& و,~MG" ١٢ )*7اU9 B2" 1?B I لG"
.ﺡ
ةU ا
:دU2 ا
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
vb = new
VertexBuffer(typeof(CustomVertex.PositionColored ), 36, device,
Usage.SoftwareProcessing |
Usage.WriteOnly,
CustomVertex.PositionColored.Format, Pool.SystemMemory );
CustomVertex.PositionColored [] verts =
(CustomVertex.PositionColored [])vb.Lock (0,0);
//Front face
//ا
اول
verts[0] = new CustomVertex.PositionColored(-
1.0f, 1.0f, 1.0f, Color.Red.ToArgb());
verts[1] = new CustomVertex.PositionColored(-
1.0f, -1.0f, 1.0f, Color.Red.ToArgb());
verts[2] = new
CustomVertex.PositionColored(1.0f, 1.0f, 1.0f, Color.Red.ToArgb());
//
ا
ا
verts[3] = new CustomVertex.PositionColored(-
1.0f, -1.0f, 1.0f, Color.Red.ToArgb());
verts[4] = new
CustomVertex.PositionColored(1.0f, -1.0f, 1.0f, Color.Red.ToArgb());
verts[5] = new
CustomVertex.PositionColored(1.0f, 1.0f, 1.0f, Color.Red.ToArgb());
// Back face
//ا
اول
verts[6] = new CustomVertex.PositionColored(-
1.0f, 1.0f, -1.0f, Color.Blue.ToArgb());
verts[7] = new
CustomVertex.PositionColored(1.0f, 1.0f, -1.0f, Color.Blue.ToArgb());
verts[8] = new CustomVertex.PositionColored(-
1.0f, -1.0f, -1.0f, Color.Blue.ToArgb());
//
ا
ا
verts[9] = new CustomVertex.PositionColored(-
1.0f, -1.0f, -1.0f, Color.Blue.ToArgb());
verts[10] = new
CustomVertex.PositionColored(1.0f, 1.0f, -1.0f, Color.Blue.ToArgb());
verts[11] = new
CustomVertex.PositionColored(1.0f, -1.0f, -1.0f, Color.Blue.ToArgb());
// Top face
//ا
اول
verts[12] = new CustomVertex.PositionColored(-
1.0f, 1.0f, 1.0f, Color.Yellow.ToArgb());
verts[13] = new
CustomVertex.PositionColored(1.0f, 1.0f, -1.0f, Color.Yellow.ToArgb());
verts[14] = new CustomVertex.PositionColored(-
1.0f, 1.0f, -1.0f, Color.Yellow.ToArgb());
//
ا
ا
verts[15] = new CustomVertex.PositionColored(-
1.0f, 1.0f, 1.0f, Color.Yellow.ToArgb());
verts[16] = new
CustomVertex.PositionColored(1.0f, 1.0f, 1.0f, Color.Yellow.ToArgb());
verts[17] = new
CustomVertex.PositionColored(1.0f, 1.0f, -1.0f, Color.Yellow.ToArgb());
// Bottom face
//ا
اول
verts[18] = new CustomVertex.PositionColored(-
1.0f, -1.0f, 1.0f, Color.Black.ToArgb());
verts[19] = new CustomVertex.PositionColored(-
1.0f, -1.0f, -1.0f, Color.Black.ToArgb());
verts[20] = new
CustomVertex.PositionColored(1.0f, -1.0f, -1.0f, Color.Black.ToArgb());
//
ا
ا
verts[21] = new CustomVertex.PositionColored(-
1.0f, -1.0f, 1.0f, Color.Black.ToArgb());
verts[22] = new
CustomVertex.PositionColored(1.0f, -1.0f, -1.0f, Color.Black.ToArgb());
verts[23] = new
CustomVertex.PositionColored(1.0f, -1.0f, 1.0f, Color.Black.ToArgb());
// **** face
//ا
اول
verts[24] = new CustomVertex.PositionColored(-
1.0f, 1.0f, 1.0f, Color.Gray.ToArgb());
verts[25] = new CustomVertex.PositionColored(-
1.0f, -1.0f, -1.0f, Color.Gray.ToArgb());
verts[26] = new CustomVertex.PositionColored(-
1.0f, -1.0f, 1.0f, Color.Gray.ToArgb());
//
ا
ا
verts[27] = new CustomVertex.PositionColored(-
1.0f, 1.0f, -1.0f, Color.Gray.ToArgb());
verts[28] = new CustomVertex.PositionColored(-
1.0f, -1.0f, -1.0f, Color.Gray.ToArgb());
verts[29] = new CustomVertex.PositionColored(-
1.0f, 1.0f, 1.0f, Color.Gray.ToArgb());
// Right face
//ا
اول
verts[30] = new
CustomVertex.PositionColored(1.0f, 1.0f, 1.0f, Color.Green.ToArgb());
verts[31] = new
CustomVertex.PositionColored(1.0f, -1.0f, 1.0f, Color.Green.ToArgb());
verts[32] = new
CustomVertex.PositionColored(1.0f, -1.0f, -1.0f, Color.Green.ToArgb());
//
ا
ا
verts[33] = new
CustomVertex.PositionColored(1.0f, 1.0f, -1.0f, Color.Green.ToArgb());
verts[34] = new
CustomVertex.PositionColored(1.0f, 1.0f, 1.0f, Color.Green.ToArgb());
verts[35] = new
CustomVertex.PositionColored(1.0f, -1.0f, -1.0f, Color.Green.ToArgb());
vb.Unlock ();
}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.Black ,1,1);
device.BeginScene ();
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 12);
device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}
while (xx.Created )
{
xx.camera ();
xx.position ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
:/ > ا12 ( ا4:7 RUN 1?
<
ت ا ـ:_ إﺡ
ا, Az> !) اAV :>9 s?t K89 دU2 ا/a :)4ﺡK"
...اH2>ﻩ ه9> آ," ًD
.aVertex
:آد
). <ﺱ9 1|a أE(A أ/<> J7 إذا,آ8 و...... " رو3 دي إJ& ا *ق12a
):+G !) اA* ل { اUtJ7 .... اآةH ﻩ وا+:z ) ا:M?B
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public Form1()
{
InitializeComponent();
}
public void ondeivce()
{
PresentParameters pp = new PresentParameters
();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16
;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
}
public void camera()
{
device.Transform.Projection =
Matrix.PerspectiveFovLH ((float)Math.PI /4,this.Width /this.Height ,1,50);
device.Transform.View = Matrix.LookAtLH (new
Vector3 (0,0,5),new Vector3 (0,0,0),new Vector3 (0,1,0));
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None;
}
public void position()
{
vb = new VertexBuffer
(typeof(CustomVertex.PositionNormalColored
),9,device,Usage.WriteOnly
,CustomVertex.PositionNormalColored.Format ,Pool.Default );
CustomVertex.PositionNormalColored [] cc =
(CustomVertex.PositionNormalColored [])vb.Lock (0,0);
for (int i =0;i<=4;i++)
{
float theta = (float)(2 * Math.PI * i) / 4;
cc[i*2].SetPosition (new Vector3
((float)Math.Cos (theta),(float)Math.Sin (theta),0));
cc[i*2].Color = Color.SkyBlue .ToArgb ();
}
vb.Unlock ();
}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.Black ,1,1);
device.BeginScene ();
device.SetStreamSource (0,vb,0);
device.VertexFormat =
CustomVertex.PositionNormalColored.Format ;
device.DrawPrimitives (PrimitiveType.LineStrip
,0,8);
device.Transform.World = Matrix.RotationAxis
(new Vector3 (0,0,3),angle);
device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}
while (xx.Created )
{
xx.camera ();
xx.position ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
:16789 12 ا/a ? آ,WMc8 ا,:9 " ,AUM& /9 مU!+ نJ9 نf{ اA" رأ
," DrawPrimitives ا ـ:>9 !ﻁa مU!<7
:آد
device.DrawPrimitives (PrimitiveType.LineStrip
,0,8);
:3 إ
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public Form1()
{
InitializeComponent();
}
public void ondeivce()
{
PresentParameters pp = new PresentParameters
();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16
;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
}
public void camera()
{
device.Transform.Projection =
Matrix.PerspectiveFovLH ((float)Math.PI /4,this.Width /this.Height ,1,50);
device.Transform.View = Matrix.LookAtLH (new
Vector3 (0,0,5),new Vector3 (0,0,0),new Vector3 (0,1,0));
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None;
}
public void position()
{
vb = new VertexBuffer
(typeof(CustomVertex.PositionNormalColored
),18,device,Usage.WriteOnly
,CustomVertex.PositionNormalColored.Format ,Pool.Default );
CustomVertex.PositionNormalColored [] cc =
(CustomVertex.PositionNormalColored [])vb.Lock (0,0);
for (int i =0;i<=4;i++)
{
float theta = (float)(2 * Math.PI * i) / 4;
cc[i*2].SetPosition (new Vector3
((float)Math.Cos (theta),(float)Math.Sin (theta),0));
cc[i*2].Color = Color.SkyBlue .ToArgb ();
}
vb.Unlock ();
}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.Black ,1,1);
device.BeginScene ();
device.SetStreamSource (0,vb,0);
device.VertexFormat =
CustomVertex.PositionNormalColored.Format ;
device.DrawPrimitives
(PrimitiveType.TriangleStrip ,0,8);
device.Transform.World = Matrix.RotationAxis
(new Vector3 (0,0,3),angle);
device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}
while (xx.Created )
{
xx.camera ();
xx.position ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
: داةE79 E!< :I لG"
:.2>9 { وذGط أآU*I E79 مU!<7 ,آ8 وK89 )A4< ا6<9
١٢٠ .z: VertexBuffer ا ـ
٥٠.z> for وا ـ
١٠٠ .z: DrawPrimitives وا ـ
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public Form1()
{
InitializeComponent();
}
public void ondeivce()
{
PresentParameters pp = new PresentParameters
();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16
;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
}
public void camera()
{
device.Transform.Projection =
Matrix.PerspectiveFovLH ((float)Math.PI /4,this.Width /this.Height ,1,50);
device.Transform.View = Matrix.LookAtLH (new
Vector3 (0,0,5),new Vector3 (0,0,0),new Vector3 (0,1,0));
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None;
}
public void position()
{
vb = new VertexBuffer
(typeof(CustomVertex.PositionNormalColored
),120,device,Usage.WriteOnly
,CustomVertex.PositionNormalColored.Format ,Pool.Default );
CustomVertex.PositionNormalColored [] cc =
(CustomVertex.PositionNormalColored [])vb.Lock (0,0);
for (int i =0;i<=50;i++)
{
float theta = (float)(2 * Math.PI * i) / 50;
cc[i*2].SetPosition (new Vector3
((float)Math.Cos (theta),(float)Math.Sin (theta),0));
cc[i*2].Color = Color.Red .ToArgb ();
}
vb.Unlock ();
}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.Black ,1,1);
device.BeginScene ();
device.SetStreamSource (0,vb,0);
device.VertexFormat =
CustomVertex.PositionNormalColored.Format ;
device.DrawPrimitives
(PrimitiveType.TriangleStrip ,0,100);
device.Transform.World = Matrix.RotationAxis
(new Vector3 (1,1,3),angle);
device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}
while (xx.Created )
{
xx.camera ();
xx.position ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
:)A4< ا6<9 و,W?t E7 :لG"
)ac إ/9 مU!<7 ~:ﺡ
:آد
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public Form1()
{
InitializeComponent();
}
public void ondeivce()
{
PresentParameters pp = new PresentParameters
();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16
;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
}
public void camera()
{
device.Transform.Projection =
Matrix.PerspectiveFovLH ((float)Math.PI /4,this.Width /this.Height ,1,50);
device.Transform.View = Matrix.LookAtLH (new
Vector3 (0,0,5),new Vector3 (0,0,0),new Vector3 (0,1,0));
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None;
}
public void position()
{
vb = new VertexBuffer
(typeof(CustomVertex.PositionNormalColored
),120,device,Usage.WriteOnly
,CustomVertex.PositionNormalColored.Format ,Pool.Default );
CustomVertex.PositionNormalColored [] cc =
(CustomVertex.PositionNormalColored [])vb.Lock (0,0);
for (int i =0;i<=50;i++)
{
float theta = (float)(2 * Math.PI * i) / 50;
}
vb.Unlock ();
}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.Black ,1,1);
device.BeginScene ();
device.SetStreamSource (0,vb,0);
device.VertexFormat =
CustomVertex.PositionNormalColored.Format ;
device.DrawPrimitives
(PrimitiveType.TriangleStrip ,0,100);
device.Transform.World = Matrix.RotationAxis
(new Vector3 (3,3,3),angle);
device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}
while (xx.Created )
{
xx.camera ();
xx.position ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public Form1()
{
InitializeComponent();
}
public void ondeivce()
{
PresentParameters pp = new PresentParameters
();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16
;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
}
public void camera()
{
device.Transform.Projection =
Matrix.PerspectiveFovLH ((float)Math.PI /4,this.Width /this.Height ,1,50);
device.Transform.View = Matrix.LookAtLH (new
Vector3 (0,0,5),new Vector3 (0,0,0),new Vector3 (0,1,0));
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None;
}
public void position()
{
vb = new VertexBuffer
(typeof(CustomVertex.PositionNormalColored
),120,device,Usage.WriteOnly
,CustomVertex.PositionNormalColored.Format ,Pool.Default );
CustomVertex.PositionNormalColored [] cc =
(CustomVertex.PositionNormalColored [])vb.Lock (0,0);
for (int i =0;i<=50;i++)
{
float theta = (float)(2 * Math.PI * i) / 50;
}
vb.Unlock ();
}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.Black ,1,1);
device.BeginScene ();
device.SetStreamSource (0,vb,0);
device.VertexFormat =
CustomVertex.PositionNormalColored.Format ;
device.DrawPrimitives
(PrimitiveType.TriangleStrip ,0,100);
device.Transform.World = Matrix.RotationAxis
(new Vector3 (3,3,3),angle);
device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}
while (xx.Created )
{
xx.camera ();
xx.position ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
: ا
رس ا
Textureا ـ-
Vertexأاع ا ـ-
--------------------
Textureا ـ-
,)#+-
ا. إ/! د12 نVertex ء ا ـ%* أ) ( ' إ+"! ً آ#
Texture.=
م ا ـ1ﺱ1 5(6 ا78 ه:;
H ﺡ# رB اHI
G
DirectX @ ا ـA!%B ا ا8=
م ه1 ﺱTexture ا ـ
Objects. ا ـ/ إBitmap أوjpg
اد1G2ا
. رB ت ا+-
ا. @ إW'ﺡ1 ا5+! HX أYG U و ا ـV ت ا ـ+-
ا.2=
م ا1ﺱ#
:H;Z H' ا/ إ6أ
device.SetTexture(0,txt);
:ً
Gا 'د آ
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public Form1()
{
InitializeComponent();
}
public void ondeivce()
{
PresentParameters pp = new PresentParameters
();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16
;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
txt = TextureLoader.FromFile (device,
Application.StartupPath + @"\..\..\RAAD.jpg");
}
public void camera()
{
device.Transform.Projection =
Matrix.PerspectiveFovLH ((float)Math.PI /4,this.Width /this.Height ,1,50);
device.Transform.View = Matrix.LookAtLH (new
Vector3 (0,0,3),new Vector3 (0,0,0),new Vector3 (0,1,0));
//device.Transform.World = Matrix.RotationAxis
(new Vector3 (5,2,3),angle);
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None;
}
public void position()
{
vb = new
VertexBuffer(typeof(CustomVertex.PositionTextured ), 3, device,
Usage.SoftwareProcessing |
Usage.WriteOnly,
CustomVertex.PositionTextured.Format, Pool.SystemMemory );
CustomVertex.PositionTextured [] verts =
(CustomVertex.PositionTextured [])vb.Lock (0,0);
vb.Unlock ();
}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.SkyBlue ,1,1);
device.BeginScene ();
device.VertexFormat =
CustomVertex.PositionTextured .Format ;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}
while (xx.Created )
{
xx.camera ();
xx.position ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
:H;Z H' \
ا6+
@ﺱZ !'دRUN H
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public Form1()
{
InitializeComponent();
}
public void ondeivce()
{
PresentParameters pp = new PresentParameters
();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16
;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
txt = TextureLoader.FromFile (device,
Application.StartupPath + @"\..\..\RAAD.jpg");
}
public void camera()
{
device.Transform.Projection =
Matrix.PerspectiveFovLH ((float)Math.PI /4,this.Width /this.Height ,1,50);
device.Transform.View = Matrix.LookAtLH (new
Vector3 (0,0,6),new Vector3 (0,0,0),new Vector3 (0,1,0));
device.Transform.World = Matrix.RotationAxis
(new Vector3 (1,2,3),angle);
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None;
}
public void position()
{
vb = new
VertexBuffer(typeof(CustomVertex.PositionTextured ), 36, device,
Usage.SoftwareProcessing |
Usage.WriteOnly,
CustomVertex.PositionTextured.Format, Pool.SystemMemory );
CustomVertex.PositionTextured [] verts =
(CustomVertex.PositionTextured [])vb.Lock (0,0);
//Front face
//ا
اول
verts[0].SetPosition (new Vector3 (-1.0f, 1.0f,
1.0f));
verts[0].Tu = 0;
verts[0].Tv = 0;
//
ا
ا
verts[3].SetPosition (new Vector3 (-1.0f, -1.0f,
1.0f));
verts[3].Tu = 0;
verts[3].Tv = 1;
// Back face
//ا
اول
verts[6].SetPosition (new Vector3 (-1.0f, 1.0f, -
1.0f));
verts[7].SetPosition (new Vector3 (1.0f, 1.0f, -
1.0f));
verts[8].SetPosition (new Vector3 (-1.0f, -1.0f, -
1.0f));
//
ا
ا
verts[9].SetPosition (new Vector3 (-1.0f, -1.0f, -
1.0f));
verts[10].SetPosition (new Vector3 (1.0f, 1.0f, -
1.0f));
verts[11].SetPosition (new Vector3 (1.0f, -1.0f, -
1.0f));
// Top face
//ا
اول
// Bottom face
//ا
اول
verts[18].SetPosition (new Vector3 (-1.0f, -1.0f,
1.0f));
verts[19].SetPosition (new Vector3 (-1.0f, -1.0f, -
1.0f));
verts[20].SetPosition (new Vector3 (1.0f, -1.0f, -
1.0f));
//
ا
ا
verts[21].SetPosition (new Vector3 (-1.0f, -1.0f,
1.0f));
verts[22].SetPosition (new Vector3 (1.0f, -1.0f, -
1.0f));
verts[23].SetPosition (new Vector3 (1.0f, -1.0f,
1.0f));
// **** face
//ا
اول
verts[24].SetPosition (new Vector3 (-1.0f, 1.0f,
1.0f));
verts[25].SetPosition (new Vector3 (-1.0f, -1.0f, -
1.0f));
verts[26].SetPosition (new Vector3 (-1.0f, -1.0f,
1.0f));
//
ا
ا
verts[27].SetPosition (new Vector3 (-1.0f, 1.0f, -
1.0f));
verts[28].SetPosition (new Vector3 (-1.0f, -1.0f, -
1.0f));
verts[29].SetPosition (new Vector3 (-1.0f, 1.0f,
1.0f));
// Right face
//ا
اول
verts[30].SetPosition (new Vector3 (1.0f, 1.0f,
1.0f));
verts[31].SetPosition (new Vector3 (1.0f, -1.0f,
1.0f));
verts[32].SetPosition (new Vector3 (1.0f, -1.0f, -
1.0f));
//
ا
ا
verts[33].SetPosition (new Vector3 (1.0f, 1.0f, -
1.0f));
verts[34].SetPosition (new Vector3 (1.0f, 1.0f,
1.0f));
verts[35].SetPosition (new Vector3 (1.0f, -1.0f, -
1.0f));
vb.Unlock ();
}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.Black ,1,1);
device.BeginScene ();
device.SetTexture(0,txt);
device.VertexFormat =
CustomVertex.PositionTextured .Format ;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 12);
device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}
while (xx.Created )
{
xx.camera ();
xx.position ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication5
{
public Form1()
{
InitializeComponent();
}
public void ondevice()
{
PresentParameters pp = new PresentParameters
();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
pp.AutoDepthStencilFormat = DepthFormat.D16
;
pp.EnableAutoDepthStencil = true;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
txt = TextureLoader.FromFile (device,
Application.StartupPath + @"\..\..\RAAD.jpg");
}
public void camera()
{
device.Transform.Projection =
Matrix.PerspectiveFovLH ((float)Math.PI /4,this.Width /this.Height ,1,50);
device.Transform.View = Matrix.LookAtLH (new
Vector3 (0,0,-5),new Vector3 (0,0,0),new Vector3 (0,1,0));
device.Transform.World = Matrix.RotationAxis
(new Vector3 (1,1,3),angle);
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None;
}
public void vertexbuffer()
{
vb = new VertexBuffer
(typeof(CustomVertex.PositionNormalTextured),100,device,Usage.Write
Only ,CustomVertex.PositionNormalTextured.Format ,Pool.Default );
CustomVertex.PositionNormalTextured [] cc =
(CustomVertex.PositionNormalTextured[])vb.Lock (0,0);
for (int i =0;i <50;i++)
{
float theta = (float)(3*Math.PI *i)/60;
cc[i*2].SetPosition (new Vector3
((float)Math.Sin (theta),(float)Math.Cos (theta),0));
cc[i*2].SetNormal (new Vector3
((float)Math.Sin (theta),(float)Math.Cos (theta),0));
cc[i*2].Tu = ((float)i )/(49);
cc[i*2].Tv = 1;
device.BeginScene ();
device.SetStreamSource (0,vb,0);
device.SetTexture (0,txt);
device.VertexFormat =
CustomVertex.PositionNormalTextured.Format ;
device.DrawPrimitives
(PrimitiveType.TriangleStrip ,0,98);
device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void OnPaint
(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}
}
}
}
}
Vertexأاع ا ـ-
أاع ا ـYG "G G
5"( 5"XاG عf ا ا8 ا ل `ن هe+%1ﺱ
Vertex
: Positional Dataًdأو
z وا ـy و ا ـx ا ـ5-
ا ﺡور ا/! ت+-
ا.2 اef# "# 1 وا
(٠،٠،٠) Point ١
(٠،١٠،٠) Point ٢
(١٠،٠،٠) Point ٣
* إ+ أنY' اYG ً( وأ,'لZ اW رHX أYG ا ا ع8=
م ه1ﺱ
. انZ ا5+ﺹI Vertex ا ـ78ه
: Normal Dataً+-
Vertex ا ـ/! ديG ي ('ن8 وه ا =ﻁ ا
Lightingاـ-
Meshاـ-
--------------------
Lightingاـ-
ً E_ ﺱBf وNormal Vertex , ﺱ_ت اـP AB ل1`ة ا('ءة واMV 7XL
ﻁgا اC هhﺱ6 5دي *) اﺱ,*Xﻁ اg ا,ﻩ ه-j_ (Vertex Math) اـ4V
:?pﺱ3_ ?M ا4V 7 آ/X',L ن,M Cross Product اـkl )
ن اـ,-f ... 13 ا4V ل7 *) اxﺱب ذP " ى آ- ا~ن أنx*) رأ
:4 ا,هCorss Product
--------------
ﺹt ?7 B5ﺹ7ا اC هkB5 Materials: ع اـ,',* A ا~ن إ4Lj-
أنhGV .. ]B ? إ'ءة7 - وMesh أوTexture * اـgء إذا إﺱ,8B
....B5ﺹ7ا اCم هgﺱ-
device.Lights[0]
..ول3ء ا,8? ا7
:آد
device.Lights[1]
..4-ء ا,8? ا7
....اCMوه
:?pﺱ3_ ?M ا4V 7 آ4اع ه,- أ/010 w,L و:ء,8 ض ا/El :ً-0
..5 اﺱAB 7ن ا,Bع ا,- 6L: ًـ010
. /Iاآة آت اC_ ن,Bا اC( هCommit) نg- :ًـX_را
. ا('ءة/GX* ﻩA ﺱTrue ﺱويL Enable اـ/ﺹt ?XG- :ً*ﺱt
:آد
device.Lights[0].Type = LightType.Directional;
device.Lights[0].Diffuse = System.Drawing.Color.White ;
device.Lights[0].Direction = new Vector3();
device.Lights[0].Commit();
device.Lights[0].Enabled = true;
-----------------
...?pﺱ3_ ?M ا4V 7 آ, وه:ول3ل ا7 ا4_ أJ ا~ن
]V ا('ءةBXw و,B7 رأس ا4V 4 ا/5EB ? إ'ءة7X_ 7f P
.. pﺹ3ن ا,B_
:ً1*د آ,Mا
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public class Form1 : System.Windows.Forms.Form
{
private Device device;
private System.ComponentModel.Container
components = null;
private float angle;
private VertexBuffer vb;
public Form1()
{
InitializeComponent();
}
public void ondeivce()
{
PresentParameters pp = new PresentParameters
();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16
;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
}
public void camera()
{
device.Transform.Projection =
Matrix.PerspectiveFovLH ((float)Math.PI /4,this.Width /this.Height ,1,50);
device.Transform.View = Matrix.LookAtLH (new
Vector3 (0,0,4),new Vector3 (0,0,0),new Vector3 (0,1,0));
device.RenderState.Lighting = true;
device.RenderState.CullMode = Cull.None;
}
public void light()
{
mtrl.Diffuse = col;
mtrl.Ambient = col;
device.Material = mtrl;
*/
device.Lights[0].Type = LightType.Directional;
device.Lights[0].Diffuse =
System.Drawing.Color.Yellow ;
//device.Lights[0].Direction = new
Vector3((float)Math.Cos(Environment.TickCount / 250.0f), 0,
(float)Math.Sin(Environment.TickCount / 250.0f));
device.Lights[0].Direction = new Vector3(0,-1,-1);
device.Lights[0].Commit();//let d3d know about
the light
device.Lights[0].Enabled = true;//turn it on
}
public void position()
{
vb = new
VertexBuffer(typeof(CustomVertex.PositionNormalColored ), 3, device,
Usage.SoftwareProcessing |
Usage.WriteOnly,
CustomVertex.PositionNormalColored .Format, Pool.SystemMemory );
CustomVertex.PositionNormalColored [] verts
= (CustomVertex.PositionNormalColored [])vb.Lock (0,0);
vb.Unlock ();
}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.LightPink ,1,1);
device.BeginScene ();
device.VertexFormat =
CustomVertex.PositionNormalColored .Format ;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
//device.Transform.World = Matrix.RotationAxis
(new Vector3 (1,1,0),angle);
device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}
while (xx.Created )
{
xx.camera ();
xx.position ();
xx.light ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
:آد
------------------
Meshاـ-
]8XJ_ /B *ﺹVertex طE- ى, ﺱ,ﺱ" * هw " ا~ن أن أيBX- 6Jأﺹ
."ﺱG ا/] ا4V ن,M , /MJط *? ا,5t /5اﺱ,_ XJا
B7 *? ا/5ل _ﺱMI _ﺱ" أ7f /E_ اروس اﺱ4V آCL 7وآ
ﻩwة *) وEX7ل اMI3ﺱً ا~ن *ذا ) اP ... /-ا,5 وا(ﺱhXM7وا
/BM7 ا%C? ه6 Mesh اـB5ء *ﺹw ه..ة أو ﺱرةl أوgI
. ?7X اB ?]وﺱ
B7ن إ*اد ا3 x وذXFile اـ4_ A7 ﺱB* ) رةJ , هMesh اـ
ـB / اﺱدﺱ/g *) اﺱ/Eا اCام هg _أت إﺱ.X , ,(هExtension)
*اJ ا4V "ﺱw ? أوMI رﺱ" أي:4 اAB ]LMV م,ELوDirectX
م,E- -V ,دX_3 ا/010 لMI3 ا/GX* * أو _اMaya أو اـD Max ٣ ?*
اـ/5اﺱ,_ B7ا اCاءة هf x ذX_ A ﺱX File /] _ﺹgL 4_
DirectX
:آد
!
تM object )M ا4_ صg ا, وهt3 اParameter اـ4E_
device"ﻩ ا(ﺱB EBlي أC وا/Iا
:آد
:ً1*د آ,Mا
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public Form1()
{
InitializeComponent();
}
public void ondevice()
{
PresentParameters pp = new PresentParameters
();
pp.SwapEffect = SwapEffect.Discard;
pp.Windowed = true;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16
;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
}
public void camera()
{
device.Transform.Projection =
Matrix.PerspectiveFovLH ((float)Math.PI /4,this.Width /this.Height ,1,50);
device.Transform.View = Matrix.LookAtLH (new
Vector3 (0,0,-20),new Vector3 (0,0,0),new Vector3 (0,1,0));
device.Transform.World = Matrix.RotationAxis
(new Vector3 (0,3,0),angle) * Matrix.Scaling (1,1,1) ;
device.RenderState.CullMode = Cull.None;
device.RenderState.Lighting =false;
device.BeginScene ();
device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void OnPaint
(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}
while (xx.Created )
{
xx.camera ();
xx.meshh ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
--------------------------------
ل7B K_ اCAR B7 اp_ "f X , ت اـpB* ) Jة أآMV Ctj- أنx* رأ
:4 ا P1 (%Mp7 اNotepad ( اـkl ) 13_
AB ي,6 hf ?( آTemplate), hا,f ) رةJ ,]V B7 ا4f_ *وأ
:4ﺱم هf أK_أر
(MeshNormals, Texture, Vertex, hEع ا,- ﺹ:ول3ﺱ" اEا
£اXSkinMeshHeader) ...
(<٣cf١٦٩ce-ff٧c-٤٤ab-٩٣c٠-?* hf ?M_ صt "f ر:4-ﺱ" اEا
Universally Unique Identifier 4_ "fا اC هA7ﺱf٧٨f٦٢d١٧٢e٢> )
(UUID).Aﺹ إgو
Datatype اي اـhEت ا-,M* AB ي,6 :ﺱ" اEا
CtjL وhEق ا1¯ وإV 4_ "M6 ا/B7 ?wن *) أ,ML :K_ﺱ" ااEا
[…].4? اMا
--------------------
--------------------
*اJى اP إ, وهMesh Viewer اـV إ.ًﺱP ... م1Mا اC] تJ0 إLأ
..?pﺱ3_ ?M ا4V 7 آDirectX SDK اـK* لL 4 ا/V'(ا
نM* t إOpen Mesh File "0 )* وFile A إh* إذه-J اp *X_
CAR ..B7ا
:4? اM_ `] اﺱرة
--------------------
ان,3 اAB ي,6 Mesh ا اـCن هj_ 13_ ن1Mان اCﺱ *) ه-
,4-? اM ا4V اءpط اﺹ,5g ا4 وهNormal Vector ( اـABو
). ا('ءةrMX مgﺱL
مfd max ٣ * اـ-_ /5اﺱ,_ _ﺱرة%Cي رﺱ" هC اgV إذن
)* *) ءP أراEV ?7Xا اC]_ وNormal, ط اـE- 6Lان و,3 اK',_
DirectX . اـ/5اﺱ,_ ءI3 ا%C ه/GX*
]- أK* ﺱرةB ان,3 اDirectX ذا " `] اـ7 ....ال ه³آ) اﺱ3و
ﻩ-j_ Bf * 13 ا4V ال³ا اﺱC هAB Jw ؟؟ أMesh ? اـtدة _ا,w,*
Material. ?7 B hGV Mesh أو اـTexture اـK* ?*X ا- *
:/ات ا,5g اKJ-
:4 آMaterial أ _ﺹ ) اـJ-
:آد
ExtendedMaterial[] material;
اCآ) ه3( و13 ا4V ﻩ7BML) ,/gL /El وB7 ا6L: ً0
Subset ? آµpL AB ?7XL 4 واout material / ا/B7G ا4V د,Mا
.دة,X" ا0 )* وExtendMaterial ? اـt_ا
:آد
:آد
!
: ً1*د آ,Mا
.Vن أ,B_ ?M ﺱ`] اxC _3ن ا,3_ ا('ءةBXw P
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public Form1()
{
InitializeComponent();
}
public void ondevice()
{
PresentParameters pp = new PresentParameters
();
pp.SwapEffect = SwapEffect.Discard;
pp.Windowed = true;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16
;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
}
public void camera()
{
device.Transform.Projection =
Matrix.PerspectiveFovLH ((float)Math.PI /4,this.Width /this.Height ,1,50);
device.Transform.View = Matrix.LookAtLH (new
Vector3 (0,0,-20),new Vector3 (0,0,0),new Vector3 (0,1,0));
device.Transform.World = Matrix.RotationAxis
(new Vector3 (0,3,0),angle) * Matrix.Scaling (1,1,1) ;
device.RenderState.CullMode = Cull.None;
device.RenderState.Lighting =true;
device.RenderState.Ambient = Color.White ;
}
public void meshh()
{
ExtendedMaterial[] material;
device.BeginScene ();
while (xx.Created )
{
xx.camera ();
xx.meshh ();
xx.light ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
-------------------
?7X ... ل اﺱرة7_ ]B 7BML 4ات ا,5g اrp- مgﺱ- "0 )*و
Material
:ً1*د آ,Mا
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public Form1()
{
InitializeComponent();
}
public void ondevice()
{
PresentParameters pp = new PresentParameters
();
pp.SwapEffect = SwapEffect.Discard;
pp.Windowed = true;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16
;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
txt = TextureLoader.FromFile
(device,Application.StartupPath + @"\..\..\Tiny_skin.bmp");
}
public void camera()
{
device.Transform.Projection =
Matrix.PerspectiveFovLH ((float)Math.PI /4,this.Width /this.Height
,1,2000);
device.Transform.View = Matrix.LookAtLH (new
Vector3 (1,-1000,30),new Vector3 (0,0,0),new Vector3 (0,1,0));
device.Transform.World = Matrix.RotationAxis
(new Vector3 (0,0,2),angle) * Matrix.Scaling (1,1,1) ;
device.RenderState.CullMode = Cull.None;
device.RenderState.Lighting =true;
device.RenderState.Ambient = Color.White;
}
public void meshh()
{
ExtendedMaterial[] material;
Directory.SetCurrentDirectory
(Application.StartupPath + @"\..\..\");
mesh = Mesh.FromFile
("Tiny.x",MeshFlags.SystemMemory ,device,out material);
mat = new Material [material.Length];
for (int i= 0;i < material.Length ;i++)
{
mat[i] = material[i].Material3D ;
mat[i].Ambient = mat[i].Diffuse ;
}
}
public void light()
{
Color col = Color.White ;
Material mm = new Material ();
mm.Ambient = col;
mm.Diffuse = col;
device.Material = mm;
device.Lights [0].Diffuse = Color.White;
device.Lights [0].Type = LightType.Directional ;
device.Lights [0].Direction = new Vector3 (0,0,6);
device.Lights [0].Commit ();
device.Lights [0].Enabled = true;
}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.Blue ,1,1);
device.SetTexture (0,txt);
device.BeginScene ();
while (xx.Created )
{
xx.camera ();
xx.meshh ();
xx.light ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
:4? اM ﺱ`] اRUN ?7
--------------------------
) )ا: ارس اا
ال-
Fontاـ-
--------------------
ال-
,34 ا, ﺱر,01) ' ﺡ*) وه, "ﺱ.ﺱ/"! ه ا# ف%ﺱ
) 14 @ل اﺱرة ا!يA 34 مC( ﺱ=<; ه!ا ا9 ,78,56اﺱ
:'D1' ارس اE
T! ه٠R٧ IJاK إI18 MJ=ات وإOKA IPCP 519 م%H# :ً*أو
Z وY وX ور1 ا3ات إOK1ا
:آد
Matrix.Translation (posx,posy,posz)
اـ34 I=9D أي5/ ﺱ5i أ0A OnKeyDown Iء ااKإﺱ: ً@P
keyboard
:آد
case Keys.Right :
posx ++;
break;
5 .ﺱ/ ا34 519( ﺱ01 ا.M زر )اﺱ34 ,On ا
Matrix.Translation اـ7 وذ ﺱx, ر%14 31) اM/ ا3اي إo
:آد
case Keys.**** :
posx --;
break;
case Keys.Up :
posy ++;
break;
case Keys.Down :
posy --;
break;
case Keys.Home :
posz ++;
break;
case Keys.End :
posz --;
break;
:ًCAد آ%ا
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public Form1()
{
InitializeComponent();
}
public void ondevice()
{
PresentParameters pp = new PresentParameters
();
pp.SwapEffect = SwapEffect.Discard;
pp.Windowed = true;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16
;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
}
public void camera()
{
device.Transform.Projection =
Matrix.PerspectiveFovLH ((float)Math.PI /4,this.Width /this.Height ,1,50);
device.Transform.View = Matrix.LookAtLH (new
Vector3 (0,0,-20),new Vector3 (0,0,0),new Vector3 (0,1,0));
device.Transform.World = Matrix.RotationAxis
(new Vector3 (0,3,0),angle) * Matrix.Scaling (1,1,1)* Matrix.Translation
(posx,posy,posz) ;
device.RenderState.CullMode = Cull.None;
device.RenderState.Lighting =true;
device.RenderState.Ambient = Color.White ;
}
public void meshh()
{
ExtendedMaterial[] material;
device.BeginScene ();
case Keys.**** :
posx --;
break;
case Keys.Up :
posy ++;
break;
case Keys.Down :
posy --;
break;
case Keys.Home :
posz ++;
break;
case Keys.End :
posz --;
break;
while (xx.Created )
{
xx.camera ();
xx.meshh ();
xx.light ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
: 56 ﺱ5 اMw ﺱRUN 51
!
------------------------------
:IwﺡCA
'E ﺹ9 ا% وهDirect٣D اـ0 % هIH' اروس اﺱE ) 14 A 5آ
وهك..(ًH ه!ا ﺱ48) I' آت اE .K اaK ا!يDirectX اـ
DirectSound اـMA IAدH' اروس اE M .4Kً ﺹ أى ﺱnأ
"ن اـ.... )%8 ا!ي أرA ...ت%' آت اﺹE .K ' اaK ا!ي%وه
Function واـClass اـ0A @ ا1M i% DirectSound واـDirect٣D
@ل1 ا5< ﺱ34 DirectX ـ4 إرك7< ﺱ1A .... .' اﺱE )MK1ا
DirectSound, ' اـE ًn وأDirect٣D ' اـE Device M1 إﺱClass هك
... ت% أم آت اﺹI آت ا5 هA<1ﺹ اH 1M"E
: ﺹ أي5 I ﺹNamespace 519 م%H# ,I41 اT! ه5
:آد
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using Microsoft.DirectX;
using dev = Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public Form1()
{
InitializeComponent();
}
device.RenderState.CullMode = dev.Cull.None;
device.RenderState.Lighting =true;
device.RenderState.Ambient = Color.White ;
}
public void meshh()
{
dev.ExtendedMaterial[] material;
mesh = dev.Mesh.FromFile
(Application.StartupPath +
@"\..\..\CAR.x",dev.MeshFlags.SystemMemory ,device,out material);
mat = new dev.Material [material.Length];
for (int i= 0;i < material.Length ;i++)
{
mat[i] = material[i].Material3D ;
mat[i].Ambient = mat[i].Diffuse ;
}
}
device.BeginScene ();
case Keys.**** :
posx --;
break;
case Keys.Up :
posy ++;
break;
case Keys.Down :
posy --;
break;
case Keys.Home :
posz ++;
break;
case Keys.End :
posz --;
break;
while (xx.Created )
{
xx.camera ();
xx.meshh ();
xx.light ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
Fontاـ-
.K * IK اI41 y# ﺱ<; آ1E Direct٣d , ' اـE (Text) IKﺹ ا8أ
اـ4 E وHE انA أMesh. أوtexture 51 I=اﺱ% y# آ5 <ةA
System.Drawing.Font I6 اT!ام هK إﺱI=اﺱ% ء9ه!ا ا.net
:'Kآ
:انOKA 0 aﺹK م%H# :ً*أو
:آد
dxfont.DrawText ("WWW.3ASFH.NET",rr,dev.DrawTextFormat.NoClip
,Color.DarkOrange );
اوفD% I6 آ34 DrawTextFormat I اﺹT! ه519
,* أمI14 آ<ت ا14 آ5=Kﺱ1 < ا5أي ه. ('1ه% ا5=Kﺱ1 ا5ا
'E أم01 اﺱر أم ا3ن إ% I14 اD% 5 ه,I14 ا5A "! آ5ه
aD%K 56ول ﺱ/ ا3 إw# أ,رق6ى اK MK/ =K( ﺱ,ﺱ%ا
:M رق6ا
:ًCAد آ%ا
:آد
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using Microsoft.DirectX;
using dev = Microsoft.DirectX.Direct3D;
namespace WindowsApplication6
{
public Form1()
{
InitializeComponent();
}
device.RenderState.CullMode = dev.Cull.None;
device.RenderState.Lighting =true;
device.RenderState.Ambient = Color.White ;
}
public void meshh()
{
dev.ExtendedMaterial[] material;
mesh = dev.Mesh.FromFile
(Application.StartupPath +
@"\..\..\CAR.x",dev.MeshFlags.SystemMemory ,device,out material);
mat = new dev.Material [material.Length];
for (int i= 0;i < material.Length ;i++)
{
mat[i] = material[i].Material3D ;
mat[i].Ambient = mat[i].Diffuse ;
}
}
device.BeginScene ();
this.font ();
for (int i=0;i < mat.Length ;i++)
{
device.Material = mat[i];
mesh.DrawSubset (i);
}
device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void OnPaint
(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}
case Keys.**** :
posx --;
break;
case Keys.Up :
posy ++;
break;
case Keys.Down :
posy --;
break;
case Keys.Home :
posz ++;
break;
case Keys.End :
posz --;
break;
while (xx.Created )
{
xx.camera ();
xx.meshh ();
xx.light ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
:'K ا5 اMw ﺱRUN 51