Skip to content

Commit 0b2c418

Browse files
author
Safarte
committed
Tangent Velocity indicator
1 parent d572636 commit 0b2c418

11 files changed

Lines changed: 158 additions & 33 deletions

File tree

.github/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Inspired by the great [Docking Port Alignment Indicator](https://spacedock.info/
2020
## Planned features
2121

2222
- [x] Basic docking informations: tangent offset, misalignment, basic metrics
23-
- [ ] Relative rotation indicator
24-
- [ ] Relative velocity indicator
23+
- [x] Relative rotation indicator
24+
- [x] Relative velocity indicator
2525
- [ ] Setting to toggle between linear and log scale for the offset indicator
2626
- [ ] Docking Mode indicator
2727
- [ ] Simple selector for nearby docking ports to target
@@ -52,6 +52,12 @@ The small arrow indicates the relative roll between your craft and the target do
5252

5353
When the arrow is at the top of the display, you are aligned in roll with the target docking port.
5454

55+
### Tangent velocity
56+
57+
![tvel_explanation](./assets/tvel_explanation.png)
58+
59+
The small green arrow indicates the current tangent velocity vector between your vessel and the target docking port as indicated on the picture.
60+
5561
### Metrics
5662

5763
- **CDST (Course Distance)**: Distance from the vessel to the target docking port in the axis parallel to the target port.
700 KB
Loading

DAD_UI/Assets/DockingAlignmentDisplay.uss

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.root {
22
min-width: 192px;
3-
min-height: 231px;
3+
min-height: 230px;
44
width: 15%;
55
height: 32%;
66
background-color: rgb(0, 0, 0);
@@ -12,6 +12,10 @@
1212
padding-right: 6px;
1313
padding-top: 6px;
1414
padding-bottom: 6px;
15+
flex-direction: row;
16+
flex-wrap: wrap;
17+
align-items: flex-start;
18+
justify-content: center;
1519
}
1620

1721
.title {
@@ -79,7 +83,7 @@
7983

8084
.screen {
8185
width: 100%;
82-
height: 83%;
86+
height: 83.4%;
8387
border-left-color: rgb(67, 70, 81);
8488
border-right-color: rgb(67, 70, 81);
8589
border-top-color: rgb(67, 70, 81);
@@ -98,10 +102,6 @@
98102
justify-content: center;
99103
}
100104

101-
.rel-info {
102-
flex-wrap: wrap;
103-
}
104-
105105
.rel-text {
106106
font-size: 12px;
107107
padding-top: 0;
@@ -255,3 +255,36 @@
255255
.tint-red {
256256
-unity-background-image-tint-color: rgb(209, 22, 13);
257257
}
258+
259+
.tvel-marker {
260+
position: absolute;
261+
width: 0;
262+
height: 0;
263+
align-items: center;
264+
justify-content: flex-end;
265+
}
266+
267+
.tvel-line {
268+
width: 1px;
269+
height: 60px;
270+
position: absolute;
271+
left: 50%;
272+
background-color: rgb(62, 152, 98);
273+
}
274+
275+
.tvel-arrow {
276+
background-image: url('/Assets/Images/rotation_marker.png');
277+
width: 10px;
278+
height: 10px;
279+
-unity-background-image-tint-color: rgb(61, 152, 98);
280+
position: absolute;
281+
}
282+
283+
.rel-info {
284+
align-items: auto;
285+
flex-wrap: wrap;
286+
flex-direction: row;
287+
justify-content: flex-start;
288+
width: 100%;
289+
margin-top: 1%;
290+
}

DAD_UI/Assets/DockingAlignmentDisplay.uxml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
22
<Style src="DockingAlignmentDisplay.uss" />
3-
<ui:VisualElement name="root" class="root" style="flex-direction: row; align-items: flex-start; justify-content: center; flex-wrap: wrap;">
3+
<ui:VisualElement name="root" class="root">
44
<ui:Label text="DOCKING-ALIGNMENT" display-tooltip-when-elided="true" name="title" class="title" />
55
<ui:Button display-tooltip-when-elided="true" text="×" name="close-button" enable-rich-text="true" class="close-button" />
66
<ui:VisualElement name="screen" class="screen" style="flex-wrap: wrap; overflow: hidden;">
@@ -21,6 +21,10 @@
2121
<ui:VisualElement name="rotation-marker" class="rotation-marker">
2222
<ui:VisualElement name="rotation-marker-sprite" class="rotation-marker-sprite" />
2323
</ui:VisualElement>
24+
<ui:VisualElement name="tvel-marker" class="tvel-marker">
25+
<ui:VisualElement name="tvel-line" class="tvel-line" />
26+
<ui:VisualElement name="tvel-arrow" class="tvel-arrow" />
27+
</ui:VisualElement>
2428
<ui:VisualElement name="tangent-hori" class="cross-hori" style="position: absolute;" />
2529
<ui:VisualElement name="tangent-vert" class="cross-vert" />
2630
<ui:VisualElement name="angle-cross" class="angle-cross">
@@ -31,7 +35,7 @@
3135
<ui:Label text="NO VALID TARGET" display-tooltip-when-elided="true" name="no-target-text" class="no-target-text" />
3236
</ui:VisualElement>
3337
</ui:VisualElement>
34-
<ui:VisualElement name="rel-info" style="align-items: auto; flex-wrap: wrap; flex-direction: row; justify-content: flex-start; width: 100%;">
38+
<ui:VisualElement name="rel-info" class="rel-info">
3539
<ui:Label text="CDST: 999.9 km" display-tooltip-when-elided="true" name="cdst" class="rel-text" />
3640
<ui:Label text="CVEL: 999.9 cm/s" display-tooltip-when-elided="true" name="cvel" class="rel-text" />
3741
<ui:Label text="TOFS: 999.9 km" display-tooltip-when-elided="true" name="tofs" class="rel-text" />
262 Bytes
Binary file not shown.

docking_alignment_display/swinfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "Docking Alignement Display",
66
"description": "Adds a new instrument providing necessary information to dock with precision.",
77
"source": "https://github.com/Safarte/DockingAlignmentDisplay",
8-
"version": "0.2.0",
8+
"version": "0.3.0",
99
"version_check": "https://raw.githubusercontent.com/Safarte/DockingAlignmentDisplay/main/docking_alignment_display/swinfo.json",
1010
"ksp2_version": {
1111
"min": "0.1.3",

images/screenshot_tvel.png

705 KB
Loading

images/tvel_explanation.kra

1.81 MB
Binary file not shown.

images/tvel_explanation.png

700 KB
Loading

src/DockingAlignmentDisplay/DadUiController.cs

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ internal class DadUiController : KerbalMonoBehaviour
4343
Label TofsLabel;
4444
// Tangent Velocity
4545
Label TvelLabel;
46+
// Flight Controls Mode
47+
//Label CtrlLabel;
4648

4749
// Main display
4850
VisualElement Screen;
@@ -61,6 +63,11 @@ internal class DadUiController : KerbalMonoBehaviour
6163
VisualElement RotationMarker;
6264
VisualElement RotationMarkerSprite;
6365

66+
// Tangent velocity marker
67+
VisualElement TvelMarker;
68+
VisualElement TvelLine;
69+
VisualElement TvelArrow;
70+
6471
// No Target error screen
6572
VisualElement NoTargetScreen;
6673

@@ -77,6 +84,12 @@ private void Update()
7784
return;
7885
}
7986

87+
// Close UI if not controlling a vessel
88+
if (Game?.ViewController?.GetActiveSimVessel(true) is null)
89+
{
90+
DockingAlignmentDisplayPlugin.Instance.ToggleButton(false);
91+
}
92+
8093
// Update GUI display status
8194
if (GUIEnabled && DockingAlignmentDisplayPlugin.InterfaceEnabled)
8295
s_container.style.display = DisplayStyle.Flex;
@@ -91,7 +104,14 @@ private void Update()
91104
_screen_height = Screen.resolvedStyle.height;
92105

93106
// Update target data
94-
target.Update(Game);
107+
target.Update();
108+
109+
// Update flight controls mode indicator
110+
//if (Game?.ViewController?.GetActiveSimVessel(true) != null)
111+
//{
112+
// Vehicle.ActiveVesselVehicle.OnFlightControlsModeChange -= OnFlightControlsModeChanged;
113+
// Vehicle.ActiveVesselVehicle.OnFlightControlsModeChange += OnFlightControlsModeChanged;
114+
//}
95115

96116
if (target.IsValid)
97117
{
@@ -102,6 +122,7 @@ private void Update()
102122
UpdateMetrics(target.RelativePosition, target.RelativeVelocity, true);
103123
UpdateAngleCrosshair(target.RelativeOrientation, true);
104124
UpdateRollIndicator(target.RelativeRoll, true);
125+
UpdateTvelIndicator(target.RelativeVelocity, true);
105126
}
106127
else
107128
{
@@ -112,6 +133,7 @@ private void Update()
112133
UpdateMetrics(Vector3.zero, Vector3.zero, false);
113134
UpdateAngleCrosshair(Vector3.zero, false);
114135
UpdateRollIndicator(0, false);
136+
UpdateTvelIndicator(Vector3.zero, false);
115137
}
116138
}
117139

@@ -163,6 +185,7 @@ private void InitElements()
163185
CvelLabel = s_container.Q<Label>("cvel");
164186
TofsLabel = s_container.Q<Label>("tofs");
165187
TvelLabel = s_container.Q<Label>("tvel");
188+
//CtrlLabel = s_container.Q<Label>("ctrl-mode");
166189

167190
// Main display
168191
Screen = s_container.Q<VisualElement>("screen");
@@ -183,13 +206,23 @@ private void InitElements()
183206
RotationMarker = s_container.Q<VisualElement>("rotation-marker");
184207
RotationMarkerSprite = s_container.Q<VisualElement>("rotation-marker-sprite");
185208

209+
// Tvel indicator
210+
TvelMarker = s_container.Q<VisualElement>("tvel-marker");
211+
TvelLine = s_container.Q<VisualElement>("tvel-line");
212+
TvelArrow = s_container.Q<VisualElement>("tvel-arrow");
213+
186214
// No Target error screen
187215
NoTargetScreen = s_container.Q<VisualElement>("no-target");
188216
NoTargetScreen.style.display = DisplayStyle.None;
189217

190218
_initialized = true;
191219
}
192220

221+
//private void OnFlightControlsModeChanged(FlightControlsMode mode)
222+
//{
223+
// CtrlLabel.text = "CTRL: " + (mode == FlightControlsMode.Docking ? "DOCKING" : "NORMAL");
224+
//}
225+
193226
/// <summary>
194227
/// Converts <c>value</c> to a 4-number string with 1 decimal point and correct unit prefix
195228
/// </summary>
@@ -281,6 +314,12 @@ private void UpdateAngleCrosshair(Vector3 relativeOrientation, bool validTarget)
281314
}
282315
}
283316

