diff --git a/PluginCommon/Vector3.cs b/PluginCommon/Vector3.cs index c9116e3..708091b 100644 --- a/PluginCommon/Vector3.cs +++ b/PluginCommon/Vector3.cs @@ -17,20 +17,20 @@ using System; namespace PluginCommon { /// - /// Simple 3-element column vector. + /// Simple 3-element column vector. Immutable. /// public class Vector3 { public double X { get { return mX; } - set { mX = value; } + private set { mX = value; } } public double Y { get { return mY; } - set { mY = value; } + private set { mY = value; } } public double Z { get { return mZ; } - set { mZ = value; } + private set { mZ = value; } } private double mX, mY, mZ; @@ -44,17 +44,32 @@ namespace PluginCommon { return Math.Sqrt(X * X + Y * Y + Z * Z); } - public void Normalize() { + public Vector3 Normalize() { double len_r = 1.0 / Magnitude(); - mX *= len_r; - mY *= len_r; - mZ *= len_r; + return new Vector3(mX * len_r, mY * len_r, mZ * len_r); } - public void Multiply(double sc) { - mX *= sc; - mY *= sc; - mZ *= sc; + public Vector3 Multiply(double sc) { + return new Vector3(mX * sc, mY * sc, mZ * sc); + } + + public Vector3 Add(Vector3 vec) { + return new Vector3(mX + vec.X, mY + vec.Y, mZ + vec.Z); + } + + public static Vector3 Add(Vector3 v0, Vector3 v1) { + return new Vector3(v0.X + v1.X, v0.Y + v1.Y, v0.Z + v1.Z); + } + + public static Vector3 Subtract(Vector3 v0, Vector3 v1) { + return new Vector3(v0.X - v1.X, v0.Y - v1.Y, v0.Z - v1.Z); + } + + public static Vector3 Cross(Vector3 v0, Vector3 v1) { + return new Vector3( + v0.Y * v1.Z - v0.Z * v1.Y, + v0.Z * v1.X - v0.X * v1.Z, + v0.X * v1.Y - v0.Y * v1.X); } public static double Dot(Vector3 v0, Vector3 v1) { diff --git a/PluginCommon/VisWireframe.cs b/PluginCommon/VisWireframe.cs index 9b072e4..10ff9ee 100644 --- a/PluginCommon/VisWireframe.cs +++ b/PluginCommon/VisWireframe.cs @@ -96,6 +96,19 @@ namespace PluginCommon { return mNormalsX.Count - 1; } + /// + /// Replaces the specified face normal. + /// + /// Face index. + /// X coordinate. + /// Y coordinate. + /// Z coordinate. + public void ReplaceFaceNormal(int index, float x, float y, float z) { + mNormalsX[index] = x; + mNormalsY[index] = y; + mNormalsZ[index] = z; + } + /// /// Marks a vertex's visibility as being tied to the specified face. The vertices and /// faces being referenced do not need to exist yet. diff --git a/SourceGen/Visualization.cs b/SourceGen/Visualization.cs index 540e57f..79696c5 100644 --- a/SourceGen/Visualization.cs +++ b/SourceGen/Visualization.cs @@ -281,7 +281,7 @@ namespace SourceGen { // Render Path to bitmap -- https://stackoverflow.com/a/23582564/294248 Rect bounds = geo.GetRenderBounds(null); - Debug.WriteLine("RenderWF dim=" + dim + " bounds=" + bounds + ": " + wireObj); + //Debug.WriteLine("RenderWF dim=" + dim + " bounds=" + bounds + ": " + wireObj); // Create bitmap. RenderTargetBitmap bitmap = new RenderTargetBitmap( diff --git a/SourceGen/WireframeObject.cs b/SourceGen/WireframeObject.cs index 61c7c42..8082ef3 100644 --- a/SourceGen/WireframeObject.cs +++ b/SourceGen/WireframeObject.cs @@ -252,8 +252,8 @@ namespace SourceGen { continue; } Vector3 camVec = rotMat.Multiply(face.Vert.Vec); - camVec.Multiply(-scale); // scale to [-1,1] and negate to get -C - camVec.Z += zadj; // translate + camVec = camVec.Multiply(-scale); // scale to [-1,1] and negate to get -C + camVec = camVec.Add(new Vector3(0, 0, zadj)); // translate // Now compute the dot product of the camera vector. double dot = Vector3.Dot(camVec, rotNorm);