Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Game1

By: a guest on Jul 26th, 2011  |  syntax: C#  |  size: 4.62 KB  |  views: 78  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11.  
  12. namespace PlanetTest
  13. {
  14.     /// <summary>
  15.     /// This is the main type for your game
  16.     /// </summary>
  17.     public class Game1 : Microsoft.Xna.Framework.Game
  18.     {
  19.         GraphicsDeviceManager graphics;
  20.         SpriteBatch spriteBatch;
  21.  
  22.         PlanetTerrainMap terrain;
  23.         Model sphere;
  24.  
  25.         Matrix ViewMatrix;
  26.         Matrix ProjectionMatrix;
  27.  
  28.         public Game1()
  29.         {
  30.             graphics = new GraphicsDeviceManager(this);
  31.             Content.RootDirectory = "Content";
  32.         }
  33.  
  34.         /// <summary>
  35.         /// Allows the game to perform any initialization it needs to before starting to run.
  36.         /// This is where it can query for any required services and load any non-graphic
  37.         /// related content.  Calling base.Initialize will enumerate through any components
  38.         /// and initialize them as well.
  39.         /// </summary>
  40.         protected override void Initialize()
  41.         {
  42.             // TODO: Add your initialization logic here
  43.             ViewMatrix = Matrix.CreateLookAt(new Vector3(0, 0, -10), new Vector3(0, 0, 0), Vector3.Up);
  44.             ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1, 1000);
  45.             base.Initialize();
  46.         }
  47.  
  48.         /// <summary>
  49.         /// LoadContent will be called once per game and is the place to load
  50.         /// all of your content.
  51.         /// </summary>
  52.         protected override void LoadContent()
  53.         {
  54.             // Create a new SpriteBatch, which can be used to draw textures.
  55.             spriteBatch = new SpriteBatch(GraphicsDevice);
  56.             sphere = Content.Load<Model>("sphere");
  57.             terrain = new PlanetTerrainMap(1000, 20, GraphicsDevice, Content);
  58.             // TODO: use this.Content to load your game content here
  59.         }
  60.  
  61.         /// <summary>
  62.         /// UnloadContent will be called once per game and is the place to unload
  63.         /// all content.
  64.         /// </summary>
  65.         protected override void UnloadContent()
  66.         {
  67.             // TODO: Unload any non ContentManager content here
  68.         }
  69.  
  70.         /// <summary>
  71.         /// Allows the game to run logic such as updating the world,
  72.         /// checking for collisions, gathering input, and playing audio.
  73.         /// </summary>
  74.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  75.         protected override void Update(GameTime gameTime)
  76.         {
  77.             // Allows the game to exit
  78.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  79.                 this.Exit();
  80.  
  81.            
  82.  
  83.             // TODO: Add your update logic here
  84.  
  85.             base.Update(gameTime);
  86.         }
  87.  
  88.         /// <summary>
  89.         /// This is called when the game should draw itself.
  90.         /// </summary>
  91.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  92.         protected override void Draw(GameTime gameTime)
  93.         {
  94.  
  95.             float time = (float)gameTime.TotalGameTime.TotalSeconds;
  96.  
  97.             Matrix rotation = Matrix.CreateRotationY(time * 0.5f);
  98.  
  99.             GraphicsDevice.Clear(Color.CornflowerBlue);
  100.  
  101.             Matrix[] transforms = new Matrix[sphere.Bones.Count];
  102.             sphere.CopyAbsoluteBoneTransformsTo(transforms);
  103.             RasterizerState rState = new RasterizerState();
  104.             rState.FillMode = FillMode.Solid;
  105.             GraphicsDevice.RasterizerState = rState;
  106.  
  107.             foreach (ModelMesh mesh in sphere.Meshes)
  108.             {
  109.                 foreach (BasicEffect effect in mesh.Effects)
  110.                 {
  111.                     effect.World = (transforms[mesh.ParentBone.Index] * rotation);
  112.                     //effect.Parameters["WorldInverseTranspose"].SetValue(Matrix.Transpose(Matrix.Invert(transforms[mesh.ParentBone.Index] * world)));
  113.                     effect.View = ViewMatrix;
  114.                     effect.Projection = ProjectionMatrix;
  115.                     effect.Texture = terrain.Image;
  116.                     //for testing purposes:
  117.                     //effect.Parameters["DiffuseColor"].SetValue(new Vector4(1, 0, 0, 1));
  118.                 }
  119.                 mesh.Draw();
  120.             }
  121.             // TODO: Add your drawing code here
  122.  
  123.             base.Draw(gameTime);
  124.         }
  125.     }
  126. }