You are on page 1of 177
: ا سر ا Transformedـ ا Vertexes ـ ا - TransformedColoredـ ا ر- --------------------

: ا سر ا Transformedـ ا Vertexes ـ ا - TransformedColoredـ ا ر-

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

Transformedـ ا Vertexes ـ ا

Transformed ـ ا ا سر ا

(Pixels) ا ط م أ

ً

نأ وأو , ا ر دا ا ا ت ا إ آ ,ر ا وا ا أ ن (Origin Point) ا ا : ا

ا أ ن (Origin Point) ا ا : ا ط ا نأ و رأ نأ رأ

ط ا نأ و رأ نأ رأ أ ن ا : آ ا إ : x = 0 , y = 0 و ا ا : x = 0 , y = 200 ا ا : x = 200 , y = 200 ا ا

ا : آ ا إ : x = 0 , y = 0 و ا ا
ا : آ ا إ : x = 0 , y = 0 و ا ا
ً DirectX:ـ ا إ ي ا م ا ل نأ ن ا أر أ ه

ً

DirectX:ـ ا إ

ي ا م ا ل نأ ن ا أر

أ ه ي او TransformedColored ـ ا ا: لو ا ة ا ط ا ت ا إ ي ا ء آ هو Transformed ـ ا عا أ أ ر ا و , ا دا ا نا او و ,(ط ا ت ا إ) ت ا (Array) vertexes و إ يأ

:د آ

CustomVertex.TransformedColored[] vertexes ;

هو vertex, ـ ا (function) اد : ا ة ا , أ رادإ و د ا أ د و , ي ا vertexes ـ (Object) آ ا ا آ هو , ر دا ا ط ا د ا : آ ن

:د آ

vertexes = new CustomVertex.TransformedColored[3];

ن آو , ر دا ا ط ا د ا نأ يأ . ا أ ت ا ا

]:0] لو ا ا

:د آ

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

[1]: ا ا

:د آ

vertexes[1].X = 200; vertexes[1].Y = 0; vertexes[1].Color = Color.Blue .ToArgb();

] :2] ا ا

:د آ

vertexes[2].X = 200; vertexes[2].Y =200; vertexes[2].Color = Color.Green .ToArgb();

] :2] ا ا : د آ vertexes[2].X = 200; vertexes[2].Y =200; vertexes[2].Color = Color.Green .ToArgb();
y و x ر ا ط ا ت ا إ د نأ : ا ا

y و x ر ا ط ا ت ا إ د نأ : ا ا

:د آ

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

آ , ي ن ء إ ا ه ا ةرو ي او TransformedColored ع vertex ـ ا د او , ا ن ا و ا ا نأ ,نا ا ا أ , ا ن ا او ,قرز ا ن ا او ا نا ا ع ر إ ToArgb() (red, green, blue).

: آ ي د ا

:د آ

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

}

آ ط ا ه م : ا ة ا : ا

=200; vertexes[2].Color = Color.Green .ToArgb(); } آ ط ا ه ﺹ م : ا ة ا
م أ ا ط ا ه ﺹ او OnPaint() ه ﺹ ا ا او ,
م أ ا ط ا ه ﺹ او OnPaint() ه ﺹ ا ا او ,

م أ ا ط ا ه او OnPaint() ه ا ا او , ا ح ر يأ نأ يأ , ا سور ا . ا ا ه ا ا OnPaint() ـ ا ا م ه

د ا ن و DrawUserPrimitives, ـ ا وVertexFormat

ا

:د آ

Public OnPaint()

{

VertexFormat();

DrawUserPrimitives();

}

ا ا ن ه إ ن ا DirectX ـ ا VertexFormat ـ ا هو و ا ـ ا هو ا دا ا Vertex ـ ا ع ً

: آ

ن وTransformedColored

:د آ

device3d.VertexFormat = CustomVertex.TransformedColored.Format ;

د DrawUserPrimitives ـ ا هو ا (Parameters) :تا ا ي أ ا ط ا ر آ أ :لو ا آ) ى آ يأ TriangleList ).ل ا ا ه

