Null

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 177

:‫ا

رس ا‬
Transformed‫  اـ‬Vertexes ‫

اـ‬-
TransformedColored‫"!  اـ‬# $%‫ر‬-

--------------------

Transformed‫  اـ‬Vertexes ‫



اـ‬

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‫ ا‬

‫ط‬5, ID[D . !";‫ أن ا‬$!>,‫"! و‬# $%‫ أر


أن أر‬-,‫ أ‬25- ‫ن‬Z‫ا‬
: +‫\ آ‬:D‫
ا‬E‫إ‬
: x = 0 , y = 0‫و‬X‫ ا‬IQ5-‫ا‬
: x = 0 , y = 200I:,"‫ ا‬IQ5-‫ا‬
: x = 200 , y = 200I""‫ ا‬IQ5-‫ا‬
DirectX:‫ اـ‬K‫ً إ‬:M#G [)X ‫ي‬c‫ل ا*[م ا‬H, ‫ن أن‬Z‫ ا‬a‫ رأ‬#

E‫ أ‬H‫ي ه‬c‫ وا‬TransformedColored ‫ )( اـ‬iGU+‫ا‬: ‫ول‬X‫ة ا‬HQ7‫ا‬


‫ط‬5-‫ت ا‬:D‫
ا‬E‫ إ‬l, ‫ي‬c‫)ء ا‬H‫ آ‬2;> H‫ وه‬Transformed ‫اع اـ‬H,‫أ‬
IHWU# I!>M-% 2\%‫ر أ‬H#X‫ ا‬2>M‫ و‬,\ $%G‫اد ا‬G;‫ان ا‬HX‫وا‬
I:Q>-%‫ و‬,(‫ط‬5-‫ت ا‬:D‫
ا‬E‫ت )إ‬,:3‫ ا‬o:G I:!;) 2\+(Array)
vertexes(*:‫ و‬$%‫أي إ‬
:‫آد‬

CustomVertex.TransformedColored[] vertexes ;

H‫ وه‬vertex, ‫  اـ‬I‫ﺹ‬s (function) .‫ دا‬2;) :I:,"‫ة ا‬HQ7‫ا‬


vY--% ,2l‫ أ‬.‫ إدار‬2>t‫د و‬H*‫ ا‬o:G 2t‫( أ‬# ‫ﻁ‬5 $\#
‫
د‬,‫ و‬,[)X .-) -;!* ‫ي‬c‫ ا‬vertexes ‫( !ـ‬Object) (w‫!\ آ‬s‫
ا‬
ID[D [)X 2*Y‫ وه آ;  ا‬,\;%‫اد ر‬G;‫ط ا‬5-‫ )
د ا‬.!s‫
ا‬
:+‫ن آ‬H*:

:‫آد‬

vertexes = new CustomVertex.TransformedColored[3];

‫ن‬/ $!>, ;‫ وآ‬,\;%‫اد ر‬G;‫ط ا‬5-‫ )


د ا‬2"; ID[D $1G‫أي أن ا‬
.GW‫ ﺹ‬$1G‫( ا‬# ‫
أ‬3 ‫ت‬HWU;‫  ا‬$:1G+‫ا‬

]:0] ‫ول‬X‫ ا‬IQ5-‫ا‬


:‫آد‬

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<
:‫آد‬

vertexes[0].Color = Color.White .ToArgb();


vertexes[1].Color = Color.Blue .ToArgb();
vertexes[2].Color = Color.Green .ToArgb();

-,/ 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:
:‫آد‬

public void tranvertex()


