Hallo zusammen!
Bin Neueinstieger bei C#/XNA 4.0. In meinem Listing soll der Himmel dargestellt werden. Das Codebeispiel stammt von "XNA.mag", allerdings funktioniert das nicht, und ich weiß nicht warum:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93:
| 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;
namespace WindowsGame8 { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch;
Model skyDome; Texture2D skydomeTex; Vector3 PlayerPosition = Vector3.Zero;
Matrix worldMatrix; Matrix viewMatrix; Matrix projectionMatrix;
public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content";
} protected override void Initialize() { base.Initialize(); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice);
skyDome = Content.Load<Model>("skydome"); skydomeTex = Content.Load<Texture2D>("skydometex");
worldMatrix = Matrix.Identity; viewMatrix = Matrix.CreateLookAt(new Vector3(10.0f, 1.0f, 4.0f), Vector3.Zero, Vector3.Up); projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), 800.0f / 600.0f, 1.0f, 100.0f); } protected override void UnloadContent() { }
protected override void Update(GameTime gameTime) { base.Update(gameTime); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Blue);
foreach (ModelMesh mesh in skyDome.Meshes) { foreach (BasicEffect ef in mesh.Effects) { ef.World = Matrix.CreateScale(1f) * Matrix.CreateTranslation(PlayerPosition);
ef.View = viewMatrix; ef.Projection = projectionMatrix;
ef.TextureEnabled = true; //Textur zulassen ef.Texture = skydomeTex; //Textur auf Model darstellen } mesh.Draw(); }
base.Draw(gameTime); } } } |
Bitte um Hilfe!
Als Anmerkung: CreateScale in der Methode Draw sollte eigentlich auf 1000 gesetzt werden. Doch damit erscheint gar nichts, also nur der leere, blaue Hintergrund....