ط ا ر آ أ :لو ا آ) ى آ ﺹ يأ TriangleList ﺹ ).ل ا
: د آ device3d.DrawUserPrimitives( PrimitiveType.TriangleList , , ); آ ﺹ ا ن TriangleStrip ﺹ

:د آ

device3d.DrawUserPrimitives( PrimitiveType.TriangleList ,

,

);

آ ا ن TriangleStrip ا

, ); آ ﺹ ا ن TriangleStrip ﺹ ا ط ا آ و ﺹ ا ن

ط ا آ و ا ن TriangleFan : ا آ ة او ك

ن TriangleFan ﺹ : ا آ ة او ك 1 هو ر دا ا ت ا

1 هو ر دا ا ت ا د : ا vertexes هو ا ي ا ا : ا : ا د ا

:د آ

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

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

TransformedColoredـ ا ر

PrimitiveType.TriangleList , 1, vertexes ); --------------------------------- TransformedColoredـ ا ر
:ً آ د ا : د آ using System; using System.Drawing; using System.Collections; using System.ComponentModel;

آ د ا

:د آ

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

();

after InitializeComponent call // } public void ondevice() { PresentParameters pp = new PresentParameters ();
pp.SwapEffect = SwapEffect.Discard; pp.Windowed = true; device3d = new Device (0,DeviceType.Hardware

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

}

PrimitiveType.TriangleList , 1, vertexes ); device3d.EndScene(); device3d.Present (); }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(

/// <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د Compile

(Form1 xx = new Form1 ()) { xx.ondevice (); xx.tranvertex (); Application.Run(xx); } } } }
: ا ةر ﺹ يوا ا ه ا Hasa8384@yahoo.com

: ا ةر

: ا ةر ﺹ يوا ا ه ا Hasa8384@yahoo.com

يوا ا ه ا

Hasa8384@yahoo.com

: ا ةر ﺹ يوا ا ه ا Hasa8384@yahoo.com
: ا سر ا PositionColoredـ ا Vertexes ـ ا - Cameraـ ا- --------------------

: ا سر ا PositionColoredـ ا Vertexes ـ ا - Cameraـ ا-

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

PositionColoredـ ا Vertexes ـ ا

ع ا ا ه (Origin Point) ا ن

ر ن او Transformed ـ ا و , ا ً

أو ,( ا سر ا ار) ا

نا ا ء إ ا

آأ ة ا ا إ أ ط ا

إ ا آأ ة ا ﺱ ا إ أ ط ا : ا ت ا ﺡ

: ا ت ا ا ي ﺱر ا آ ى ن ا

: x = ٠ , y = ٠ , z = ٠ و ا ا

: x = ١٠ , y = ٠, z = ٠ ا ا : x = ٥ , y = ١٠ , z = ٠ ا ا

= ٠ , y = ٠ , z = ٠ و ا ا : x =
ف ﺱ DirectX ـ ا إ ﻁ ا ا ه ـ ا ﺱ ا سر
ف ﺱ DirectX ـ ا إ ﻁ ا ا ه ـ ا ﺱ ا سر

ف DirectX ـ ا إ ا ا ه ـ ا ا سر ا ه ﺱإ ا تا ا PositionColored.ـ ا ه ﺱTransformed

ط ا ي ﺱ ي ا PositionColored ـ ا ء ا أ د ا آ vertices ا ا ا ه (Vertex)

.

:د آ

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

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 =

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

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

ا (Class) ا د و ه د ا ا ه ا لو ا هو ت ا ﺡإ اوVector٣ z. ـ ا ر او y ر او x ـ ا ر ا إ أ , ا ع ر ا z ر ا ن ل ا

:

ا ع ر ا z ر ا ن ل ا : ﺱ هو OnPaint ـ ا

هو OnPaint ـ ا اد ا Vertex ـ ا ا سر ا ا Transformed ـ ا ـ ا ا م ه ﻩ أ ا CustomVertex.PositionColored

:د آ

device.VertexFormat = CustomVertex.PositionColored.Format; device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices);

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