{
vertexes = new
CustomVertex.TransformedColored[3];

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‫ه‬
:‫آد‬

device3d.DrawUserPrimitives( PrimitiveType.TriangleList ,.. ,..);


 ;‫ آ‬I*3J 2*Y 2:‫ﺹ‬H+‫ن ا‬H*:% TriangleStrip I:‫ﺹ‬s
2W%X 2*Y‫ا‬

‫ط‬5-‫ ا‬2‫ آ‬:E IE‫و‬G# 2*Y 2:‫ﺹ‬H+‫ن ا‬H*:% TriangleFan I:‫ﺹ‬s


:2W%X 2*Y‫
ة آ;  ا‬E‫ وا‬IQ5- ‫ك‬G+Y+%

1 -"#  H‫ وه‬$\;%‫اد ر‬G;‫



)
د ا;"!"ت ا‬+ : I:,"‫ا‬
vertexesH‫)[ وه‬X‫  ا‬IwY, -;1 ‫ي‬c‫( ا‬w*‫ ا‬: I""‫ا‬
:+‫ ا‬2*Y ‫د‬H*‫ ا‬i3U:
:‫آد‬

device3d.DrawUserPrimitives( PrimitiveType.TriangleList , 1, vertexes );


---------------------------------

TransformedColored‫ اـ‬ !"# $%‫ر‬


:ً[#‫د آ‬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 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
//
}

public void ondevice()


{
PresentParameters pp = new PresentParameters
();
pp.SwapEffect = SwapEffect.Discard;

pp.Windowed = true;

device3d = new Device (0,DeviceType.Hardware


,this,CreateFlags.SoftwareVertexProcessing ,pp);
}

public void tranvertex()


{
vertexes = new
CustomVertex.TransformedColored[3];

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();

protected override void OnPaint


(System.Windows.Forms.PaintEventArgs e)
{
device3d.Clear (ClearFlags.Target ,Color.Red
,1,0);
device3d.BeginScene();

// draw the triangle


device3d.VertexFormat =
CustomVertex.TransformedColored.Format ;
device3d.DrawUserPrimitives(
PrimitiveType.TriangleList , 1, vertexes );

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 );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

/// <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‫اـ‬-

--------------------

PositionColored‫  اـ‬Vertexes ‫



اـ‬

5671  ‫*ع‬1‫ا ا‬2‫ ه‬4 (Origin Point) "#$‫ ا‬%&'( ‫*ن‬+


‫ ﺱر‬ABCD4 ‫*ن‬+ 7‫ وا‬Transformed ‫ و<; " اـ‬,%89‫ا‬
‫*ان‬B‫&ء ا‬C‫ إ‬+II‫ً  ا‬K‫ وأ‬,(E4‫ ا
رس اﺱ‬EF‫ )را‬%89‫ا‬
..O‫ة أآ‬O+M‫ ا‬VW*77 "M‫ﺱ‬$4 "+9‫ ا‬A‫ إ‬OP(‫'ط أ‬1‫ ا‬R2S

:%<7‫_ *ي ا]ﺡ


ا[<ت ا‬B `‫ رﺱ‬+II‫  ا‬5<‫ى آ‬O1 ‫ن‬Y‫ا‬

: 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

‫'ط‬1‫ي ﺱ<*ي ا‬2‫ ا‬PositionColored ‫ء اـ‬C*B q+‫" ا‬Ir4 ‫


أ‬n(
‫*د‬+‫  ا‬I‫ آ‬vertices `‫ ا]ﺱ‬q+‫ا ا‬2‫& ه‬r((Vertex)
."M‫ﺱ‬$4
:‫آد‬

CustomVertex.PositionColored[] vertices = new


CustomVertex.PositionColored[3];
:7‫ آ‬SI‫اد رﺱ‬OI‫'ط ا‬1‫و [` (
د ا‬

:‫آد‬

vertices[0].SetPosition(new Vector3(0f, 0f, 0f));


vertices[0].Color = Color.Red.ToArgb();

vertices[1].SetPosition(new Vector3(10f, 0f, 0f));


vertices[1].Color = Color.Green.ToArgb();

vertices[2].SetPosition(new Vector3(5f, 10f, 0f));


vertices[2].Color = Color.Yellow.ToArgb();
AI‫ﺱ‬I‫( ا‬Class) %uM‫*د ا‬F‫*د ه* و‬+‫ا ا‬2‫

 ه‬F R‫ا‬O( 
ABC ‫ول‬$‫ ا‬x<O74 *‫ إﺡ
ا[<ت وه‬%[h[

 1r 7‫وا‬Vector٣
E<&7‫ (ﺱ‬z. ‫ *ر اـ‬ABC _‫ وا‬y ‫ *ر‬ABC (‫ وا‬x ‫*ر اـ‬
"+9‫ ا‬A‫ إ‬OP(‫ أ‬,V&‫ اﺱ‬C ‫ع‬M‫" ا]ر‬I z ‫*ر‬I‫ن ا‬D4 ‫ا'*ل‬
:"M‫ﺱ‬$4

‫ وه‬OnPaint ‫ اـ‬%‫" دا‬y‫


ا‬4 Vertex ‫ اـ‬C VO67‫ ا‬1
 '4
‫  ا
رس‬S1C 1IB+ 7‫ ا‬Transformed ‫ اـ‬%'Oz ;M14
‫ اـ‬4 S‫
ا‬n7‫{ﺱ‬4 ‫ ('*م‬1‫ أ(ﻩ ه‬O<~ p4‫اﺱ‬
CustomVertex.PositionColored

:‫آد‬

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 class WinForm : System.Windows.Forms.Form

private Device device;


private System.ComponentModel.Container components = null;

public WinForm()

{
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);

public void InitializeDevice()

PresentParameters presentParams = new


PresentParameters();

presentParams.Windowed = true;

presentParams.SwapEffect = SwapEffect.Discard;

device = new Device(0, DeviceType.Hardware, this,


CreateFlags.SoftwareVertexProcessing, presentParams);

}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)

CustomVertex.PositionColored[] vertices = new


CustomVertex.PositionColored[3];

vertices[0].SetPosition(new Vector3(0f, 0f, 0f));


vertices[0].Color = Color.Red.ToArgb();

vertices[1].SetPosition(new Vector3(10f, 0f, 0f));


vertices[1].Color = Color.Green.ToArgb();

vertices[2].SetPosition(new Vector3(5f, 10f, 0f));


vertices[2].Color = Color.Yellow.ToArgb();

device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);

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);

private void InitializeComponent()

this.components = new System.ComponentModel.Container();

this.Size = new System.Drawing.Size(500,500);

this.Text = "DirectX Tutorial";

static void Main()

using (WinForm our_directx_form = new WinForm())

{
our_directx_form.InitializeDevice();
Application.Run(our_directx_form);
}
}
}
}
:7‫" ا‬+9‫ ا‬1 OSP<‫ ﺱ‬,hC$‫*د  ا‬+B run "IC
1C

‫_ ؟؟؟؟‬BI‫آ أ ا‬$‫و‬

1I Transformed ‫ اـ‬ABC 1IB+ 


1C WI‫ ا
رس ا‬

ام اـ‬j7‫
إﺱ‬1C ‫( أ‬Pixels) "‫ﺱ‬+n‫ق ا‬Oz C ‫

ا]ﺡ
ا[<ت‬74
‫ أي‬World Space ‫ ا]ﺡ
ا[<ت  اـ‬E<IF Vn67PositionColored
OP1‫اد ا‬OI‫'ط ا‬1‫ 

ا‬x‡ †2 ,E‫ء ا*اﺱ‬KM‫"  أ(†  ا‬
...‫ا‬O<I+‫
ام ا‬j7‫{ﺱ‬4 S<‫إ‬

......................................

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$‫ا‬

(World ‫ؤ  اـ‬O‫ 



‡ل ا‬4 ‫ا‬O<I+‫ ا‬%M<Œ‫ و‬I+: ً<([
‫ا‬O<I+‫ ا‬EW*4 1I _<‫ ﺡ‬,"M‫ﺱ‬$4 "+9‫ ا‬A‫ إ‬OP(‫أ‬Space) ,
A "+9‫ر ا‬SŒ‫" إ‬F‫ )ا]ﺱ'ط(  أ‬z‫و‬OjI‫" ا‬+94 %BI7I‫ا‬
.‫'ﻁ‬

1<BC x‡ (‫ا‬O<I+‫ )ا‬z‫و‬OjI‫" ا‬+9‫ ا‬E*




O( 
1C: ً[
:‫ن اـ‬n‫ﺱ‬4 2yD( ‫أن‬
‫  *ر‬A1I<‫ﻩ ا‬S‡‫ ا‬A‫ إ‬O<9 7‫وا‬PerspectiveFovRH
"M‫ﺱ‬$‫ ا‬A‫م إ‬S4]‫*ن ا‬+ _<‫" ﺡ‬M‫ﺱ‬$4 "+9‫ ا‬A‫ إ‬OP(‫ا]ﺡ
ا[<ت أ‬
Z.‫*ر‬IB ‫*ازي‬
‫ى  *ر‬O‫ﻩ ا<ﺱ‬S‡‫ ا‬A‫ إ‬O<9 7‫وا‬PerspectiveFovLH
hC$‫ ا‬A‫م إ‬S4]‫*ن ا‬+ _<‫" ﺡ‬M‫ﺱ‬$4 "+9‫ ا‬A‫ إ‬OP(‫ا]ﺡ
ا[<ت أ‬
Z.‫*ر‬IB ‫*ازي‬
"I ‫(ﻩ‬$ PerspectiveFovLH ‫
م ه* اـ‬j7‫ﺱ‬I‫ وا‬Eq9‫" ا‬+9‫ا‬
.‫ ا'<' ”ﺡ
ا[<ت‬EW*7‫ا‬

...‫ وه‬hC$4 ‫ل‬I‫ﺡ


ا[<ت  ا‬$‫ ا‬2yD( 1C‫ د‬..O‫ أآ‬S<W*7‫و‬

:‫آد‬

vertices[0].SetPosition(new Vector3(0f, 0f, 0f));


vertices[1].SetPosition(new Vector3(10f, 0f, 0f));
vertices[2].SetPosition(new Vector3(5f, 10f, 0f));

PerspectiveFovLH ‫ اـ‬1
j7‫ ا]ﺡ
ا[<ت وإﺱ‬R2‫<" ه‬I74 1I ‫إذا‬
:7‫ آ‬r<n&‫ ا‬SrW*4 ‫ ا]ﺡ
ا[<ت‬%‫ رؤ‬%SF ‫*ن‬+7‫ﺱ‬
:‫آد‬

device.Transform.Projection = Matrix.PerspectiveFovLH();

%‫ؤ‬O‫ ا‬%SF ‫*ن‬+7‫ ﺱ‬PerspectiveFovRH ‫ اـ‬1


j7‫أ إذا إﺱ‬
:7‫; آ‬+r4
:‫آد‬

device.Transform.Projection = Matrix.PerspectiveFovRH ();

‫ن أن‬Y‫' ا‬4 ,%‫ؤ‬O‫ ا‬%SF



74 %'4‫&*ة اﺱ‬j‫  ا‬1I: ًr4‫را‬
(Projection), ‫ ا]ﺱ'ط‬%<BIC ‫ا أي‬O<I+‫ 
ى ا‬%‫ؤ‬O‫(
د 
ى ا‬
%<BC ‫ه‬O‫آ أآ‬$‫و‬, ‫ ا]ﺱ'ط‬%<BIC 2<M1 "F‫ق  أ‬Oz ‫
ة‬C
F*
‫(ﻩ '*م‬$ (Perspective Projection) ‫*ري‬P1I‫ه* ا]ﺱ'ط ا‬
‫ا‬O<I+‫ ا‬C ‫<
ة‬rn‫ل ا‬+8$‫
و ا‬n _<4 %<‫
ﺱ‬1S‫ل ا‬+8$‫{ﺱ'ط ا‬4
‫'
ة‬r %*M6 ‫
م‬j7‫<ً ﺱ‬W‫ ر‬,‫ا‬O<I+‫  ا‬%nO'‫† ا‬B  O–#‫أ‬

ام ا
اﻩ‬j7‫{ﺱ‬4 †‫ء وذ‬1r‫ا ا‬2‫ ه‬DirectX ‫ اـ‬1<BC O‫آ و‬$‫ و‬,†2
PerspectiveFovRH().‫أو‬PerspectiveFovLH()
‫ز‬SF V7M `‫ أ‬... O‫آ‬27 ‫ ﺡول أن‬...˜94 hC$4 "+9‫ك ا‬O‫آ‬2 ‰‫أ‬
‫ز‬SF 17 ‫` {ذا‬r( .... 1ISM ‫
أت‬4 †(D4
'7C‫ أ‬.. "n  ‫ز‬MB7‫ا‬
(z‫و‬Oj "+8) EI 4 %*#* %89‫ن ا‬D4 ‫ي‬O( ‫ز ﺱ*ف‬MB7‫ا‬
;M( ‫
ام‬j7‫{ﺱ‬4 DirectX ‫ اـ‬2y‫ أ‬1‫  ه‬... hC$4 "+9‫ ا‬%n9
ً<W‫ ر‬S‫&ع آ‬7‫ز وإﺱ‬MB7‫ ا‬%
j7‫ي ﺱ‬2‫*ر ا‬P1I‫ ا‬%OP(
‫ أو‬PerspectiveFovLH() <7‫
ام إﺡ
ى ه< ا
ا‬j7‫{ﺱ‬4
PerspectiveFovRH()

: ‫<ﻩ‬7‫( ا‬Parameters) ‫ات‬O7<‫را‬n‫ن ا‬7‫ هن ا


ا‬2yD
‫*ر اـ‬D4 %#j‫( وه ا‬FOV) ‫ ه‬hC$4 "+9‫  ا‬: %‫ؤ‬O‫ ا‬%‫زاو‬-
"*74 xCh‫ ﺡ<_ '*م ا‬%<4O‫ب ا‬r$‫
م  ا‬j7‫وﺱ‬Zooming ,
E<&7‫ <ﺱ‬%‫ﺡ‬h‫ ﺱ‬ABC ‫*دة‬F*I‫ة ا‬On+I‫ ا‬%‫
ﺱ‬r‫ ا‬A‫ؤﻩ إ‬O‫م ا‬P(
‫ ﺡ<_ أن اـ‬PI/٤ %‫ زاو‬4 %C*W* ‫*ن‬+  ًn~‫ و‬.‫
اء‬C$‫ص ا‬17‫إ‬
;M( ‫ وه‬%F‫ در‬٤٥ ‫ وﺱوي‬١٨٠/٤ Vn6 ‫(أي‬١٨٠) ‫ﺱوي‬PI
%<#y
F* ‫(ﻩ‬D4 ž‫ﺡ‬h( _<‫ ﺡ‬,‫ز‬MB7‫ز ا‬SF S
j7‫ ﺱ‬7‫ ا‬%F‫ا
ر‬
,<r
S9I ZOOM "IC %<(+‫ إ‬%
‫Ÿ*(ت ا‬MB7‫ ا‬ r4 
,%‫ اŸاو‬O<–6 pOz C ...`r( ,†24 ‫ '*م‬5<‫` آ‬Br( 1n#‫ن أ‬Y‫ا‬
‫–ﻁ‬K %‫ اŸاو‬O–# ‫ن‬$ †‫ ا‡ﺱ` وذ‬On‫ آ‬IB‫ آ‬%‫ت اŸاو‬O–# IB+

م‬j7‫ ﺱ‬%I‡‫ ﺡ‬On‫ آ‬A‫دي إ‬¢ I ‫م‬$‫ ا‬A‫ب إ‬O7'< `‫ ا‡ﺱ‬ABC
.14 ‫  ‡ل‬£‫" ذ† وه <ﺱ‬F‫'
ة  أ‬r %<W‫<ت ر‬BIC

‫ي‬2‫ وا‬,‫*رم‬M‫ أي ا‬.. S<BC "Ir( 7‫ ا‬%88 ‫ وه‬Near : ‫اـ‬-


ABC ‫ض‬Or‫'ﺱ` ا‬74 ‫ً  ('*م‬n~‫و‬, ‫ض‬Or‫*ن  ا&*ل وا‬+7 ‫
ورة‬4
‫ﺱ*م‬OI‫" ا‬+9‫` ا‬BD ABC
C‫ا ﺱ‬2S width/height , ‫ا&*ل‬
.%89‫ ا‬O<–6‫ و‬O<n+
1C ‫*رم‬M‫ ا‬x‫ﺱ‬4
`‫ 

ا‡ﺱ‬ABC
C‫ي ﺱ‬2‫ ا‡ﺱ` وا‬pIC *‫ وه‬Far : ‫اـ‬-
.‫ا‬O<I+‫ ا‬C
<rn‫ وا‬xO'‫ا‬

:7‫ آ‬%B‫ آ‬%‫د‬rI‫ ا‬Vn67

:‫آد‬

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(
:‫آد‬

device.Transform.View = Matrix.LookAtLH(new Vector3(0,0,-30), new


Vector3(0,0,0), new Vector3(0,1,0));
,(%F‫و‬$‫ ا‬%B4O~ Culling Face (‫ اـ‬VB&6 %Or 1<BC x‡: ً‫ﺱدﺱ‬
OSP ‫ي‬2‫ ا‬%F*‫ وه* ا‬$‫ ا‬,MBy‫ن أ و‬SF‫ﺱ` و‬F "+
$‫ ا‬%F*‫ﻩ ا‬n‡ _<‫ ﺡ‬R‫ا‬O( ‰ ‫ي‬2‫ ا‬%F*‫ وه* ا‬MBj‫ ا‬,1‫أ‬
)."M‫ﺱ‬$4 "+9‫ ا‬A‫ إ‬OP(‫)أ‬
:‫ وه‬Culling ‫ـ‬B ‫ ﺡ‰ت‬%[h[
F*
%<MBj‫ ا‬%F‫و‬$‫ء )ا‬My‫ )إ‬%B4O~ %<BIC ‫ إ–ء‬1r 7‫وا‬Cull.None :
."‫" آ‬+94
‫'رب‬C E ‫ 
ور‬7‫ت ا‬BI‫ ا‬%B4O~ 1r 7‫وا‬Cull.Clockwise :
.%C‫اﺱ‬
‫ 
ور‬7‫ت ا‬BI‫ ا‬%B4O~ 1r 7‫وا‬Cull.CounterClockwise :
).%<W‫ا‬O7]‫ ا‬%‫ا ه ا‬2‫ )وه‬%C‫'رب اﺱ‬C ;+C

‫ﺱم‬F$‫ ا‬E<IF ‫ ﺹ‬ABC ‫( وه* '*م‬Clipping), ‫ اـ‬VB&6 :ًr4‫ﺱ‬


%({ ,"M‫ﺱ‬$4 "+9‫ ا‬A‫ إ‬OP(‫ أ‬,‫*ر‬P1I‫رج ﺡ
ود ا‬y  E' 7‫ا‬
_BI‫  ا‬OI‫ﺡ‬$‫ وا‡Ÿء ا‬A "+8 _BI‫ر ا‬SŒ‫ إ‬4 ‫ﺱ*ف '*م‬
CPU ‫ و اـ‬GPU ‫ اـ‬VO %<BIr‫ ا‬R2‫ ه‬C, ‫'ﺹ ا‡Ÿء‬4 ‫ وﺱ<'*م‬B, "+8
%'&1 ‫رج‬y EW*7 7‫ﺱ*ت ا‬O‫ ا‬%‡r ‫ء‬1C  ‫ة‬O‫اآ‬2‫وا‬
.‫*ر‬P1I‫ا‬
"<6M74 C `B+71‫ءة( ﺡ<_ ﺱ‬W]‫ ا‬Lighting (‫*ع اـ‬W*: ً1[
%I<'‫ ا‬4 ‫ﻩ‬rK( 1(D4 %B‫ﺡ‬OI‫ ا‬R2‫ ه‬A‫ إ‬M+‫ و‬,%‫
روس ا'د‬4
false

:7‫" ا‬+94, hC$4 ‫'ط‬1‫ ا‬E<IF ‫<ﺹ‬B 11+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 class WinForm : System.Windows.Forms.Form


{
private Device device;
private System.ComponentModel.Container components = null;

public WinForm()
{

InitializeComponent();

this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);

public void InitializeDevice()

PresentParameters presentParams = new


PresentParameters();

presentParams.Windowed = true;

presentParams.SwapEffect = SwapEffect.Discard;

device = new Device(0, DeviceType.Hardware, this,


CreateFlags.SoftwareVertexProcessing, presentParams);

protected override void


OnPaint(System.Windows.Forms.PaintEventArgs e)

{
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.RenderState.Lighting = false;

device.RenderState.CullMode = Cull.None ;
device.RenderState.Clipping = true;

CustomVertex.PositionColored[] vertices = new


CustomVertex.PositionColored[3];

vertices[0].SetPosition(new Vector3(0f, 0f, 0f));

vertices[0].Color = Color.Red.ToArgb();

vertices[1].SetPosition(new Vector3(10f, 0f, 0f));

vertices[1].Color = Color.Green.ToArgb();

vertices[2].SetPosition(new Vector3(5f, 10f, 0f));

vertices[2].Color = Color.Yellow.ToArgb();

device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);

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);

private void InitializeComponent()

this.components = new System.ComponentModel.Container();

this.Size = new System.Drawing.Size(500,500);

this.Text = "DirectX Tutorial";

static void Main()

using (WinForm our_directx_form = new WinForm())

our_directx_form.InitializeDevice();

Application.Run(our_directx_form);
‫}‬

‫}‬

‫}‬

‫}‬

‫‪*+B run "IC


1C‬د ‪ hC$4‬ﺱ<‪ OSP‬ا‪$4 "+9‬ﺱ‪:"M‬‬

‫‪----‬‬
‫إ(‪ 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

:U‫ وه‬U‫و‬5‫ ا‬#‫


ا‬$%‫ي ) ا‬2‫( وا‬A) ='59 7R‫ ا‬U> X$=*
x = ٢-
y=٨
:U‫ ا* وه‬#‫
ا‬$%‫وا‬
x = ٨-
y=٢

‫ر‬D)‫@ ا‬A' ١٢ ‫
ار‬d9 A 7RA ‫ أر
' إ*)ب‬U*‫ن أ‬c‫ ا‬d/
y‫ر‬D)‫@ ا‬A' -١٠ ‫
ار‬dE‫و‬x ,
(B).7R‫ ا‬N/‫ ا‬U> /g‫ﻉ‬

K. *‫ا وإ‬27‫ت ه‬A‫ اﻉ‬K. i j7>‫!ا‬I‫ ا‬K' U9 dd)‫ ا‬U>


l!m &' K. ‫ت‬A‫ اﻉ‬n*‫! آ‬E5‫دئ ا‬9 U> ,‫>ت‬DC‫ اﺹ‬g‫ا‬D9
‫>ت‬DC‫!وا اﺹ‬79‫ﻉ
ه إ‬9‫( و‬x,y,z), U‫ وه‬#=‫>ت ا‬DC‫اﺹ‬
9‫ ا!ا‬U#‫
ا‬$%‫ ا‬2vw x$ (x,y,z,w) U‫وه‬x٤ Matrix ٤ '9!‫ا‬
K' U> ,>DC‫ازن اﺹ‬D. @A' ‫ظ‬C)A
$‫ وا‬d‫(دا ً ا‬w)
:!‫!ة أآ‬7C‫ ا‬BVD UA‫ اﻉ‬l:g‫& ا‬E H>‫
أ‬4D i ‫ت‬V!‫ا‬
‫ﻩ‬A' ‫!ي‬I*‫( و‬B). 7R‫( وا‬A) 7R‫'= ا‬59 ‫ ال‬jC* 2vw/
.‫*)ب‬%‫> ا‬DC‫ﺹ‬E ‫
ام‬-|9 ‫*)ب‬%‫ ا‬A'
:‫ اﻉد ا‬U9 ‫*)ب‬%‫> ا‬DC‫ﺹ‬E Ug‫ﻉ‬.
------------
‫!اه‬. U‫ ا‬V!‫=ت ا‬D)‫ء وا‬/‫ا اﻉ‬2‫& ه‬E DirectX ‫ اـ‬/$‫أرا‬
v‫
ا‬9 V‫ و‬UC7> Translation() ‫
ام ا
ا‬-|9 8‫'= وذ‬59
:Uƒ:9 C7 D‫*)ب وه‬%‫ت ا‬#‫
ا‬$‫& إ‬Dd‫ا‬
:‫آد‬

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 class WinForm : System.Windows.Forms.Form


{
private Device device;
private System.ComponentModel.Container components = null;

public WinForm()
{

InitializeComponent();

this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);

public void InitializeDevice()

PresentParameters presentParams = new


PresentParameters();

presentParams.Windowed = true;

presentParams.SwapEffect = SwapEffect.Discard;

device = new Device(0, DeviceType.Hardware, this,


CreateFlags.SoftwareVertexProcessing, presentParams);

protected override void


OnPaint(System.Windows.Forms.PaintEventArgs e)

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;

CustomVertex.PositionColored[] vertices = new


CustomVertex.PositionColored[3];

vertices[0].SetPosition(new Vector3(0f, 0f, 0f));

vertices[0].Color = Color.Red.ToArgb();

vertices[1].SetPosition(new Vector3(10f, 0f, 0f));

vertices[1].Color = Color.Green.ToArgb();

vertices[2].SetPosition(new Vector3(5f, 10f, 0f));

vertices[2].Color = Color.Yellow.ToArgb();

device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);

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);

private void InitializeComponent()

this.components = new System.ComponentModel.Container();

this.Size = new System.Drawing.Size(500,500);

this.Text = "DirectX Tutorial";

}
static void Main()
{
using (WinForm our_directx_form = new WinForm())
{
our_directx_form.InitializeDevice();

Application.Run(our_directx_form);
}
}
}
}
Rotation‫اـ‬-

z‫ و‬y ‫ و‬x ‫ر‬D)‫ل ا‬D$ ‫


ار ااو‬d9 KI‫
و! ا‬. :‫و‬

,‫ت‬#‫
ا‬$%‫ر ا‬D)E @A' K4 ‫ 
ي‬:U‫ ا
وران آ‬A' -.
,4‫ در‬٣٠ ‫او ƒ
ره‬9 KI‫ا ا‬2N (Rotation) ‫وأرد* أن *ﻉ‬
:C59 7R‫ ا‬U> ‫! آ‬NT>

: E‫ ه‬V‫ت ر‬T$=E

‫
م ا
ا‬-.‫( و‬Radian) ‫!ادن‬9 ‫ن‬D7. ‫ت اوا‬4‫ در‬4 :ًi‫أو‬
‫م‬T* &E D)‫ ا‬4‫& أ‬E Geometry.DegreeToRadian ‫ا‬
(Radian).‫ت إ@ اـ‬4‫ا
ر‬

)C59 7R‫! إ@ ا‬T*‫ ا


وران( أ‬U> d!m ‫ر‬D)E 7 :ً*#
‫‪ -/‬ا‪ !E5‬آ‪!C/ :U‬ض أن 
ي ا‪ C59 7R‬وه‪! m D‬ة‬
‫‪!E‬و‪:$‬‬

‫ا‪c‬ن ‪Dd/‬م ‪9‬ﻉ دوران ‪ 12N‬ا‪! g‬ة ‪9‬او ƒ


ره ‪ ٣٠‬در‪@A' 4‬‬
‫ا)‪D‬ر ‪ X,‬ﺹ‪ NA7† B:‬آ‪:U‬‬
‫ا‪c‬ن ‪Dd/‬م ‪9‬ﻉ دوران ‪ 12N‬ا‪! g‬ة ‪9‬او ƒ
ره ‪ ٣٠‬در‪@A' 4‬‬
‫ا)‪D‬ر ‪ Y,‬ﺹ‪ NA7† B:‬آ‪:U‬‬

‫ا‪c‬ن ‪Dd/‬م ‪9‬ﻉ دوران ‪ 12N‬ا‪! g‬ة ‪9‬او ƒ


ره ‪ ٣٠‬در‪@A' 4‬‬
‫ا)‪D‬ر ‪ Z,‬ﺹ‪ NA7† B:‬آ‪:U‬‬
‫‪ '
/' :ً#‬دوران )‪2N> ,KIA (Rotation‬ا ﻉ‪w9 U/‬ن ا‪
$%‬ا‪#‬ت‬
‫ا‪ ƒ “)9 !G 
d‬ااو اﻉ‪.1g‬‬
‫ر‪ &E ًV‬أ‪$ 4‬ب ه‪ 12‬ا‪d/‬ط ا‪

I‬ة‪ 4)9 &)/> ,‬إ@‬
‫ا‪
$%‬ا‪#‬ت ا‪ 
d‬و اـ ‪ Cos‬و اـ ‪ Sin‬او ا
وران ‪.‬‬

‫‪
:/‬أ ‪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‫ت ا‬#‫
ا‬$‫إ‬
:‫آد‬

vertices[0].SetPosition(new Vector3(0f, 0f, 0f));


vertices[1].SetPosition(new Vector3(10f, 0f, 0f));
vertices[2].SetPosition(new Vector3(5f, 10f, 0f));
:U‫ ه‬X ‫ر‬D)A ‫> ا
وران‬DC‫ﺹ‬E
: U‫و‬5‫ ا‬gd/‫ا‬
:‫آد‬

vertices[0].SetPosition(new Vector3(0f, 0f, 0f));


‫ )ب‬U'‫
دا‬4D => ‫ إذن‬,!C0 ‫وي‬. #=‫ أن ا)ور ا‬9
).٠،٠،٠) U‫ آ ه‬Ud: I/‫ن ا‬5 ‫=ف‬v%‫ا‬

: *‫ ا‬gd/‫ا‬
:‫آد‬

vertices[1].SetPosition(new Vector3(10f, 0f, 0f));

:‫ ا‬gd/‫ا‬
:‫آد‬

vertices[2].SetPosition(new Vector3(5f, 10f, 0f));


:4‫ در‬١٨٠ ‫او‬9 ‫ ا
وران‬A'
‫ﻉ‬9 ‫

ة‬I‫ ا‬xA‫ت ا‬#‫
ا‬$‫إ‬

:‫آد‬

vertices[0].SetPosition(new Vector3(0f, 0f, 0f));


vertices[1].SetPosition(new Vector3(10f, 0f, 0f));
vertices[2].SetPosition(new Vector3(5f, -10f, 0f));
-----------
KA‫ﻉ‬. ‫ أن‬UC7 1='‫ أ‬l: E ‫& آ‬E ! @A' 8‫ﻉ‬Am‫ن أ‬c‫ ا‬U/'‫د‬
U‫ت ا‬9)‫ء ا‬/' &E /)!. ‫ دا‬DirectX ‫ اـ‬U>
4D :U‫ا‬
:U‫'= وه‬59
X‫ر‬D)‫@ ا‬A' ‫دا ا
وران‬
:‫آد‬

device.Transform.World = Matrix.RotationX();
Y‫ر‬D)‫@ ا‬A' ‫دا ا
وران‬

:‫آد‬

device.Transform.World = Matrix.RotationY();

Z‫ر‬D)‫@ ا‬A' ‫دا ا


