Files
Barbs/Program.cs
2021-03-28 17:55:16 +02:00

90 lines
3.0 KiB
C#

using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Barbs
{
class Program : Game
{
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()
{
// TODO: Add your initialization logic here
graphics.PreferredBackBufferHeight = 1824;
graphics.PreferredBackBufferWidth = 2736;
graphics.ApplyChanges();
base.Initialize();
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
ballTexture = Content.Load<Texture2D>("ball");
world = Matrix.CreateTranslation(0, 0, 0);
view = Matrix.CreateLookAt(new Vector3(0, 0, 3), 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<Effect>("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)};
this.testLine = new Line(new List<Vector2>(arr), 0.01f, Color.DarkSlateGray);
this.testLine.InitOnGraphicalDevice(GraphicsDevice);
}
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)
{
var pro = new Program();
pro.Run();
}
}
}