1, vertices); ------------------------------------------------------------------
: آ د ا : د آ using System; using System.Drawing; using System.Collections; using System.ComponentModel;

: آ د ا

:د آ

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

}

device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { CustomVertex.PositionColored[] vertices = new

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)

device.Present(); this.Invalidate(); } protected override void Dispose (bool disposing) { if (disposing)
{ if (components != null) { components.Dispose(); } } base.Dispose(disposing); } private void

{

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

}

}

}

}

= new WinForm()) { our_directx_form.InitializeDevice(); Application.Run(our_directx_form); } } } }
: ا ا ﺱ , ا د run ؟؟؟؟ ا أ آ و Transformed ـ

: ا ا ﺱ , ا د run

: ا ا ﺱ , ا د run ؟؟؟؟ ا أ آ و Transformed ـ ا

؟؟؟؟ ا أ آ و

Transformed ـ ا ا سر ا

ـ ا ما ﺱإ أ (Pixels) ا ق ت ا ا يأ World Space ـ ا ت ا ا PositionColored ا دا ا ط ا , ﺱا ا ء ا أ

ا ا ما إ

Cameraـ ا-

ا DirectX, ـ ا ا ا هأ هو : ء أ ة هذ نأ ا ا : ه و ا إ ل ا ﺱر وأ ط ا ت ا ﺡإ ا ﺱر ﻩ و(Local Space):

إ ,ﻩﺱ ا ص ا z و y و x ر ا (Vectors) : أ ا

ﺱر ﻩ و(Local Space): إ ,ﻩﺱ ا ص ا z و y و x ر ا
, ا ء ا إ ﺱ ا هو(World Space) : ﺱ او او ا ن
, ا ء ا إ ﺱ ا هو(World Space) : ﺱ او او ا ن

, ا ء ا إ ا هو(World Space) :

او او ا ن ﺡ : ا إ أ ,م ا

ﺱ ﺡ : ﺱ ا إ أ ,م ﺱ ا ً (World ـ ا ؤ ا

ً

(World ـ ا ؤ ا ل ا ا و :

ﺱ ﺡ : ﺱ ا إ أ ,م ﺱ ا ً (World ـ ا ؤ ا
ا ا ﺡ , ﺱ ا إ أSpace) , A ا ر إ أ (ط

ا ا ﺡ , ا إ أSpace) , A ا ر إ أ ا) و ا ا .ﻁ

ر إ أ (ط ﺱ ا) و ا ا .ﻁ ً (ا ا) و ا ا

ً

ا) و ا ا : ا ن نأ ر ا ﻩ ا إ اوPerspectiveFovRH ا إ م ا ن ا إ أ ت ا ا Z.ر يزا ر ى ا ﻩ ا إ اوPerspectiveFovLH ا إ م ا ن ا إ أ ت ا ا Z.ر يزا

إ اوPerspectiveFovLH ا إ م ا ن ﺡ ﺱ ا إ أ ت ا ﺡ ا
ﻩ PerspectiveFovLH ـ ا ه م ﺱ او ا ا .ت ا ﺡ ا ا
ﻩ PerspectiveFovLH ـ ا ه م ﺱ او ا ا .ت ا ﺡ ا ا

PerspectiveFovLH ـ ا ه م او ا ا .ت ا ا ا

هو ل ا ت ا ا د

:د آ

آأ و

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 ـ ا ﺱإو ت ا ا ه اذإ : آ ا ت ا ا ؤر ن

ـ ا ﺱإو ت ا ﺡ ا ه اذإ : آ ا ت ا ﺡ ا
: د آ device.Transform.Projection = Matrix.PerspectiveFovLH(); ؤ ا ن ﺱ PerspectiveFovRH ـ ا
: د آ device.Transform.Projection = Matrix.PerspectiveFovLH(); ؤ ا ن ﺱ PerspectiveFovRH ـ ا

:د آ

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

ؤ ا ن PerspectiveFovRH ـ ا ﺱإ اذإ أ : آ

