C++ Programmer's Cookbook

{C++ 基础} {C++ 高级} {C#界面,C++核心算法} {设计模式} {C#基础}

Managed directx -----the different of transformed vertex and untransformed vertex

transformed  vertex :  默认的有视口,不需要再建立camara.

public void OnCreateVertexBuffer(object sender, EventArgs e)
        
{
            VertexBuffer vb 
= (VertexBuffer)sender;
            GraphicsStream stm 
= vb.Lock(000);
            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.0f0);
            
//Begin the scene
            device.BeginScene();
            
            device.SetStreamSource( 
0, vertexBuffer, 0);
            device.VertexFormat 
= CustomVertex.TransformedColored.Format;
            device.DrawPrimitives(PrimitiveType.TriangleList, 
01);
            
//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.0f0);
            
//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, 
01);
            
//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.0f3.0f,-5.0f ), new Vector3( 0.0f0.0f0.0f ), new Vector3( 0.0f1.0f0.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 / 41.0f1.0f100.0f );
        }
看好拉,多了一个建立matrix的function: 她的作用看代码喽!!!~~~~~~~~~~~~~~

posted on 2006-06-09 16:33 梦在天涯 阅读(557) 评论(1)  编辑 收藏 引用 所属分类: DirectX

评论

# re: the different of transformed vertex and untransformed vertex 2006-06-09 16:37 梦在天涯

都有这个device.SetStreamSource(0, vertexBuffer, 0);
她的作用?可以不要吗?
  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


公告

EMail:itech001#126.com

导航

统计

  • 随笔 - 461
  • 文章 - 4
  • 评论 - 746
  • 引用 - 0

常用链接

随笔分类

随笔档案

收藏夹

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

积分与排名

  • 积分 - 1783918
  • 排名 - 5

最新评论

阅读排行榜