アットウィキロゴ

cs0209

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace game0209c
{
  
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        BasicEffect effect;

        VertexPositionColor[] vertices = new VertexPositionColor[3];
        float angle = 0;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);

            vertices[0] = new VertexPositionColor(new Vector3(1, 1, 0), Color.Blue);
            vertices[1] = new VertexPositionColor(new Vector3(0, 0, 0), Color.Black);
            vertices[2] = new VertexPositionColor(new Vector3(-1, 1, 0), Color.Red);
        }

        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
                effect = new BasicEffect(graphics.GraphicsDevice, null);
                effect.VertexColorEnabled = true;
                effect.Projection = Matrix.CreatePerspectiveFieldOfView(
                    MathHelper.ToRadians(45),
                    Window.ClientBounds.Width / (float)Window.ClientBounds.Height,
                    1,
                    100
                    );
            }
        }

        protected override void Update(GameTime gameTime)
        {
            angle = angle+0.01f;
        }

        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

            graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration(
                graphics.GraphicsDevice,
                VertexPositionColor.VertexElements
                );

            effect.View = Matrix.CreateLookAt(
                new Vector3(3 * (float)Math.Cos(angle), 0, 3 * (float)Math.Tan(angle)),
                new Vector3(0, 0, 0),
                new Vector3(0, 1, 0)
                );

            effect.Begin();

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();

                graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
                    PrimitiveType.TriangleList, vertices, 0, 1);
                pass.End();
            }

            effect.End();
        }
    }
}
最終更新:2011年02月11日 07:16