وران‬

:‫آد‬

device.Transform.World = Matrix.RotationZ();

(X,Y,Z)#=‫@ ا)ور ا‬A' ‫دا ا


وران‬
:‫آد‬

device.Transform.World = Matrix. RotationAxis ();

‫ر‬D)‫@ ا‬A' 4‫ در‬١٨٠ ‫او‬9 ‫ ا


وران‬D‫'= وه‬59 ‫) ال‬9 ‫م‬Dd/
As a pies of Cake ً ‫م أذ* دا‬Dd ‫ وآ‬m:‫ ا‬G9 )‫ا‬X,
.Uƒ:9 C7 OnPaint ‫ ا
ا‬U> !g‫ا ا‬2‫> ه‬V‫ إ‬UC7>

:‫آد‬

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

public class WinForm : System.Windows.Forms.Form


{
private Device device;
private System.ComponentModel.Container components = null;
private float angle ;
public WinForm()
{

InitializeComponent();

this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);

public void InitializeDevice()

PresentParameters presentParams = new


PresentParameters();

presentParams.Windowed = true;

presentParams.SwapEffect = SwapEffect.Discard;

device = new Device(0, DeviceType.Hardware, this,


CreateFlags.SoftwareVertexProcessing, presentParams);
}

protected override void


OnPaint(System.Windows.Forms.PaintEventArgs e)

device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, -1f, 1f);

device.Transform.View = Matrix.LookAtLH(new Vector3(0,0,-


30), new Vector3(0,0,0), new Vector3(0,1,0));

device.Transform.World =
Matrix.RotationX (Geometry.DegreeToRadian (180));

device.RenderState.Lighting = false;

device.RenderState.CullMode = Cull.None ;
device.RenderState.Clipping = true;

CustomVertex.PositionColored[] vertices = new


CustomVertex.PositionColored[3];

vertices[0].SetPosition(new Vector3(0f, 0f, 0f));

vertices[0].Color = Color.Red.ToArgb();

vertices[1].SetPosition(new Vector3(10f, 0f, 0f));

vertices[1].Color = Color.Green.ToArgb();

vertices[2].SetPosition(new Vector3(5f, 10f, 0f));

vertices[2].Color = Color.Yellow.ToArgb();

device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);

device.BeginScene();
device.VertexFormat =
CustomVertex.PositionColored.Format;

device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);

device.EndScene();

device.Present();

this.Invalidate();
angle += 0.05f;

protected override void Dispose (bool disposing)

if (disposing)

if (components != null)

components.Dispose();

base.Dispose(disposing);

private void InitializeComponent()

this.components = new System.ComponentModel.Container();

this.Size = new System.Drawing.Size(500,500);


this.Text = "DirectX Tutorial";

static void Main()

using (WinForm our_directx_form = new WinForm())

our_directx_form.InitializeDevice();

Application.Run(our_directx_form);

:U‫ ا‬7R‫! ا‬NT> ='59 ‫د‬D7A RUN '


/'
.. 
‫ا‬. ‫او‬9 ‫ 
ور‬KI‫ﻉ ا‬I* ‫ن‬w9 H* ‫ن أن‬c‫ ا‬8‫ رأ‬E
:8‫ﻉ ذ‬
:U‫ آ‬angle K%‫ ا‬g‫ﻉ‬/‫! و‬GE &' B!‫ﺹ‬9 ‫م‬Dd*: ًi‫أو‬
:‫آد‬

private float angle ;


12‫ زادت ه‬A7> , ٠™٠٥ &7‫ا
 و‬. ƒ ‫ء ااو‬g'|9 ‫م‬Dd*: ً*#
.KI‫ !' دوران ا‬9d9 ‫ زاد‬d‫ا‬
:‫آد‬

angle += 0.05f;
:U‫ آ‬angle ‫ء دا ا
وران ƒ اـ‬g'‫إ‬: ً#
:‫آد‬

device.Transform.World = Matrix.RotationX (angle);


:ً=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 class WinForm : System.Windows.Forms.Form


{
private Device device;
private System.ComponentModel.Container components = null;
private float angle ;
public WinForm()
{

InitializeComponent();

this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
}

public void InitializeDevice()

PresentParameters presentParams = new


PresentParameters();

presentParams.Windowed = true;

presentParams.SwapEffect = SwapEffect.Discard;

device = new Device(0, DeviceType.Hardware, this,


CreateFlags.SoftwareVertexProcessing, presentParams);

protected override void


OnPaint(System.Windows.Forms.PaintEventArgs e)

device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, -1f, 1f);