317+
/// <summary>
318+
/// Moves the rotation indicator arrow based on the relative rotation between the current vessel's docking port
319+
/// and the target docking port. The arrow is green is the angle is less that 5° and red otherwise.
320+
/// </summary>
321+
/// <param name="relativeRoll">Relative roll between the two docking ports</param>
322+
/// <param name="validTarget"></param>
284323
private void UpdateRollIndicator(float relativeRoll, bool validTarget)
285324
{
286325
if (validTarget)
@@ -309,6 +348,46 @@ private void UpdateRollIndicator(float relativeRoll, bool validTarget)
309348
}
310349
}
311350

351+
/// <summary>
352+
/// Moves the tangent velocity indicator arrow based on the relative velocity between the two crafts in the target's
353+
/// docking port parallel frame.
354+
/// </summary>
355+
/// <param name="relativeVel">Relative velocity in the target parallel frame</param>
356+
/// <param name="validTarget"></param>
357+
private void UpdateTvelIndicator(Vector3 relativeVel, bool validTarget)
358+
{
359+
if (validTarget)
360+
{
361+
// Display indicator
362+
TvelMarker.style.display = DisplayStyle.Flex;
363+
364+
// Tangent velocity vector
365+
Vector2 tVel = new Vector2(relativeVel.x, -relativeVel.y);
366+
367+
// Magnitude
368+
float mag = tVel.magnitude;
369+
370+
// Display indicator if magnitude > 10cm/s
371+
// TvelMarker.style.display = mag > 0.1f ? DisplayStyle.Flex : DisplayStyle.None;
372+
373+
// Angle from vertical
374+
Vector2 upVec = new Vector2(0, 1);
375+
float angle = Vector2.SignedAngle(upVec, tVel);
376+
377+
// Rotate indicator
378+
TvelMarker.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
379+
380+
// Arrow length
381+
float screenMag = (Mathf.Log10(Mathf.Clamp(mag, 0.1f, 990f)) + 1) / 8 * (_screen_height / 2);
382+
TvelLine.style.height = screenMag;
383+
TvelArrow.style.bottom = screenMag - 5;
384+
}
385+
else
386+
{
387+
TvelMarker.style.display = DisplayStyle.None;
388+
}
389+
}
390+
312391
/// <summary>
313392
/// Updates the numerical metrics that represent: course distance, course velocity, tangent offset and tangent velocity.
314393
/// </summary>

0 commit comments

Comments
 (0)