アットウィキロゴ

30i

using System;
using System.Collections.Generic;
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 game0223
{

   public class Game1 : Microsoft.Xna.Framework.Game
   {

       private GraphicsDeviceManager graphics = null;
       private SpriteBatch spriteBatch = null;
       private VertexDeclaration vertexDeclaration = null;
       private VertexBuffer vertexBuffer = null;
       private BasicEffect basicEffect = null;


       public Game1()
       {
           this.graphics = [[new]] GraphicsDeviceManager(this);
           this.Content.RootDirectory = "Content";
       }


       protected override void Initialize()
       {
           base.Initialize();
       }


       protected override void LoadContent()
       {

           this.spriteBatch = new SpriteBatch(this.GraphicsDevice);

           this.vertexDeclaration = new VertexDeclaration(
               this.GraphicsDevice, VertexPositionColor.VertexElements);


           this.basicEffect = new BasicEffect(this.GraphicsDevice, null);


           this.basicEffect.VertexColorEnabled = true;

           this.basicEffect.View = Matrix.CreateLookAt(
                   new Vector3(0.0f, 0.0f, 10.0f),
                   Vector3.Zero,
                   Vector3.Up
               );

           // プロジェクションマトリックスをあらかじめ設定
           this.basicEffect.Projection = Matrix.CreatePerspectiveFieldOfView(
                   MathHelper.ToRadians(45.0f),
                   (float)this.GraphicsDevice.Viewport.Width /
                       (float)this.GraphicsDevice.Viewport.Height,
                   1.0f,
                   [[100]].0f
               );

           // 頂点の数
           int vertexCount = 3;

           // 頂点バッファ作成
           this.vertexBuffer = new VertexBuffer(this.GraphicsDevice,
               VertexPositionColor.SizeInBytes * vertexCount, BufferUsage.None);

           // 頂点データを作成する
           VertexPositionColor[] pointList = new VertexPositionColor[vertexCount];

           pointList[0] = new VertexPositionColor(new Vector3(0.0f, 3.0f, 0.0f), Color.Red);
           pointList[1] = new VertexPositionColor(new Vector3(3.0f, -2.0f, 0.0f), Color.Blue);
           pointList[2] = new VertexPositionColor(new Vector3(-3.0f, -2.0f, 0.0f), Color.Green);

           // 頂点データを頂点バッファに書き込む
           this.vertexBuffer.SetData<VertexPositionColor>(pointList);
       }

       /// <summary>
       /// ゲームが終了するときに一回だけ呼ばれ
       /// すべてのゲームコンテンツをアンロードします
       /// </summary>
       protected override void UnloadContent()
       {
           // TODO: ContentManager で管理されていないコンテンツを
           //       ここでアンロードしてください
       }

       /// <summary>
       /// 描画以外のデータ更新等の処理を行うメソッド
       /// 主に入力処理、衝突判定などの物理計算、オーディオの再生など
       /// </summary>
       /// <param name="gameTime">このメソッドが呼ばれたときのゲーム時間</param>
       protected override void Update(GameTime gameTime)
       {
           // Xbox 360 コントローラの BACK ボタンを押したときにゲームを終了させます
           if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
               this.Exit();

           // TODO: ここに更新処理を記述してください

           // 登録された GameComponent を更新する
           base.Update(gameTime);
       }

       /// <summary>
       /// 描画処理を行うメソッド
       /// </summary>
       /// <param name="gameTime">このメソッドが呼ばれたときのゲーム時間</param>
       protected override void Draw(GameTime gameTime)
       {
           // 画面を指定した色でクリアします
           this.GraphicsDevice.Clear(Color.CornflowerBlue);

           // 描画する頂点データの定義を設定
           this.GraphicsDevice.VertexDeclaration = this.vertexDeclaration;

           // 描画に使用する頂点バッファをセットします
           this.GraphicsDevice.Vertices[0].SetSource(
               this.vertexBuffer,
               0,
               VertexPositionColor.SizeInBytes);

           // エフェクトの使用を開始します
           this.basicEffect.Begin();

           // パスの数だけ繰り返し描画
           [[foreach]] (EffectPass pass in this.basicEffect.CurrentTechnique.Passes)
           {
               // パスの開始
               pass.Begin();

               // 三角形を描画する
               this.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);

               // パスの終了
               pass.End();
           }

           // エフェクトの使用を終了する
           this.basicEffect.End();

           // 登録された DrawableGameComponent を描画する
           base.Draw(gameTime);
       }
   }
}
最終更新:2011年02月16日 10:14