device.Transform.View = Matrix.LookAtLH(new Vector3(0,0,-


30), new Vector3(0,0,0), new Vector3(0,1,0));

device.Transform.World =
Matrix.RotationX (angle);

device.RenderState.Lighting = false;

device.RenderState.CullMode = Cull.None ;
device.RenderState.Clipping = true;

CustomVertex.PositionColored[] vertices = new


CustomVertex.PositionColored[3];

vertices[0].SetPosition(new Vector3(0f, 0f, 0f));


vertices[0].Color = Color.Red.ToArgb();

vertices[1].SetPosition(new Vector3(10f, 0f, 0f));

vertices[1].Color = Color.Green.ToArgb();

vertices[2].SetPosition(new Vector3(5f, 10f, 0f));

vertices[2].Color = Color.Yellow.ToArgb();

device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);

device.BeginScene();

device.VertexFormat =
CustomVertex.PositionColored.Format;

device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);

device.EndScene();

device.Present();

this.Invalidate();
angle += 0.05f;

protected override void Dispose (bool disposing)

if (disposing)

if (components != null)

components.Dispose();
}

base.Dispose(disposing);

private void InitializeComponent()

this.components = new System.ComponentModel.Container();

this.Size = new System.Drawing.Size(500,500);

this.Text = "DirectX Tutorial";

static void Main()

using (WinForm our_directx_form = new WinForm())

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

public class WinForm : System.Windows.Forms.Form


{
private Device device;
private System.ComponentModel.Container components = null;
private float angle ;
public WinForm()
{

InitializeComponent();

this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);

public void InitializeDevice()

PresentParameters presentParams = new


PresentParameters();

presentParams.Windowed = true;

presentParams.SwapEffect = SwapEffect.Discard;

device = new Device(0, DeviceType.Hardware, this,


CreateFlags.SoftwareVertexProcessing, presentParams);

protected override void


OnPaint(System.Windows.Forms.PaintEventArgs e)

{
device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, -1f, 1f);

device.Transform.View = Matrix.LookAtLH(new Vector3(0,0,-


30), new Vector3(0,0,0), new Vector3(0,1,0));

device.Transform.World =
Matrix.RotationAxis (new Vector3 (2,2,2),angle);

device.RenderState.Lighting = false;

device.RenderState.CullMode = Cull.None ;
device.RenderState.Clipping = true;

CustomVertex.PositionColored[] vertices = new


CustomVertex.PositionColored[3];

vertices[0].SetPosition(new Vector3(0f, 0f, 0f));

vertices[0].Color = Color.Red.ToArgb();

vertices[1].SetPosition(new Vector3(10f, 0f, 0f));

vertices[1].Color = Color.Green.ToArgb();

vertices[2].SetPosition(new Vector3(5f, 10f, 0f));

vertices[2].Color = Color.Yellow.ToArgb();

device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);

device.BeginScene();

device.VertexFormat =
CustomVertex.PositionColored.Format;

device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);

device.EndScene();
device.Present();

this.Invalidate();
angle += 0.05f;

protected override void Dispose (bool disposing)

if (disposing)

if (components != null)

components.Dispose();

base.Dispose(disposing);

private void InitializeComponent()

this.components = new System.ComponentModel.Container();

this.Size = new System.Drawing.Size(500,500);

this.Text = "DirectX Tutorial";

static void Main()


{

using (WinForm our_directx_form = new WinForm())

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

public class WinForm : System.Windows.Forms.Form


{
private Device device;
private System.ComponentModel.Container components = null;
// private float angle ;
public WinForm()
{

InitializeComponent();

this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);

public void InitializeDevice()

PresentParameters presentParams = new


PresentParameters();

presentParams.Windowed = true;

presentParams.SwapEffect = SwapEffect.Discard;

device = new Device(0, DeviceType.Hardware, this,


CreateFlags.SoftwareVertexProcessing, presentParams);

protected override void


OnPaint(System.Windows.Forms.PaintEventArgs e)

device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, -1f, 1f);

device.Transform.View = Matrix.LookAtLH(new Vector3(0,0,-


30), new Vector3(0,0,0), new Vector3(0,1,0));

device.Transform.World =
Matrix.RotationX((System.Environment.TickCount / 450.0f));

device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None ;
device.RenderState.Clipping = true;

CustomVertex.PositionColored[] vertices = new


CustomVertex.PositionColored[3];

vertices[0].SetPosition(new Vector3(0f, 0f, 0f));

vertices[0].Color = Color.Red.ToArgb();

vertices[1].SetPosition(new Vector3(10f, 0f, 0f));

vertices[1].Color = Color.Green.ToArgb();

vertices[2].SetPosition(new Vector3(5f, 10f, 0f));

vertices[2].Color = Color.Yellow.ToArgb();

device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);

device.BeginScene();

device.VertexFormat =
CustomVertex.PositionColored.Format;

device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);

device.EndScene();

device.Present();

this.Invalidate();
// angle += 0.05f;

protected override void Dispose (bool disposing)

if (disposing)
{

if (components != null)

components.Dispose();

base.Dispose(disposing);

private void InitializeComponent()

this.components = new System.ComponentModel.Container();

this.Size = new System.Drawing.Size(500,500);

this.Text = "DirectX Tutorial";

static void Main()

using (WinForm our_directx_form = new WinForm())

our_directx_form.InitializeDevice();

Application.Run(our_directx_form);

}
}

}
:‫ا
رس ا‬

Scaling‫اـ‬-
Scaling ‫ و اـ‬Rotation ‫ و اـ‬Translation ‫ ـ‬Matrix ‫ اـ‬-

--------------------

Scaling‫اـ‬-

