diff --git a/.gitignore b/.gitignore index 5176664c..2d918dc2 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,8 @@ extensions/build/SharpGL.2010.vsix extensions/build/SharpGL.vsix extensions/Seeds/packages *.GhostDoc.xml +source/SharpGL/.idea/.idea.SharpGL/.idea/discord.xml +source/SharpGL/.idea/.idea.SharpGL/.idea/encodings.xml +source/SharpGL/.idea/.idea.SharpGL/.idea/indexLayout.xml +source/SharpGL/.idea/.idea.SharpGL/.idea/vcs.xml +source/SharpGL/Core/SharpGL.WinForms/SharpGL.WinForms.csproj.DotSettings diff --git a/source/SharpGL/.idea/.idea.SharpGL/.idea/.gitignore b/source/SharpGL/.idea/.idea.SharpGL/.idea/.gitignore new file mode 100644 index 00000000..4c021cc8 --- /dev/null +++ b/source/SharpGL/.idea/.idea.SharpGL/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/.idea.SharpGL.iml +/modules.xml +/projectSettingsUpdater.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/source/SharpGL/Core/SharpGL.SceneGraph.Tests/VertexTests.cs b/source/SharpGL/Core/SharpGL.SceneGraph.Tests/VertexTests.cs index 2c07c4e5..cc4d3e84 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph.Tests/VertexTests.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph.Tests/VertexTests.cs @@ -7,17 +7,17 @@ public class VertexTests [Test] public void Can_Normalize_Non_Zero_Vertex() { - var vertex = new Vertex(0.1f, 0f, 0f); + var vertex = new System.Numerics.Vector3(0.1f, 0f, 0f); vertex.Normalize(); - Assert.That(vertex, Is.EqualTo(new Vertex(1f, 0f, 0f))); + Assert.That(vertex, Is.EqualTo(new System.Numerics.Vector3(1f, 0f, 0f))); } [Test] public void Can_Normalize_Zero_Vertex() { - var vertex = new Vertex(0f, 0f, 0f); + var vertex = new System.Numerics.Vector3(0f, 0f, 0f); vertex.Normalize(); - Assert.That(vertex, Is.EqualTo(new Vertex(0f, 0f, 0f))); + Assert.That(vertex, Is.EqualTo(new System.Numerics.Vector3(0f, 0f, 0f))); } } } diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/ArcBallCamera.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/ArcBallCamera.cs index 82dad0bc..d2dc303c 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/ArcBallCamera.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/ArcBallCamera.cs @@ -31,8 +31,8 @@ public override void TransformProjectionMatrix(OpenGL gl) // Perform the perspective transformation. arcBall.SetBounds(viewport[2], viewport[3]); gl.Perspective(FieldOfView, AspectRatio, Near, Far); - Vertex target = new Vertex(0, 0, 0); - Vertex upVector = new Vertex(0, 0, 1); + System.Numerics.Vector3 target = new System.Numerics.Vector3(0, 0, 0); + System.Numerics.Vector3 upVector = new System.Numerics.Vector3(0, 0, 1); // Perform the look at transformation. gl.LookAt((double)Position.X, (double)Position.Y, (double)Position.Z, diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/Camera.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/Camera.cs index 66998e4d..15ac0ee2 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/Camera.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/Camera.cs @@ -58,7 +58,7 @@ public virtual void Project(OpenGL gl) /// /// The camera position. /// - private Vertex position = new Vertex(0, 0, 0); + private System.Numerics.Vector3 position = new System.Numerics.Vector3(0, 0, 0); /// /// Every time a camera is used to project, the projection matrix calculated @@ -78,7 +78,7 @@ public virtual void Project(OpenGL gl) /// The position. /// [Description("The position of the camera"), Category("Camera")] - public Vertex Position + public System.Numerics.Vector3 Position { get { return position; } set { position = value; } diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/LookAtCamera.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/LookAtCamera.cs index a874bf5e..be1523dc 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/LookAtCamera.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/LookAtCamera.cs @@ -35,13 +35,13 @@ public override void TransformProjectionMatrix(OpenGL gl) /// /// This is the point in the scene that the camera is pointed at. /// - protected Vertex target = new Vertex(0, 0, 0); + protected System.Numerics.Vector3 target = new System.Numerics.Vector3(0, 0, 0); /// /// This is a vector that describes the 'up' direction (normally 0, 0, 1). /// Use this to tilt the camera. /// - protected Vertex upVector = new Vertex(0, 0, 1); + protected System.Numerics.Vector3 upVector = new System.Numerics.Vector3(0, 0, 1); /// /// Gets or sets the target. @@ -50,7 +50,7 @@ public override void TransformProjectionMatrix(OpenGL gl) /// The target. /// [Description("The target of the camera (the point it's looking at"), Category("Camera")] - public Vertex Target + public System.Numerics.Vector3 Target { get {return target;} set {target = value;} @@ -63,7 +63,7 @@ public Vertex Target /// Up vector. /// [Description("The up direction, relative to camera. (Controls tilt)."), Category("Camera")] - public Vertex UpVector + public System.Numerics.Vector3 UpVector { get {return upVector;} set {upVector = value;} diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/PerspectiveCamera.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/PerspectiveCamera.cs index 895195c5..93d52cb6 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/PerspectiveCamera.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Cameras/PerspectiveCamera.cs @@ -29,8 +29,8 @@ public override void TransformProjectionMatrix(OpenGL gl) // Perform the perspective transformation. //gl.Translate(Position.X, Position.Y, Position.Z); gl.Perspective(fieldOfView, AspectRatio, near, far); - Vertex target = new Vertex(0, 0, 0); - Vertex upVector = new Vertex(0, 0, 1); + System.Numerics.Vector3 target = new System.Numerics.Vector3(0, 0, 0); + System.Numerics.Vector3 upVector = new System.Numerics.Vector3(0, 0, 1); // Perform the look at transformation. gl.LookAt((double)Position.X, (double)Position.Y, (double)Position.Z, (double)target.X, (double)target.Y, (double)target.Z, diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Collections.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Collections.cs index 9bf1e7bf..c692e502 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Collections.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Collections.cs @@ -19,7 +19,7 @@ public static class VertexSearch /// The target of the search. /// The threshhold of the distance from each dimension of the vertex for the search. /// - public static int Search(List vertices, int start, Vertex vertex, float accuracy) + public static int Search(List vertices, int start, System.Numerics.Vector3 vertex, float accuracy) { // Go through the verticies. for (int i = start; i < vertices.Count; i++) diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Core/ArcBall.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Core/ArcBall.cs index 74f43185..a6e9912c 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Core/ArcBall.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Core/ArcBall.cs @@ -59,7 +59,7 @@ public void MouseUp(int x, int y) lastRotationMatrix.FromOtherMatrix(thisRotationMatrix, 3, 3); thisRotationMatrix.SetIdentity(); - startVector = new Vertex(0, 0, 0); + startVector = new System.Numerics.Vector3(0, 0, 0); } private Matrix Matrix3fSetRotationFromQuat4f(float[] q1) @@ -96,7 +96,7 @@ private void Matrix4fSetRotationFromMatrix3f(ref Matrix transform, Matrix matrix private float[] CalculateQuaternion() { // Compute the cross product of the begin and end vectors. - Vertex cross = startVector.VectorProduct(currentVector); + System.Numerics.Vector3 cross = startVector.VectorProduct(currentVector); // Is the perpendicular length essentially non-zero? if (cross.Magnitude() > 1.0e-5) @@ -111,14 +111,14 @@ private float[] CalculateQuaternion() } } - public Vertex MapToSphere(float x, float y) + public System.Numerics.Vector3 MapToSphere(float x, float y) { //hyperboloid mapping taken from https://www.opengl.org/wiki/Object_Mouse_Trackball float pX = x * adjustWidth - 1.0f; float pY = y * adjustHeight - 1.0f; - Vertex P = new Vertex(pX, -pY, 0); + System.Numerics.Vector3 P = new System.Numerics.Vector3(pX, -pY, 0); //sphere radius const float radius = .5f; @@ -158,8 +158,8 @@ public void SetBounds(float width, float height, float sphereRadius) private float adjustWidth = 1.0f; private float adjustHeight = 1.0f; - public Vertex startVector = new Vertex(0, 0, 0); - public Vertex currentVector = new Vertex(0, 0, 0); + public System.Numerics.Vector3 startVector = new System.Numerics.Vector3(0, 0, 0); + public System.Numerics.Vector3 currentVector = new System.Numerics.Vector3(0, 0, 0); Matrix transformMatrix = new Matrix(4, 4); diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Core/BoundingVolume.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Core/BoundingVolume.cs index 62a86236..aba6d700 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Core/BoundingVolume.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Core/BoundingVolume.cs @@ -21,7 +21,7 @@ public BoundingVolume() /// Creates the volume from vertices. /// /// The vertices. - public void FromVertices(IEnumerable vertices) + public void FromVertices(IEnumerable vertices) { var vertexList = vertices.ToList(); if (vertexList.Count < 2) @@ -77,7 +77,7 @@ public void FromVertices(IEnumerable vertices) /// /// The centre. /// The radius. - public void FromSphericalVolume(Vertex centre, float radius) + public void FromSphericalVolume(System.Numerics.Vector3 centre, float radius) { // Set the centre. lll = centre; @@ -100,18 +100,18 @@ public void FromSphericalVolume(Vertex centre, float radius) /// The height. /// The base radius. /// The top radius. - public void FromCylindricalVolume(Vertex baseline, float height, float baseRadius, float topRadius) + public void FromCylindricalVolume(System.Numerics.Vector3 baseline, float height, float baseRadius, float topRadius) { - Vertex[] set = new Vertex[6]; + System.Numerics.Vector3[] set = new System.Numerics.Vector3[6]; set[0] = baseline; - set[1] = baseline + new Vertex(0, 0, height); + set[1] = baseline + new System.Numerics.Vector3(0, 0, height); - set[2] = baseline + new Vertex(baseRadius, baseRadius , 0); - set[3] = baseline + new Vertex(-baseRadius, -baseRadius, 0); + set[2] = baseline + new System.Numerics.Vector3(baseRadius, baseRadius , 0); + set[3] = baseline + new System.Numerics.Vector3(-baseRadius, -baseRadius, 0); - set[4] = set[1] + new Vertex(topRadius, topRadius, 0); - set[5] = set[1] + new Vertex(-topRadius, -topRadius, 0); + set[4] = set[1] + new System.Numerics.Vector3(topRadius, topRadius, 0); + set[5] = set[1] + new System.Numerics.Vector3(-topRadius, -topRadius, 0); FromVertices(set); } @@ -216,13 +216,13 @@ public void Render(OpenGL gl, RenderMode renderMode) gl.PopAttrib(); } - private Vertex lll; - private Vertex hll; - private Vertex lhl; - private Vertex llh; - private Vertex hhl; - private Vertex hlh; - private Vertex lhh; - private Vertex hhh; + private System.Numerics.Vector3 lll; + private System.Numerics.Vector3 hll; + private System.Numerics.Vector3 lhl; + private System.Numerics.Vector3 llh; + private System.Numerics.Vector3 hhl; + private System.Numerics.Vector3 hlh; + private System.Numerics.Vector3 lhh; + private System.Numerics.Vector3 hhh; } } diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Core/VertexGrid.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Core/VectorGrid.cs similarity index 88% rename from source/SharpGL/Core/SharpGL.SceneGraph/Core/VertexGrid.cs rename to source/SharpGL/Core/SharpGL.SceneGraph/Core/VectorGrid.cs index aecf995f..51675828 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Core/VertexGrid.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Core/VectorGrid.cs @@ -1,147 +1,147 @@ -using System; -using System.ComponentModel; -using System.Collections; -using System.Collections.Generic; - -using SharpGL.SceneGraph; -using SharpGL.SceneGraph.Collections; -using SharpGL.SceneGraph.Core; -using SharpGL.SceneGraph.Primitives; - -namespace SharpGL.SceneGraph.Core -{ - /// - /// This class represent's a grid of points, just like you'd get on a NURBS - /// surface, or a patch. - /// - [Serializable()] - public class VertexGrid - { - public virtual void CreateGrid(int x, int y) - { - // Clear the current array. - vertices.Clear(); - - // Add a new set of control points. - for(int yvals = 0; yvals < y; yvals++) - { - for(int xvals = 0; xvals < x; xvals++) - vertices.Add( new Vertex(xvals, 1.0f, yvals)); - } - - this.x = x; - this.y = y; - } - - /// - /// Use this to draw the vertex grid. - /// - /// OpenGL object. - /// Draw each individual vertex (with selection names). - /// Draw the lines connecting the points. - public virtual void Draw(OpenGL gl, bool points, bool lines) - { - // Save the attributes. - gl.PushAttrib(OpenGL.GL_ALL_ATTRIB_BITS); - gl.Disable(OpenGL.GL_LIGHTING); - gl.Color(1, 0, 0, 1); - - if(points) - { - int name = 0; - - gl.PointSize(5); - - // Add a new name (the vertex name). - gl.PushName(0); - - foreach(Vertex v in vertices) - { - // Set the name, draw the vertex. - gl.LoadName((uint)name++); - //todo draw vertex - //((IInteractable)v).DrawPick(gl); - } - - // Pop the name. - gl.PopName(); - } - - if(lines) - { - // Draw lines along each row, then along each column. - gl.DepthFunc(OpenGL.GL_ALWAYS); - - gl.LineWidth(1); - gl.Disable(OpenGL.GL_LINE_SMOOTH); - - for(int col=0; col < y; col++) - { - for(int row=0; row < x; row++) - { - // Create vertex indicies. - int nTopLeft = (col * x) + row; - int nBottomLeft = ((col + 1) * x) + row; - - gl.Begin(OpenGL.GL_LINES); - if(row < (x-1)) - { - gl.Vertex(vertices[nTopLeft]); - gl.Vertex(vertices[nTopLeft + 1]); - } - if(col < (y-1)) - { - gl.Vertex(vertices[nTopLeft]); - gl.Vertex(vertices[nBottomLeft]); - } - gl.End(); - } - } - gl.DepthFunc(OpenGL.GL_LESS); - } - - gl.PopAttrib(); - } - - /// - /// This function returns all of the control points as a float array, which - /// is in the format [0] = vertex 1 X, [1] = vertex 1 Y, [2] = vertex 1 Z, - /// [3] = vertex 2 X etc etc... This array is suitable for OpenGL functions - /// for evaluators and NURBS. - /// - /// An array of floats. - public float[] ToFloatArray() - { - float[] floats = new float[Vertices.Count * 3]; - int index = 0; - foreach(Vertex pt in Vertices) - { - floats[index++] = pt.X; - floats[index++] = pt.Y; - floats[index++] = pt.Z; - } - - return floats; - } - - protected List vertices = new List(); - protected int x = 0; - protected int y = 0; - - public List Vertices - { - get {return vertices;} - set {vertices = value;} - } - public int Width - { - get {return x;} - set {x = value;} - } - public int Height - { - get {return x;} - set {y = value;} - } - } +using System; +using System.ComponentModel; +using System.Collections; +using System.Collections.Generic; + +using SharpGL.SceneGraph; +using SharpGL.SceneGraph.Collections; +using SharpGL.SceneGraph.Core; +using SharpGL.SceneGraph.Primitives; + +namespace SharpGL.SceneGraph.Core +{ + /// + /// This class represent's a grid of points, just like you'd get on a NURBS + /// surface, or a patch. + /// + [Serializable()] + public class VectorGrid + { + public virtual void CreateGrid(int x, int y) + { + // Clear the current array. + vertices.Clear(); + + // Add a new set of control points. + for(int yvals = 0; yvals < y; yvals++) + { + for(int xvals = 0; xvals < x; xvals++) + vertices.Add( new System.Numerics.Vector3(xvals, 1.0f, yvals)); + } + + this.x = x; + this.y = y; + } + + /// + /// Use this to draw the vertex grid. + /// + /// OpenGL object. + /// Draw each individual vertex (with selection names). + /// Draw the lines connecting the points. + public virtual void Draw(OpenGL gl, bool points, bool lines) + { + // Save the attributes. + gl.PushAttrib(OpenGL.GL_ALL_ATTRIB_BITS); + gl.Disable(OpenGL.GL_LIGHTING); + gl.Color(1, 0, 0, 1); + + if(points) + { + int name = 0; + + gl.PointSize(5); + + // Add a new name (the vertex name). + gl.PushName(0); + + foreach(System.Numerics.Vector3 v in vertices) + { + // Set the name, draw the vertex. + gl.LoadName((uint)name++); + //todo draw vertex + //((IInteractable)v).DrawPick(gl); + } + + // Pop the name. + gl.PopName(); + } + + if(lines) + { + // Draw lines along each row, then along each column. + gl.DepthFunc(OpenGL.GL_ALWAYS); + + gl.LineWidth(1); + gl.Disable(OpenGL.GL_LINE_SMOOTH); + + for(int col=0; col < y; col++) + { + for(int row=0; row < x; row++) + { + // Create vertex indicies. + int nTopLeft = (col * x) + row; + int nBottomLeft = ((col + 1) * x) + row; + + gl.Begin(OpenGL.GL_LINES); + if(row < (x-1)) + { + gl.Vertex(vertices[nTopLeft]); + gl.Vertex(vertices[nTopLeft + 1]); + } + if(col < (y-1)) + { + gl.Vertex(vertices[nTopLeft]); + gl.Vertex(vertices[nBottomLeft]); + } + gl.End(); + } + } + gl.DepthFunc(OpenGL.GL_LESS); + } + + gl.PopAttrib(); + } + + /// + /// This function returns all of the control points as a float array, which + /// is in the format [0] = vertex 1 X, [1] = vertex 1 Y, [2] = vertex 1 Z, + /// [3] = vertex 2 X etc etc... This array is suitable for OpenGL functions + /// for evaluators and NURBS. + /// + /// An array of floats. + public float[] ToFloatArray() + { + float[] floats = new float[Vertices.Count * 3]; + int index = 0; + foreach(System.Numerics.Vector3 pt in Vertices) + { + floats[index++] = pt.X; + floats[index++] = pt.Y; + floats[index++] = pt.Z; + } + + return floats; + } + + protected List vertices = new List(); + protected int x = 0; + protected int y = 0; + + public List Vertices + { + get {return vertices;} + set {vertices = value;} + } + public int Width + { + get {return x;} + set {x = value;} + } + public int Height + { + get {return x;} + set {y = value;} + } + } } \ No newline at end of file diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Evaluators/Evaluator.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Evaluators/Evaluator.cs index a555c4b9..4db6e9df 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Evaluators/Evaluator.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Evaluators/Evaluator.cs @@ -58,7 +58,7 @@ public void PopObjectSpace(OpenGL gl) /// /// The control points. /// - private VertexGrid controlPoints = new VertexGrid(); + private VectorGrid controlPoints = new VectorGrid(); /// /// Draw points flag. @@ -82,7 +82,7 @@ public void PopObjectSpace(OpenGL gl) /// The control points. /// [Description("The control points."), Category("Evaluator")] - public VertexGrid ControlPoints + public VectorGrid ControlPoints { get {return controlPoints;} set {controlPoints = value; } diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Face.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Face.cs index abb752f3..b819420b 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Face.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Face.cs @@ -29,9 +29,9 @@ public Face() public float[] GetPlaneEquation(Polygon parent) { // Get refs to vertices. - Vertex v1 = parent.Vertices[indices[0].Vertex]; - Vertex v2 = parent.Vertices[indices[1].Vertex]; - Vertex v3 = parent.Vertices[indices[2].Vertex]; + System.Numerics.Vector3 v1 = parent.Vertices[indices[0].Vertex]; + System.Numerics.Vector3 v2 = parent.Vertices[indices[1].Vertex]; + System.Numerics.Vector3 v3 = parent.Vertices[indices[2].Vertex]; float a = v1.Y * (v2.Z - v3.Z) + v2.Y * (v3.Z - v1.Z) + v3.Y * (v1.Z - v2.Z); float b = v1.Z * (v2.X - v3.X) + v2.Z * (v3.X - v1.X) + v3.Z * (v1.X - v2.X); @@ -48,17 +48,17 @@ public float[] GetPlaneEquation(Polygon parent) /// /// The parent. /// - public Vertex GetSurfaceNormal(Polygon parent) + public System.Numerics.Vector3 GetSurfaceNormal(Polygon parent) { // Do we have enough vertices for a normal? if (indices.Count < 3) - return new Vertex(0, 0, 0); + return new System.Numerics.Vector3(0, 0, 0); - Vertex v1 = parent.Vertices[indices[0].Vertex]; - Vertex v2 = parent.Vertices[indices[1].Vertex]; - Vertex v3 = parent.Vertices[indices[2].Vertex]; - Vertex va = v1 - v2; - Vertex vb = v2 - v3; + System.Numerics.Vector3 v1 = parent.Vertices[indices[0].Vertex]; + System.Numerics.Vector3 v2 = parent.Vertices[indices[1].Vertex]; + System.Numerics.Vector3 v3 = parent.Vertices[indices[2].Vertex]; + System.Numerics.Vector3 va = v1 - v2; + System.Numerics.Vector3 vb = v2 - v3; return va.VectorProduct(vb); } @@ -97,7 +97,7 @@ public void GenerateNormals(Polygon parent) if (Indices.Count >= 3) { // Create a normal. - Vertex vNormal = GetSurfaceNormal(parent); + System.Numerics.Vector3 vNormal = GetSurfaceNormal(parent); vNormal.UnitLength(); // Add it to the normals, setting the index for next time. diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Feedback/Triangulator.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Feedback/Triangulator.cs index cf09a064..b013219f 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Feedback/Triangulator.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Feedback/Triangulator.cs @@ -54,12 +54,12 @@ protected override void ParseData(OpenGL gl, int values) int vertexCount = (int)feedbackBuffer[values - count--]; // Create an array of vertices. - Vertex[] vertices = new Vertex[vertexCount]; + System.Numerics.Vector3[] vertices = new System.Numerics.Vector3[vertexCount]; // Parse them. for (int i = 0; i < vertexCount; i++) { - vertices[i] = new Vertex(); + vertices[i] = new System.Numerics.Vector3(); double x = (double)feedbackBuffer[values - count--]; double y = (double)feedbackBuffer[values - count--]; double z = (double)feedbackBuffer[values - count--]; diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Helpers/SceneHelper.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Helpers/SceneHelper.cs index b2c3ae39..8c1d4bbe 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Helpers/SceneHelper.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Helpers/SceneHelper.cs @@ -30,9 +30,9 @@ public static void InitialiseModelingScene(Scene scene) // Create the 'Look At' camera var lookAtCamera = new LookAtCamera() { - Position = new Vertex(-10f, -10f, 10f), - Target = new Vertex(0f, 0f, 0f), - UpVector = new Vertex(0f, 0f, 1f) + Position = new System.Numerics.Vector3(-10f, -10f, 10f), + Target = new System.Numerics.Vector3(0f, 0f, 0f), + UpVector = new System.Numerics.Vector3(0f, 0f, 1f) }; // Set the look at camera as the current camera. @@ -49,21 +49,21 @@ public static void InitialiseModelingScene(Scene scene) { Name="Light 1", On = true, - Position = new Vertex(-9, -9, 11), + Position = new System.Numerics.Vector3(-9, -9, 11), GLCode = OpenGL.GL_LIGHT0 }; Light light2 = new Light() { Name = "Light 2", On = true, - Position = new Vertex(9, -9, 11), + Position = new System.Numerics.Vector3(9, -9, 11), GLCode = OpenGL.GL_LIGHT1 }; Light light3 = new Light() { Name = "Light 3", On = true, - Position = new Vertex(0, 15, 15), + Position = new System.Numerics.Vector3(0, 15, 15), GLCode = OpenGL.GL_LIGHT2 }; // Add the lights. diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Lighting/Light.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Lighting/Light.cs index 4b8bc2a0..7d816919 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Lighting/Light.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Lighting/Light.cs @@ -21,7 +21,7 @@ public class Light : SceneElement, IBindable, IVolumeBound public Light() { Name = "Light"; - Position = new Vertex(0, 3, 0); + Position = new System.Numerics.Vector3(0, 3, 0); } /// @@ -109,7 +109,7 @@ public virtual void Bind(OpenGL gl) /// /// The position of the light. /// - private Vertex position = new Vertex(0, 0, 0); + private System.Numerics.Vector3 position = new System.Numerics.Vector3(0, 0, 0); /// /// Should the light cast a shadow? @@ -151,7 +151,7 @@ public uint GLCode /// The position. /// [Category("Light"), Description("The position.")] - public Vertex Position + public System.Numerics.Vector3 Position { get { return position; } set diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Lighting/Spotlight.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Lighting/Spotlight.cs index 4c69cb2a..bd496384 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Lighting/Spotlight.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Lighting/Spotlight.cs @@ -19,7 +19,7 @@ public class Spotlight : Light public Spotlight() { Name = "Spotlight"; - Position = new Vertex(0, 3, 0); + Position = new System.Numerics.Vector3(0, 3, 0); } /// @@ -36,7 +36,7 @@ public override void Bind(OpenGL gl) { // Set the spot parameters. gl.Light(GLCode, OpenGL.GL_SPOT_CUTOFF, spotCutoff); - gl.Light(GLCode, OpenGL.GL_SPOT_DIRECTION, direction); + gl.Light(GLCode, OpenGL.GL_SPOT_DIRECTION, direction.Array()); } } @@ -49,7 +49,7 @@ public override void Bind(OpenGL gl) /// /// A Vector describing the direction of the spotlight. /// - private Vertex direction = new Vertex(0, 1, 0); + private System.Numerics.Vector3 direction = new System.Numerics.Vector3(0, 1, 0); /// /// Gets or sets the direction. @@ -58,7 +58,7 @@ public override void Bind(OpenGL gl) /// The direction. /// [Category("Light"), Description("The spotlight direction.")] - public Vertex Direction + public System.Numerics.Vector3 Direction { get {return direction;} set {direction = value; } diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Matrix.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Matrix.cs index 9b655734..222e7207 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Matrix.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Matrix.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Collections; using System.Collections.Generic; +using System.Numerics; namespace SharpGL.SceneGraph { @@ -665,6 +666,40 @@ public static Matrix Multiply(Matrix Mat1, Matrix Mat2) return new Matrix(Multiply(Mat1.in_Mat, Mat2.in_Mat)); } } + + /// + /// Implements the operator *. + /// + /// The LHS. + /// The RHS. + /// + /// The result of the operator. + /// + public static Vector3 operator * (Vector3 lhs, Matrix rhs) + { + float X = lhs.X * (float)rhs[0,0] + lhs.Y * (float)rhs[1,0] + lhs.Z * (float)rhs[2,0]; + float Y = lhs.X * (float)rhs[0,1] + lhs.Y * (float)rhs[1,1] + lhs.Z * (float)rhs[2,1]; + float Z = lhs.X * (float)rhs[0,2] + lhs.Y * (float)rhs[1,2] + lhs.Z * (float)rhs[2,2]; + + return new Vector3(X, Y, Z); + } + + /// + /// Implements the operator *. + /// + /// The LHS. + /// The RHS. + /// + /// The result of the operator. + /// + public static Vector3 operator *(Matrix lhs, Vector3 rhs) + { + float X = rhs.X * (float)lhs[0, 0] + rhs.Y * (float)lhs[1, 0] + rhs.Z * (float)lhs[2, 0]; + float Y = rhs.X * (float)lhs[0, 1] + rhs.Y * (float)lhs[1, 1] + rhs.Z * (float)lhs[2, 1]; + float Z = rhs.X * (float)lhs[0, 2] + rhs.Y * (float)lhs[1, 2] + rhs.Z * (float)lhs[2, 2]; + + return new Vector3(X, Y, Z); + } #endregion #region "Determinant of a Matrix" diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/OpenGLAttributes/CurrentAttributes.cs b/source/SharpGL/Core/SharpGL.SceneGraph/OpenGLAttributes/CurrentAttributes.cs index e17e710d..459fdced 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/OpenGLAttributes/CurrentAttributes.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/OpenGLAttributes/CurrentAttributes.cs @@ -63,9 +63,9 @@ public override bool AreAnyAttributesSet() private GLColor currentColor; private int? currentColorIndex; - private Vertex? currentNormalVector; + private System.Numerics.Vector3? currentNormalVector; private UV? currentTextureCoordiate; - private Vertex? currentRasterPosition; + private System.Numerics.Vector3? currentRasterPosition; private GLColor currentRasterColor; private int? currentRasterColorIndex; private UV? currentRasterTextureCoordiate; @@ -104,7 +104,7 @@ public int? CurrentColorIndex /// The current normal vector. /// [Description(""), Category("Current")] - public Vertex? CurrentNormalVector + public System.Numerics.Vector3? CurrentNormalVector { get { return currentNormalVector; } set { currentNormalVector = value; } @@ -130,7 +130,7 @@ public UV? CurrentTextureCoordiate /// The current raster position. /// [Description(""), Category("Current")] - public Vertex? CurrentRasterPosition + public System.Numerics.Vector3? CurrentRasterPosition { get { return currentRasterPosition; } set { currentRasterPosition = value; } diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/OpenGLSceneGraphExtensions.cs b/source/SharpGL/Core/SharpGL.SceneGraph/OpenGLSceneGraphExtensions.cs index e6fbb33c..c3832116 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/OpenGLSceneGraphExtensions.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/OpenGLSceneGraphExtensions.cs @@ -32,7 +32,7 @@ public static void Color(this OpenGL gl, GLColor color) /// /// The screen coords. /// - public static Vertex Project(this OpenGL gl, Vertex vertex) + public static System.Numerics.Vector3 Project(this OpenGL gl, System.Numerics.Vector3 vertex) { // THIS CODE MUST BE TESTED double[] modelview = new double[16]; @@ -47,7 +47,7 @@ public static Vertex Project(this OpenGL gl, Vertex vertex) gl.Project(vertex.X, vertex.Y, vertex.Z, modelview, projection, viewport, x, y, z); - return new Vertex((float)x[0], (float)y[0], (float)z[0]); + return new System.Numerics.Vector3((float)x[0], (float)y[0], (float)z[0]); } /// @@ -97,7 +97,7 @@ public static Matrix GetTextureMatrix(this OpenGL gl) /// The type. /// The stride. /// The pointer. - public static void VertexPointer(this OpenGL gl, int size, uint type, int stride, Vertex[] pointer) + public static void VertexPointer(this OpenGL gl, int size, uint type, int stride, System.Numerics.Vector3[] pointer) { // TODO debug this. var handle = GCHandle.Alloc(pointer, GCHandleType.Pinned); diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/ParticleSystem/Particle.cs b/source/SharpGL/Core/SharpGL.SceneGraph/ParticleSystem/Particle.cs index 90b1ce06..a3b8bbbb 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/ParticleSystem/Particle.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/ParticleSystem/Particle.cs @@ -106,27 +106,27 @@ public override void Draw(OpenGL gl) /// /// This is the vertex's current position in space. /// - protected Vertex position = new Vertex(0, 0, 0); + protected System.Numerics.Vector3 position = new System.Numerics.Vector3(0, 0, 0); /// /// This is the velocity, do not modify! /// - protected Vertex velocity = new Vertex(0, 0, 0); + protected System.Numerics.Vector3 velocity = new System.Numerics.Vector3(0, 0, 0); /// /// This is the direction of the particle. /// - protected Vertex direction = new Vertex(0, 0, 0); + protected System.Numerics.Vector3 direction = new System.Numerics.Vector3(0, 0, 0); /// /// This shows the potential magnitude of the random effects of the direction. /// - protected Vertex directionRandomise = new Vertex(0.1f, 0.1f, 0.1f); + protected System.Numerics.Vector3 directionRandomise = new System.Numerics.Vector3(0.1f, 0.1f, 0.1f); /// /// This is the gravity affecting the particle. /// - protected Vertex gravity = new Vertex(0, -0.1f, 0); + protected System.Numerics.Vector3 gravity = new System.Numerics.Vector3(0, -0.1f, 0); /// /// Particles colour. @@ -157,27 +157,27 @@ public override void Draw(OpenGL gl) #region Properties - public Vertex Position + public System.Numerics.Vector3 Position { get { return position; } set { position = value; } } - public Vertex Velocity + public System.Numerics.Vector3 Velocity { get { return velocity; } set { velocity = value; } } - public Vertex Direction + public System.Numerics.Vector3 Direction { get { return direction; } set { direction = value; } } - public Vertex DirectionRandomise + public System.Numerics.Vector3 DirectionRandomise { get { return directionRandomise; } set { directionRandomise = value; } } - public Vertex Gravity + public System.Numerics.Vector3 Gravity { get { return gravity; } set { gravity = value; } diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Plane.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Plane.cs index d29ad065..a33b73a4 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Plane.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Plane.cs @@ -25,7 +25,7 @@ public Plane() /// /// Less than 0 if behind, 0 if on, Greater than 0 if in front. /// - public float ClassifyPoint(Vertex point) + public float ClassifyPoint(System.Numerics.Vector3 point) { // (X-P)*N = 0. Where, X is a point to test, P is a point // on the plane, and N is the normal to the plane. @@ -36,12 +36,12 @@ public float ClassifyPoint(Vertex point) /// /// The position. /// - public Vertex position = new Vertex(0, 0, 0); + public System.Numerics.Vector3 position = new System.Numerics.Vector3(0, 0, 0); /// /// The normal. /// - public Vertex normal = new Vertex(0, 0, 0); + public System.Numerics.Vector3 normal = new System.Numerics.Vector3(0, 0, 0); /// /// The equation. diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Primitives/Cube.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Primitives/Cube.cs index 2a6edfbb..820850b3 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Primitives/Cube.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Primitives/Cube.cs @@ -36,14 +36,14 @@ private void CreateCubeGeometry() UVs.Add(new UV(1, 0)); // Add the vertices. - Vertices.Add(new Vertex(-1, -1, -1)); - Vertices.Add(new Vertex( 1, -1, -1)); - Vertices.Add(new Vertex( 1, -1, 1)); - Vertices.Add(new Vertex(-1, -1, 1)); - Vertices.Add(new Vertex(-1, 1, -1)); - Vertices.Add(new Vertex( 1, 1, -1)); - Vertices.Add(new Vertex( 1, 1, 1)); - Vertices.Add(new Vertex(-1, 1, 1)); + Vertices.Add(new System.Numerics.Vector3(-1, -1, -1)); + Vertices.Add(new System.Numerics.Vector3( 1, -1, -1)); + Vertices.Add(new System.Numerics.Vector3( 1, -1, 1)); + Vertices.Add(new System.Numerics.Vector3(-1, -1, 1)); + Vertices.Add(new System.Numerics.Vector3(-1, 1, -1)); + Vertices.Add(new System.Numerics.Vector3( 1, 1, -1)); + Vertices.Add(new System.Numerics.Vector3( 1, 1, 1)); + Vertices.Add(new System.Numerics.Vector3(-1, 1, 1)); // Add the faces. Face face = new Face(); // bottom diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Primitives/Polygon.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Primitives/Polygon.cs index b4b55762..b8e99aba 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Primitives/Polygon.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Primitives/Polygon.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; - +using System.Numerics; using SharpGL.SceneGraph.Collections; using SharpGL.SceneGraph.Core; using SharpGL.SceneGraph.Lighting; @@ -44,13 +44,13 @@ public Polygon() /// array, and create a face. It will take account of duplicate vertices too! /// /// A set of vertices to make into a face. - public virtual void AddFaceFromVertexData(Vertex[] vertexData) + public virtual void AddFaceFromVertexData(System.Numerics.Vector3[] vertexData) { // Create a face. Face newFace = new Face(); // Go through the vertices... - foreach(Vertex v in vertexData) + foreach(System.Numerics.Vector3 v in vertexData) { // Do we have this vertex already? int at = VertexSearch.Search(vertices, 0, v, 0.01f); @@ -143,14 +143,14 @@ public virtual void Render(OpenGL gl, RenderMode renderMode) // Set a normal, or generate one. if (index.Normal != -1) - gl.Normal(normals[index.Normal]); + gl.Normal(normals[index.Normal].Array()); else { // Do we have enough vertices for a normal? if (face.Indices.Count >= 3) { // Create a normal. - Vertex vNormal = face.GetSurfaceNormal(this); + System.Numerics.Vector3 vNormal = face.GetSurfaceNormal(this); vNormal.UnitLength(); // todo use auto smoothing instead @@ -158,7 +158,7 @@ public virtual void Render(OpenGL gl, RenderMode renderMode) normals.Add(vNormal); index.Normal = normals.Count - 1; - gl.Normal(vNormal); + gl.Normal(vNormal.Array()); } } @@ -191,11 +191,11 @@ public virtual void Render(OpenGL gl, RenderMode renderMode) if (index.Normal != -1 && index.Vertex != -1) { // Get the vertex. - Vertex vertex = vertices[index.Vertex]; + Vector3 vertex = vertices[index.Vertex]; // Get the normal vertex. - Vertex normal = normals[index.Normal]; - Vertex vertex2 = vertex + normal; + System.Numerics.Vector3 normal = normals[index.Normal]; + System.Numerics.Vector3 vertex2 = vertex + normal; gl.Begin(OpenGL.GL_LINES); gl.Vertex(vertex); @@ -246,7 +246,7 @@ public virtual bool CreateFromMap(string filename, int xPoints, int yPoints) float yPos = (float)y / (float)yPoints; // Create a control point from it. - Vertex v = new Vertex(xPos, 0, yPos); + System.Numerics.Vector3 v = new System.Numerics.Vector3(xPos, 0, yPos); // Add the 'height', based on color. v.Y = (float)col.R / 255.0f + (float)col.G / 255.0f + @@ -318,7 +318,7 @@ public virtual void Validate(bool regenerateNormals) if(regenerateNormals) { // Find a normal for the face. - Vertex normal = face.GetSurfaceNormal(this); + System.Numerics.Vector3 normal = face.GetSurfaceNormal(this); // Does this normal already exist? int index = VertexSearch.Search(normals, 0, normal, 0.001f); @@ -356,17 +356,17 @@ private Intersection TestIntersection(Ray ray) // Find the point of intersection upon the plane, as a point 't' along // the ray. - Vertex point1OnPlane = vertices[face.Indices[0].Vertex]; - Vertex point2OnPlane = vertices[face.Indices[1].Vertex]; - Vertex point3OnPlane = vertices[face.Indices[2].Vertex]; - Vertex midpointOpp1 = (point2OnPlane + point3OnPlane) / 2; - Vertex midpointOpp2 = (point1OnPlane + point3OnPlane) / 2; - Vertex midpointOpp3 = (point1OnPlane + point2OnPlane) / 2; + System.Numerics.Vector3 point1OnPlane = vertices[face.Indices[0].Vertex]; + System.Numerics.Vector3 point2OnPlane = vertices[face.Indices[1].Vertex]; + System.Numerics.Vector3 point3OnPlane = vertices[face.Indices[2].Vertex]; + System.Numerics.Vector3 midpointOpp1 = (point2OnPlane + point3OnPlane) / 2; + System.Numerics.Vector3 midpointOpp2 = (point1OnPlane + point3OnPlane) / 2; + System.Numerics.Vector3 midpointOpp3 = (point1OnPlane + point2OnPlane) / 2; - Vertex planeNormal = face.GetSurfaceNormal(this); + System.Numerics.Vector3 planeNormal = face.GetSurfaceNormal(this); - Vertex diff = point1OnPlane - ray.origin; + System.Numerics.Vector3 diff = point1OnPlane - ray.origin; float s1 = diff.ScalarProduct(planeNormal); float s2 = ray.direction.ScalarProduct(planeNormal); @@ -380,19 +380,19 @@ private Intersection TestIntersection(Ray ray) if(denomintor < 0.00001f && denomintor > -0.00001f) continue; // doesn't intersect the plane. - // Vertex v = point1OnPlane - ray.origin; + // System.Numerics.Vector3 v = point1OnPlane - ray.origin; // float t = (v.ScalarProduct(planeNormal)) / denomintor; // Now we can get the point of intersection. - Vertex vIntersect = ray.origin + (ray.direction * t); + System.Numerics.Vector3 vIntersect = ray.origin + (ray.direction * t); // Do my cool test. - Vertex vectorTo1 = vIntersect - point1OnPlane; - Vertex vectorTo2 = vIntersect - point2OnPlane; - Vertex vectorTo3 = vIntersect - point3OnPlane; - Vertex vectorMidTo1 = midpointOpp1 - point1OnPlane; - Vertex vectorMidTo2 = midpointOpp2 - point2OnPlane; - Vertex vectorMidTo3 = midpointOpp3 - point3OnPlane; + System.Numerics.Vector3 vectorTo1 = vIntersect - point1OnPlane; + System.Numerics.Vector3 vectorTo2 = vIntersect - point2OnPlane; + System.Numerics.Vector3 vectorTo3 = vIntersect - point3OnPlane; + System.Numerics.Vector3 vectorMidTo1 = midpointOpp1 - point1OnPlane; + System.Numerics.Vector3 vectorMidTo2 = midpointOpp2 - point2OnPlane; + System.Numerics.Vector3 vectorMidTo3 = midpointOpp3 - point3OnPlane; if(vectorTo1.Magnitude() > vectorMidTo1.Magnitude()) continue; @@ -487,13 +487,13 @@ public int Subdivide() continue; // Now get the vertices of the face. - Vertex v1 = Vertices[face.Indices[0].Vertex]; - Vertex v2 = Vertices[face.Indices[1].Vertex]; - Vertex v3 = Vertices[face.Indices[2].Vertex]; + System.Numerics.Vector3 v1 = Vertices[face.Indices[0].Vertex]; + System.Numerics.Vector3 v2 = Vertices[face.Indices[1].Vertex]; + System.Numerics.Vector3 v3 = Vertices[face.Indices[2].Vertex]; // Add the vertices to get a the midpoint of the edge formed by those // vectors. - Vertex vMidpoint = (v1 + v2 + v3) / 3; + System.Numerics.Vector3 vMidpoint = (v1 + v2 + v3) / 3; Index iMidpoint = new Index(Vertices.Count); Vertices.Add(vMidpoint); @@ -599,7 +599,7 @@ public Polygon DeepClone() /// /// The vertices that make up the polygon. /// - private List vertices = new List(); + private List vertices = new List(); /// /// The UV coordinates (texture coodinates) for the polygon. @@ -609,7 +609,7 @@ public Polygon DeepClone() /// /// The normals of the polygon object. /// - private List normals = new List(); + private List normals = new List(); /// /// Should the normals be drawn? @@ -641,7 +641,7 @@ public List Faces /// The vertices. /// [Description("The vertices that make up the polygon."), Category("Polygon")] - public List Vertices + public List Vertices { get {return vertices;} set {vertices = value; } @@ -667,7 +667,7 @@ public List UVs /// The normals. /// [Description("The normals."), Category("Normals")] - public List Normals + public List Normals { get {return normals;} set {normals = value; } diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Primitives/Shadow.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Primitives/Shadow.cs index 7d55c13f..2e34f108 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Primitives/Shadow.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Primitives/Shadow.cs @@ -122,7 +122,7 @@ private void CastShadow(OpenGL gl) bool[] facesVisible = new bool[faces.Count]; // Get the light position relative to the polygon. - Vertex lightPos = light.Position; + System.Numerics.Vector3 lightPos = light.Position; lightPos = lightPos - ParentPolygon.Transformation.TranslationVertex; // Go through every face, finding out whether it's visible to the light. @@ -203,7 +203,7 @@ private void CastShadow(OpenGL gl) /// The OpenGL object. /// The position of the light casting the shadow. /// An array of bools indicating the visible faces. - private void DoShadowPass(OpenGL gl, Vertex lightPos, bool[] visibleArray) + private void DoShadowPass(OpenGL gl, System.Numerics.Vector3 lightPos, bool[] visibleArray) { // Helpful references. var faces = ParentPolygon.Faces; @@ -229,12 +229,12 @@ private void DoShadowPass(OpenGL gl, Vertex lightPos, bool[] visibleArray) if(neighbourIndex == -1 || visibleArray[neighbourIndex] == false ) { // Get the edge vertices. - Vertex v1 = vertices[face.Indices[j].Vertex]; - Vertex v2 = vertices[face.Indices[(j+1)%face.Indices.Count].Vertex]; + System.Numerics.Vector3 v1 = vertices[face.Indices[j].Vertex]; + System.Numerics.Vector3 v2 = vertices[face.Indices[(j+1)%face.Indices.Count].Vertex]; // Create the two distant vertices. - Vertex v3 = (v1 - lightPos) * 100; - Vertex v4 = (v2 - lightPos) * 100; + System.Numerics.Vector3 v3 = (v1 - lightPos) * 100; + System.Numerics.Vector3 v4 = (v2 - lightPos) * 100; // Draw the shadow volume. gl.Begin(OpenGL.GL_TRIANGLE_STRIP); diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Quadrics/Cylinder.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Quadrics/Cylinder.cs index c8c589f7..c33e7c08 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Quadrics/Cylinder.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Quadrics/Cylinder.cs @@ -81,7 +81,7 @@ public double BaseRadius set { baseRadius = value; - BoundingVolume.FromCylindricalVolume(new Vertex(), (float)height, (float)baseRadius, (float)topRadius); + BoundingVolume.FromCylindricalVolume(new System.Numerics.Vector3(), (float)height, (float)baseRadius, (float)topRadius); } } @@ -98,7 +98,7 @@ public double TopRadius set { topRadius = value; - BoundingVolume.FromCylindricalVolume(new Vertex(), (float)height, (float)baseRadius, (float)topRadius); + BoundingVolume.FromCylindricalVolume(new System.Numerics.Vector3(), (float)height, (float)baseRadius, (float)topRadius); } } @@ -115,7 +115,7 @@ public double Height set { height = value; - BoundingVolume.FromCylindricalVolume(new Vertex(), (float)height, (float)baseRadius, (float)topRadius); + BoundingVolume.FromCylindricalVolume(new System.Numerics.Vector3(), (float)height, (float)baseRadius, (float)topRadius); } } diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Quadrics/Sphere.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Quadrics/Sphere.cs index 54089e32..f74761bf 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Quadrics/Sphere.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Quadrics/Sphere.cs @@ -75,7 +75,7 @@ public double Radius // Update the bounding volume. boundingVolumeHelper.BoundingVolume.FromSphericalVolume( - new Vertex(0, 0, 0), (float)value + 0.1f); + new System.Numerics.Vector3(0, 0, 0), (float)value + 0.1f); } } diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/Intersection.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/Intersection.cs index 3b4ce601..6b95877e 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/Intersection.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/Intersection.cs @@ -19,12 +19,12 @@ public class Intersection /// /// The normal. /// - public Vertex normal = new Vertex(); + public System.Numerics.Vector3 normal = new System.Numerics.Vector3(); /// /// The point. /// - public Vertex point = new Vertex(); + public System.Numerics.Vector3 point = new System.Numerics.Vector3(); /// /// The closeness. diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/Ray.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/Ray.cs index 9e7dfc1a..48f8f055 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/Ray.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/Ray.cs @@ -19,11 +19,11 @@ public class Ray /// /// The origin. /// - public Vertex origin = new Vertex(); + public System.Numerics.Vector3 origin = new System.Numerics.Vector3(); /// /// The direction. /// - public Vertex direction = new Vertex(); + public System.Numerics.Vector3 direction = new System.Numerics.Vector3(); } } diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/RayTracer.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/RayTracer.cs index da1e63a0..ade05806 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/RayTracer.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/RayTracer.cs @@ -37,9 +37,9 @@ public Image Render(Scene scene, Camera camera) int screenheight = viewport[3]; // From frustum data, we make a screen origin, and s/t vectors. - Vertex s = new Vertex(0, 0.03f, 0); - Vertex t = new Vertex(0, 0, 0.05f); - Vertex vScreenOrigin = new Vertex(0, 0, 5); + System.Numerics.Vector3 s = new System.Numerics.Vector3(0, 0.03f, 0); + System.Numerics.Vector3 t = new System.Numerics.Vector3(0, 0, 0.05f); + System.Numerics.Vector3 vScreenOrigin = new System.Numerics.Vector3(0, 0, 5); // Go through every pixel we have, and convert it into a screen pixel. ScreenPixel[] pixels = new ScreenPixel[viewport[2] * viewport[3]]; @@ -60,7 +60,7 @@ public Image Render(Scene scene, Camera camera) ScreenPixel pixel = new ScreenPixel(); pixel.x = x; pixel.y = y; - pixel.worldpos = new Vertex(worldX, worldY, worldZ); + pixel.worldpos = new System.Numerics.Vector3(worldX, worldY, worldZ); pixel.ray.origin = camera.Position; pixel.ray.direction = pixel.worldpos - camera.Position; diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/ScreenPixel.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/ScreenPixel.cs index 9de013a3..d2247068 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/ScreenPixel.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Raytracing/ScreenPixel.cs @@ -15,6 +15,6 @@ public class ScreenPixel public Ray ray = new Ray(); public int x = 0; public int y = 0; - public Vertex worldpos = new Vertex(); + public System.Numerics.Vector3 worldpos = new System.Numerics.Vector3(); } } diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/SharpGL.SceneGraph.csproj b/source/SharpGL/Core/SharpGL.SceneGraph/SharpGL.SceneGraph.csproj index 96151042..56bbbb4a 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/SharpGL.SceneGraph.csproj +++ b/source/SharpGL/Core/SharpGL.SceneGraph/SharpGL.SceneGraph.csproj @@ -1,6 +1,6 @@  - netcoreapp2.0;netcoreapp3.0;netcoreapp3.1;net40;net45;net472 + net46;net472;netcoreapp2.0;netcoreapp3.0;netcoreapp3.1 Library SharpGL.SceneGraph diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Transformations/LinearTransformation.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Transformations/LinearTransformation.cs index 289c6a50..2c02407f 100644 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Transformations/LinearTransformation.cs +++ b/source/SharpGL/Core/SharpGL.SceneGraph/Transformations/LinearTransformation.cs @@ -132,9 +132,9 @@ public LinearTransformation DeepClone() /// [Browsable(false)] [XmlIgnore] - public Vertex TranslationVertex + public System.Numerics.Vector3 TranslationVertex { - get { return new Vertex(translateX, translateY, translateZ); } + get { return new System.Numerics.Vector3(translateX, translateY, translateZ); } } /// diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/VectorExtensions.cs b/source/SharpGL/Core/SharpGL.SceneGraph/VectorExtensions.cs new file mode 100644 index 00000000..544268e6 --- /dev/null +++ b/source/SharpGL/Core/SharpGL.SceneGraph/VectorExtensions.cs @@ -0,0 +1,73 @@ +using System; +using System.Numerics; +using System.Xml.Serialization; + +namespace SharpGL.SceneGraph +{ + /// + /// The Vertex class represents a 3D point in space. + /// + public static class VectorExtensions + { + /// + /// Sets the specified X. + /// + /// The X. + /// The Y. + /// The Z. + [Obsolete] + public static void Set(this ref Vector3 it, float X, float Y, float Z) + { + it.X = X; it.Y = Y; it.Z = Z; + } + + [Obsolete] + public static void Push(this ref Vector3 it, float X, float Y, float Z) { it.X += X; it.Y += Y; it.Z += Z; } + + /// + /// This finds the Scalar Product (Dot Product) of two vectors. + /// + /// The right hand side of the equation. + /// A Scalar Representing the Dot-Product. + [Obsolete] + public static float ScalarProduct(this ref Vector3 it, Vector3 rhs) + { + return it.X * rhs.X + it.Y * rhs.Y + it.Z * rhs.Z; + } + + /// + /// Find the Vector product (cross product) of two vectors. + /// + /// The right hand side of the equation. + /// The Cross Product. + [Obsolete] + public static Vector3 VectorProduct(this ref Vector3 it, Vector3 rhs) + { + return new Vector3((it.Y * rhs.Z) - (it.Z * rhs.Y), (it.Z * rhs.X) - (it.X * rhs.Z), + (it.X * rhs.Y) - (it.Y * rhs.X)); + } + + /// + /// If You use this as a Vector, then call this function to get the vector + /// magnitude. + /// + /// + public static double Magnitude(this Vector3 it) => Math.Sqrt(it.X * it.X + it.Y * it.Y + it.Z * it.Z); + + /// + /// Make this vector unit length. + /// + [Obsolete] + public static void UnitLength(this ref Vector3 it) => it = it.Magnitude() == 0 ? Vector3.Zero : Vector3.Normalize(it); + + /// + /// Normalizes this instance. + /// + [Obsolete] + public static void Normalize(this ref Vector3 it) => it.UnitLength(); + + public static float[] Array(this Vector2 it) => new float[] { it.X, it.Y}; + public static float[] Array(this Vector3 it) => new float[] { it.X, it.Y, it.Z }; + public static float[] Array(this Vector4 it) => new float[] { it.X, it.Y, it.Z, it.W }; + } +} diff --git a/source/SharpGL/Core/SharpGL.SceneGraph/Vertex.cs b/source/SharpGL/Core/SharpGL.SceneGraph/Vertex.cs deleted file mode 100644 index fbf1bb4b..00000000 --- a/source/SharpGL/Core/SharpGL.SceneGraph/Vertex.cs +++ /dev/null @@ -1,245 +0,0 @@ -using System; -using System.Xml.Serialization; - -namespace SharpGL.SceneGraph -{ - /// - /// The Vertex class represents a 3D point in space. - /// - public struct Vertex - { - /// - /// Initializes a new instance of the struct. - /// - /// The x. - /// The y. - /// The z. - public Vertex(float x, float y, float z) - { - this.x = x; - this.y = y; - this.z = z; - } - - /// - /// Initializes a new instance of the struct. - /// - /// The vertex. - public Vertex(Vertex vertex) - { - this.x = vertex.X; - this.y = vertex.Y; - this.z = vertex.Z; - } - - /// - /// Sets the specified X. - /// - /// The X. - /// The Y. - /// The Z. - public void Set(float X, float Y, float Z) - { - this.X = X; this.Y = Y; this.Z = Z; - } - - public void Push(float X, float Y, float Z) { this.X += X; this.Y += Y; this.Z += Z; } - - public override string ToString() - { - return "(" + X + ", " + Y + ", " + Z + ")"; - } - - /// - /// Implements the operator +. - /// - /// The LHS. - /// The RHS. - /// - /// The result of the operator. - /// - public static Vertex operator +(Vertex lhs, Vertex rhs) - { - return new Vertex(lhs.X + rhs.X, lhs.Y + rhs.Y, lhs.Z + rhs.Z); - } - - /// - /// Implements the operator -. - /// - /// The LHS. - /// The RHS. - /// - /// The result of the operator. - /// - public static Vertex operator -(Vertex lhs, Vertex rhs) - { - return new Vertex(lhs.X - rhs.X, lhs.Y - rhs.Y, lhs.Z - rhs.Z); - } - - /// - /// Implements the operator *. - /// - /// The LHS. - /// The RHS. - /// - /// The result of the operator. - /// - public static Vertex operator *(Vertex lhs, Vertex rhs) - { - return new Vertex(lhs.X * rhs.X, lhs.Y * rhs.Y, lhs.Z * rhs.Z); - } - - /// - /// Implements the operator *. - /// - /// The LHS. - /// The RHS. - /// - /// The result of the operator. - /// - public static Vertex operator *(Vertex lhs, float rhs) - { - return new Vertex(lhs.X * rhs, lhs.Y * rhs, lhs.Z * rhs); - } - - /// - /// Implements the operator *. - /// - /// The LHS. - /// The RHS. - /// - /// The result of the operator. - /// - public static Vertex operator * (Vertex lhs, Matrix rhs) - { - float X = lhs.X * (float)rhs[0,0] + lhs.Y * (float)rhs[1,0] + lhs.Z * (float)rhs[2,0]; - float Y = lhs.X * (float)rhs[0,1] + lhs.Y * (float)rhs[1,1] + lhs.Z * (float)rhs[2,1]; - float Z = lhs.X * (float)rhs[0,2] + lhs.Y * (float)rhs[1,2] + lhs.Z * (float)rhs[2,2]; - - return new Vertex(X, Y, Z); - } - - /// - /// Implements the operator *. - /// - /// The LHS. - /// The RHS. - /// - /// The result of the operator. - /// - public static Vertex operator *(Matrix lhs, Vertex rhs) - { - float X = rhs.X * (float)lhs[0, 0] + rhs.Y * (float)lhs[1, 0] + rhs.Z * (float)lhs[2, 0]; - float Y = rhs.X * (float)lhs[0, 1] + rhs.Y * (float)lhs[1, 1] + rhs.Z * (float)lhs[2, 1]; - float Z = rhs.X * (float)lhs[0, 2] + rhs.Y * (float)lhs[1, 2] + rhs.Z * (float)lhs[2, 2]; - - return new Vertex(X, Y, Z); - } - - /// - /// Implements the operator /. - /// - /// The LHS. - /// The RHS. - /// - /// The result of the operator. - /// - public static Vertex operator /(Vertex lhs, float rhs) - { - return new Vertex(lhs.X / rhs, lhs.Y / rhs, lhs.Z / rhs); - } - - /// - /// This finds the Scalar Product (Dot Product) of two vectors. - /// - /// The right hand side of the equation. - /// A Scalar Representing the Dot-Product. - public float ScalarProduct(Vertex rhs) - { - return X * rhs.X + Y * rhs.Y + Z * rhs.Z; - } - - /// - /// Find the Vector product (cross product) of two vectors. - /// - /// The right hand side of the equation. - /// The Cross Product. - public Vertex VectorProduct(Vertex rhs) - { - return new Vertex((Y * rhs.Z) - (Z * rhs.Y), (Z * rhs.X) - (X * rhs.Z), - (X * rhs.Y) - (Y * rhs.X)); - } - - /// - /// If You use this as a Vector, then call this function to get the vector - /// magnitude. - /// - /// - public double Magnitude() - { - return System.Math.Sqrt(X * X + Y * Y + Z * Z); - } - - /// - /// Make this vector unit length. - /// - public void UnitLength() - { - // Zero length vertexes are always normalized to zero. - if (x == 0f && y == 0f && z == 0f) return; - - float f = X * X + Y * Y + Z * Z; - float frt = (float)Math.Sqrt(f); - X /= frt; - Y /= frt; - Z /= frt; - } - - /// - /// Normalizes this instance. - /// - public void Normalize() - { - UnitLength(); - } - - public static implicit operator float[](Vertex rhs) - { - return new float[] { rhs.X, rhs.Y, rhs.Z }; - } - - private float x; - private float y; - private float z; - - /// - /// The X coordinate. - /// - [XmlAttribute] - public float X - { - get { return x; } - set { x = value; } - } - - /// - /// The Y coordinate. - /// - [XmlAttribute] - public float Y - { - get { return y; } - set { y = value; } - } - - /// - /// The Z coordinate. - /// - [XmlAttribute] - public float Z - { - get { return z; } - set { z = value; } - } - } -} diff --git a/source/SharpGL/Core/SharpGL.Serialization.Tests/ObjFileFormatTests.cs b/source/SharpGL/Core/SharpGL.Serialization.Tests/ObjFileFormatTests.cs index e28e2075..1b9c87af 100644 --- a/source/SharpGL/Core/SharpGL.Serialization.Tests/ObjFileFormatTests.cs +++ b/source/SharpGL/Core/SharpGL.Serialization.Tests/ObjFileFormatTests.cs @@ -32,7 +32,7 @@ public void OBJ_file_is_correctly_parsed_whatever_the_current_culture(string cul // The first vertex line is: v 29.564405 140.987503 67.743927 var vertex = polygon.Vertices.First(); - Assert.That(vertex, Is.EqualTo(new Vertex(29.564405f, 140.987503f, 67.743927f))); + Assert.That(vertex, Is.EqualTo(new System.Numerics.Vector3(29.564405f, 140.987503f, 67.743927f))); // Materials should have been read too // First material is DBody; its ambient light is defined as: Ka 1.0000 0.6667 0.0000 diff --git a/source/SharpGL/Core/SharpGL.Serialization/Caligari/CaligariPrimitives.cs b/source/SharpGL/Core/SharpGL.Serialization/Caligari/CaligariPrimitives.cs index 4dc06b12..a75684f9 100644 --- a/source/SharpGL/Core/SharpGL.Serialization/Caligari/CaligariPrimitives.cs +++ b/source/SharpGL/Core/SharpGL.Serialization/Caligari/CaligariPrimitives.cs @@ -38,18 +38,18 @@ internal class CaligariAxies { public virtual void Read(BinaryReader stream) { - centre = new Vertex(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle()); - directionX = new Vertex(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle()); - directionY = new Vertex(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle()); - directionZ = new Vertex(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle()); + centre = new System.Numerics.Vector3(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle()); + directionX = new System.Numerics.Vector3(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle()); + directionY = new System.Numerics.Vector3(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle()); + directionZ = new System.Numerics.Vector3(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle()); // The X axis in SharpGL is always (1, 0, 0). - xAxis = new Vertex(1, 0, 0); + xAxis = new System.Numerics.Vector3(1, 0, 0); float angleX = xAxis.ScalarProduct(directionX); - yAxis = new Vertex(0, 1, 0); + yAxis = new System.Numerics.Vector3(0, 1, 0); float angleY = yAxis.ScalarProduct(directionY); - zAxis = new Vertex(0, 0, 1); + zAxis = new System.Numerics.Vector3(0, 0, 1); float angleZ = zAxis.ScalarProduct(directionZ); angleX = (float)System.Math.Asin(angleX); angleY = (float)System.Math.Asin(angleY); @@ -59,7 +59,7 @@ public virtual void Read(BinaryReader stream) angleY = (180 * angleY) / (float)Math.PI; angleZ = (180 * angleZ) / (float)Math.PI; - rotate = new Vertex(-angleX, -angleY, -angleZ); + rotate = new System.Numerics.Vector3(-angleX, -angleY, -angleZ); xAxis = xAxisGL = directionX; yAxis = zAxisGL = directionY; @@ -67,19 +67,19 @@ public virtual void Read(BinaryReader stream) xAxisGL.X = -xAxisGL.X; } - public Vertex centre; - public Vertex rotate; - - public Vertex directionX; - public Vertex directionY; - public Vertex directionZ; - - public Vertex xAxis; - public Vertex yAxis; - public Vertex zAxis; - public Vertex xAxisGL; - public Vertex yAxisGL; - public Vertex zAxisGL; + public System.Numerics.Vector3 centre; + public System.Numerics.Vector3 rotate; + + public System.Numerics.Vector3 directionX; + public System.Numerics.Vector3 directionY; + public System.Numerics.Vector3 directionZ; + + public System.Numerics.Vector3 xAxis; + public System.Numerics.Vector3 yAxis; + public System.Numerics.Vector3 zAxis; + public System.Numerics.Vector3 xAxisGL; + public System.Numerics.Vector3 yAxisGL; + public System.Numerics.Vector3 zAxisGL; } internal class CaligariPosition diff --git a/source/SharpGL/Core/SharpGL.Serialization/Caligari/PolygonChunk.cs b/source/SharpGL/Core/SharpGL.Serialization/Caligari/PolygonChunk.cs index c9762a8a..b6fcb918 100644 --- a/source/SharpGL/Core/SharpGL.Serialization/Caligari/PolygonChunk.cs +++ b/source/SharpGL/Core/SharpGL.Serialization/Caligari/PolygonChunk.cs @@ -46,7 +46,7 @@ protected override object ReadData(BinaryReader reader) for (int i = 0; i < verticesCount; i++) { // Read a vertex. - Vertex vertex = new Vertex(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); + System.Numerics.Vector3 vertex = new System.Numerics.Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); // Multiply it by the position matrix. vertex = vertex * pos.matrix; diff --git a/source/SharpGL/Core/SharpGL.Serialization/Discreet/Chunks.cs b/source/SharpGL/Core/SharpGL.Serialization/Discreet/Chunks.cs index d356e4d3..8bd7f87e 100644 --- a/source/SharpGL/Core/SharpGL.Serialization/Discreet/Chunks.cs +++ b/source/SharpGL/Core/SharpGL.Serialization/Discreet/Chunks.cs @@ -269,7 +269,7 @@ public override void ReadData(Scene scene, BinaryReader stream) // Read each vertex and add it. for (short i = 0; i < vertexCount; i++) { - Vertex v = new Vertex(); + System.Numerics.Vector3 v = new System.Numerics.Vector3(); v.X = stream.ReadSingle(); v.Y = stream.ReadSingle(); v.Z = stream.ReadSingle(); @@ -277,7 +277,7 @@ public override void ReadData(Scene scene, BinaryReader stream) } } - public List vertices = new List(); + public List vertices = new List(); } internal class FaceListChunk : MAXChunk diff --git a/source/SharpGL/Core/SharpGL.Serialization/SharpGL.Serialization.csproj b/source/SharpGL/Core/SharpGL.Serialization/SharpGL.Serialization.csproj index 73d78caa..e08416e8 100644 --- a/source/SharpGL/Core/SharpGL.Serialization/SharpGL.Serialization.csproj +++ b/source/SharpGL/Core/SharpGL.Serialization/SharpGL.Serialization.csproj @@ -1,6 +1,6 @@  - netcoreapp2.0;netcoreapp3.0;netcoreapp3.1;net40;net45;net472 + net46;net472;netcoreapp2.0;netcoreapp3.0;netcoreapp3.1 Library SharpGL.Serialization diff --git a/source/SharpGL/Core/SharpGL.Serialization/Wavefront/ObjFileFormat.cs b/source/SharpGL/Core/SharpGL.Serialization/Wavefront/ObjFileFormat.cs index 200ba831..be2ecc56 100644 --- a/source/SharpGL/Core/SharpGL.Serialization/Wavefront/ObjFileFormat.cs +++ b/source/SharpGL/Core/SharpGL.Serialization/Wavefront/ObjFileFormat.cs @@ -62,7 +62,7 @@ public Scene LoadData(string path) float z = float.Parse(values[2], CultureInfo.InvariantCulture); // Add the normal. - polygon.Normals.Add(new Vertex(x, y, z)); + polygon.Normals.Add(new System.Numerics.Vector3(x, y, z)); continue; } @@ -78,7 +78,7 @@ public Scene LoadData(string path) float z = float.Parse(values[2], CultureInfo.InvariantCulture); // Add the vertices. - polygon.Vertices.Add(new Vertex(x, y, z)); + polygon.Vertices.Add(new System.Numerics.Vector3(x, y, z)); continue; } diff --git a/source/SharpGL/Core/SharpGL.WPF/SharpGL.WPF.csproj b/source/SharpGL/Core/SharpGL.WPF/SharpGL.WPF.csproj index a1c7a6fd..26dbf477 100644 --- a/source/SharpGL/Core/SharpGL.WPF/SharpGL.WPF.csproj +++ b/source/SharpGL/Core/SharpGL.WPF/SharpGL.WPF.csproj @@ -1,6 +1,6 @@  - netcoreapp3.0;netcoreapp3.1;net40;net45;net472 + net46;net472;netcoreapp3.0;netcoreapp3.1 library true diff --git a/source/SharpGL/Core/SharpGL.WinForms.Tests/NETDesignSurface/Converters/VertexConverterTests.cs b/source/SharpGL/Core/SharpGL.WinForms.Tests/NETDesignSurface/Converters/VertexConverterTests.cs index 8a35598a..ddf56a58 100644 --- a/source/SharpGL/Core/SharpGL.WinForms.Tests/NETDesignSurface/Converters/VertexConverterTests.cs +++ b/source/SharpGL/Core/SharpGL.WinForms.Tests/NETDesignSurface/Converters/VertexConverterTests.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +using System.Numerics; +using NUnit.Framework; using SharpGL.SceneGraph; using SharpGL.WinForms.NETDesignSurface.Converters; @@ -16,9 +17,9 @@ public void Vertex_is_correctly_parsed_whatever_the_current_culture(string cultu { var text = " ( 1.2 , -3.4 , 5.6789 ) "; var converter = new VertexConverter(); - var vertex = (Vertex)converter.ConvertFrom(text); + var vertex = (Vector3)converter.ConvertFrom(text); - Assert.That(vertex, Is.EqualTo(new Vertex(1.2f, -3.4f, 5.6789f))); + Assert.That(vertex, Is.EqualTo(new System.Numerics.Vector3(1.2f, -3.4f, 5.6789f))); } } } diff --git a/source/SharpGL/Core/SharpGL.WinForms/NETDesignSurface/Converters/VertexConverter.cs b/source/SharpGL/Core/SharpGL.WinForms/NETDesignSurface/Converters/VertexConverter.cs index 30166cff..abc9abf9 100644 --- a/source/SharpGL/Core/SharpGL.WinForms/NETDesignSurface/Converters/VertexConverter.cs +++ b/source/SharpGL/Core/SharpGL.WinForms/NETDesignSurface/Converters/VertexConverter.cs @@ -53,7 +53,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, parsed = s.Substring(nextcomma + 1, closebracket - (nextcomma + 1)).Trim(); zValue = float.Parse(parsed, CultureInfo.InvariantCulture); - return new Vertex(xValue, yValue, zValue); + return new System.Numerics.Vector3(xValue, yValue, zValue); } } } @@ -71,10 +71,10 @@ public override object ConvertFrom(ITypeDescriptorContext context, public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is Vertex) + if (destType == typeof(string) && value is System.Numerics.Vector3) { // We can easily convert a vertex to a string, format (x, y, z). - Vertex v = (Vertex)value; + System.Numerics.Vector3 v = (System.Numerics.Vector3)value; return "(" + v.X + ", " + v.Y + ", " + v.Z + ")"; } diff --git a/source/SharpGL/Core/SharpGL.WinForms/NETDesignSurface/DesignSurface.cs b/source/SharpGL/Core/SharpGL.WinForms/NETDesignSurface/DesignSurface.cs index 4b9dd2bc..3c342b2b 100644 --- a/source/SharpGL/Core/SharpGL.WinForms/NETDesignSurface/DesignSurface.cs +++ b/source/SharpGL/Core/SharpGL.WinForms/NETDesignSurface/DesignSurface.cs @@ -14,11 +14,11 @@ public static void InitialiseDesignSurface() { // TODO: When can we call this? - // We cannot decorate the 'Texture', 'Vertex' and associated SceneGraph classes with the attributes which define + // We cannot decorate the 'Texture', 'System.Numerics.Vector3' and associated SceneGraph classes with the attributes which define // the type converters and editors, becauses the SceneGraph library is cross-platform. So we have to associate // the attributes at runtime. TypeDescriptor.AddAttributes(typeof(Texture), new EditorAttribute(typeof(UITextureEditor), typeof(UITypeEditor))); - TypeDescriptor.AddAttributes(typeof(Vertex), new EditorAttribute(typeof(VertexConverter), typeof(TypeConverter))); + TypeDescriptor.AddAttributes(typeof(System.Numerics.Vector3), new EditorAttribute(typeof(VertexConverter), typeof(TypeConverter))); } } } diff --git a/source/SharpGL/Core/SharpGL.WinForms/SharpGL.WinForms.csproj b/source/SharpGL/Core/SharpGL.WinForms/SharpGL.WinForms.csproj index 149e69d9..817bce06 100644 --- a/source/SharpGL/Core/SharpGL.WinForms/SharpGL.WinForms.csproj +++ b/source/SharpGL/Core/SharpGL.WinForms/SharpGL.WinForms.csproj @@ -1,6 +1,6 @@  - netcoreapp3.0;netcoreapp3.1;net40;net45;net472 + net46;net472;netcoreapp3.0;netcoreapp3.1 Library true diff --git a/source/SharpGL/Core/SharpGL.WinForms/VertexControl.cs b/source/SharpGL/Core/SharpGL.WinForms/VertexControl.cs index bb6591c4..e644c942 100644 --- a/source/SharpGL/Core/SharpGL.WinForms/VertexControl.cs +++ b/source/SharpGL/Core/SharpGL.WinForms/VertexControl.cs @@ -111,7 +111,7 @@ private void InitializeComponent() private System.Windows.Forms.TextBox textBoxY; private System.Windows.Forms.TextBox textBoxZ; - protected Vertex vertex; + protected System.Numerics.Vector3 vertex; protected void DoVertexChanged() { @@ -168,8 +168,8 @@ private void textBoxZ_TextChanged(object sender, System.EventArgs e) DoVertexChanged(); } - [Description("This is the vertex associated with the control."), Category("Vertex Control")] - public Vertex Vertex + [Description("This is the vertex associated with the control."), Category("System.Numerics.Vector3 Control")] + public System.Numerics.Vector3 Vertex { get {return vertex;} set diff --git a/source/SharpGL/Core/SharpGL/OpenGL.cs b/source/SharpGL/Core/SharpGL/OpenGL.cs index b8cb13e6..511b4ebf 100644 --- a/source/SharpGL/Core/SharpGL/OpenGL.cs +++ b/source/SharpGL/Core/SharpGL/OpenGL.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Numerics; using System.ComponentModel; using System.Runtime.InteropServices; using SharpGL.RenderContextProviders; @@ -6292,6 +6293,10 @@ public double[] UnProject(double winx, double winy, double winz) return result; } + public void Vertex(System.Numerics.Vector2 vector) => Vertex(vector.X, vector.Y); + public void Vertex(System.Numerics.Vector3 vector) => Vertex(vector.X, vector.Y, vector.Z); + public void Vertex(System.Numerics.Vector4 vector) => Vertex(vector.X, vector.Y, vector.Z, vector.W); + /// /// Set the current vertex (must be called between 'Begin' and 'End'). /// @@ -6308,7 +6313,7 @@ public void Vertex(double x, double y) /// Set the current vertex (must be called between 'Begin' and 'End'). /// /// Specifies the coordinate. - public void Vertex(double[] v) + public void Vertex(params double[] v) { PreGLCall(); if (v.Length == 2) @@ -6348,7 +6353,7 @@ public void Vertex(int x, int y) /// Set the current vertex (must be called between 'Begin' and 'End'). /// /// Specifies the coordinate. - public void Vertex(int[] v) + public void Vertex(params int[] v) { PreGLCall(); if (v.Length == 2) @@ -6376,7 +6381,7 @@ public void Vertex(short x, short y) /// Set the current vertex (must be called between 'Begin' and 'End'). /// /// Specifies the coordinate. - public void Vertex2sv(short[] v) + public void Vertex2sv(params short[] v) { PreGLCall(); if (v.Length == 2) @@ -6418,7 +6423,7 @@ public void Vertex(float x, float y, float z) /// Sets the current vertex (must be called between 'Begin' and 'End'). /// /// An array of 2, 3 or 4 floats. - public void Vertex(float []v) + public void Vertex(params float []v) { PreGLCall(); if(v.Length == 2) diff --git a/source/SharpGL/Core/SharpGL/SharpGL.csproj b/source/SharpGL/Core/SharpGL/SharpGL.csproj index b54caa2e..20f29666 100644 --- a/source/SharpGL/Core/SharpGL/SharpGL.csproj +++ b/source/SharpGL/Core/SharpGL/SharpGL.csproj @@ -1,6 +1,6 @@  - netcoreapp2.0;netcoreapp3.0;netcoreapp3.1;net40;net45;net472 + net46;net472;netcoreapp2.0;netcoreapp3.0;netcoreapp3.1 Library SharpGL