/// <summary> /// This takes the click point, and returns a point from 0 to 1 /// </summary> private static Point3D GetScaledPoint(MouseEventArgs e, FrameworkElement relativeTo, double depth, ViewDirection direction) { Point clickPoint = e.GetPosition(relativeTo); double width = relativeTo.ActualWidth; double height = relativeTo.ActualHeight; if (Math1D.IsNearZero(width) || Math1D.IsNearZero(height)) { // The window has no size return(new Point3D(0, 0, 0)); } Point3D point = new Point3D(clickPoint.X / width, clickPoint.Y / height, depth); switch (direction) { case ViewDirection.Front: return(new Point3D(point.X, point.Y, point.Z)); case ViewDirection.Right: return(new Point3D(1d - point.Z, point.Y, point.X)); case ViewDirection.Left: return(new Point3D(point.Z, point.Y, 1d - point.X)); case ViewDirection.Top: return(new Point3D(point.X, point.Z, 1d - point.Y)); case ViewDirection.Bottom: return(new Point3D(point.X, 1d - point.Z, point.Y)); case ViewDirection.Back: return(new Point3D(1d - point.X, point.Y, 1d - point.Z)); default: throw new ApplicationException("Unknown ViewDirection: " + direction.ToString()); } }
private void SetVelocityViewerCameraPosition() { if (_velocityVisualizerWindow == null) { return; } switch (_viewDirection) { case ViewDirection.Front: _velocityVisualizerWindow.ViewChanged(new DoubleVector(0, 0, 1, 0, -1, 0)); break; case ViewDirection.Right: _velocityVisualizerWindow.ViewChanged(new DoubleVector(-1, 0, 0, 0, -1, 0)); break; case ViewDirection.Left: _velocityVisualizerWindow.ViewChanged(new DoubleVector(1, 0, 0, 0, -1, 0)); break; case ViewDirection.Top: _velocityVisualizerWindow.ViewChanged(new DoubleVector(0, 1, 0, 0, 0, 1)); break; case ViewDirection.Bottom: _velocityVisualizerWindow.ViewChanged(new DoubleVector(0, -1, 0, 0, 0, -1)); break; case ViewDirection.Back: _velocityVisualizerWindow.ViewChanged(new DoubleVector(0, 0, -1, 0, -1, 0)); break; default: throw new ApplicationException("Unknown ViewDirection: " + _viewDirection.ToString()); } }
private static void DrawField(WriteableBitmap bitmap, FluidField3D field, ViewDirection viewDirection, byte[] colorZFront, byte[] colorZBack) { Int32Rect rect = new Int32Rect(0, 0, field.Size, field.Size); int size = rect.Width * rect.Height * 4; byte[] pixels = new byte[size]; double[] ink = field.Ink; bool[] blocked = field.Blocked; switch (viewDirection) { case ViewDirection.Front: #region Front DrawFieldSprtDoIt(pixels, ink, blocked, field.Size, colorZFront, colorZBack, new AxisFor(Axis.X, 0, field.Size - 1), new AxisFor(Axis.Y, 0, field.Size - 1), new AxisFor(Axis.Z, field.Size - 1, 0)); // pixel z needs to start at the back, because the colors are overlaid #endregion break; case ViewDirection.Right: #region Right DrawFieldSprtDoIt(pixels, ink, blocked, field.Size, colorZFront, colorZBack, new AxisFor(Axis.Z, 0, field.Size - 1), new AxisFor(Axis.Y, 0, field.Size - 1), new AxisFor(Axis.X, 0, field.Size - 1)); #endregion break; case ViewDirection.Left: #region Left DrawFieldSprtDoIt(pixels, ink, blocked, field.Size, colorZFront, colorZBack, new AxisFor(Axis.Z, field.Size - 1, 0), new AxisFor(Axis.Y, 0, field.Size - 1), new AxisFor(Axis.X, field.Size - 1, 0)); #endregion break; case ViewDirection.Top: #region Top DrawFieldSprtDoIt(pixels, ink, blocked, field.Size, colorZFront, colorZBack, new AxisFor(Axis.X, 0, field.Size - 1), new AxisFor(Axis.Z, field.Size - 1, 0), new AxisFor(Axis.Y, field.Size - 1, 0)); #endregion break; case ViewDirection.Bottom: #region Bottom DrawFieldSprtDoIt(pixels, ink, blocked, field.Size, colorZFront, colorZBack, new AxisFor(Axis.X, 0, field.Size - 1), new AxisFor(Axis.Z, 0, field.Size - 1), new AxisFor(Axis.Y, 0, field.Size - 1)); #endregion break; case ViewDirection.Back: #region Back //NOTE: This one is up for interpretation. I will rotate left to right, because I think that is more intuitive. If rotating //top to bottom, it would be upside down from the way I am presenting DrawFieldSprtDoIt(pixels, ink, blocked, field.Size, colorZFront, colorZBack, new AxisFor(Axis.X, field.Size - 1, 0), new AxisFor(Axis.Y, 0, field.Size - 1), new AxisFor(Axis.Z, 0, field.Size - 1)); // The alternate //DrawField_DoIt(pixels, ink, blocked, field.Size, colorZFront, colorZBack, // new AxisFor(Axis.X, 0, field.Size - 1), // new AxisFor(Axis.Y, field.Size - 1, 0), // new AxisFor(Axis.Z, 0, field.Size - 1)); #endregion break; default: throw new ApplicationException("Unknown ViewDirection: " + viewDirection.ToString()); } bitmap.WritePixels(rect, pixels, rect.Width * 4, 0); }
/// <summary> /// This takes the click point, and returns a point from 0 to 1 /// </summary> private static Point3D GetScaledPoint(MouseEventArgs e, FrameworkElement relativeTo, double depth, ViewDirection direction) { Point clickPoint = e.GetPosition(relativeTo); double width = relativeTo.ActualWidth; double height = relativeTo.ActualHeight; if (Math1D.IsNearZero(width) || Math1D.IsNearZero(height)) { // The window has no size return new Point3D(0, 0, 0); } Point3D point = new Point3D(clickPoint.X / width, clickPoint.Y / height, depth); switch (direction) { case ViewDirection.Front: return new Point3D(point.X, point.Y, point.Z); case ViewDirection.Right: return new Point3D(1d - point.Z, point.Y, point.X); case ViewDirection.Left: return new Point3D(point.Z, point.Y, 1d - point.X); case ViewDirection.Top: return new Point3D(point.X, point.Z, 1d - point.Y); case ViewDirection.Bottom: return new Point3D(point.X, 1d - point.Z, point.Y); case ViewDirection.Back: return new Point3D(1d - point.X, point.Y, 1d - point.Z); default: throw new ApplicationException("Unknown ViewDirection: " + direction.ToString()); } }
private static void DrawField(WriteableBitmap bitmap, FluidField3D field, ViewDirection viewDirection, byte[] colorZFront, byte[] colorZBack) { Int32Rect rect = new Int32Rect(0, 0, field.Size, field.Size); int size = rect.Width * rect.Height * 4; byte[] pixels = new byte[size]; double[] ink = field.Ink; bool[] blocked = field.Blocked; switch (viewDirection) { case ViewDirection.Front: #region Front DrawFieldSprtDoIt(pixels, ink, blocked, field.Size, colorZFront, colorZBack, new AxisFor(Axis.X, 0, field.Size - 1), new AxisFor(Axis.Y, 0, field.Size - 1), new AxisFor(Axis.Z, field.Size - 1, 0)); // pixel z needs to start at the back, because the colors are overlaid #endregion break; case ViewDirection.Right: #region Right DrawFieldSprtDoIt(pixels, ink, blocked, field.Size, colorZFront, colorZBack, new AxisFor(Axis.Z, 0, field.Size - 1), new AxisFor(Axis.Y, 0, field.Size - 1), new AxisFor(Axis.X, 0, field.Size - 1)); #endregion break; case ViewDirection.Left: #region Left DrawFieldSprtDoIt(pixels, ink, blocked, field.Size, colorZFront, colorZBack, new AxisFor(Axis.Z, field.Size - 1, 0), new AxisFor(Axis.Y, 0, field.Size - 1), new AxisFor(Axis.X, field.Size - 1, 0)); #endregion break; case ViewDirection.Top: #region Top DrawFieldSprtDoIt(pixels, ink, blocked, field.Size, colorZFront, colorZBack, new AxisFor(Axis.X, 0, field.Size - 1), new AxisFor(Axis.Z, field.Size - 1, 0), new AxisFor(Axis.Y, field.Size - 1, 0)); #endregion break; case ViewDirection.Bottom: #region Bottom DrawFieldSprtDoIt(pixels, ink, blocked, field.Size, colorZFront, colorZBack, new AxisFor(Axis.X, 0, field.Size - 1), new AxisFor(Axis.Z, 0, field.Size - 1), new AxisFor(Axis.Y, 0, field.Size - 1)); #endregion break; case ViewDirection.Back: #region Back //NOTE: This one is up for interpretation. I will rotate left to right, because I think that is more intuitive. If rotating //top to bottom, it would be upside down from the way I am presenting DrawFieldSprtDoIt(pixels, ink, blocked, field.Size, colorZFront, colorZBack, new AxisFor(Axis.X, field.Size - 1, 0), new AxisFor(Axis.Y, 0, field.Size - 1), new AxisFor(Axis.Z, 0, field.Size - 1)); // The alternate //DrawField_DoIt(pixels, ink, blocked, field.Size, colorZFront, colorZBack, // new AxisFor(Axis.X, 0, field.Size - 1), // new AxisFor(Axis.Y, field.Size - 1, 0), // new AxisFor(Axis.Z, 0, field.Size - 1)); #endregion break; default: throw new ApplicationException("Unknown ViewDirection: " + viewDirection.ToString()); } bitmap.WritePixels(rect, pixels, rect.Width * 4, 0); }