From 01d64f79b7ffa9cabb1983f6685f95aee1e1d2dc Mon Sep 17 00:00:00 2001
From: Andy McFadden
Date: Tue, 10 Mar 2020 17:18:46 -0700
Subject: [PATCH] Relocate Matrix/Vector code to lib where plugins can use it
Also, tweak the perspective projection scaling to fill out the area
a bit more, and change the visualization editor to use the grid's
size when setting the path dimensions.
Also, note gimbal lock.
---
{CommonUtil => PluginCommon}/Matrix44.cs | 5 ++---
{CommonUtil => PluginCommon}/Vector3.cs | 3 +--
PluginCommon/VisWireframe.cs | 5 +++--
SourceGen/RuntimeData/Help/visualization.html | 5 ++++-
SourceGen/WireframeObject.cs | 6 +++++-
SourceGen/WpfGui/EditVisualization.xaml.cs | 2 +-
6 files changed, 16 insertions(+), 10 deletions(-)
rename {CommonUtil => PluginCommon}/Matrix44.cs (98%)
rename {CommonUtil => PluginCommon}/Vector3.cs (98%)
diff --git a/CommonUtil/Matrix44.cs b/PluginCommon/Matrix44.cs
similarity index 98%
rename from CommonUtil/Matrix44.cs
rename to PluginCommon/Matrix44.cs
index ec73371..9b83f43 100644
--- a/CommonUtil/Matrix44.cs
+++ b/PluginCommon/Matrix44.cs
@@ -17,7 +17,7 @@ using System;
using System.Collections.Generic;
using System.Text;
-namespace CommonUtil {
+namespace PluginCommon {
///
/// Simple 4x4 matrix.
///
@@ -26,7 +26,6 @@ namespace CommonUtil {
get { return mVal; }
private set { mVal = value; }
}
-
private double[,] mVal;
public Matrix44() {
@@ -67,7 +66,7 @@ namespace CommonUtil {
double sycx = sy * cx;
double sysx = sy * sx;
- bool useXyz = false;
+ bool useXyz = true;
if (useXyz) {
// R = Rz * Ry * Rx (from wikipedia)
Val[0, 0] = cz * cy;
diff --git a/CommonUtil/Vector3.cs b/PluginCommon/Vector3.cs
similarity index 98%
rename from CommonUtil/Vector3.cs
rename to PluginCommon/Vector3.cs
index cce04e6..c9116e3 100644
--- a/CommonUtil/Vector3.cs
+++ b/PluginCommon/Vector3.cs
@@ -15,7 +15,7 @@
*/
using System;
-namespace CommonUtil {
+namespace PluginCommon {
///
/// Simple 3-element column vector.
///
@@ -32,7 +32,6 @@ namespace CommonUtil {
get { return mZ; }
set { mZ = value; }
}
-
private double mX, mY, mZ;
public Vector3(double x, double y, double z) {
diff --git a/PluginCommon/VisWireframe.cs b/PluginCommon/VisWireframe.cs
index 558d340..9b072e4 100644
--- a/PluginCommon/VisWireframe.cs
+++ b/PluginCommon/VisWireframe.cs
@@ -172,8 +172,9 @@ namespace PluginCommon {
}
}
- // TODO(maybe): confirm that every face has a vertex. Not strictly necessary
- // since you can do orthographic-projection BFC without it... but who does that?
+ // TODO(maybe): confirm that every face (i.e. normal) has a vertex we can use for
+ // BFC calculation. Not strictly necessary since you can do orthographic-projection
+ // BFC without it... but who does that?
msg = string.Empty;
return true;
diff --git a/SourceGen/RuntimeData/Help/visualization.html b/SourceGen/RuntimeData/Help/visualization.html
index 61ea67b..cb5cd0d 100644
--- a/SourceGen/RuntimeData/Help/visualization.html
+++ b/SourceGen/RuntimeData/Help/visualization.html
@@ -111,7 +111,10 @@ render with a perspective projection and without culling.
axes. The viewer provides a conventional right-handed coordinate system,
with +X toward the right, +Y toward the top of the screen, and +Z
coming out of the screen. Positive rotations cause a counter-clockwise
-rotation when looking down the axis in the positive direction.
+rotation when looking down the axis in the positive direction. The
+rotations are performed with a matrix using Euler angles, and are
+subject to gimbal lock (e.g. if you set Y to 90 degrees, X and Z rotate
+about the same axis).
If you check the "Animated" box, you can add a simple spin. Choose
the number of degrees to rotate per frame, how many frames to generate before
resetting, and the delay between each frame. Clicking the "Auto" button
diff --git a/SourceGen/WireframeObject.cs b/SourceGen/WireframeObject.cs
index e80c339..61c7c42 100644
--- a/SourceGen/WireframeObject.cs
+++ b/SourceGen/WireframeObject.cs
@@ -52,6 +52,10 @@ namespace SourceGen {
Vec = new Vector3(x, y, z);
Faces = new List();
}
+
+ public override string ToString() {
+ return Vec.ToString() + " + " + Faces.Count + " faces";
+ }
}
private class Edge {
@@ -226,7 +230,7 @@ namespace SourceGen {
double scale = 1.0 / mBigMag;
if (doPersp) {
// objects closer to camera are bigger; reduce scale slightly
- scale = (scale * zadj) / (zadj + 0.5);
+ scale = (scale * zadj) / (zadj + 0.3);
}
Matrix44 rotMat = new Matrix44();
diff --git a/SourceGen/WpfGui/EditVisualization.xaml.cs b/SourceGen/WpfGui/EditVisualization.xaml.cs
index 5a1e9b4..e213f26 100644
--- a/SourceGen/WpfGui/EditVisualization.xaml.cs
+++ b/SourceGen/WpfGui/EditVisualization.xaml.cs
@@ -605,7 +605,7 @@ namespace SourceGen.WpfGui {
previewGrid.Background = Brushes.Black;
previewImage.Source = Visualization.BLANK_IMAGE;
double dim = Math.Floor(
- Math.Min(previewImage.ActualWidth, previewImage.ActualHeight));
+ Math.Min(previewGrid.ActualWidth, previewGrid.ActualHeight));
WireframeObject wireObj = WireframeObject.Create(visWire);
wireframePath.Data = Visualization.GenerateWireframePath(wireObj, dim, parms);
BitmapDimensions = "n/a";