/// <summary> /// Create an arrow representing the magnitude and direction /// for a given bin. This will create an arrow within a column. /// The Column will start at 0 and go down, using the bin times a scale /// factor to move down the column for each bin. The magnitude will /// give the length and color of the arrow. The angle will be used to rotate around /// the origin of 0,0, to give the direction. The angle is based off North = 0 degrees. /// </summary> /// <param name="bin">Bin to create.</param> /// <param name="mag">Magnitude of the bin.</param> /// <param name="angleYNorth">Direction of the bin with reference to Y as North.</param> /// <returns>3D model of the arrow.</returns> private GeometryModel3D CreateBin(int bin, double mag, double angleYNorth) { // Location on the axis for each bin // Set the Camera UpDirection in XMAL to UpDirection="0, 1, 0" to make it use Y axis as Up. Default is Z up. double xAxisLoc = 0; double yAxisLoc = 0; double zAxisLoc = 0; if (YAxis) { yAxisLoc = -bin * TRANSLATION_SCALE; } else { xAxisLoc = bin * TRANSLATION_SCALE; } // Create the shape of the object // This will be an arrow // Use the magnitude to get the length of the arrow // Create a column of bins with arrows var mb = new MeshBuilder(false, false); if (YAxis) { mb.AddArrow(new Point3D(xAxisLoc, yAxisLoc, zAxisLoc), new Point3D(mag * SCALE_ARROW, yAxisLoc, zAxisLoc), ARROW_HEAD_SIZE); } else { mb.AddArrow(new Point3D(xAxisLoc, yAxisLoc, zAxisLoc), new Point3D(xAxisLoc, mag * SCALE_ARROW, zAxisLoc), ARROW_HEAD_SIZE); } Geometry3D geometry = mb.ToMesh(); // Set the color based off the magnitude // If the bin is selected, use the selected color Material material; if (bin != SelectedBin) { material = MaterialHelper.CreateMaterial(GenerateColor(mag)); } else { material = MaterialHelper.CreateMaterial(SELECTED_BIN_COLOR); } material.Freeze(); // Rotate the object var rotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(xAxisLoc, yAxisLoc, zAxisLoc), angleYNorth)); rotation.Freeze(); // Create the model with the rotation var tg = new Transform3DGroup(); tg.Children.Add(rotation); var model = new GeometryModel3D(geometry, material) { Transform = tg }; return(model); }