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 game0218
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
private GraphicsDeviceManager graphics = null;
private SpriteBatch spriteBatch = null;
private VertexDeclaration vertexDeclaration = null;
private VertexPositionColor[] vertices = 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
);
this.vertices = new VertexPositionColor[6];
this.vertices[0] = new VertexPositionColor(new Vector3(0.0f, 3.0f, 0.0f),
Color.Red);
this.vertices[1] = new VertexPositionColor(new Vector3(3.0f, -2.0f, 0.0f),
Color.Blue);
this.vertices[2] = new VertexPositionColor(new Vector3(-3.0f, -2.0f, 0.0f),
Color.Green);
this.vertices[3] = new VertexPositionColor(new Vector3(0.0f, -2.0f, 1.0f),
Color.Green);
this.vertices[4] = new VertexPositionColor(new Vector3(3.0f, -2.0f, 1.5f),
Color.Blue);
this.vertices[5] = new VertexPositionColor(new Vector3(-3.0f, -2.0f, 2.0f),
Color.Green);
}
protected override void UnloadContent()
{
// TODO: ContentManager で管理されていないコンテンツを
// ここでアンロードしてください
}
protected override void Update(GameTime gameTime)
{
// Xbox 360 コントローラの BACK ボタンを押したときにゲームを終了させます
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
this.GraphicsDevice.Clear(Color.CornflowerBlue);
this.GraphicsDevice.VertexDeclaration = this.vertexDeclaration;
this.basicEffect.Begin();
[[foreach]] (EffectPass pass in this.basicEffect.CurrentTechnique.Passes)
{
pass.Begin();
this.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
PrimitiveType.TriangleList,
vertices,
0,
2
);
pass.End();
}
this.basicEffect.End();
base.Draw(gameTime);
}
}
}
最終更新:2011年02月16日 23:28