「VCS/XnaModel」の編集履歴(バックアップ)一覧はこちら

VCS/XnaModel - (2012/12/26 (水) 21:31:20) の1つ前との変更点

追加された行は緑色になります。

削除された行は赤色になります。

|開発環境|Microsoft Visual C# 2010 Express (SP1)| |実行環境|Microsoft Windows XP Home Edition (SP3)| |プロジェクトの種類|Windows Game (4.0)| |プロジェクト名|XnaModel| Game1.cs #highlight(c#){{ using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace XnaModel { class Game1 : Game { GraphicsDeviceManager graphics; SpriteBatch sprite; SpriteFont font; Model model; Matrix[] worlds; Matrix proj; // fps int sec; int draw = 0; int fps = 0; // カメラ int camLat = 30; int camLong = 90; float camDist = 10; public Game1() { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; Content.RootDirectory = "Content"; IsMouseVisible = true; } protected override void LoadContent() { sprite = new SpriteBatch(GraphicsDevice); font = Content.Load<SpriteFont>("SpriteFont1"); model = Content.Load<Model>("aircraft"); worlds = new Matrix[3]; worlds[0] = Matrix.CreateTranslation(new Vector3(0, 0, 0)); worlds[1] = Matrix.CreateTranslation(new Vector3(-10, 0, -10)); worlds[2] = Matrix.CreateTranslation(new Vector3(10, 0, -10)); proj = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45), GraphicsDevice.Viewport.AspectRatio, 0.1f, 1000); foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.DiffuseColor = new Vector3(0.8f, 0.8f, 0.8f); } } base.LoadContent(); } protected override void Update(GameTime gameTime) { KeyboardState kState = Keyboard.GetState(); if (kState.IsKeyDown(Keys.Escape)) Exit(); if (kState.IsKeyDown(Keys.Up)) camLat = Math.Min(camLat + 1, 89); if (kState.IsKeyDown(Keys.Down)) camLat = Math.Max(camLat - 1, -89); if (kState.IsKeyDown(Keys.Left)) camLong = (camLong + 1) % 360; if (kState.IsKeyDown(Keys.Right)) camLong = (camLong + 359) % 360; if (kState.IsKeyDown(Keys.PageUp)) camDist -= 0.2f; if (kState.IsKeyDown(Keys.PageDown)) camDist += 0.2f; base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.BlendState = BlendState.Opaque; //GraphicsDevice.RasterizerState = new RasterizerState { FillMode = FillMode.WireFrame}; // カメラ位置 Vector3 pos; float rad = MathHelper.ToRadians(camLat); pos.Y = (float)Math.Sin(rad) * camDist; float r = (float)Math.Cos(rad) * camDist; rad = MathHelper.ToRadians(camLong); pos.X = (float)Math.Cos(rad) * r; pos.Z = (float)Math.Sin(rad) * r; Matrix view = Matrix.CreateLookAt(pos, Vector3.Zero, Vector3.Up); foreach (Matrix world in worlds) { model.Draw(world, view, proj); } // fps draw++; if (gameTime.TotalGameTime.Seconds != sec) { fps = draw; draw = 0; sec = gameTime.TotalGameTime.Seconds; } // 2D描画 sprite.Begin(); string text = String.Format( "fps={0} lat={1} long={2} dist={3:f1}", fps, camLat, camLong, camDist); sprite.DrawString(font, text, new Vector2(0, 0), Color.White); sprite.End(); base.Draw(gameTime); } } } }}
|開発環境|Microsoft Visual C# 2010 Express (SP1)| |実行環境|Microsoft Windows XP Home Edition (SP3)| |プロジェクトの種類|Windows Game (4.0)| |プロジェクト名|XnaModel| Game1.cs #highlight(c#){{ using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace XnaModel { class Game1 : Game { GraphicsDeviceManager graphics; SpriteBatch sprite; SpriteFont font; Model model; Matrix[] worlds; Matrix proj; MouseState mStateOld = new MouseState(); // fps int sec; int draw = 0; int fps = 0; // カメラ float camLat = 30; float camLon = -150; float camDist = 10; public Game1() { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; Content.RootDirectory = "Content"; IsMouseVisible = true; } protected override void LoadContent() { sprite = new SpriteBatch(GraphicsDevice); font = Content.Load<SpriteFont>("SpriteFont1"); model = Content.Load<Model>("aircraft"); worlds = new Matrix[3]; worlds[0] = Matrix.CreateTranslation(new Vector3(0, 0, 0)); worlds[1] = Matrix.CreateTranslation(new Vector3(10, 0, -10)); worlds[2] = Matrix.CreateTranslation(new Vector3(10, 0, 10)); proj = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45), GraphicsDevice.Viewport.AspectRatio, 0.1f, 1000); foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); //effect.DiffuseColor = new Vector3(0.8f, 0.8f, 0.8f); } } base.LoadContent(); } protected override void Update(GameTime gameTime) { float deltaLat = 0; float deltaLon = 0; float deltaDist = 0; // キーボード KeyboardState kState = Keyboard.GetState(); if (kState.IsKeyDown(Keys.Escape)) Exit(); if (kState.IsKeyDown(Keys.Up)) deltaLat = 1; if (kState.IsKeyDown(Keys.Down)) deltaLat = -1; if (kState.IsKeyDown(Keys.Left)) deltaLon = 1; if (kState.IsKeyDown(Keys.Right)) deltaLon = -1; if (kState.IsKeyDown(Keys.PageUp)) deltaDist = -0.2f; if (kState.IsKeyDown(Keys.PageDown)) deltaDist = 0.2f; // マウス MouseState mState = Mouse.GetState(); if (mState.LeftButton == ButtonState.Pressed) { deltaLat = (mState.Y - mStateOld.Y) * 0.5f; deltaLon = (mState.X - mStateOld.X) * 0.5f; } if (mState.ScrollWheelValue != mStateOld.ScrollWheelValue) { deltaDist = (mState.ScrollWheelValue - mStateOld.ScrollWheelValue) / -120; } mStateOld = mState; // カメラ移動 if (deltaLat != 0) { camLat = MathHelper.Clamp(camLat + deltaLat, -89.9f, 89.9f); } if (deltaLon != 0) { camLon += deltaLon; if (camLon <= -180) camLon += 360; if (180 < camLon) camLon -= 360; } if (deltaDist != 0) { camDist = MathHelper.Clamp(camDist + deltaDist, 1, 1000); } base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.BlendState = BlendState.AlphaBlend; //GraphicsDevice.RasterizerState = new RasterizerState { FillMode = FillMode.WireFrame}; // カメラ位置 float rad = MathHelper.ToRadians(camLat); float y = (float)Math.Sin(rad) * camDist; float r = (float)Math.Cos(rad) * camDist; rad = MathHelper.ToRadians(camLon); float x = (float)Math.Cos(rad) * r; float z = (float)Math.Sin(rad) * r; Matrix view = Matrix.CreateLookAt(new Vector3(x, y, z), Vector3.Zero, Vector3.Up); foreach (Matrix world in worlds) { model.Draw(world, view, proj); } // fps draw++; if (gameTime.TotalGameTime.Seconds != sec) { fps = draw; draw = 0; sec = gameTime.TotalGameTime.Seconds; } // 2D描画 sprite.Begin(); string text = String.Format( "fps={0} lat={1} long={2} dist={3:f1}", fps, camLat, camLon, camDist); sprite.DrawString(font, text, new Vector2(0, 0), Color.White); sprite.End(); base.Draw(gameTime); } } } }}

表示オプション

横に並べて表示:
変化行の前後のみ表示: