init commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
bin/
|
||||||
|
.vscode/
|
||||||
|
obj/
|
||||||
14
Barbs.csproj
Normal file
14
Barbs.csproj
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.0.1641" />
|
||||||
|
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
33
Content.mgcb
Normal file
33
Content.mgcb
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
#----------------------------- Global Properties ----------------------------#
|
||||||
|
|
||||||
|
/outputDir:bin\Debug\net5.0
|
||||||
|
/intermediateDir:obj
|
||||||
|
/platform:Windows
|
||||||
|
/config:
|
||||||
|
/profile:Reach
|
||||||
|
/compress:False
|
||||||
|
|
||||||
|
#-------------------------------- References --------------------------------#
|
||||||
|
|
||||||
|
|
||||||
|
#---------------------------------- Content ---------------------------------#
|
||||||
|
|
||||||
|
#begin ball.png
|
||||||
|
/importer:TextureImporter
|
||||||
|
/processor:TextureProcessor
|
||||||
|
/processorParam:ColorKeyColor=255,0,255,255
|
||||||
|
/processorParam:ColorKeyEnabled=True
|
||||||
|
/processorParam:GenerateMipmaps=False
|
||||||
|
/processorParam:PremultiplyAlpha=True
|
||||||
|
/processorParam:ResizeToPowerOfTwo=False
|
||||||
|
/processorParam:MakeSquare=False
|
||||||
|
/processorParam:TextureFormat=Color
|
||||||
|
/build:ball.png
|
||||||
|
|
||||||
|
#begin line.fx
|
||||||
|
/importer:EffectImporter
|
||||||
|
/processor:EffectProcessor
|
||||||
|
/processorParam:DebugMode=Auto
|
||||||
|
/build:line.fx
|
||||||
|
|
||||||
111
Line.cs
Normal file
111
Line.cs
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
|
public class Line
|
||||||
|
{
|
||||||
|
private List<Vector2> points;
|
||||||
|
private float thickness = 1.0f;
|
||||||
|
|
||||||
|
public enum JoinType
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Miter,
|
||||||
|
Bevel,
|
||||||
|
Round
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum LineCaps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Round
|
||||||
|
}
|
||||||
|
|
||||||
|
private Color LineColor { get; set; }
|
||||||
|
|
||||||
|
//Graphical representation
|
||||||
|
private VertexBuffer vbo;
|
||||||
|
private IndexBuffer ibo;
|
||||||
|
private GraphicsDevice gDevice;
|
||||||
|
|
||||||
|
public Line(List<Vector2> points)
|
||||||
|
{
|
||||||
|
this.points = points;
|
||||||
|
this.LineColor = Color.Black;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Line(List<Vector2> points, float thickness)
|
||||||
|
{
|
||||||
|
this.points = points;
|
||||||
|
this.thickness = thickness;
|
||||||
|
this.LineColor = Color.Black;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Line(List<Vector2> points, float thickness, Color color)
|
||||||
|
{
|
||||||
|
this.points = points;
|
||||||
|
this.thickness = thickness;
|
||||||
|
this.LineColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InitOnGraphicalDevice(GraphicsDevice device)
|
||||||
|
{
|
||||||
|
this.gDevice = device;
|
||||||
|
Debug.Assert(this.points.Count >= 2);
|
||||||
|
List<VertexPositionColorTexture> vertices = new List<VertexPositionColorTexture>();
|
||||||
|
List<ushort> indices = new List<ushort>();
|
||||||
|
|
||||||
|
for(int i = 0; i < this.points.Count - 1 ; i++)
|
||||||
|
{
|
||||||
|
var p = this.points[i];
|
||||||
|
var pNext = this.points[i+1];
|
||||||
|
|
||||||
|
Vector2 dir = pNext - p;
|
||||||
|
Vector2 perpendincularVector = new Vector2(dir.Y, -dir.X);
|
||||||
|
perpendincularVector.Normalize();
|
||||||
|
|
||||||
|
var offsetPoint1 = new Vector3(p.X, p.Y ,0.0f);
|
||||||
|
var offsetPoint2 = new Vector3(p.X, p.Y ,0.0f);
|
||||||
|
vertices.Add(new VertexPositionColorTexture(offsetPoint1,this.LineColor, perpendincularVector));
|
||||||
|
vertices.Add(new VertexPositionColorTexture(offsetPoint2,this.LineColor, perpendincularVector * -1));
|
||||||
|
var offsetPoint1Next = new Vector3(pNext.X, pNext.Y ,0.0f);
|
||||||
|
var offsetPoint2Next = new Vector3(pNext.X, pNext.Y ,0.0f);
|
||||||
|
vertices.Add(new VertexPositionColorTexture(offsetPoint1Next,this.LineColor, perpendincularVector));
|
||||||
|
vertices.Add(new VertexPositionColorTexture(offsetPoint2Next,this.LineColor, perpendincularVector * -1));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < vertices.Count; i+=4)
|
||||||
|
{
|
||||||
|
indices.Add((ushort)(i));
|
||||||
|
indices.Add((ushort)(i + 1));
|
||||||
|
indices.Add((ushort)(i + 2));
|
||||||
|
|
||||||
|
indices.Add((ushort)(i + 2));
|
||||||
|
indices.Add((ushort)(i + 1));
|
||||||
|
indices.Add((ushort)(i + 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.vbo = new VertexBuffer(device, typeof(VertexPositionColorTexture), (this.points.Count - 1) * 4, BufferUsage.WriteOnly);
|
||||||
|
this.vbo.SetData<VertexPositionColorTexture>(vertices.ToArray());
|
||||||
|
this.ibo = new IndexBuffer(device, typeof(ushort), indices.Count,BufferUsage.WriteOnly);
|
||||||
|
this.ibo.SetData<ushort>(indices.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(Effect lineEffect)
|
||||||
|
{
|
||||||
|
this.gDevice.SetVertexBuffer(this.vbo);
|
||||||
|
this.gDevice.Indices = this.ibo;
|
||||||
|
RasterizerState rasterizerState = new RasterizerState();
|
||||||
|
rasterizerState.CullMode = CullMode.None;
|
||||||
|
this.gDevice.RasterizerState = rasterizerState;
|
||||||
|
lineEffect.Parameters["thickness"].SetValue(this.thickness);
|
||||||
|
foreach (EffectPass pass in lineEffect.CurrentTechnique.Passes)
|
||||||
|
{
|
||||||
|
pass.Apply();
|
||||||
|
this.gDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,this.ibo.IndexCount / 3);
|
||||||
|
//this.gDevice.DrawPrimitives(PrimitiveType.LineList, 0, this.vbo.VertexCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
89
Program.cs
Normal file
89
Program.cs
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
app.manifest
Normal file
9
app.manifest
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
<asmv3:application>
|
||||||
|
<asmv3:windowsSettings>
|
||||||
|
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
|
||||||
|
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2,PerMonitor</dpiAwareness>
|
||||||
|
</asmv3:windowsSettings>
|
||||||
|
</asmv3:application>
|
||||||
|
</assembly>
|
||||||
57
line.fx
Normal file
57
line.fx
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#if OPENGL
|
||||||
|
#define SV_POSITION POSITION
|
||||||
|
#define VS_SHADERMODEL vs_3_0
|
||||||
|
#define PS_SHADERMODEL ps_3_0
|
||||||
|
#else
|
||||||
|
#define VS_SHADERMODEL vs_4_0_level_9_1
|
||||||
|
#define PS_SHADERMODEL ps_4_0_level_9_1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
matrix WorldViewProjection;
|
||||||
|
float thickness;
|
||||||
|
|
||||||
|
struct VertexShaderInput
|
||||||
|
{
|
||||||
|
float4 Position : POSITION0;
|
||||||
|
float4 Color : COLOR0;
|
||||||
|
float2 Normal : TEXCOORD0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexShaderOutput
|
||||||
|
{
|
||||||
|
float4 Position : SV_POSITION;
|
||||||
|
float4 Color : COLOR0;
|
||||||
|
float2 Normal : TEXCOORD0;
|
||||||
|
};
|
||||||
|
|
||||||
|
VertexShaderOutput MainVS(in VertexShaderInput input)
|
||||||
|
{
|
||||||
|
VertexShaderOutput output = (VertexShaderOutput)0;
|
||||||
|
float4 temp = input.Position + (float4(input.Normal,0.0,0.0) * thickness);
|
||||||
|
output.Position = mul(temp, WorldViewProjection);
|
||||||
|
output.Color = input.Color;
|
||||||
|
output.Normal = input.Normal;
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
float4 MainPS(VertexShaderOutput input) : COLOR
|
||||||
|
{
|
||||||
|
float feather = 0.2; //Fade off part
|
||||||
|
float4 res = input.Color;
|
||||||
|
float distFromLine = length(input.Normal);
|
||||||
|
float alpha = 1.0 - ((clamp(distFromLine, (1.0 - feather),1.0) - (1.0 - feather)) / feather);
|
||||||
|
res.a = alpha;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
technique BasicColorDrawing
|
||||||
|
{
|
||||||
|
pass P0
|
||||||
|
{
|
||||||
|
AlphaBlendEnable = TRUE;
|
||||||
|
DestBlend = INVSRCALPHA;
|
||||||
|
SrcBlend = SRCALPHA;
|
||||||
|
VertexShader = compile VS_SHADERMODEL MainVS();
|
||||||
|
PixelShader = compile PS_SHADERMODEL MainPS();
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user