Skip to content

Commit

Permalink
Completed the great vector swapover of 2015
Browse files Browse the repository at this point in the history
 - The content pipeline still uses XNA vectors everywhere. That system interacts so heavily with XNA that there's no point using numerics vectors
 - Added Some types to replace XNA geometry types with equivalents using Numerics.Vectors (BoundingBox, BoundingFrustum, BoundingSphere, Ray). These are not complete wrappers and should be expanded as needed
 - Minor fixes made to some tests in GraphicsTests (looks like mistakes that would have been broken before, in the more rarely run tests)

Signed-off-by: Martin Evans <martindevans@gmail.com>
  • Loading branch information
martindevans committed Aug 25, 2015
1 parent d8c18c1 commit 0fc9d11
Show file tree
Hide file tree
Showing 237 changed files with 2,159 additions and 1,565 deletions.
5 changes: 4 additions & 1 deletion Myre/ContentBuilderGame/ContentBuilderGame/Game1.cs
@@ -1,8 +1,11 @@
using Microsoft.Xna.Framework;
using System;
using System.IO;
using System.Windows.Forms;

using Color = Microsoft.Xna.Framework.Color;
using Game = Microsoft.Xna.Framework.Game;
using GameTime = Microsoft.Xna.Framework.GameTime;
using GraphicsDeviceManager = Microsoft.Xna.Framework.GraphicsDeviceManager;

namespace ContentBuilderGame
{
Expand Down
7 changes: 6 additions & 1 deletion Myre/Myre.Debugging.UI/CommandConsole.cs
Expand Up @@ -6,7 +6,6 @@
using System.Linq;
using System.Reflection;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Myre.UI;
Expand All @@ -15,6 +14,12 @@
using Myre.UI.InputDevices;
using Myre.UI.Text;

using Game = Microsoft.Xna.Framework.Game;
using PlayerIndex = Microsoft.Xna.Framework.PlayerIndex;
using Color = Microsoft.Xna.Framework.Color;
using GameTime = Microsoft.Xna.Framework.GameTime;
using Rectangle = Microsoft.Xna.Framework.Rectangle;

namespace Myre.Debugging.UI
{
public class CommandConsole
Expand Down
23 changes: 9 additions & 14 deletions Myre/Myre.Debugging.UI/Graph.cs
@@ -1,5 +1,9 @@
using Microsoft.Xna.Framework;
using System.Numerics;
using Microsoft.Xna.Framework.Graphics;
using Myre.Extensions;

using Color = Microsoft.Xna.Framework.Color;
using Rectangle = Microsoft.Xna.Framework.Rectangle;

namespace Myre.Debugging.UI
{
Expand Down Expand Up @@ -42,9 +46,9 @@ public Graph(GraphicsDevice device, int resolution)
{
LightingEnabled = false,
VertexColorEnabled = true,
World = Matrix.Identity,
View = Matrix.Identity,
Projection = Matrix.Identity
World = Matrix4x4.Identity.ToXNA(),
View = Matrix4x4.Identity.ToXNA(),
Projection = Matrix4x4.Identity.ToXNA()
};

_dirty = true;
Expand Down Expand Up @@ -92,7 +96,7 @@ public void Draw(Rectangle area)
x + (i / (float)(_data.Length - 1)) * width,
(y - height) + _data[i] * height,
0);
_transformedData[i] = new VertexPositionColor(position, _colour);
_transformedData[i] = new VertexPositionColor(position.ToXNA(), _colour);
}

_vertices.SetData<VertexPositionColor>(_transformedData);
Expand All @@ -101,18 +105,9 @@ public void Draw(Rectangle area)
_previousArea = area;
}