= Matrix.PerspectiveFovLH(); ؤ ا ن ﺱ PerspectiveFovRH ـ ا ﺱإ اذإ أ : آ
: د آ device.Transform.Projection = Matrix.PerspectiveFovRH (); نأ ن ا , ؤ ا ﺱ ا
: د آ device.Transform.Projection = Matrix.PerspectiveFovRH (); نأ ن ا , ؤ ا ﺱ ا

:د آ

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

نأ ن ا , ؤ ا ا ة ا :

ً

ار

(Projection), ط ا يأ ا ا ى ؤ ا ى د ه آأ آ و, ط ا أ ق ة م (Perspective Projection) ير ا ط ا ه ا ا ة ا ل ا و ا ل ا ط ً

ة م

ا ا ما ذو ء ا ا ه DirectX ـ ا و آ و ,

ر ,ا ا ا أ

PerspectiveFovRH().وأPerspectiveFovLH()

ا ا ه DirectX ـ ا و آ و , ر ,ا ا ا أ PerspectiveFovRH().وأPerspectiveFovLH()
ز أ ز اذ آ نأ لو ﺡ تأ أ ا ك آ أ ز
ز أ ز اذ آ نأ لو ﺡ تأ أ ا ك آ أ ز

ز أ ز اذ

آ نأ لو

تأ أ

ا ك آ أ

ز

ا

( و ) ا ن ي ف ز ا

ما DirectX ـ ا أ ه

ً

ا

ر آ ع ﺱإو ز ا ي ا ر ا

وأ PerspectiveFovLH() ا ا ه ى ﺡإ ما

PerspectiveFovRH()

ا ا ه ى ﺡإ ما ﺱ PerspectiveFovRH() : ﻩ ا (Parameters) تا ار ا ن

: ﻩ ا (Parameters) تا ار ا ن ا ا ن ه ـ ا ر ا هو (FOV) ه ا : ؤ ا واز- ا م ا ب ا م وZooming ,

ا هو (FOV) ه ا : ؤ ا واز- ا م ﺡ ا ب ا م
ﺱ ﺡ ﺱ ةد ا ة ا ﺱ ا إ ﻩ ؤ ا م ً

ةد ا ة ا ا إ ﻩ ؤ ا م ً

ـ ا نأ ﺡ PI/٤ واز ن

و .ءا ا ص إ

هو رد ٤٥ يو و ١٨٠/٤ يأ(١٨٠) يو PI ﺡ ,ز ا ز ا ر ا , ZOOM إ ا ت ا

, وا ا

, م آ أ ن ا

وا ا ن ذو ا آ آ وا ا ت م آ إ يد م ا إ ب ا . ل هو ذ أ ة ر ت

ي او ,مر ا يأ ض ا م

ً

ا هو Near : ـ ا- و, ض او ل ا ن ةرو

م ا ا ا width/height , ل ا . ا و مر ا ا ي او ا هو Far : ـ ا- .ا ا او ا

: آ آ د ا

:د آ

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

د نأ , ر او ,ا ا ن د ﺡ نأ : ً ﺱ ي او LookAtLH ا ا ما ذو ا (Parameters).تا ار World Spaceـ ا (eyePoint) ا ا د :لو ا- ), (forwardDirection)ف ا) إ ا دا ا ا : ا- (upDirection). أ إ ا ا : ا- : ا إ أ

إ ا دا ا ﺱ ا : ا- (upDirection). أ إ ا ا : ا- :
ﻩ د و ( ا ﺱر) هو لو ا إ Vector٣(٠،٠,-٣٠) ا ت ا ﺡ
ﻩ د و ( ا ﺱر) هو لو ا إ Vector٣(٠،٠,-٣٠) ا ت ا ﺡ

د و ( ا ﺱر) هو لو ا إ Vector٣(٠،٠,-٣٠) ا ت ا ا eyepoint ـ ا ا ت ا ا forwardDirection ـ او Vector٣(٠،٠،٠) Vector٣(٠،١،٠) ا ت ا ا upDirection ـ ا و

ا ا