z .‫ و‬y ‫ و‬x ‫* ا)('هت‬+ ,-'‫ ا‬./0(‫ و‬.12( :"#$‫ و‬Scaling ‫اـ‬

:<.6‫ﺡ" ا;>ط ا‬$ ,- ‫ض أن 


ي‬D; :*6‫ل ا‬#‫ ا‬89:;
٤ ‫وي‬-$ Y ‫ر‬H‫ واﺡ‬-------- ٤ ‫وي‬-$ X ‫ر‬H‫ اﺡ‬: *‫و‬G‫ ا‬EF>;‫ا‬
٤- ‫وي‬-$ Y ‫ر‬H‫ واﺡ‬-------- ٤- ‫وي‬-$ X ‫ر‬H‫ اﺡ‬: E.L#‫ ا‬EF>;‫ا‬
(A)"2M‫* ا‬+ ‫آ‬

TR ‫ن‬H2( V.‫ﺡ‬W (A), "2M‫ ا‬TR Scaling "R


$‫* أر‬L‫ن أ‬S‫;>" ا‬
.٢ ‫وي‬-( Y ‫ر‬H‫ اﺡ‬TR‫ و‬٢/١ (X0L X (‫ر‬H‫اﺡ‬
\8‫`
م ه‬6-;‫ ﺱ‬V.‫ ﺡ‬DirectX ‫" اـ‬D$ ‫ آ‬E:-‫\ ا‬8‫;ﺡ" ه‬
(Matrix):E+HD0‫ا‬
‫ﺡ‪ ً;-‬ا‪S‬ن إذا ‪ f gd‬أر * ا'‪ ,-‬إ‪ T‬ﺡ‪ <6‬ا‪G‬و‪"1d T‬‬
‫إﺡ
اث ‪ E.R‬اـ ‪) <.R Scaling‬أي إرع ا'‪ jk ,-‬ا‪ B "2M‬إ‪T‬‬
‫ا‪A)."2‬‬
:*6‫ آ‬o106 (Matrix) E+HD0‫س ا‬H2k ‫`
م‬6-L ‫ن‬8n
;R

----

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‫اﺡ‬
٠ ‫وي‬-$

:‫آد‬

device.Transform.World = Matrix.Scaling (1,2,0);

:ً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

public class WinForm : System.Windows.Forms.Form


{
private Device device;
private System.ComponentModel.Container components = null;
private float angle ;
public WinForm()
{

InitializeComponent();

this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);

public void InitializeDevice()

PresentParameters presentParams = new


PresentParameters();

presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;

device = new Device(0, DeviceType.Hardware, this,


CreateFlags.SoftwareVertexProcessing, presentParams);

protected override void


OnPaint(System.Windows.Forms.PaintEventArgs e)

device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, -1f, 1f);

device.Transform.View = Matrix.LookAtLH(new Vector3(0,0,-


30), new Vector3(0,0,0), new Vector3(0,1,0));

device.Transform.World =
Matrix.Scaling (1,2,0);

device.RenderState.Lighting = false;

device.RenderState.CullMode = Cull.None ;
device.RenderState.Clipping = true;

CustomVertex.PositionColored[] vertices = new


CustomVertex.PositionColored[3];

vertices[0].SetPosition(new Vector3(0f, 0f, 0f));

vertices[0].Color = Color.Red.ToArgb();

vertices[1].SetPosition(new Vector3(10f, 0f, 0f));

vertices[1].Color = Color.Green.ToArgb();

vertices[2].SetPosition(new Vector3(5f, 10f, 0f));

vertices[2].Color = Color.Yellow.ToArgb();

device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);


device.BeginScene();

device.VertexFormat =
CustomVertex.PositionColored.Format;

device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);

device.EndScene();

device.Present();

this.Invalidate();
angle += 0.05f;

protected override void Dispose (bool disposing)

if (disposing)

if (components != null)

components.Dispose();

base.Dispose(disposing);

private void InitializeComponent()

this.components = new System.ComponentModel.Container();


this.Size = new System.Drawing.Size(500,500);

this.Text = "DirectX Tutorial";

static void Main()

using (WinForm our_directx_form = new WinForm())

our_directx_form.InitializeDevice();

Application.Run(our_directx_form);

:*6‫" ا‬2M‫; ا‬.F.-+ ‫د‬H2‫ا ا‬8{ RUN "R


;R
Scaling ‫ و اـ‬Rotation ‫ و اـ‬Translation ‫ ـ‬Matrix ‫ اـ‬-

‫ب‬r‫  و~ح و‬E.D.‫ آ‬jR ,26;‫ ﺱ‬E.‫\ ا‬8‫ ه‬,{+ "‫ أ‬jk‫و‬
(Matrix)‫ت‬+HD0‫ا‬

:'‫ ا‬E.W ‫
أ‬1L
(B):E+HD0‫( وا‬A) E+HD0‫ن 
ي ا‬:W ‫ض‬D;

:*6‫ن آ‬H2.‫ﺡﺹ" { ﺱ‬

!

:*6‫ن آ‬H2.‫ﺡﺹ" ~ﺡ{ ﺱ‬

!
:*6‫ن آ‬H2.‫{ ﺱ‬Wr "‫ﺡﺹ‬

----------------------------

......f‫ ذ‬TR *R 89:;

W ‫ اـ‬Z = ٠ ‫ اـ‬Y= ٠ ‫ اـ‬X = ٥ ‫ اـ‬E.6‫ت ا‬.€‫ﺡ" ا)ﺡ


ا‬$ ‫; ع‬$

‫م‬H>;= ١
E€q#‫ اﺡور ا‬TR ٥/١ ‫ أي‬٥ TR ١ ‫>
ار‬W < Scaling "W :ً…‫أو‬
x,y,z
y ‫ر‬H‫ل اﺡ‬H‫ن ﺡ‬$‫ راد‬٤ / ‫ي‬W ‫>
ار‬W < Rotation "W :ً.L€
‫ر‬H‫ اﺡ‬TR ٢ ‫ و‬x ‫ر‬H‫ اﺡ‬TR ١ ‫>
ار‬W < Translation "W :ً#€
z‫ر‬H‫ اﺡ‬TR ٣- ‫و‬y
) ?,-'‫ع )ا‬M‫ا ا‬8{ ‫
ة‬$
'‫ت ا‬.€‫ˆ ا)ﺡ
ا‬-‫إﺡ‬

----------------------

‫ˆ اـ‬-‫ﺡ‬L ‫ة‬HF9 ‫" (اآ* أي أن أول‬2MW E.‫\ ا‬8‫ن ه‬H2(


89:L‫ و‬Rotation ‫{ اـ‬.R v1FL ,€ jk‫ و‬E'.6;‫ ا‬89:L‫و‬Scaling
Translation‫{ اـ‬.R v1F; E'.6;‫ا‬
:"‫اﺡ‬
!
‫Šه‬1W ‫ت‬+HD0k E€q#‫ب ا‬r *‫ى ﺡ" وه‬9‫ أ‬E>$~ ‫أو ه;ك‬
... 1‫ا‬

:1‫Š{ ا‬1W ‫ت‬+HD0k E€q#‫'* Šب ا‬k1‫د ا‬H2‫;ى ا‬

:‫آد‬

device.Transform.World = Matrix.Scaling (2,2,0) * Matrix.RotationX


(Geometry.DegreeToRadian (180))* Matrix.Translation (0,10,1);

:ً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

public class WinForm : System.Windows.Forms.Form


{
private Device device;
private System.ComponentModel.Container components = null;
private float angle ;
public WinForm()
{

InitializeComponent();

this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);

public void InitializeDevice()


{

PresentParameters presentParams = new


PresentParameters();

presentParams.Windowed = true;

presentParams.SwapEffect = SwapEffect.Discard;

device = new Device(0, DeviceType.Hardware, this,


CreateFlags.SoftwareVertexProcessing, presentParams);

protected override void


OnPaint(System.Windows.Forms.PaintEventArgs e)

device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, -1f, 1f);

device.Transform.View = Matrix.LookAtLH(new Vector3(0,0,-


30), new Vector3(0,0,0), new Vector3(0,1,0));

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;

CustomVertex.PositionColored[] vertices = new


CustomVertex.PositionColored[3];

vertices[0].SetPosition(new Vector3(0f, 0f, 0f));

vertices[0].Color = Color.Red.ToArgb();
vertices[1].SetPosition(new Vector3(10f, 0f, 0f));

vertices[1].Color = Color.Green.ToArgb();

vertices[2].SetPosition(new Vector3(5f, 10f, 0f));

vertices[2].Color = Color.Yellow.ToArgb();

device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);

device.BeginScene();

device.VertexFormat =
CustomVertex.PositionColored.Format;

device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
vertices);

device.EndScene();

device.Present();

this.Invalidate();
angle += 0.05f;

protected override void Dispose (bool disposing)

if (disposing)

if (components != null)

components.Dispose();

}
base.Dispose(disposing);

private void InitializeComponent()

this.components = new System.ComponentModel.Container();

this.Size = new System.Drawing.Size(500,500);

this.Text = "DirectX Tutorial";

static void Main()

using (WinForm our_directx_form = new WinForm())

our_directx_form.InitializeDevice();

Application.Run(our_directx_form);

}
:*6‫" ا‬2M‫; ا‬$
 {u.-+ qRGW ‫د‬H2 RUN "R
;R
‫‪( k‬ﺡ‪.‬ت ا‪ k1‬ه‪ *L‬اŽاوي ا‪u6L‬و‪ *+ L‬ا
رس ا>دم‬
: ‫ا رس ا دي‬

Vertex Math‫ا ـ‬-


Vertex Buffer‫ا ـ‬-
--------------------

Vector Math (Vertex)‫ا ـ‬-


12 ‫ ا‬3 ‫ إ‬4+‫ و"! ار )أ‬$%&‫!*) ( إ‬+ , ‫رة‬. /‫ وه‬Vector, ‫ا ـ‬
)16789

:16789 12 ‫ ا‬3 ‫ إ‬4+‫ أ‬,‫(ﻩ‬%>? ‫ت ا‬:?2 ‫) وا‬A‫ د‬B ‫ت ا‬:?2 ‫ ا‬,:9 ‫ق‬6<
:)A‫ د‬B ‫ ا‬E:! ‫ ا‬:ًD‫أو‬
:/ > ‫ل ا‬G? ‫ ا‬HIJ<

/‫ وه‬Normalization Vector ‫) ا ـ‬A4+ (:M N.*< v ‫ و‬u K89 ‫ل‬G? ‫ ا‬,"


‫ع‬B^ /9 /?‫ و&ﺱ‬, ‫ واﺡ‬/ )A‫ "ﺱو‬Vectors ‫ال ا ـ‬UV‫ أ‬W:?X 1B%+ ‫أن‬
:‫اﺡ ة‬U ‫ا‬
‫_‪ ً:+‬ا !‪ E:‬ا ?>‪(%‬ﻩ‪:‬‬
‫‪U!+‬ل ‪J9‬ن هذان ا ?>‪(%‬ن )‪>" (Vectors‬ﺱو‪A‬ن ‪U2& " < /a‬ن‪:‬‬

‫‪U2A‬ن ‪ W?X‬و‪V‬ح و‪c‬ب ا ـ ‪ Vectors‬آ > ‪:/‬‬

‫‪ /&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 ,
:‫آد‬

new VertexBuffer(typeof(CustomVertex.PositionColored ), 3, device,


Usage.Dynamic |
Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default);
:‫>ات‬:"‫را‬9 ‫)  ة‬j6 ‫ ا‬$H‫ ه‬1?& ...‫ى‬+ ?‫آ‬

(PositionColored, ‫ﻩ‬B" 1"B> ‫ ا ?اد ا‬Vertex ‫ع ا ـ‬U+ A > :‫ول‬8‫ا‬


Vertex ‫ع ا ـ‬U+ A >9 s?t ‫ ة إذا‬t ‫ه‬HIPositionNormal, … etc) ,
‫ا‬H‫ ه‬, ‫د‬U2 ‫اء ا‬oX‫ أ‬W:?%9 ‫ح‬z>7 {+J9 /<BA ‫ا‬H(a PositionColored ,2: ‫و‬
.‫ﺱﻩ‬6+ Vectex ‫ا ـ‬

Maximum Number‫ﻩ ا ـ‬:a W|+ ً‫ ودة‬Vertex ‫  د ا ـ‬U‫ وه‬:/+G ‫ا‬

‫ آت‬, <?M2& " < $+J+‫ي أ‬H ‫ ا‬,2M W9& U‫ وه‬Device ‫ ا ـ‬:~ G ‫ا‬
.)^ ‫ا‬

..(<"‫و‬, ‫ت‬:‫ﺡ‬Kz ‫ د ا‬A ‫ي‬H ‫ ا‬U‫ وه‬Usage ‫ ا ـ‬:W9‫ا ا‬


Clipping‫) ا ـ‬:‫ﺹ‬I /9 Vertex ‫ـ‬M ƒ?‫ﺱ‬A D ‫ي‬H ‫ر ا‬:r ‫ ا‬U‫وه‬DoNotClip
/a ‫ان‬U<B ‫ وا‬E% ‫>ﻩ ا‬9_ )!*<" o%9 ƒ:>A ‫ي‬H ‫ر ا‬:r ‫ ا‬U‫وه‬Dynamic
.‫اآة‬H ‫ا‬
.‫!ﻁ‬a ‫ ا <!ط‬W" 1"B> ‫ م < ا‬r>‫ﺱ‬A ‫ي‬H ‫ر ا‬:r ‫ ا‬U‫وه‬Points
‫ ا ـ‬/a Vertex ‫) ا ـ‬% B" ‫ﻩ‬:a E>& ‫ي‬H ‫ر ا‬:r ‫ ا‬U‫وه‬SoftwareProcessing
Software
Buffer ‫ ا ـ‬," ‫ ا !اءة‬W<" 1X‫ أ‬," ‫ م‬r>‫ﺱ‬A ‫ي‬H ‫ر ا‬:r ‫ ا‬U‫وه‬WriteOnly

Buffer ‫ ا ـ‬1I‫ ا‬9 )<Aor& ‫ ا ?اد‬Vertex ‫ع ا ـ‬U+ A > :"r ‫ا‬

:‫رات‬:I ‫ وه<ك  ة‬Buffer ‫ن ا ـ‬2" A > : Pool ‫ا ﺱدس‬


.1.t ," $+‫ي ﺡ د‬H ‫ وا‬Usage ‫ ا ـ‬3M ‫ر‬:r ‫ا ا‬H‫>? ه‬BADefault :
VGA‫ ا ـ‬1I‫ ا‬9 Vertex ‫ ا ـ‬,Aor& ):M? ‫ن‬U2&Managed :
RAM‫ ا ـ‬1I‫ ا‬9 Vertex ‫ ا ـ‬,Aor& ):M? ‫ن‬U2&SystemMemory :

---------
‫>د‬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 ();

: / > ‫ً آ‬K"‫د آ‬U2 ‫ƒ ي ا‬.z:


:‫آد‬

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,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.SetStreamSource(0, vb, 0);

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 ();
}

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondeivce ();
xx.Show ();

while (xx.Created )
{
xx.camera ();
xx.position ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}

:/ > ‫ ا‬12 ‫( < ا‬4:‫ﺱ‬a K89 ‫د‬U2M RUN 1? <

...‫ات‬:‘> ‫’ ا‬B9 ‫د‬U2 ‫ا ا‬H‫ ه‬/a “‫ﺡ‬K+


Vertex ‫ ا ـ‬/9 )‫ﺹ‬I ‫ى‬I‫ وأ‬Camera ‫ـ‬M )‫ﺹ‬I Function 1?B9 <?t ~:‫ﺡ‬
OnPaint) ‫ ا ا‬3M ‫< ا |‘ﻁ‬66I { H9‫ و‬Render ... ‫ ا ـ‬/9 ‫ى‬I‫وأ‬

)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
{

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,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.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.SetStreamSource(0, vb, 0);


device.VertexFormat =
CustomVertex.PositionColored .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 ();
}

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondeivce ();
xx.Show ();

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
:‫آد‬

verts[0].SetPosition (new Vector3 (-1.0f, 1.0f, 1.0f));


verts[0].Color = Color.Red.ToArgb
();

..)!A* ‫ ا‬$H(9 ‫>ﻩ‬9>29 s?t


:‫آد‬

verts[0] = new CustomVertex.PositionColored(-1.0f, 1.0f, 1.0f,


Color.Red.ToArgb());

).‫ <ﺱ‬9 1|a‫ أ‬E(A‫ أ‬/<> J7 ‫ إذا‬,‫آ‬8‫ و‬...... "‫ رو‬3 ‫دي إ‬J& ‫ ا *ق‬12a
):+G ‫!) ا‬A* ‫ل { ا‬UtJ7 .... ‫اآة‬H ‫ﻩ وا‬+:z ‫) ا‬:M?B

...I˜ ‫ل‬G" HIJ<


:16789 12 ‫ ا‬/a ?‫) آ‬BV!>" ‫ط‬U*I )B9‫ أر‬E7‫ ر‬A‫ أر‬/+‫ أ‬1!<
:{ ‫ ذا‬1?B
‫ب‬UM*? ‫ ا‬," G‫ أي أآ‬٩ /9 )?%‫ د ﺡ‬+‫ و‬VertexBuffer, 1?B9 ‫م‬U!<7 :ًD‫أو‬
‫ﻁ‬I 12 ‫ و‬٤ /‫ ه‬K89 12 ‫ ا‬/a ‫ن  د ا <!ط‬J9 “‫ﺡ‬K+ ~:‫اﺡ ﺡ‬U9
٨ ƒ.zA ‫!*>ن إذا‬+
:‫آد‬

vb = new VertexBuffer (typeof(CustomVertex.PositionNormalColored


),100,device,Usage.WriteOnly
,CustomVertex.PositionNormalColored.Format ,Pool.Default );
CustomVertex.PositionNormalColored [] cc =
(CustomVertex.PositionNormalColored [])vb.Lock (0,0);
?9‫ و‬for )M?X )A‫ار‬2> ‫ ا‬1?% ‫ ا‬," ‫ م‬r>‫<ﺱ‬7 (% ‫ وا‬stU ‫ ا‬:aU> : ً:+_
:/ > ‫ƒ آ‬.z>‫ﺱ‬a ‫!ط‬+ W9‫ أر‬E7‫ ر‬A‫ أر‬/+‫أ‬
:‫آد‬

for (int i =0;i<=4;i++)


NAV , )A‫او‬o ‫د ا‬%A‫إ‬: ًG _
/‫?( وه‬7‫ع ا <!ط ا ?اد ر‬U?%" E:‫( &!ﺱ‬i) ‫ د‬B ‫?) ا‬:t ‫ب‬c٣٦٠ (PI*٢)
٤
:‫آد‬

float theta = (float)(2 * Math.PI * i) / 4;


.)A‫او‬o ‫ ا‬sin /9 y )*!< ‫) وا‬A‫او‬o ‫ ا‬cos /9 x )*!< ‫ت ا‬:_‫د ا›ﺡ ا‬%A‫إ‬: ًB9‫را‬
:‫آد‬

cc[i*2].SetPosition (new Vector3 ((float)Math.Cos (theta),(float)Math.Sin


(theta),0));
DrawPrimitives ) ‫ ا ا‬/a (?7‫  د ا <!ط ا ?اد ر‬A >9 ‫م‬U!+: ً‫"ﺱ‬I
٨ ‫ و&ﺱوي‬٢ ‫ب‬c ٤ U‫<( وه‬:9 1:‫ﺹ‬U> ‫ن  د ا <!ط ا ?اد ا‬U2A‫و‬

:‫آد‬

device.DrawPrimitives (PrimitiveType.LineStrip ,0,8);

:ًK"‫د آ‬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
{

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,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 ();
}

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondeivce ();
xx.Show ();

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 ‫إ‬
:‫آد‬

device.DrawPrimitives (PrimitiveType.TriangleStrip ,0,8);


‫ان‬U 8‫ ا‬HIJ:7 ‫ﻩ‬+8 { ‫ وذ‬,:&?9 .‫ أآ‬VertexBuffer ‫ ا ـ‬E%‫ن ﺡ‬U2:7 ً|A‫وأ‬
١٨ ‫ و&ﺱوي‬٢ ‫ب‬c ٩ ‫ت أي‬:_‫وا›ﺡ ا‬

:ًK"‫د آ‬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
{

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,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 ();
}

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondeivce ();
xx.Show ();

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 ‫وا ـ‬

:16789 12 ‫ ا‬3 ‫ إ‬4+‫أ‬

:ًK"‫د آ‬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
{

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,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 ();
}

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondeivce ();
xx.Show ();

while (xx.Created )
{
xx.camera ();
xx.position ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
:)A4< ‫ ا‬6<9‫ و‬,W?t E7 :‫ل‬G"
)ac‫ إ‬/9 ‫م‬U!<7 ~:‫ﺡ‬

:‫آد‬

cc[i*2].SetPosition (new Vector3 ((float)Math.Cos (theta),(float)Math.Sin


(theta),0));
cc[i*2].SetPosition (new Vector3 ((float)Math.Cos (theta),(float)Math.Sin
(theta),2));

:/ > ‫ ا‬12 ‫( < ا‬4:


:ًK"‫د آ‬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
{

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,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].SetPosition (new Vector3
((float)Math.Cos (theta),(float)Math.Sin (theta),2));
cc[i*2].Color = Color.Aqua .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 (3,3,3),angle);

device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondeivce ();
xx.Show ();

while (xx.Created )
{
xx.camera ();
xx.position ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}

):)A4< ‫ ا‬6<9) /+‫ا‬U*7‫ إ‬12^ 1?B I˜ ‫ل‬G"

