private void SetupToTrackball() { Model3DGroup model = new Model3DGroup(); // Major arrow along x model.Children.Add(TrackballGrabber.GetMajorArrow(Axis.X, true, _colors.TrackballAxisMajor_To, _colors.TrackballAxisSpecular)); // Minor arrow along z model.Children.Add(TrackballGrabber.GetMinorArrow(Axis.Z, true, _colors.TrackballAxisMinor_To, _colors.TrackballAxisSpecular)); ModelVisual3D visual = new ModelVisual3D(); visual.Content = model; _viewportTo.Children.Add(visual); _orientationVisualsTo.Add(visual); // Create the trackball _orientationTrackballTo = new TrackballGrabber(grdTo, _viewportTo, 1d, _colors.TrackballGrabberHoverLight); _orientationTrackballTo.SyncedLights.Add(_cameraToLight); _orientationTrackballTo.RotationChanged += new EventHandler(OrientationTrackballTo_RotationChanged); // Faint lines _orientationTrackballTo.HoverVisuals.Add(TrackballGrabber.GetGuideLine(Axis.X, false, _colors.TrackballAxisLine_To)); _orientationTrackballTo.HoverVisuals.Add(TrackballGrabber.GetGuideLineDouble(Axis.Y, _colors.TrackballAxisLine_To)); _orientationTrackballTo.HoverVisuals.Add(TrackballGrabber.GetGuideLine(Axis.Z, false, _colors.TrackballAxisLine_To)); }
private static void EnsureSnapped45(TrackballGrabber trackball) { //TODO: I think this is invalid thinking. Instead?: // Use the quaternion to project a vector // Snap that projected vector to the nearest aligned vector // Get a new quaternion that describes how to rotate to that snapped vector //TODO: When the trackball's transform is set, the lights get screwed up Quaternion currentOrientation = trackball.Transform.ToQuaternion(); // Snap the axis to nearest 45 Vector3D snappedAxis = currentOrientation.Axis; // Snap the angle to nearest 45 double snappedAngle = GetSnappedAngle(currentOrientation.Angle, 45d); trackball.Transform = new RotateTransform3D(new AxisAngleRotation3D(snappedAxis, snappedAngle)); }