Vector٣(٠،٠،٠) Vector٣(٠،١،٠) ا ت ا ﺡ ا upDirection ـ ا و :ت ا ﺡ ا
: آ DirectX ـ ا ت ا ﺡ ا ة ه : د آ device.Transform.View
: آ DirectX ـ ا ت ا ﺡ ا ة ه : د آ device.Transform.View

: آ DirectX ـ ا ت ا ا ة ه

:د آ

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

,( و ا Culling Face (ـ ا : ً ﺱد ي ا ا هو ا , و أ ن و ا ا ﻩ ا ي ا ا هو ا , أ ). ا إ أ)

أ ن و ﺱ ا ا ﻩ ﺡ ا ي ا ا هو ا , أ
: هو Culling ـ ت ﺡ ا و ا) ء إ) ء إ اوCull.None :
: هو Culling ـ ت ﺡ ا و ا) ء إ) ء إ اوCull.None :

: هو Culling ـ ت ا و ا) ء إ) ء إ اوCull.None :

. آ

بر رو ا ت ا اوCull.Clockwise :

. ا

رو ا ت ا اوCull.CounterClockwise :

). ا ا ا ه ا هو) ا بر

م ا م هو (Clipping), ـ ا , ا إ أ ,ر ا دو ﺡ جر ا ا ا ء او A ا ر إ م ف ﺱ CPU ـ ا و GPU ـ ا ا ه C, ء ا ﺹ م ﺱو B, جر ا ت ا ء ة آا او .ر ا

ا ا ه C, ء ا ﺹ م ﺱو B, جر ا ت ﺱ ا ء
ً ﺱ ﺡ (ةء ا Lighting (ـ ا ع : ا ﻩ ﺡ ا ه
ً ﺱ ﺡ (ةء ا Lighting (ـ ا ع : ا ﻩ ﺡ ا ه

ً

ﺡ (ةء ا Lighting (ـ ا ع : ا ا ه إ و , د ا سور false

: ا , ط ا

د ا سور false : ا , ط ا ﺹ ـ ا ما ﺱ نأ د

ـ ا ما نأ د ا ى ن ا و Clipping و CullMode و LookAtLH وPerspectiveFovLH Lighting

:د آ

using System; using System.Drawing;

ن ا و Clipping و CullMode و LookAtLH وPerspectiveFovLH Lighting : د آ using System; using
using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using

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)

{

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

}

1, vertices); device.EndScene(); device.Present(); this.Invalidate(); }
protected override void Dispose (bool disposing) { if (disposing) { if (components != null) {

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

(WinForm our_directx_form = new WinForm()) { our_directx_form.InitializeDevice(); Application.Run(our_directx_form);
} } } } : ﺱ ا ﺱ د run ---- م ا سرد إ

}

}

}

}

: ا د run

} } } } : ﺱ ا ﺱ د run ---- م ا سرد إ س

----

م ا سرد إ

س ا

) ا ء نإ) ا سر ا

سر ا ا ه ن ل أ أ و

ن هذ ا ة آأ ﻩ ءا

ا ﺡ سر ا ا ه ن ل أ ﺡ أ و ن هذ ا ﺱ
: ا سر ا Translation ـ ا- Rotation ـ ا- -------------------- Translation ـ ا- م

: ا سر ا

Translation ـ ا- Rotation ـ ا-

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

Translation ـ ا-

م , ا ت ا ا ب ا : و Translation ـ ا ً

ا وأ ا ا ا ا ه

ك ا R ف ا ا ا

, ى ا ﻩ ا ك L ف ا وأ ا ﻩ ا

ا إ أ ر ل أ ا

:

ا هو

ا ﻩ ا ا إ أ ر ل أ ا : ا هو : هو و

: هو و ا ا ا ي او (A) ا

x = ٢-

y = ٨

: هو ا ا او

x = ٨-

y = ٢

ر ا ١٢ را A ب إ رأ أ ن ا ا -١٠ را وx ,

او x = ٨- y = ٢ ر ا ١٢ را A ب إ رأ أ
(B). ا ا ﻉ إو ا ه ت ﻉ ا ا ا ا ت ﻉ
(B). ا ا ﻉ إو ا ه ت ﻉ ا ا ا ا ت ﻉ