:ًK"‫د آ‬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
{

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,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].SetPosition (new Vector3
((float)Math.Cos (theta),(float)Math.Sin (theta),0));
cc[i*2].Color = Color.Gold .ToArgb ();

cc[i*2+1].SetPosition (new Vector3


((float)Math.Cos (theta),(float)Math.Sin (theta),1));
cc[i*2+1].SetPosition (new Vector3
((float)Math.Cos (theta),(float)Math.Sin (theta),1));
cc[i*2+1].Color = Color.Azure .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 (3,3,3),angle);

device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion
static void Main()
{
using (Form1 xx = new Form1 ())
{
xx.ondeivce ();
xx.Show ();

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‫أ‬

: 1 ‫\ آ‬+! ‫ت‬+-‫ ا‬.2‫ ا‬A]B1‫ @ﺱ‬H;Z‫ر @ ا‬B ‫ ا‬78‫ت ه‬8I‫أي  أ‬


.....Ya‫ أي آ‬/! ‫رة‬B ‫ل ا‬I‫ إد‬HX‫ أ‬YG ,! " ‫_ ا‬+]%1 ‫ ا‬8I` ‫ا^ن‬

,‫!* ا وع‬G :; HI‫  ا‬H;Z‫رة @ ا‬B ‫ ا‬78‫ ه‬ef ‫ م‬:ًd‫أو‬


RAAD W2‫\ ا‬+%"‫و‬

: 1 ‫ آ‬Texture +i1 ‫ ا‬Y A(B1  ‫ م‬:ً+-


private Texture txt;
5 ‫ ا ا‬eG TextureLoader / ‫( ا ﺱ‬Class) 5l; ‫= م ا‬1‫ ﺱ‬:ً -
‫رة ا اد‬B ‫ﺱر ا‬G ( ‫ﺡ‬# 5+!  HX‫ أ‬YG FromFile / ‫(ا ﺱ‬Function)
. ‫اآة‬8 ‫(\ @ ا‬v=#‫و‬, \"G HG"1 ‫ا‬
:‫آد‬

txt = TextureLoader.FromFile (device, Application.StartupPath +


@"\..\..\RAAD.jpg");

{|( ‫ أي‬,‫ ا ﺱر ا ﺡ  ! وع‬H ( Application.StartupPath ‫ أن‬w+.


RAAD.jpg ‫ و‬,‫) ا وع‬+@ }vI ‫ي‬8 ‫ﺱر ا !* ا‬G :; ‫رة‬B ‫ ا‬ef‫و‬
./ ‫و‬Z‫ة ا‬%=  \"f‫ و‬1 ‫ اد وا‬1G2‫ ا‬eG ‫رة‬B ‫ ا‬W‫ إ‬H (

‫ ا ـ‬/ ‫ إ‬PositionColored YG X‫ أ(  و‬Vertex ‫ ع ا ـ‬+i1 ‫ م‬:ً"‫را‬


‫  ا ـ‬Vertex ‫ة €  ﻁ ط ا ـ‬%= ‫ ا‬78\]@PositionTextured ,
‫ت‬+-‫ ا‬.‫ إ‬ef#‫ و‬w! ‫ ط‬H ( ‫ي‬8 ‫ وا‬H;Z ‫ ى ا ل‬Texture.
u.‫ و ا ـ‬v ‫ ا ـ‬/! ‫ د‬12 \ +! (Texture) ‫رة‬B ‫ا‬
:‫آد‬

verts[0].SetPosition(new Vector3(0, 0f, 0));


verts[0].Tv = 0.5f;
verts[0].Tu = 0.5f;

verts[1].SetPosition(new Vector3(-1, -1, 0));


verts[1].Tv = 1;
verts[1].Tu = 0;

verts[2].SetPosition(new Vector3(1, -1.0f,0));


verts[2].Tv = 1;
verts[2].Tu = 1;

: 1 ‫= ام ا 'د ا‬1‚ ƒ ‫رة وذ‬B ‫ €اءة ا‬5+!  +! /]# :ً‫ﺱ‬GI


:‫آد‬

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 class Form1 : System.Windows.Forms.Form


{
private Device device;
private System.ComponentModel.Container
components = null;
private float angle;
private VertexBuffer vb;
private Texture txt;

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);

verts[0].SetPosition(new Vector3(0, 0f, 0));


verts[0].Tv = 0.5f;
verts[0].Tu = 0.5f;

verts[1].SetPosition(new Vector3(-1, -1, 0));


verts[1].Tv = 1;
verts[1].Tu = 0;

verts[2].SetPosition(new Vector3(1, -1.0f,0));


verts[2].Tv = 1;
verts[2].Tu = 1;

vb.Unlock ();

}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.SkyBlue ,1,1);
device.BeginScene ();

device.SetStreamSource(0, vb, 0);


device.SetTexture(0,txt);

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 ();
}

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondeivce ();
xx.Show ();

while (xx.Created )
{
xx.camera ();
xx.position ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}
:H;Z H' ‫\   ا‬6+‫… @ﺱ‬Z ‫ !'د‬RUN H  

YG ) Texture H " ‫ل ا '"{ )ا رس ا ﺡدي ( وم‬G 8I`


..‫\ن‬X‫و‬
:H;Z H' ‫آ  @ ا‬
:ً…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 class Form1 : System.Windows.Forms.Form


{
private Device device;
private System.ComponentModel.Container
components = null;
private float angle;
private VertexBuffer vb;
private Texture txt;

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[1].SetPosition (new Vector3 (-1.0f, -1.0f,


1.0f));
verts[1].Tu = 0;
verts[1].Tv = 1;

verts[2].SetPosition (new Vector3 (1.0f, 1.0f,


1.0f));
verts[2].Tu = 1;
verts[2].Tv = 0;

// ‫ا
ا‬
verts[3].SetPosition (new Vector3 (-1.0f, -1.0f,
1.0f));
verts[3].Tu = 0;
verts[3].Tv = 1;

verts[4].SetPosition (new Vector3 (1.0f, -1.0f,


1.0f));
verts[4].Tu = 1;
verts[4].Tv = 1;

verts[5].SetPosition (new Vector3 (1.0f, 1.0f,


1.0f));
verts[5].Tu = 1;
verts[5].Tv = 0;

// 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
//‫ا
اول‬

verts[12].SetPosition (new Vector3 (-1.0f, 1.0f,


1.0f));
verts[12].Tu = 0;
verts[12].Tv = 0;

verts[13].SetPosition (new Vector3 (1.0f, 1.0f, -


1.0f));
verts[13].Tu = 1;
verts[13].Tv = 1;

verts[14].SetPosition (new Vector3 (-1.0f, 1.0f, -


1.0f));
verts[14].Tu = 0;
verts[14].Tv = 1;
// ‫ا
ا‬

verts[15].SetPosition (new Vector3 (-1.0f, 1.0f,


1.0f));
verts[15].Tu = 0;
verts[15].Tv = 0;

verts[16].SetPosition (new Vector3 (1.0f, 1.0f,


1.0f));
verts[16].Tu = 1;
verts[16].Tv = 0;

verts[17].SetPosition (new Vector3 (1.0f, 1.0f, -


1.0f));
verts[17].Tu = 1;
verts[17].Tv = 1;

// 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.SetStreamSource(0, vb, 0);

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 ();
}

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondeivce ();
xx.Show ();

while (xx.Created )
{
xx.camera ();
xx.position ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}

@  ‫) آ‬, ‫ا) )ا رس ا ﺡدي‬%2‫ل ا‬G /! 5]% 5(6 ‫ ا‬:;‫و‬


:H;Z H' ‫ا‬
:ً…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 WindowsApplication5
{

public class Form1 : System.Windows.Forms.Form


{
private float angle;
private Device device;
private VertexBuffer vb;
private Texture txt;
private System.ComponentModel.Container
components = null;

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;

cc[i*2 + 1].SetPosition (new Vector3


((float)Math.Sin (theta),(float)Math.Cos (theta),3));
cc[i*2 + 1].SetNormal (new Vector3
((float)Math.Sin (theta),(float)Math.Cos (theta),3));
cc[i*2 + 1].Tu = ((float)i )/(49);
cc[i*2 + 1].Tv = 0;
}
vb.Unlock ();
}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.Green ,1,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 ();
}

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondevice ();
xx.Show ();
while (xx.Created )
{
xx.camera ();
xx.vertexbuffer ();
xx.render ();
Application.DoEvents ();
}

}
}
}
}
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 ‫وه ا =ﻁ ا‬

@ ) W!'1 (Lighting), ‫ءة‬f2‫ ا‬eG HG"1 ‫ا ا ع  ا‬8‫= م ه‬1‫(ﺱ‬


: ‫ا رس ا‬

Lighting‫اـ‬-
Mesh‫اـ‬-
--------------------

Lighting‫اـ‬-

:"‫ وه‬%‫اع *) ا('ء‬,-‫ أ‬/010 Direct٣D ‫  اـ‬


?*‫ آ‬AB ‫ء‬,8‫ا ا‬C‫ﻁ ه‬E‫( ﺱ‬Ambient Light) , 4567‫ء ا‬,8‫ ا‬:‫ول‬3‫ا‬
/7‫ د آ‬6. ("‫ﺱ‬G‫ ا‬AB ‫ة‬IJ* KEL ‫) ا('ءة‬ML " ‫ وإن‬AP ,"‫ﺱ‬G‫ا‬
).5‫ ) اﺱ‬LL 4‫ ا‬7‫ء ا‬,8‫ا‬
%GL‫ إ‬4V ‫ء‬,8‫ا ا‬C‫ﻁ ه‬E‫( ﺱ‬Diffuse Light), ‫ري‬-(‫ء ا‬,8‫ ا‬:4-‫ا‬
).5‫ ) اﺱ‬LL 4‫ ا‬4567‫ء ا‬,8‫ ا‬/7‫ د آ‬6) 5‫ﺱ‬3‫ ا‬AB ‫*ﺱوي‬
AB ‫ء‬,8‫ا ا‬C‫ﻁ ه‬E‫( ﺱ‬Specular Light), 4‫ﺱ‬MX-(‫ء ا‬,8‫ ا‬:‫ا‬
]‫ﺱ‬MX 4‫ ا‬4‫ﺱ‬MX-(‫ء ا‬,8‫ ا‬/7‫ د آ‬6) ‫ﻁ‬EV ]‫ر إ‬7‫ ا‬/E57‫ا‬
).5‫اﺱ‬

ً 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 )

Normal Vector ?7X_ ‫م‬,E- )‫آ‬3‫ ة و‬E‫ ا‬rp- ‫ م‬g‫ﺱ‬- ‫ ا('ءة‬/B7 4V


..]‫ﺱ‬p- Vertex ‫ط اـ‬E- AB

:4‫ل ا‬7‫ ا‬Ctj


:‫ت اﻩ‬0‫ ا‬P(‫? ا‬76 uB* ‫ض أن  ي‬p
:‫آد‬

verts[0].SetPosition(new Vector3(0.0f, 1.0f, 1.0f));


verts[1].SetPosition(new Vector3(-1.0f, -1.0f, 1.0f));
verts[2].SetPosition(new Vector3(1.0f, -1.0f, 1.0f));
4_ ‫م‬,E- ‫ت‬0‫ ا‬P(‫ ا‬xBL AB (Normal Vector) ‫دي‬,* ‫ﻁ‬t ?7 ?w‫و*) أ‬
/B7X‫ ا‬%C]JV ‫ط‬E‫ت ا‬0‫ ا‬P‫ إ‬rp- Ctj SetNormal /‫ﺹ‬g‫ ا‬/V'‫إ‬
: /w‫ در‬٩٠ /‫ زاو‬AB ?‫ﺹ‬6-
:‫آد‬

verts[0].SetNormal(new Vector3(0f, 1f, 1.0f));


verts[1].SetNormal(new Vector3(-1.0f, -1.0f, 1.0f));
verts[2].SetNormal(new Vector3(1.0f, -1.0f, 1.0f));

‫ن اـ‬,-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‫ﺱ‬-

:4‫ن آ‬,M Material ‫اﺹ ) اـ‬


.‫ء‬,8B (Object) )„‫? آ‬7 :ً†‫أو‬
Material.‫ـ‬B (Object) )„‫? آ‬7 :ً-0
Diffuse.‫ـ‬B ‫ن‬, ‫ء‬5‫ إ‬:ً0
Ambient.‫ـ‬B ‫ن‬, ‫ء‬5‫ إ‬:ًX_‫را‬
Material.‫ اـ‬AB device ‫ اـ‬XL :ً‫*ﺱ‬t
:‫آد‬

Color col = Color.White ;


Material mtrl = new Material();
mtrl.Diffuse = col;
mtrl.Ambient = col;
device.Material = mtrl;
h‫ﺱ‬6_ ‫ء‬L 7‫‹ه آ‬L K5‫ﺱ‬L x-ŠV ,‫_ﻩ‬0 u‫ات ﺱ‬,5g‫ ا‬%C‫ ه‬:ًXJl
. % L ‫ي‬C‫ء ا‬,8‫ا‬
---------------

... ‫ ا~ن‬A‫ إ‬X* * * Kw‫ا‬


- ‫ي ﺱ‬C‫ وا‬Normal Vertex ‫" ) اـ‬BM_ ‫ أول ا رس‬4V -‫آ _ أ‬CL 7‫آ‬
4‫ وا‬Material ‫ اـ‬A‫  إ‬6‫ ا‬-Ct‫" أ‬0 )*‫ و‬,‫ء‬,8‫ﺱ_ت ا‬P /B7 4V
‫ء دور‬w ‫ وا~ن‬Mesh..... ‫ أو‬Texture ‫ هك‬u-‫ء إذا آ‬,8‫ﺹ„ƒ ا‬t ‫ﺹ‬L
.‫ﺱﻩ‬p- ‫ء‬,8‫ اﺹ ) ا‬4‫ة وه‬t3‫ة ا‬,5g‫ا‬

../V,p‫? *ﺹ‬t‫ء _ ا‬,8‫ ا‬AB ‫م _ﺹ‬,E- :ً†‫أو‬


‫أي أن‬
:‫آد‬

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()
{

/*Color col = Color.Black ;

Material mtrl = new Material();

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);

verts[0].SetPosition(new Vector3(0.0f, 1.0f,


1.0f));
verts[0].SetNormal(new Vector3(0f, 1f, 1.0f));
verts[0].Color = System.Drawing.Color.White
.ToArgb();

verts[1].SetPosition(new Vector3(-1.0f, -1.0f,


1.0f));
//verts[1].SetNormal(new Vector3(-1.0f, -1.0f,
1.0f));
verts[1].Color = System.Drawing.Color.White
.ToArgb();

verts[2].SetPosition(new Vector3(1.0f, -1.0f,


1.0f));
//verts[2].SetNormal(new Vector3(1.0f, -1.0f,
1.0f));
verts[2].Color = System.Drawing.Color.White
.ToArgb();

vb.Unlock ();

}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.LightPink ,1,1);
device.BeginScene ();

device.SetStreamSource(0, vb, 0);

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 ();
}

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondeivce ();
xx.Show ();

while (xx.Created )
{
xx.camera ();
xx.position ();
xx.light ();
xx.render ();
Application.DoEvents ();
}
}
}
}
}

...13_ ‫د‬,M‫ ا‬AB ‫`ت‬P17‫ ا‬X_   ‫ه‬


45X 4M ,_3‫ *? ا‬pt ‫ن‬,B_ ]BXG- Vertex ‫ـ‬B ‫ن‬, ‫ء‬5‫  إ‬:ً†‫أو‬
.‫ة‬0jL ‫ء‬,8‫ا‬
Direction‫ و‬SetNormal ‫ و‬SetPosition ‫ت اـ‬0‫ ا‬P‫ * _) إ‬/f1X‫ ا‬:ً-0

