private void RenderAllCooridnateSystemAxes(CoordinateSystemRenderSettings coordinateSystemRenderSettings) { List <CoordinateSystemAxis> coordinateSystemAxes = CoordinateSystemAxes.GetAll(); foreach (CoordinateSystemAxis axis in coordinateSystemAxes) { RenderCoordinateSystemAxis(axis, coordinateSystemRenderSettings); } }
private void RenderCoordinateSystemAxis(CoordinateSystemAxis axis, CoordinateSystemRenderSettings coordinateSystemRenderSettings) { if (coordinateSystemRenderSettings.IsAxisVisible(axis)) { GizmosColor.Push(coordinateSystemRenderSettings.GetAxisColor(axis)); Vector3 axisVector = CoordinateSystemAxes.GetGlobalVector(axis); Gizmos.DrawLine(Vector3.zero, axisVector * coordinateSystemRenderSettings.GetAxisSize(axis)); GizmosColor.Pop(); } }
public List <Vector3> GetAllAxesVectors() { List <CoordinateSystemAxis> allAxes = CoordinateSystemAxes.GetAll(); var allAxesVectors = new List <Vector3>(allAxes.Count); foreach (CoordinateSystemAxis axis in allAxes) { allAxesVectors.Add(GetAxisVector(axis)); } return(allAxesVectors); }
private static void SaveSnapLookAndFeel(XmlTextWriter xmlWriter, Octave3DConfigSaveLoadSettings saveSettings) { if (saveSettings.SnapLookAndFeel) { XZGridRenderSettings xzGridRenderSettings = ObjectSnapping.Get().XZSnapGrid.RenderSettings; XZGridRenderSettings objSurfaceGridRenderSettings = ObjectSnapping.Get().RenderSettingsForColliderSnapSurfaceGrid; CoordinateSystemRenderSettings coordSystemRenderSettings = ObjectSnapping.Get().XZSnapGrid.RenderableCoordinateSystem.RenderSettings; xmlWriter.WriteNewLine(1); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.SnapLookAndFeelNode); xmlWriter.WriteNewLine(2); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.XZGridLookAndFeelNode); xmlWriter.WriteNewLine(3); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.IsXZGridVisibleNode); xmlWriter.WriteString(xzGridRenderSettings.IsVisible.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(3); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.XZGridCellLineColorNode); xmlWriter.WriteColorString(xzGridRenderSettings.CellLineColor); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(3); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.XZGridCellLineThicknessNode); xmlWriter.WriteString(xzGridRenderSettings.CellLineThickness.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(3); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.XZGridPlaneColorNode); xmlWriter.WriteColorString(xzGridRenderSettings.PlaneColor); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(2); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(2); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.XZGridCoordSystemLookAndFeelNode); xmlWriter.WriteNewLine(3); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.IsXZGridCoordSystemVisibleNode); xmlWriter.WriteString(coordSystemRenderSettings.IsVisible.ToString()); xmlWriter.WriteEndElement(); List <CoordinateSystemAxis> allAxes = CoordinateSystemAxes.GetAll(); foreach (var axis in allAxes) { xmlWriter.WriteNewLine(3); xmlWriter.WriteStartElement(axis.ToString()); xmlWriter.WriteNewLine(4); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.IsXZGridCoordSystemAxisVisibleNode); xmlWriter.WriteString(coordSystemRenderSettings.IsAxisVisible(axis).ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(4); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.IsXZGridCoordSystemAxisInfiniteNode); xmlWriter.WriteString(coordSystemRenderSettings.IsAxisRenderedInfinite(axis).ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(4); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.XZGridCoordSystemAxisFiniteSizeNode); xmlWriter.WriteString(coordSystemRenderSettings.GetAxisFinitSize(axis).ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(4); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.XZGridCoordSystemAxisColorNode); xmlWriter.WriteColorString(coordSystemRenderSettings.GetAxisColor(axis)); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(3); xmlWriter.WriteEndElement(); } xmlWriter.WriteNewLine(2); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(2); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.ObjectSnapSurfaceGridLookAndFeelNode); xmlWriter.WriteNewLine(3); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.IsObjectSnapSurfaceGridVisibleNode); xmlWriter.WriteString(objSurfaceGridRenderSettings.IsVisible.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(3); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.ObjectSnapSurfaceGridCellLineColorNode); xmlWriter.WriteColorString(objSurfaceGridRenderSettings.CellLineColor); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(3); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.ObjectSnapSurfaceGridCellLineThicknessNode); xmlWriter.WriteString(objSurfaceGridRenderSettings.CellLineThickness.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(3); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.ObjectSnapSurfaceGridPlaneColorNode); xmlWriter.WriteColorString(objSurfaceGridRenderSettings.PlaneColor); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(2); xmlWriter.WriteEndElement(); xmlWriter.WriteNewLine(1); xmlWriter.WriteEndElement(); } }
public static Quaternion CalculateRotationQuaternionForAxisAlignment(Quaternion currentRotation, CoordinateSystemAxis alignmentAxis, Vector3 destinationAxis) { TransformMatrix rotationMatrix = TransformMatrix.GetIdentity(); rotationMatrix.Rotation = currentRotation; Vector3 axisToAlign = CoordinateSystemAxes.GetLocalVector(alignmentAxis, rotationMatrix); bool isAlignmentAxisNegative = CoordinateSystemAxes.IsNegativeAxis(alignmentAxis); // Already aligned? bool pointsInSameDirection; bool isAlignedWithDestinationAxis = destinationAxis.IsAlignedWith(axisToAlign, out pointsInSameDirection); if (isAlignedWithDestinationAxis && pointsInSameDirection) { return(currentRotation); } if (!isAlignedWithDestinationAxis) { Vector3 rotationAxis = Vector3.Cross(axisToAlign, destinationAxis); rotationAxis.Normalize(); return(Quaternion.AngleAxis(axisToAlign.AngleWith(destinationAxis), rotationAxis) * currentRotation); } else { // If this point is reached, it means the axis is aligned with the destination axis but points in the opposite // direction. In this case we can not use the cross product, so we will have to regenerate the axes. Vector3 newRightAxis, newUpAxis, newLookAxis; if (alignmentAxis == CoordinateSystemAxis.PositiveRight || alignmentAxis == CoordinateSystemAxis.NegativeRight) { newRightAxis = destinationAxis; if (isAlignmentAxisNegative) { newRightAxis *= -1.0f; } bool worldUpPointsSameDirAsRightAxis; if (newRightAxis.IsAlignedWith(Vector3.up, out worldUpPointsSameDirAsRightAxis)) { newLookAxis = worldUpPointsSameDirAsRightAxis ? Vector3.forward : Vector3.back; } else { newLookAxis = Vector3.Cross(newRightAxis, Vector3.up); } if (isAlignmentAxisNegative) { newLookAxis *= -1.0f; } newUpAxis = Vector3.Cross(newLookAxis, newRightAxis); } if (alignmentAxis == CoordinateSystemAxis.PositiveUp || alignmentAxis == CoordinateSystemAxis.NegativeUp) { newUpAxis = destinationAxis; if (isAlignmentAxisNegative) { newUpAxis *= -1.0f; } bool worldUpPointsSameDirAsUpAxis; if (newUpAxis.IsAlignedWith(Vector3.up, out worldUpPointsSameDirAsUpAxis)) { newLookAxis = worldUpPointsSameDirAsUpAxis ? Vector3.forward : Vector3.back; } else { newLookAxis = Vector3.Cross(newUpAxis, Vector3.up); } if (isAlignmentAxisNegative) { newLookAxis *= -1.0f; } } else { newLookAxis = destinationAxis; if (isAlignmentAxisNegative) { newLookAxis *= -1.0f; } bool worldUpPointsSameDirAsLookAxis; if (newLookAxis.IsAlignedWith(Vector3.up, out worldUpPointsSameDirAsLookAxis)) { newUpAxis = worldUpPointsSameDirAsLookAxis ? Vector3.forward : Vector3.back; } else { newUpAxis = Vector3.Cross(newLookAxis, Vector3.up); } if (isAlignmentAxisNegative) { newUpAxis *= -1.0f; } } // Normalize the axes which were calculated newUpAxis.Normalize(); newLookAxis.Normalize(); // Now use the axes to calculate the rotation quaternion return(Quaternion.LookRotation(newLookAxis, newUpAxis)); } }