using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace Barbs { class Program : Game, IDisposable { Texture2D ballTexture; private GraphicsDeviceManager graphics; private SpriteBatch spriteBatch; BasicEffect basicEffect; Matrix world; Matrix view; Matrix projection; Line testLine; Effect lineEffect; public Program() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "."; } protected override void Initialize() { graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height; graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width; graphics.ApplyChanges(); Window.IsBorderless = true; base.Initialize(); } protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); ballTexture = Content.Load("ball"); world = Matrix.CreateTranslation(0, 0, 0); view = Matrix.CreateLookAt(new Vector3(0.3f, 0, 2.0f), new Vector3(0, 0, 0), new Vector3(0, 1, 0)); projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 480f, 0.01f, 100f); basicEffect = new BasicEffect(GraphicsDevice); lineEffect = Content.Load("line"); Vector2[] arr = { new Vector2(0.0f,0.0f), new Vector2(0.2f,0.5f), new Vector2(0.2f,0.0f), new Vector2(0.5f,0.0f), new Vector2(0.7f,-0.5f), new Vector2(1.0f, 1.0f)}; this.testLine = new Line(new List(arr), 0.01f, Color.DarkSlateGray); this.testLine.InitOnGraphicalDevice(GraphicsDevice); } protected void Dispose() { //Cleanup // OR Final call before shutdown } protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); // TODO: Add your update logic here base.Update(gameTime); } protected override void Draw(GameTime gameTime) { //graphics.GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.Clear(Color.White); // TODO: Add your drawing code here // spriteBatch.Begin(); // spriteBatch.Draw(ballTexture, new Vector2(0, 0), Color.White); // spriteBatch.End(); basicEffect.World = world; basicEffect.View = view; basicEffect.Projection = projection; basicEffect.VertexColorEnabled = true; lineEffect.Parameters["WorldViewProjection"].SetValue(world*view*projection); this.testLine.Draw(this.lineEffect); base.Draw(gameTime); } static void Main(string[] args) { using (Program game = new Program()) { game.Run(); } } } }