:‫آد‬

verts[0].SetPosition(new Vector3(0.0f, 1.0f, 1.0f));


-----------------------------------------------------
:‫آد‬

verts[0].SetNormal(new Vector3(0f, 1f, 1.0f));


-----------------------------------------------------
:‫آد‬

device.Lights[0].Direction = new Vector3(0,-1,-1);


,/5EB ‫ت‬0‫ ا‬P(‫  ا‬6L AB ?7X ‫ي‬C‫ وا‬SetPosition ‫ اـ‬I ‫ أول‬4Lj
?w‫ *) أ‬/5E‫ ا‬%C‫ ه‬AB ‫دي‬,* ‫ﻁ‬t ?7X SetNormal ‫ ه اـ‬X_ 4Lj
‫ءه‬5Š_ 7f ‫ا‬C‫ * ه‬4V‫ و‬... ‫ت‬0‫ ا‬P‫„] أي إ‬5‫ إ‬M7‫ ا('ءة و‬rM
?*X‫ وﺱ]? ا‬٩٠ 7]_ /‫ن ااو‬,M SetPosition ‫ت اـ‬0‫ ا‬P‫ إ‬rp-
 6L 4‫ة وه‬t3‫ة ا‬,5g‫ ا‬A‫ إ‬4Lj- .. 13_ ‫ا‬C‫ ) ه‬7BML‫ و‬.. ]X*
‫ت‬0‫ ا‬P‫ أي إ‬Normal Vertex AB ‫د‬7(_ ‫ ‘'ءة‬Direction ‫ت اـ‬0‫ ا‬P‫إ‬
‫ درس اـ‬Kw‫ **** را‬Hand (‫ ة اـ‬f 4_ ?7X- -‫ أ‬7_‫ و‬SetNormal ‫اـ‬
?p‫ *) أﺱ‬Normal Vertex ‫ن اـ‬,M‫ ﺱ‬xC ,/‫رب اﺱ‬E K* ‫أي‬Camera)
... ‫ء‬,8‫ط ا‬E‫ط (ﺱ‬E‫س ا‬,MX* Ctj- xC, /5E‫ا‬
]‫ﺱ‬M‫ وإ‬SetPosition ‫ت اـ‬0‫ ا‬P‫ *? إ‬SetNormal ‫ اـ‬K' … ‫م‬1M‫ﺹ ا‬g*
.. hw,* h‫ واﺱ‬h‫ ﺱ‬hw,7‫? ا‬Xw‫ أي إ‬Direction ‫ اـ‬

------------------

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

:4‫ل ا‬7‫ ا‬Ctj ‫ا~ن‬


B7‫? ا‬L X_ , ‫ *) هـــــ‬B7‫? ا‬76L K5‫ﺱ‬L ... ‫رة ) ﺱرة‬J ,‫وه‬
.‫وع‬7‫ ا‬B* ?t‫ﻩ _ ا‬X',_ ‫م‬,E-: ً†‫ أو‬CAR , "‫? ا(ﺱ‬76 ‫ي‬C‫وا‬
:‫ت‬pX‫ ا‬/E5* 4V 4‫د ا‬,M‫ ا‬8- :ً-0
private Mesh mesh;
Mesh ‫ اـ‬X_ ‫م‬,E mesh ‫ اـ‬4_ /‫ﺹ‬t (Function) ?7X_ ‫م‬,E- :ً0
:4‫ن آ‬,ML‫] و‬Bt‫_ ا‬

:‫آد‬

public void meshh()


{

mesh = Mesh.FromFile (Application.StartupPath +


@"\..\..\CAR.x",MeshFlags.SystemMemory ,device);

‫ اـ‬B* ‫  *ﺱر‬6L ?w‫ *) أ‬function ‫ اـ‬%C‫ م ه‬g‫ﺱ‬LMesh.FromFile