#if XNA_3_1
effect.Begin();
effect.Techniques[0].Passes[0].Begin();
device.Vertices[0].SetSource(vertices, 0, VertexPositionColor.SizeInBytes);
device.DrawPrimitives(PrimitiveType.LineStrip, 0, data.Length - 1);
effect.Techniques[0].Passes[0].End();
effect.End();
#else
_effect.Techniques[0].Passes[0].Apply();
device.SetVertexBuffer(_vertices);
device.DrawPrimitives(PrimitiveType.LineStrip, 0, _data.Length - 1);
#endif
}
}
}
6 changes: 6 additions & 0 deletions Myre/Myre.Debugging.UI/Myre.Debugging.UI.csproj
Expand Up @@ -36,6 +36,8 @@
<Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -59,6 +61,10 @@
<Project>{56fa6d49-e949-4a90-a5ea-ed48805cba92}</Project>
<Name>Myre.UI</Name>
</ProjectReference>
<ProjectReference Include="..\Myre\Myre.csproj">
<Project>{150b5101-1046-43e9-9fd0-a2ddd33c352f}</Project>
<Name>Myre</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
19 changes: 12 additions & 7 deletions Myre/Myre.Debugging.UI/StatisticGraph.cs
@@ -1,12 +1,15 @@
using System;
using System.Globalization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Myre.Debugging.Statistics;
using Myre.UI;
using Myre.UI.Controls;
using Myre.UI.Text;

using Color = Microsoft.Xna.Framework.Color;
using Rectangle = Microsoft.Xna.Framework.Rectangle;
using GameTime = Microsoft.Xna.Framework.GameTime;

