Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Vertex class with Vector3 class #202

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions source/SharpGL/.idea/.idea.SharpGL/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions source/SharpGL/Core/SharpGL.SceneGraph.Tests/VertexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions source/SharpGL/Core/SharpGL.SceneGraph/Cameras/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public virtual void Project(OpenGL gl)
/// <summary>
/// The camera position.
/// </summary>
private Vertex position = new Vertex(0, 0, 0);
private System.Numerics.Vector3 position = new System.Numerics.Vector3(0, 0, 0);

/// <summary>
/// Every time a camera is used to project, the projection matrix calculated
Expand All @@ -78,7 +78,7 @@ public virtual void Project(OpenGL gl)
/// The position.
/// </value>
[Description("The position of the camera"), Category("Camera")]
public Vertex Position
public System.Numerics.Vector3 Position
{
get { return position; }
set { position = value; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public override void TransformProjectionMatrix(OpenGL gl)
/// <summary>
/// This is the point in the scene that the camera is pointed at.
/// </summary>
protected Vertex target = new Vertex(0, 0, 0);
protected System.Numerics.Vector3 target = new System.Numerics.Vector3(0, 0, 0);

/// <summary>
/// This is a vector that describes the 'up' direction (normally 0, 0, 1).
/// Use this to tilt the camera.
/// </summary>
protected Vertex upVector = new Vertex(0, 0, 1);
protected System.Numerics.Vector3 upVector = new System.Numerics.Vector3(0, 0, 1);

/// <summary>
/// Gets or sets the target.
Expand All @@ -50,7 +50,7 @@ public override void TransformProjectionMatrix(OpenGL gl)
/// The target.
/// </value>
[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;}
Expand All @@ -63,7 +63,7 @@ public Vertex Target
/// Up vector.
/// </value>
[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;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion source/SharpGL/Core/SharpGL.SceneGraph/Collections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class VertexSearch
/// <param name="vertex">The target of the search.</param>
/// <param name="accuracy">The threshhold of the distance from each dimension of the vertex for the search.</param>
/// <returns></returns>
public static int Search(List<Vertex> vertices, int start, Vertex vertex, float accuracy)
public static int Search(List<System.Numerics.Vector3> vertices, int start, System.Numerics.Vector3 vertex, float accuracy)
{
// Go through the verticies.
for (int i = start; i < vertices.Count; i++)
Expand Down
12 changes: 6 additions & 6 deletions source/SharpGL/Core/SharpGL.SceneGraph/Core/ArcBall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
34 changes: 17 additions & 17 deletions source/SharpGL/Core/SharpGL.SceneGraph/Core/BoundingVolume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public BoundingVolume()
/// Creates the volume from vertices.
/// </summary>
/// <param name="vertices">The vertices.</param>
public void FromVertices(IEnumerable<Vertex> vertices)
public void FromVertices(IEnumerable<System.Numerics.Vector3> vertices)
{
var vertexList = vertices.ToList();
if (vertexList.Count < 2)
Expand Down Expand Up @@ -77,7 +77,7 @@ public void FromVertices(IEnumerable<Vertex> vertices)
/// </summary>
/// <param name="centre">The centre.</param>
/// <param name="radius">The radius.</param>
public void FromSphericalVolume(Vertex centre, float radius)
public void FromSphericalVolume(System.Numerics.Vector3 centre, float radius)
{
// Set the centre.
lll = centre;
Expand All @@ -100,18 +100,18 @@ public void FromSphericalVolume(Vertex centre, float radius)
/// <param name="height">The height.</param>
/// <param name="baseRadius">The base radius.</param>
/// <param name="topRadius">The top radius.</param>
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);
}
Expand Down Expand Up @@ -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;
}
}
Loading