AppleSeeker's Tech Blog
Welcome to AppleSeeker's space
posts - 84,  comments - 767,  trackbacks - 6

毫无疑问,实现这个旋转的正方形只涉及了XNA中的基础内容。现在对项目进行简单的修改从而使显示出来的图形更加生动且更富吸引力。

按代码所示来修改Draw函数的代码,将会看到绘制到屏幕上的图形发生了重大的变化

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);
    // Reset the world matrix
    _effect.World = Matrix.Identity;
    // Loop for each square
    for (int i = 0; i < 20; i++)
    {
        foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
        {
            // Apply a further rotation
            _effect.World = Matrix.CreateRotationZ(_angle) * _effect.World;
            // Scale the object so that it is shown slightly smaller
            _effect.World = Matrix.CreateScale(0.85f) * _effect.World;
            // Apply the pass
            pass.Apply();
            // Draw the square
            GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, _vertices, 0, 2);
        }
    }
    base.Draw(gameTime);
}

image

遗憾屏幕截图无法反应出项目中真实的运行效果;虽然动态内容肯定要比静止的图像好的多,但这种使用短小代码块来生成效果的方式非常好。

在循环中所做的就是绘制20个形状,每一个都比上一个略小并旋转到不同的角度。缩放和旋转操作是累计的,这意味着第一个(最大的)正方形以指定的角度_angle进行旋转,则第二个正方形就会以该角度的两倍进行旋转,第三个则以三倍角度旋转,以此类推。

posted on 2011-07-01 21:14 AppleSeeker(冯峰) 阅读(263) 评论(0) 编辑 收藏
Free Hit Counter

MSN:appleseeker@hotmail.com
Mail:appleseeker@gmail.com MVP


【新品特价】SPORTICA 防水商务10春新款内里绒夹克外套03409081
[YT001]深层去斑美白去斑套餐 去黑淡痘印 最好最热产品日销千套
昵称:AppleSeeker(冯峰)
园龄:6年6个月
粉丝:33
关注:3

<2011年7月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

搜索

 

常用链接

最新随笔

我的标签

随笔分类(124)

随笔档案(84)

Mobile Blog

Recommend Blog

  • 李占卫

Recommend Site

  • Green IT

积分与排名

  • 积分 - 230256
  • 排名 - 352

最新评论

阅读排行榜

评论排行榜

推荐排行榜