(B). ا ا

إو ا ه ت ا ا ا ا ت ا آ ا ئد ا ا

ت ا او إ ه و (x,y,z), هو ا ت ا ا ا ا ا (x,y,z,w) هوx٤ Matrix ٤ ا ً

, ا نزا ظ او ا

اد(w)

: آأ ة ا ا ا أ ت ا ﻩ ي و (B). او (A) ا ل ا

ا ما ب ا : ا د ا ب ا

او (A) ا ل ا .ب ا ﺹ ما ب ا : ا د ﻉ ا
او (A) ا ل ا .ب ا ﺹ ما ب ا : ا د ﻉ ا
------------ ها ا ا ت او ء ﻉ ا ا ه DirectX ـ ا ارأ
------------ ها ا ا ت او ء ﻉ ا ا ه DirectX ـ ا ارأ
------------ ها ا ا ت او ء ﻉ ا ا ه DirectX ـ ا ارأ

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

ها ا ا ت او ء ا ا ه DirectX ـ ا ارأ

ا و Translation() ا ا ما ذو : هو ب ا ت ا إ ا

:د آ

device.Transform.World = Matrix.Translation(-8,2,0)

:نأ . ا ت ا إ هو device : ـ ا ا ث ف ا نأ يأTransform.world:

:نأ . ا ت ا إ هو device : ـ ا ا ﻉ ث ف ا
.م ا ت ا ا ن ن او از ا ﺹ هوMatrix.Translation . , ا

ا ت ا ا ن ن او از ا هوMatrix.Translation

.

, ا سر ا ي ا ( ا ر) ل ا ن ا و ٨- را x ر ا ب ا ث و ا ا ا ا ا ذو ٣- را y ر ا OnPaint :

:د آ

device.Transform.World = Matrix.Translation(-8,-3,0);

: ا ا

= Matrix.Translation(-8,-3,0); : ا ا ﻉ ﻉ أ , ا ﻩ ا أ ن آ نأ

أ , ا ﻩ ا أ ن آ نأ ا ن . ا آ ب ا

آ د ا

:د آ

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data;

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 :

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

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

}

1, vertices); device.EndScene(); device.Present(); this.Invalidate(); }
protected override void Dispose (bool disposing) { if (disposing) { if (components != null) {

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

}

}

}

}

= new WinForm()) { our_directx_form.InitializeDevice(); Application.Run(our_directx_form); } } } }
Rotationـ ا- zو y و x ر ا ل وا ا را ا و :

Rotationـ ا-

zو y و x ر ا ل وا ا را ا و : و

ا ا ر ي : آ نارو ا , رد ٣٠ هر وا ا ا (Rotation) نأ درأو : ا آ

ا (Rotation) ﻉ نأ درأو : ا آ : ه ر ت ا ا م و

: ه ر ت

ا ا م و (Radian) ن دا ن او ا ت رد وأ م ا أ Geometry.DegreeToRadian ا (Radian).ـ ا إ ت ر ا

) ا إ أ (نارو ا ر

Geometry.DegreeToRadian ا (Radian).ـ ا إ ت ر ا ) ا إ أ (نارو ا ر :ً
ة هو ا ي نأ ض : آ ا : و رد ٣٠ هر وا
ة هو ا ي نأ ض : آ ا : و رد ٣٠ هر وا

ة هو ا ي نأ ض : آ ا

: و

ة هو ا ي نأ ض : آ ا : و رد ٣٠ هر وا ة

رد ٣٠ هر وا ة ا نارود م ن ا : آ X, ر ا

ا : و رد ٣٠ هر وا ة ا نارود ﻉ م ن ا : آ
رد ٣٠ هر وا ة ا نارود ﻉ م ن ا : آ ﺹ Y,
رد ٣٠ هر وا ة ا نارود ﻉ م ن ا : آ ﺹ Y,

رد ٣٠ هر وا ة ا نارود م ن ا : آ Y, ر ا

ﻉ م ن ا : آ ﺹ Y, ر ا رد ٣٠ هر وا ة ا

رد ٣٠ هر وا ة ا نارود م ن ا : آ Z, ر ا

Y, ر ا رد ٣٠ هر وا ة ا نارود ﻉ م ن ا : آ
ت ا ا ن ﻉ ا , (Rotation) نارود :ً . ﻉ ا وا ا
ت ا ا ن ﻉ ا , (Rotation) نارود :ً . ﻉ ا وا ا

ت ا ا ن ا , (Rotation) نارود . ا وا ا ا إ ا ط ا ه ب أ

. نارو ا وا Sin ـ ا و Cos ـ ا و ا ت ا ا

ً

ر

ن ا هو) ة ا ة اد هو ل أ : ا آ ,( او يو ا إ

ا ا ً ر ن ا هو) ة ا ة اد هو ل أ : ا
ا ا ً ر ن ا هو) ة ا ة اد هو ل أ : ا
آ ا رد ٣٠ وا نارود تدرأ أ ض و X ـ ت ا ا