namespace Myre.Debugging.UI
{
public class StatisticGraph
Expand Down Expand Up @@ -35,15 +38,17 @@ public StatisticGraph(Control parent, SpriteFont font, Statistic statistic, Time
Strata = new ControlStrata() { Layer = Layer.Overlay };
_tracker = new StatisticTracker(statistic, accessInterval);
_graph = new Graph(Device, (int)(15f / (float)accessInterval.TotalSeconds)); //(byte)MathHelper.Clamp(15f / (float)accessInterval.TotalSeconds, 15, 15 * 60));
_label = new Label(this, font);
_label.Text = statistic.Name;
_label.Justification = Justification.Centre;
_label = new Label(this, font) {
Text = statistic.Name,
Justification = Justification.Centre
};
_label.SetPoint(Points.TopLeft, 2, 2);
_label.SetPoint(Points.TopRight, -2, 2);

_value = new Label(this, font);
_value.Text = "0";
_value.Justification = Justification.Centre;
_value = new Label(this, font) {
Text = "0",
Justification = Justification.Centre
};
_value.SetPoint(Points.BottomLeft, 2, -2);
_value.SetPoint(Points.BottomRight, -2, -2);

Expand Down
4 changes: 3 additions & 1 deletion Myre/Myre.Debugging.UI/StatisticTextLog.cs
Expand Up @@ -2,10 +2,12 @@
using System.Collections.Generic;
using Myre.Debugging.Statistics;
using Myre.UI;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Myre.UI.Controls;

using Color = Microsoft.Xna.Framework.Color;
using GameTime = Microsoft.Xna.Framework.GameTime;

namespace Myre.Debugging.UI
{
/// <summary>
Expand Down
145 changes: 75 additions & 70 deletions Myre/Myre.Debugging/DebugShapeRenderer.cs
Expand Up @@ -10,8 +10,13 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using System.Numerics;
using Microsoft.Xna.Framework.Graphics;
using Myre.Extensions;

using Color = Microsoft.Xna.Framework.Color;
using GameTime = Microsoft.Xna.Framework.GameTime;
using MathHelper = Microsoft.Xna.Framework.MathHelper;

namespace Myre.Debugging
{
Expand Down Expand Up @@ -94,8 +99,8 @@ public static void Initialize(GraphicsDevice graphicsDevice)
{
VertexColorEnabled = true,
TextureEnabled = false,
DiffuseColor = Vector3.One,
World = Matrix.Identity
DiffuseColor = Vector3.One.ToXNA(),
World = Matrix4x4.Identity.ToXNA()
};

// Create our unit sphere vertices
Expand All @@ -116,8 +121,8 @@ public static void AddLine(Vector3 a, Vector3 b, Color color, float life = 0f)
DebugShape shape = GetShapeForLines(1, life);

// Add the two vertices to the shape
shape.Vertices[0] = new VertexPositionColor(a, color);
shape.Vertices[1] = new VertexPositionColor(b, color);
shape.Vertices[0] = new VertexPositionColor(a.ToXNA(), color);
shape.Vertices[1] = new VertexPositionColor(b.ToXNA(), color);
}

/// <summary>
Expand All @@ -135,12 +140,12 @@ public static void AddTriangle(Vector3 a, Vector3 b, Vector3 c, Color color, flo
DebugShape shape = GetShapeForLines(3, life);

// Add the vertices to the shape
shape.Vertices[0] = new VertexPositionColor(a, color);
shape.Vertices[1] = new VertexPositionColor(b, color);
shape.Vertices[2] = new VertexPositionColor(b, color);
shape.Vertices[3] = new VertexPositionColor(c, color);
shape.Vertices[4] = new VertexPositionColor(c, color);
shape.Vertices[5] = new VertexPositionColor(a, color);
shape.Vertices[0] = new VertexPositionColor(a.ToXNA(), color);
shape.Vertices[1] = new VertexPositionColor(b.ToXNA(), color);
shape.Vertices[2] = new VertexPositionColor(b.ToXNA(), color);
shape.Vertices[3] = new VertexPositionColor(c.ToXNA(), color);
shape.Vertices[4] = new VertexPositionColor(c.ToXNA(), color);
shape.Vertices[5] = new VertexPositionColor(a.ToXNA(), color);
}

/// <summary>
Expand All @@ -159,34 +164,34 @@ public static void AddBoundingFrustum(BoundingFrustum frustum, Color color, floa
frustum.GetCorners(_corners);

// Fill in the vertices for the bottom of the frustum
shape.Vertices[0] = new VertexPositionColor(_corners[0], color);
shape.Vertices[1] = new VertexPositionColor(_corners[1], color);
shape.Vertices[2] = new VertexPositionColor(_corners[1], color);
shape.Vertices[3] = new VertexPositionColor(_corners[2], color);
shape.Vertices[4] = new VertexPositionColor(_corners[2], color);
shape.Vertices[5] = new VertexPositionColor(_corners[3], color);
shape.Vertices[6] = new VertexPositionColor(_corners[3], color);
shape.Vertices[7] = new VertexPositionColor(_corners[0], color);
shape.Vertices[0] = new VertexPositionColor(_corners[0].ToXNA(), color);
shape.Vertices[1] = new VertexPositionColor(_corners[1].ToXNA(), color);
shape.Vertices[2] = new VertexPositionColor(_corners[1].ToXNA(), color);
shape.Vertices[3] = new VertexPositionColor(_corners[2].ToXNA(), color);
shape.Vertices[4] = new VertexPositionColor(_corners[2].ToXNA(), color);
shape.Vertices[5] = new VertexPositionColor(_corners[3].ToXNA(), color);
shape.Vertices[6] = new VertexPositionColor(_corners[3].ToXNA(), color);
shape.Vertices[7] = new VertexPositionColor(_corners[0].ToXNA(), color);

// Fill in the vertices for the top of the frustum
shape.Vertices[8] = new VertexPositionColor(_corners[4], color);
shape.Vertices[9] = new VertexPositionColor(_corners[5], color);
shape.Vertices[10] = new VertexPositionColor(_corners[5], color);
shape.Vertices[11] = new VertexPositionColor(_corners[6], color);
shape.Vertices[12] = new VertexPositionColor(_corners[6], color);
shape.Vertices[13] = new VertexPositionColor(_corners[7], color);
shape.Vertices[14] = new VertexPositionColor(_corners[7], color);
shape.Vertices[15] = new VertexPositionColor(_corners[4], color);
shape.Vertices[8] = new VertexPositionColor(_corners[4].ToXNA(), color);
shape.Vertices[9] = new VertexPositionColor(_corners[5].ToXNA(), color);
shape.Vertices[10] = new VertexPositionColor(_corners[5].ToXNA(), color);
shape.Vertices[11] = new VertexPositionColor(_corners[6].ToXNA(), color);
shape.Vertices[12] = new VertexPositionColor(_corners[6].ToXNA(), color);
shape.Vertices[13] = new VertexPositionColor(_corners[7].ToXNA(), color);
shape.Vertices[14] = new VertexPositionColor(_corners[7].ToXNA(), color);
shape.Vertices[15] = new VertexPositionColor(_corners[4].ToXNA(), color);

// Fill in the vertices for the vertical sides of the frustum
shape.Vertices[16] = new VertexPositionColor(_corners[0], color);
shape.Vertices[17] = new VertexPositionColor(_corners[4], color);
shape.Vertices[18] = new VertexPositionColor(_corners[1], color);
shape.Vertices[19] = new VertexPositionColor(_corners[5], color);
shape.Vertices[20] = new VertexPositionColor(_corners[2], color);
shape.Vertices[21] = new VertexPositionColor(_corners[6], color);
shape.Vertices[22] = new VertexPositionColor(_corners[3], color);
shape.Vertices[23] = new VertexPositionColor(_corners[7], color);
shape.Vertices[16] = new VertexPositionColor(_corners[0].ToXNA(), color);
shape.Vertices[17] = new VertexPositionColor(_corners[4].ToXNA(), color);
shape.Vertices[18] = new VertexPositionColor(_corners[1].ToXNA(), color);
shape.Vertices[19] = new VertexPositionColor(_corners[5].ToXNA(), color);
shape.Vertices[20] = new VertexPositionColor(_corners[2].ToXNA(), color);
shape.Vertices[21] = new VertexPositionColor(_corners[6].ToXNA(), color);
shape.Vertices[22] = new VertexPositionColor(_corners[3].ToXNA(), color);
shape.Vertices[23] = new VertexPositionColor(_corners[7].ToXNA(), color);
}

/// <summary>
Expand All @@ -205,34 +210,34 @@ public static void AddBoundingBox(BoundingBox box, Color color, float life = 0f)
box.GetCorners(_corners);

// Fill in the vertices for the bottom of the box
shape.Vertices[0] = new VertexPositionColor(_corners[0], color);
shape.Vertices[1] = new VertexPositionColor(_corners[1], color);
shape.Vertices[2] = new VertexPositionColor(_corners[1], color);
shape.Vertices[3] = new VertexPositionColor(_corners[2], color);
shape.Vertices[4] = new VertexPositionColor(_corners[2], color);
shape.Vertices[5] = new VertexPositionColor(_corners[3], color);
shape.Vertices[6] = new VertexPositionColor(_corners[3], color);
shape.Vertices[7] = new VertexPositionColor(_corners[0], color);
shape.Vertices[0] = new VertexPositionColor(_corners[0].ToXNA(), color);
shape.Vertices[1] = new VertexPositionColor(_corners[1].ToXNA(), color);
shape.Vertices[2] = new VertexPositionColor(_corners[1].ToXNA(), color);
shape.Vertices[3] = new VertexPositionColor(_corners[2].ToXNA(), color);
shape.Vertices[4] = new VertexPositionColor(_corners[2].ToXNA(), color);
shape.Vertices[5] = new VertexPositionColor(_corners[3].ToXNA(), color);
shape.Vertices[6] = new VertexPositionColor(_corners[3].ToXNA(), color);
shape.Vertices[7] = new VertexPositionColor(_corners[0].ToXNA(), color);

// Fill in the vertices for the top of the box
shape.Vertices[8] = new VertexPositionColor(_corners[4], color);
shape.Vertices[9] = new VertexPositionColor(_corners[5], color);
shape.Vertices[10] = new VertexPositionColor(_corners[5], color);
shape.Vertices[11] = new VertexPositionColor(_corners[6], color);
shape.Vertices[12] = new VertexPositionColor(_corners[6], color);
shape.Vertices[13] = new VertexPositionColor(_corners[7], color);
shape.Vertices[14] = new VertexPositionColor(_corners[7], color);
shape.Vertices[15] = new VertexPositionColor(_corners[4], color);
shape.Vertices[8] = new VertexPositionColor(_corners[4].ToXNA(), color);
shape.Vertices[9] = new VertexPositionColor(_corners[5].ToXNA(), color);
shape.Vertices[10] = new VertexPositionColor(_corners[5].ToXNA(), color);
shape.Vertices[11] = new VertexPositionColor(_corners[6].ToXNA(), color);
shape.Vertices[12] = new VertexPositionColor(_corners[6].ToXNA(), color);
shape.Vertices[13] = new VertexPositionColor(_corners[7].ToXNA(), color);
shape.Vertices[14] = new VertexPositionColor(_corners[7].ToXNA(), color);
shape.Vertices[15] = new VertexPositionColor(_corners[4].ToXNA(), color);

// Fill in the vertices for the vertical sides of the box
shape.Vertices[16] = new VertexPositionColor(_corners[0], color);
shape.Vertices[17] = new VertexPositionColor(_corners[4], color);
shape.Vertices[18] = new VertexPositionColor(_corners[1], color);
shape.Vertices[19] = new VertexPositionColor(_corners[5], color);
shape.Vertices[20] = new VertexPositionColor(_corners[2], color);
shape.Vertices[21] = new VertexPositionColor(_corners[6], color);
shape.Vertices[22] = new VertexPositionColor(_corners[3], color);
shape.Vertices[23] = new VertexPositionColor(_corners[7], color);
shape.Vertices[16] = new VertexPositionColor(_corners[0].ToXNA(), color);
shape.Vertices[17] = new VertexPositionColor(_corners[4].ToXNA(), color);
shape.Vertices[18] = new VertexPositionColor(_corners[1].ToXNA(), color);
shape.Vertices[19] = new VertexPositionColor(_corners[5].ToXNA(), color);
shape.Vertices[20] = new VertexPositionColor(_corners[2].ToXNA(), color);
shape.Vertices[21] = new VertexPositionColor(_corners[6].ToXNA(), color);
shape.Vertices[22] = new VertexPositionColor(_corners[3].ToXNA(), color);
shape.Vertices[23] = new VertexPositionColor(_corners[7].ToXNA(), color);
}

/// <summary>
Expand All @@ -254,7 +259,7 @@ public static void AddBoundingSphere(BoundingSphere sphere, Color color, float l
Vector3 vertPos = _unitSphere[i] * sphere.Radius + sphere.Center;

// Add the vertex to the shape
shape.Vertices[i] = new VertexPositionColor(vertPos, color);
shape.Vertices[i] = new VertexPositionColor(vertPos.ToXNA(), color);
}
}

Expand All @@ -265,11 +270,11 @@ public static void AddBoundingSphere(BoundingSphere sphere, Color color, float l
/// <param name="view">The view matrix to use when rendering the shapes.</param>
/// <param name="projection">The projection matrix to use when rendering the shapes.</param>
[Conditional("DEBUG")]
public static void Draw(GameTime gameTime, Matrix view, Matrix projection)
public static void Draw(GameTime gameTime, Matrix4x4 view, Matrix4x4 projection)
{
// Update our effect with the matrices.
_effect.View = view;
_effect.Projection = projection;
_effect.View = view.ToXNA();
_effect.Projection = projection.ToXNA();

// Calculate the total number of vertices we're going to be rendering.
int vertexCount = 0;
Expand Down Expand Up @@ -353,30 +358,30 @@ private static void InitializeSphere()
_unitSphere = new Vector3[SPHERE_LINE_COUNT * 2];

// Compute our step around each circle
const float step = MathHelper.TwoPi / SPHERE_RESOLUTION;
const float STEP = MathHelper.TwoPi / SPHERE_RESOLUTION;

// Used to track the index into our vertex array
int index = 0;

// Create the loop on the XY plane first
for (float a = 0f; a < MathHelper.TwoPi; a += step)
for (float a = 0f; a < MathHelper.TwoPi; a += STEP)
{
_unitSphere[index++] = new Vector3((float)Math.Cos(a), (float)Math.Sin(a), 0f);
_unitSphere[index++] = new Vector3((float)Math.Cos(a + step), (float)Math.Sin(a + step), 0f);
_unitSphere[index++] = new Vector3((float)Math.Cos(a + STEP), (float)Math.Sin(a + STEP), 0f);
}

// Next on the XZ plane
for (float a = 0f; a < MathHelper.TwoPi; a += step)
for (float a = 0f; a < MathHelper.TwoPi; a += STEP)
{
_unitSphere[index++] = new Vector3((float)Math.Cos(a), 0f, (float)Math.Sin(a));
_unitSphere[index++] = new Vector3((float)Math.Cos(a + step), 0f, (float)Math.Sin(a + step));
_unitSphere[index++] = new Vector3((float)Math.Cos(a + STEP), 0f, (float)Math.Sin(a + STEP));
}

// Finally on the YZ plane
for (float a = 0f; a < MathHelper.TwoPi; a += step)
for (float a = 0f; a < MathHelper.TwoPi; a += STEP)
{
_unitSphere[index++] = new Vector3(0f, (float)Math.Cos(a), (float)Math.Sin(a));
_unitSphere[index++] = new Vector3(0f, (float)Math.Cos(a + step), (float)Math.Sin(a + step));
_unitSphere[index++] = new Vector3(0f, (float)Math.Cos(a + STEP), (float)Math.Sin(a + STEP));
}
}

Expand Down

0 comments on commit 0fc9d11

Please sign in to comment.