/5‫اﺱ‬,_ ‫وع‬7‫ ا‬B* rp- ?t‫ﻩ _ ا‬-j_ %-‫ د‬P PMesh
CAR.X.,‫ وه‬B7‫ إﺱ" ا‬-‫ د‬P "0 )*‫و‬Application.StartupPath
)‫ د أ‬6 ‫ي‬C‫ وا‬MeshFlags ‫ اـ‬,‫ وه‬t~‫ ا‬Parameter ‫ اـ‬A‫ ا~ن إ‬4Lj-
‫د‬,M‫ ا‬4V 7f P Car B7‫ ا‬4_ /‫ﺹ‬g‫( ا‬Data) ‫ت‬-_ )gL " ‫ف‬,‫ﺱ‬
‫ت‬-_ )gL /B7 ‫ن‬j_ 4XL 4‫ وا‬SystemMemory ‫ر اـ‬tŠ_ 13_
)* 7‫ و‬...L,J7M‫ ا‬4_ /‫ﺹ‬g‫ ا‬RAM ‫? ذاآة اـ‬t‫ ﺱ" _ ا‬B7‫ا‬
.?p‫ﺱ‬3_ ‫ ول‬G‫ ا‬A‫` إ‬-‫رات أ‬g‫ ا‬%C‫ت _) ه‬V1t(‫ل ا‬,P ‫*ت‬,BX7‫ا‬

!
‫ت‬M object )„M‫ ا‬4_ ‫ص‬g‫ ا‬,‫ وه‬t3‫ ا‬Parameter ‫   اـ‬4E_
device"‫ﻩ ا(ﺱ‬B EBl‫ي أ‬C‫ وا‬/I‫ا‬

A‫ إ‬RAM ‫( *) اـ‬CAR) B7‫ أي إرﺱل ا‬,"‫ اﺱ‬/BP* ‫ ا~ن‬uE_ :ًX_‫را‬


RAM ‫ت *) اـ‬-J‫ إرﺱل ا‬/B7 ‫ إن‬/EE6‫ ا‬4V ,‫ﻩ‬L‫اء‬E /I‫آت ا‬
B7‫ﺱ" ا‬EL kl ) "L 7-‫ وإ‬,‫ ة‬P‫ وا‬/XV _ "L † /I‫ آت ا‬A‫إ‬
?w‫ *) أ‬For ‫ ام اـ‬g‫ إﺱ‬4_ ‫م‬,E- xC SubSet, 4_ A7‫ﺱ‬L ‫اء‬w‫ أ‬A‫إ‬CAR
(function) /‫ ا ا‬/5‫اﺱ‬,_ ]7‫ا„] ورﺱ‬f "0 )*‫اء و‬w3‫ ا‬%C‫? ه‬76L
DrawSubset. A7‫ﺱ‬7‫ا‬

:‫آد‬

for (int i=0;i < 20 ;i++)


{
mesh.DrawSubset (i);
}
"B‫ اž أ‬... ‫ن‬,M‫ ﺱ‬4_‫ا‬,GV subset ?‫" آ‬GP "‫ آ‬4j‫ﺱ‬L ‫إذا أردت أن‬
VGA ‫ع اـ‬,-‫]ز و‬G‫ ا‬/‫ وﺱ‬RAM ‫" اـ‬GP AB 7X‫آ ﺱ‬j_ ‫آﻩ‬3‫و‬
.‫ﺱﻩ‬p- B7‫" ا‬GP A‫ إ‬/V'(_

:ً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 class Form1 : System.Windows.Forms.Form


{
private Device device;
private float angle;
private Mesh mesh;
private System.ComponentModel.Container
components = null;

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;

public void meshh()


{

mesh = Mesh.FromFile (Application.StartupPath


+ @"\..\..\CAR.x",MeshFlags.SystemMemory ,device);

public void render()


{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.Blue ,1,1);

device.BeginScene ();

for (int i=0;i < 20 ;i++)


{
mesh.DrawSubset (i);
}

device.EndScene ();
device.Present ();
angle += 0.05f;
}
protected override void OnPaint
(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondevice ();
xx.Show ();

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_

:4‫ي ا‬,6 ‫ *ﻩ‬5‫Šن أول ﺱ‬V B7‫ا ا‬C‫ ه‬V 


./B ‫ف‬X‫ ا‬DirectX ‫ اـ‬K5‫ ﺱ‬xfile ‫ـ‬B ‫ة‬77‫وف ا‬6‫? ا‬7L 4‫وا‬Xof
./g‫" اﺱ‬f‫? ر‬7L 4‫وا‬٠٣
.B7‫ع ا‬,- ?7L 4‫وا‬Txt
.‫ت‬-J‫ع ا‬,- ?7L 4‫وا‬٠٠٣٢

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‫ا‬

X).‫ت اـ‬pB* K7w AB ‫م‬1M‫ا ا‬C‫ ه‬kJ5(

--------------------

‫ واـ‬Matrix ‫ اـ‬K7w —‫) أن أ‬M77‫ *) ا‬4-j_ ,13_ ‫م‬1M‫ﺱ— *) ا‬-


D MAX ٣ ‫*— *? اـ‬-_ /5‫اﺱ‬,_ Vertex ‫ واـ‬Texture ‫واـ‬Normal Vectors
... ‫ﻁ‬Ef B7‫ا ا‬C‫اءة ه‬f DirectX ‫ اـ‬AB AEJ‫ و‬X FILE ‫ اـ‬/‹‫] _ﺹ‬-t‫وأ‬

--------------------

—*‫ا‬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-
:‫آد‬

private Material[] mat;


%C‫? ه‬7XL P ExtendedMaterial /V,p‫ﺹ‬7B Object ?7X_ ‫م‬,E-: ً-0
Mesh.‫ اـ‬4_ /‫ﺹ‬g‫ ا‬Subset ‫*ت اـ‬,BX* )gL AB /V,p‫ﺹ‬7‫ا‬
:‫آد‬

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‫_ ا‬
:‫آد‬

mesh = Mesh.FromFile (Application.StartupPath +


@"\..\..\CAR.x",MeshFlags.SystemMemory ,device,out material);

material.Length.‫  ده‬h‫ﺱ‬6_ subset ‫ـ‬B for loop ?7: ًX_‫را‬


Material٣D.]-‫ أ‬4_ Material ‫ع اـ‬,- ‫ د‬6-
.‫ء ا('ءة‬5‫ إ‬/B7 ?w‫ *) أ‬Diffuse ‫ و اـ‬Ambient ‫ﺹح ) اـ‬-

:‫آد‬

for (int i= 0;i < material.Length ;i++)


{
mat[i] = material[i].Material3D ;
mat[i].Ambient = mat[i].Diffuse ;
}

Materials‫ واـ‬Subset ‫اءة )رﺱ"( اـ‬f 4‫ة وه‬t~‫ ا‬/BP7‫ا‬


:‫آد‬

for (int i=0;i < mat.Length ;i++)


{
device.Material = mat[i];
mesh.DrawSubset (i);
}
---------------

!
: ً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 class Form1 : System.Windows.Forms.Form


{
private Device device;
private float angle;
private Mesh mesh;
private Material[] mat;
private System.ComponentModel.Container
components = null;

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;

mesh = Mesh.FromFile (Application.StartupPath


+ @"\..\..\CAR.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,2);
device.Lights [0].Commit ();
device.Lights [0].Enabled = true;
}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.Blue ,1,1);

device.BeginScene ();

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 ();
}

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondevice ();
xx.Show ();

while (xx.Created )
{
xx.camera ();
xx.meshh ();
xx.light ();
xx.render ();
Application.DoEvents ();
}
}

}
}
}
-------------------

Tiny4_ A7‫ﺱ‬7‫ر ا‬,]7‫ ا‬Microsoft ‫ *ل‬,‫ وه‬. t· ‫ *ل‬Ctj

.‫وع‬7‫ ا‬rp- ?t‫ _ ا‬Texture ‫ا اـ‬C‫) ه‬g_ ‫م‬,E- :ً†‫أو‬


Tiny_skin"‫ ا(ﺱ‬/5X-‫و‬
"‫ ا(ﺱ‬/5X-‫وع و‬7‫ ا‬rp- ?t‫ً _ ا‬8‫ أ‬Mesh ‫ا اـ‬C‫ ه‬K',_ ‫م‬,E-: ً-0
tiny

?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 class Form1 : System.Windows.Forms.Form


{
private Device device;
private float angle;

private Mesh mesh;


private Material[] mat;
private Texture txt;
private System.ComponentModel.Container
components = null;

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 ();

for (int i=0;i < mat.Length ;i++)


{
device.Material = mat[i];
mesh.DrawSubset (i);
}
device.EndScene ();
device.Present ();
angle += 0.5f;
}
protected override void OnPaint
(System.Windows.Forms.PaintEventArgs e)
{
this.render ();
}

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondevice ();
xx.Show ();

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‫ا‬
:‫آد‬

float posx = 0.7f;


float posy = 0.7f;
float posz = 0.7f;
‫ "ن‬HK‫ أ‬Translation (‫ اـ‬Matrix 5‫ات  ا‬OK1‫ ا‬T!‫ ه‬D% ‫م‬%H# :ً#P
‫ اـ‬T!‫م ) ه‬%H ‫ ا!ي‬A ‫ ﺡ‬IH‫' ا روس اﺱ‬6E aD‫م وا‬C‫ه!ا ا‬
Matrix)
:‫آد‬

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

:‫آد‬

protected override void OnKeyDown


(System.Windows.Forms.KeyEventArgs e)
{
switch (e.KeyCode )
{
case Keys.Right :
posx ++;
break;

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 class Form1 : System.Windows.Forms.Form


{
private Device device;
private float angle;
private Mesh mesh;
private Material[] mat;
private System.ComponentModel.Container
components = null;
float posx = 0.7f;
float posy = 0.7f;
float posz = 0.7f;

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;

mesh = Mesh.FromFile (Application.StartupPath


+ @"\..\..\CAR.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,2);
device.Lights [0].Commit ();
device.Lights [0].Enabled = true;
}
public void render()
{
device.Clear (ClearFlags.Target |
ClearFlags.ZBuffer ,Color.Blue ,1,1);

device.BeginScene ();

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 ();
}

protected override void OnKeyDown


(System.Windows.Forms.KeyEventArgs e)
{
switch (e.KeyCode )
{
case Keys.Right :
posx ++;
break;

case Keys.**** :
posx --;
break;
case Keys.Up :
posy ++;
break;

case Keys.Down :
posy --;
break;

case Keys.Home :
posz ++;
break;

case Keys.End :
posz --;
break;

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondevice ();
xx.Show ();

while (xx.Created )
{
xx.camera ();
xx.meshh ();
xx.light ();
xx.render ();
Application.DoEvents ();
}
}

}
}
}
: 56‫ ﺱ‬5‫ ا‬Mw‫ ﺱ‬RUN 51 

!

:5‫ ه!ا ا‬K


.a61‫ ا‬I‫ﺡ‬% 0A 01‫ ا‬.M‫ زر اﺱ‬34 ,OD‫ إ‬01
.a61‫ ا‬I‫ﺡ‬% 0A ‫ اﺱ‬.M‫ زر اﺱ‬34 ,OD‫ﺱر إ‬
.a61‫ ا‬I‫ﺡ‬% 0A 34‫ ا‬.M‫ زر اﺱ‬34 ,OD‫ق إ‬%E
.a61‫ ا‬I‫ﺡ‬% 0A 56‫ اﺱ‬.M‫ زر اﺱ‬34 ,OD‫ إ‬y
.a61‫ ا‬I‫ﺡ‬% 0A Home ‫ زر‬34 ,OD‫ إ‬.‫ﺱ‬/‫< ا‬K
.a61‫ ا‬I‫ﺡ‬% 0A End ‫ زر‬34 ,OD‫ إ‬.‫ﺱ‬/‫ ا‬O‫ﺹ‬K

------------------------------

: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 dev = Microsoft.DirectX.Direct3D;


using snd = Microsoft.DirectX.DirectSound;

‫ أي آت‬Direct٣D (‫ ا‹ص ' اـ‬Device ‫ اـ‬5@1 dev.Device ‫ اـ‬a<‫ا‰ن أﺹ‬


). I‫ا‬
‫ أي آت‬DirectSound (‫ ا‹ص ' اـ‬Device ‫ اـ‬5@1 snd.Device ‫ اـ‬a<‫وأﺹ‬
).‫ت‬%‫اﺹ‬
:a<‫ )اﺱرة( ﺱﺹ‬C T<K‫د ا!ي آ‬%‫Œن ا‬E )4‫و‬

:‫آد‬

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 class Form1 : System.Windows.Forms.Form


{
private dev.Device device;
private float angle;
private dev.Mesh mesh;
private dev.Material [] mat;
private System.ComponentModel.Container
components = null;
float posx = 0.7f;
float posy = 0.7f;
float posz = 0.7f;

public Form1()
{
InitializeComponent();
}

public void ondevice()


{
dev.PresentParameters pp = new
dev.PresentParameters ();
pp.SwapEffect = dev.SwapEffect.Discard;
pp.Windowed = true;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat =
dev.DepthFormat.D16 ;
device = new dev.Device
(0,dev.DeviceType.Hardware
,this,dev.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 = 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 ;
}
}

public void light()


{
Color col = Color.White ;
dev.Material mm = new dev.Material ();
mm.Ambient = col;
mm.Diffuse = col;
device.Material = mm;

device.Lights [0].Diffuse = Color.White;


device.Lights [0].Type =
dev.LightType.Directional ;
device.Lights [0].Direction = new Vector3 (0,0,2);
device.Lights [0].Commit ();
device.Lights [0].Enabled = true;
}
public void render()
{
device.Clear (dev.ClearFlags.Target |
dev.ClearFlags.ZBuffer ,Color.Blue ,1,1);

device.BeginScene ();

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 ();
}

protected override void OnKeyDown


(System.Windows.Forms.KeyEventArgs e)
{
switch (e.KeyCode )
{
case Keys.Right :
posx ++;
break;

case Keys.**** :
posx --;
break;

case Keys.Up :
posy ++;
break;

case Keys.Down :
posy --;
break;
case Keys.Home :
posz ++;
break;

case Keys.End :
posz --;
break;

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondevice ();
xx.Show ();

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 IŽ6‫ ا‬T!‫‹ ام ه‬K‫ إﺱ‬I=‫اﺱ‬% ‫ء‬9‫ه!ا ا‬.net
:'K‫آ‬
:‫ان‬OKA 0 a‫ﺹ‬K ‫م‬%H# :ً*‫أو‬
:‫آد‬

private Font winfont;


private dev.Font dxfont;
windows‫' اـ‬E ‫دة‬%i%1‫‹ ام اوف ا‬K‫‘ﺱ‬: (winfont) ‫اول‬
‫' اـ‬E IK4 MA‫‹ ا‬K‫( وإﺱ‬winfont) ‫ اـ‬0A ‫أ! اوف‬: (dxfont) '#@‫ا‬
DirectX

:'K‫( آ‬5K‫واﺱ‬, ./‫ ا‬,,‹‫ع ا‬%# winfont(‫’ اـ‬9 :ً#P


:‫آد‬

winfont = new System.Drawing.Font


("Arial",20,System.Drawing.FontStyle.Bold);
).I4‫  ا‬winfont ‫” اـ‬J‫ ﺹ‬D‫ و‬dxfont (‫’ اـ‬9: ً@P
:‫آد‬

dxfont = new dev.Font(device,winfont);


0A ‫ < أ‬text (‫ اـ‬D% ‫ن‬A  K (‫ف‬6) '1‫ وه‬5=K‫ﺱ‬A 51: ً9‫را‬
).IH‫' ا روس اﺱ‬E ) 14 Pixel (‫' اـ‬E 1‫( آ‬I‫ ﺱر ا‬34‫أ‬
:‫آد‬

Rectangle rr = new Rectangle (0,0,0,0);


.'1‫ه‬%‫ ا‬5=K‫ﺱ‬1‫ ا‬5‫)  ا‬KK‫اد آ‬1‫  ا” ا‬
:‫آد‬

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 class Form1 : System.Windows.Forms.Form


{
private dev.Device device;
private float angle;
private dev.Mesh mesh;
private dev.Material [] mat;
private System.ComponentModel.Container
components = null;
float posx = 0.7f;
float posy = 0.7f;
float posz = 0.7f;

private Font winfont;


private dev.Font dxfont;

public Form1()
{
InitializeComponent();
}

public void ondevice()


{
dev.PresentParameters pp = new
dev.PresentParameters ();
pp.SwapEffect = dev.SwapEffect.Discard;
pp.Windowed = true;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat =
dev.DepthFormat.D16 ;
device = new dev.Device
(0,dev.DeviceType.Hardware
,this,dev.CreateFlags.SoftwareVertexProcessing ,pp);

public void font()


{
winfont = new System.Drawing.Font
("Arial",20,System.Drawing.FontStyle.Bold);
dxfont = new dev.Font(device,winfont);
Rectangle rr = new Rectangle (0,0,0,0);
Rectangle rr2 = new Rectangle(0,30,0,0);
dxfont.DrawText
("WWW.3ASFH.NET",rr,dev.DrawTextFormat.NoClip ,Color.DarkOrange
);
dxfont.DrawText
("RAAD",rr2,dev.DrawTextFormat.NoClip ,Color.White );

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 = 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 ;
}
}

public void light()


{
Color col = Color.White ;
dev.Material mm = new dev.Material ();
mm.Ambient = col;
mm.Diffuse = col;
device.Material = mm;

device.Lights [0].Diffuse = Color.White;


device.Lights [0].Type =
dev.LightType.Directional ;
device.Lights [0].Direction = new Vector3 (0,0,2);
device.Lights [0].Commit ();
device.Lights [0].Enabled = true;
}
public void render()
{
device.Clear (dev.ClearFlags.Target |
dev.ClearFlags.ZBuffer ,Color.DarkSlateBlue ,1,1);

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 ();
}

protected override void OnKeyDown


(System.Windows.Forms.KeyEventArgs e)
{
switch (e.KeyCode )
{
case Keys.Right :
posx ++;
break;

case Keys.**** :
posx --;
break;

case Keys.Up :
posy ++;
break;

case Keys.Down :
posy --;
break;

case Keys.Home :
posz ++;
break;

case Keys.End :
posz --;
break;

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

static void Main()


{
using (Form1 xx = new Form1 ())
{
xx.ondevice ();
xx.Show ();

while (xx.Created )
{
xx.camera ();
xx.meshh ();
xx.light ();
xx.render ();
Application.DoEvents ();
}
}

}
}
}
:'K‫ ا‬5‫ ا‬Mw‫ ﺱ‬RUN 51 

You might also like