mirror of
https://github.com/fadden/6502bench.git
synced 2025-01-28 08:32:42 +00:00
Tweak Vector3 and VisWireframe
Made vectors immutable. Added calls to support rewriting of surface normals.
This commit is contained in:
parent
01d64f79b7
commit
31d2462628
@ -17,20 +17,20 @@ using System;
|
|||||||
|
|
||||||
namespace PluginCommon {
|
namespace PluginCommon {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Simple 3-element column vector.
|
/// Simple 3-element column vector. Immutable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Vector3 {
|
public class Vector3 {
|
||||||
public double X {
|
public double X {
|
||||||
get { return mX; }
|
get { return mX; }
|
||||||
set { mX = value; }
|
private set { mX = value; }
|
||||||
}
|
}
|
||||||
public double Y {
|
public double Y {
|
||||||
get { return mY; }
|
get { return mY; }
|
||||||
set { mY = value; }
|
private set { mY = value; }
|
||||||
}
|
}
|
||||||
public double Z {
|
public double Z {
|
||||||
get { return mZ; }
|
get { return mZ; }
|
||||||
set { mZ = value; }
|
private set { mZ = value; }
|
||||||
}
|
}
|
||||||
private double mX, mY, mZ;
|
private double mX, mY, mZ;
|
||||||
|
|
||||||
@ -44,17 +44,32 @@ namespace PluginCommon {
|
|||||||
return Math.Sqrt(X * X + Y * Y + Z * Z);
|
return Math.Sqrt(X * X + Y * Y + Z * Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Normalize() {
|
public Vector3 Normalize() {
|
||||||
double len_r = 1.0 / Magnitude();
|
double len_r = 1.0 / Magnitude();
|
||||||
mX *= len_r;
|
return new Vector3(mX * len_r, mY * len_r, mZ * len_r);
|
||||||
mY *= len_r;
|
|
||||||
mZ *= len_r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Multiply(double sc) {
|
public Vector3 Multiply(double sc) {
|
||||||
mX *= sc;
|
return new Vector3(mX * sc, mY * sc, mZ * 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) {
|
public static double Dot(Vector3 v0, Vector3 v1) {
|
||||||
|
@ -96,6 +96,19 @@ namespace PluginCommon {
|
|||||||
return mNormalsX.Count - 1;
|
return mNormalsX.Count - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Replaces the specified face normal.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index">Face index.</param>
|
||||||
|
/// <param name="x">X coordinate.</param>
|
||||||
|
/// <param name="y">Y coordinate.</param>
|
||||||
|
/// <param name="z">Z coordinate.</param>
|
||||||
|
public void ReplaceFaceNormal(int index, float x, float y, float z) {
|
||||||
|
mNormalsX[index] = x;
|
||||||
|
mNormalsY[index] = y;
|
||||||
|
mNormalsZ[index] = z;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Marks a vertex's visibility as being tied to the specified face. The vertices and
|
/// Marks a vertex's visibility as being tied to the specified face. The vertices and
|
||||||
/// faces being referenced do not need to exist yet.
|
/// faces being referenced do not need to exist yet.
|
||||||
|
@ -281,7 +281,7 @@ namespace SourceGen {
|
|||||||
// Render Path to bitmap -- https://stackoverflow.com/a/23582564/294248
|
// Render Path to bitmap -- https://stackoverflow.com/a/23582564/294248
|
||||||
Rect bounds = geo.GetRenderBounds(null);
|
Rect bounds = geo.GetRenderBounds(null);
|
||||||
|
|
||||||
Debug.WriteLine("RenderWF dim=" + dim + " bounds=" + bounds + ": " + wireObj);
|
//Debug.WriteLine("RenderWF dim=" + dim + " bounds=" + bounds + ": " + wireObj);
|
||||||
|
|
||||||
// Create bitmap.
|
// Create bitmap.
|
||||||
RenderTargetBitmap bitmap = new RenderTargetBitmap(
|
RenderTargetBitmap bitmap = new RenderTargetBitmap(
|
||||||
|
@ -252,8 +252,8 @@ namespace SourceGen {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Vector3 camVec = rotMat.Multiply(face.Vert.Vec);
|
Vector3 camVec = rotMat.Multiply(face.Vert.Vec);
|
||||||
camVec.Multiply(-scale); // scale to [-1,1] and negate to get -C
|
camVec = camVec.Multiply(-scale); // scale to [-1,1] and negate to get -C
|
||||||
camVec.Z += zadj; // translate
|
camVec = camVec.Add(new Vector3(0, 0, zadj)); // translate
|
||||||
|
|
||||||
// Now compute the dot product of the camera vector.
|
// Now compute the dot product of the camera vector.
|
||||||
double dot = Vector3.Dot(camVec, rotNorm);
|
double dot = Vector3.Dot(camVec, rotNorm);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user