-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configurable north direction for NED and ENU conversions
Co-authored-by: LaurieCheers <[email protected]>
- Loading branch information
1 parent
8f443da
commit 56e9738
Showing
8 changed files
with
366 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
com.unity.robotics.ros-tcp-connector/Runtime/ROSGeometry/GeometryCompass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace Unity.Robotics.ROSTCPConnector.ROSGeometry | ||
{ | ||
public enum CardinalDirection | ||
{ | ||
North = 0, | ||
East = 1, | ||
South = 2, | ||
West = 3, | ||
} | ||
|
||
public class GeometryCompass : ScriptableObject | ||
{ | ||
public const string k_CompassSettingsAsset = "GeometryCompassSettings.asset"; | ||
|
||
[SerializeField] | ||
CardinalDirection m_ZAxisDirection; | ||
|
||
static GeometryCompass s_Instance; | ||
|
||
static GeometryCompass GetOrCreateSettings() | ||
{ | ||
if (s_Instance != null) | ||
return s_Instance; | ||
#if UNITY_EDITOR | ||
string assetPath = System.IO.Path.Combine("Assets/Resources", k_CompassSettingsAsset); | ||
s_Instance = UnityEditor.AssetDatabase.LoadAssetAtPath<GeometryCompass>(assetPath); | ||
if (s_Instance == null) | ||
{ | ||
s_Instance = ScriptableObject.CreateInstance<GeometryCompass>(); | ||
s_Instance.m_ZAxisDirection = CardinalDirection.North; | ||
if(!UnityEditor.AssetDatabase.IsValidFolder("Assets/Resources")) | ||
UnityEditor.AssetDatabase.CreateFolder("Assets", "Resources"); | ||
UnityEditor.AssetDatabase.CreateAsset(s_Instance, assetPath); | ||
UnityEditor.AssetDatabase.SaveAssets(); | ||
} | ||
#else | ||
s_Instance = Resources.Load<GeometryCompass>(k_CompassSettingsAsset); | ||
#endif | ||
return s_Instance; | ||
} | ||
|
||
public static CardinalDirection UnityZAxisDirection | ||
{ | ||
get | ||
{ | ||
GeometryCompass compass = GetOrCreateSettings(); | ||
return (compass == null) ? CardinalDirection.North : compass.m_ZAxisDirection; | ||
} | ||
|
||
#if UNITY_EDITOR | ||
set | ||
{ | ||
GeometryCompass compass = GetOrCreateSettings(); | ||
if (compass.m_ZAxisDirection != value) | ||
{ | ||
compass.m_ZAxisDirection = value; | ||
UnityEditor.EditorUtility.SetDirty(compass); | ||
UnityEditor.AssetDatabase.SaveAssets(); | ||
} | ||
} | ||
#endif | ||
} | ||
|
||
public static readonly Quaternion k_NinetyYaw = Quaternion.Euler(0, 90, 0); | ||
public static readonly Quaternion k_OneEightyYaw = Quaternion.Euler(0, 180, 0); | ||
public static readonly Quaternion k_NegativeNinetyYaw = Quaternion.Euler(0, -90, 0); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.robotics.ros-tcp-connector/Runtime/ROSGeometry/GeometryCompass.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.