آ ا رد ٣٠ وا نارود تدرأ أ ض و X ـ ت ا ا إ ج ه , ا لو ا F, ا د ط إ م Y , ـ ا ا ه ب و Y, ر ا او X ر ا : آ ن ٠ ٨٦٧ : يو و ٣٠ ـ اX = Cos : ٠ ٥يو و ٣٠ ـ اY = Sin ). ا إ أ(

٥يو و ٣٠ ـ اY = Sin ). ا إ أ( ----------------- ﺹ ما ﻉ ا

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

ما ا م DirectX ـ ا أ (Matrix Rotation).نارو ا : ه X ر نارو ا

ا أ (Matrix Rotation).نارو ا : ه X ر نارو ا ﺹ : ه Y ر

: ه Y ر نارو ا

ا أ (Matrix Rotation).نارو ا : ه X ر نارو ا ﺹ : ه Y ر
: ه Z ر نارو ا ﺹ ----------------------- ا سر ا ل ا Matrix ـ
: ه Z ر نارو ا ﺹ ----------------------- ا سر ا ل ا Matrix ـ

: ه Z ر نارو ا

: ه Z ر نارو ا ﺹ ----------------------- ا سر ا ل ا Matrix ـ ا

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

ا سر ا ل ا Matrix ـ ا آ ي رد ١٨٠ وا نارو ا و, ا هو .نارو ا ة ا ت ا ا ى X, ر ا

: هو ا ا ت ا إ

:د آ

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

: ه X ر نارو ا

Vector3(10f, 0f, 0f)); vertices[2].SetPosition(new Vector3(5f, 10f, 0f)); : ه X ر نارو ا ﺹ
Vector3(10f, 0f, 0f)); vertices[2].SetPosition(new Vector3(5f, 10f, 0f)); : ه X ر نارو ا ﺹ
: و ا ا : د آ vertices[0].SetPosition(new Vector3(0f, 0f, 0f)); ب اد نذإ ,

: و ا ا

:د آ

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

ب اد نذإ , يو ا رو ا نأ ).٠،٠،٠) ه آ ا ن ف ا

: ا ا

:د آ

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

د آ vertices[1].SetPosition(new Vector3(10f, 0f, 0f)); : ا ا : د آ vertices[2].SetPosition(new

: ا ا

:د آ

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

Vector3(10f, 0f, 0f)); : ا ا : د آ vertices[2].SetPosition(new Vector3(5f, 10f, 0f));
Vector3(10f, 0f, 0f)); : ا ا : د آ vertices[2].SetPosition(new Vector3(5f, 10f, 0f));
: رد ١٨٠ وا نارو ا ﻉ ة ا ا ت ا إ : د

: رد ١٨٠ وا نارو ا ة ا ا ت ا إ

:د آ

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

-----------

نأ أ آ أ ن ا د ا ت ا ء اد DirectX ـ ا : ا : هو ا نارو ا اد

:د آ

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

ا نارو ا اد

:د