transformed? vertex :? 默認(rèn)的有視口,不需要再建立camara.
public?void?OnCreateVertexBuffer(object?sender,?EventArgs?e)

????????
{
????????????VertexBuffer?vb?=?(VertexBuffer)sender;
????????????GraphicsStream?stm?=?vb.Lock(0,?0,?0);
????????????CustomVertex.TransformedColored[]?verts?=?new?CustomVertex.TransformedColored[3];

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

????????
{
????????????if?(device?==?null)?
????????????????return;

????????????//Clear?the?backbuffer?to?a?blue?color?(ARGB?=?000000ff)
????????????device.Clear(ClearFlags.Target,?System.Drawing.Color.Blue,?1.0f,?0);
????????????//Begin?the?scene
????????????device.BeginScene();
????????????
????????????device.SetStreamSource(?0,?vertexBuffer,?0);
????????????device.VertexFormat?=?CustomVertex.TransformedColored.Format;
????????????device.DrawPrimitives(PrimitiveType.TriangleList,?0,?1);
????????????//End?the?scene
????????????device.EndScene();
????????????device.Present();
????????}untransformed vertex : 必須的manual建立camare去顯示
public?void?OnCreateVertexBuffer(object?sender,?EventArgs?e)

????????
{
????????????VertexBuffer?vb?=?(VertexBuffer)sender;
????????????CustomVertex.PositionColored[]?verts?=?(CustomVertex.PositionColored[])vb.Lock(0,0);
????????????verts[0].X=-1.0f;?verts[0].Y=-1.0f;?verts[0].Z=0.0f;?verts[0].Color?=?System.Drawing.Color.DarkGoldenrod.ToArgb();
????????????verts[1].X=1.0f;?verts[1].Y=-1.0f?;verts[1].Z=0.0f;?verts[1].Color?=?System.Drawing.Color.MediumOrchid.ToArgb();
????????????verts[2].X=0.0f;?verts[2].Y=1.0f;?verts[2].Z?=?0.0f;?verts[2].Color?=?System.Drawing.Color.Cornsilk.ToArgb();
????????????vb.Unlock();
????????}

????????private?void?Render()

????????
{
????????????if?(device?==?null)?
????????????????return;

????????????if?(pause)
????????????????return;

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

????????private?void?SetupMatrices()

????????
{
????????????//?For?our?world?matrix,?we?will?just?rotate?the?object?about?the?y-axis.

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

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

????????????//?For?the?projection?matrix,?we?set?up?a?perspective?transform?(which
????????????//?transforms?geometry?from?3D?view?space?to?2D?viewport?space,?with
????????????//?a?perspective?divide?making?objects?smaller?in?the?distance).?To?build
????????????//?a?perpsective?transform,?we?need?the?field?of?view?(1/4?pi?is?common),
????????????//?the?aspect?ratio,?and?the?near?and?far?clipping?planes?(which?define?at
????????????//?what?distances?geometry?should?be?no?longer?be?rendered).
????????????device.Transform.Projection?=?Matrix.PerspectiveFovLH(?(float)Math.PI?/?4,?1.0f,?1.0f,?100.0f?);
????????}看好拉,多了一個建立matrix的function: 她的作用看代碼嘍!!!~~~~~~~~~~~~~~