Skip to content

Commit b1878ca

Browse files
committed
Initial object moving
1 parent 680949b commit b1878ca

File tree

8 files changed

+269
-151
lines changed

8 files changed

+269
-151
lines changed

Source/Contrib/TrackViewer/Drawing/Labels/DrawLabels.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ private void CreateContextMenu()
156156

157157
SetLocationMenuItem = new MenuItem() { Header = "View scene here" };
158158
SetLocationMenuItem.Click += new RoutedEventHandler((sender, e) => TrackViewer.menuControl.MenuSceneWindow_Click(sender, e));
159-
SetLocationMenuItem.Click += new RoutedEventHandler(async (sender, e) => await TrackViewer.SceneViewer?.SetCameraLocation());
159+
SetLocationMenuItem.Click += new RoutedEventHandler(async (sender, e) => await TrackViewer.SceneViewer?.SetCameraLocation(
160+
SetLocationMenuItem.CommandParameter as WorldLocation? ?? new WorldLocation()));
160161
ContextMenu.Items.Add(SetLocationMenuItem);
161162
}
162163

Source/Contrib/TrackViewer/SceneViewer.cs

Lines changed: 161 additions & 76 deletions
Large diffs are not rendered by default.

Source/Contrib/TrackViewer/UserInterface/MenuControl.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,8 +1233,7 @@ public void MenuSceneWindow_Click(object sender, RoutedEventArgs e)
12331233
if (trackViewer.CurrentRoute == null)
12341234
return;
12351235
trackViewer.InitializeSceneViewer(null);
1236-
trackViewer.SceneViewer.SceneWindow.Show();
1237-
trackViewer.SceneViewer.SceneWindow.Activate();
1236+
trackViewer.SceneViewer.Show();
12381237
}
12391238
}
12401239

Source/Contrib/TrackViewer/UserInterface/SceneWindow.xaml

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
<ColumnDefinition Width="Auto" />
2323
<ColumnDefinition Width="58" />
2424
<ColumnDefinition Width="58" />
25+
<ColumnDefinition Width="58" />
2526
<ColumnDefinition Width="Auto" />
27+
<ColumnDefinition Width="85" />
2628
<ColumnDefinition Width="Auto" />
27-
<ColumnDefinition Width="42" />
28-
<ColumnDefinition Width="Auto" />
29+
<ColumnDefinition Width="58" />
30+
<ColumnDefinition Width="58" />
31+
<ColumnDefinition Width="58" />
2932
<ColumnDefinition Width="Auto" />
30-
<ColumnDefinition Width="80" />
31-
<ColumnDefinition Width="42" />
32-
<ColumnDefinition Width="60" />
3333
<ColumnDefinition Width="60" />
3434
<ColumnDefinition Width="Auto" />
3535
<ColumnDefinition Width="*"/>
@@ -68,46 +68,35 @@
6868
</StatusBarItem>
6969
<Separator Grid.Column="5"/>
7070
<StatusBarItem Grid.Column="6">
71-
<Border BorderThickness="1 1 0 0" BorderBrush="Gray">
72-
<Border BorderThickness="0 0 1 1" BorderBrush="AntiqueWhite">
73-
<TextBlock Name="statusTrIndex" Width="37" TextAlignment="Right"
74-
ToolTip="Index in the Track DataBase (.tdb) file"/>
75-
</Border>
76-
</Border>
71+
<TextBlock Name="tileXZcursor">
72+
<TextBlock.ToolTip>
73+
<TextBlock Text="Shows tileX and tileZ of the world location at the mouse pointer"/>
74+
</TextBlock.ToolTip>
75+
</TextBlock>
7776
</StatusBarItem>
78-
<Separator Grid.Column="7"/>
77+
<Separator Grid.Column="7" />
7978
<StatusBarItem Grid.Column="8">
80-
<TextBlock Text="Item"/>
79+
<TextBlock Name="LocationXcursor" Width="55" TextAlignment="Right">
80+
<TextBlock.ToolTip>
81+
<TextBlock Text="X-coordinate (without tileX) at the mouse pointer"/>
82+
</TextBlock.ToolTip>
83+
</TextBlock>
8184
</StatusBarItem>
8285
<StatusBarItem Grid.Column="9">
83-
<Border BorderThickness="1 1 0 0" BorderBrush="Gray">
84-
<Border BorderThickness="0 0 1 1" BorderBrush="AntiqueWhite">
85-
<TextBlock Name="statusTrItemType" Width="75"/>
86-
</Border>
87-
</Border>
86+
<TextBlock Name="LocationYcursor" Width="55" TextAlignment="Right">
87+
<TextBlock.ToolTip>
88+
<TextBlock Text="Y-coordinate at the mouse pointer"/>
89+
</TextBlock.ToolTip>
90+
</TextBlock>
8891
</StatusBarItem>
8992
<StatusBarItem Grid.Column="10">
90-
<Border BorderThickness="1 1 0 0" BorderBrush="Gray">
91-
<Border BorderThickness="0 0 1 1" BorderBrush="AntiqueWhite">
92-
<TextBlock Name="statusTrItemIndex" Width="37" TextAlignment="Right"
93-
ToolTip="Index in the Track DataBase (.tdb) file"/>
94-
</Border>
95-
</Border>
96-
</StatusBarItem>
97-
<StatusBarItem Grid.Column="11">
98-
<Border BorderThickness="1 1 0 0" BorderBrush="Gray">
99-
<Border BorderThickness="0 0 1 1" BorderBrush="AntiqueWhite">
100-
<TextBlock Name="statusTrItemLocationX" Width="55" TextAlignment="Right"/>
101-
</Border>
102-
</Border>
103-
</StatusBarItem>
104-
<StatusBarItem Grid.Column="12">
105-
<Border BorderThickness="1 1 0 0" BorderBrush="Gray">
106-
<Border BorderThickness="0 0 1 1" BorderBrush="AntiqueWhite">
107-
<TextBlock Name="statusTrItemLocationZ" Width="55" TextAlignment="Right"/>
108-
</Border>
109-
</Border>
93+
<TextBlock Name="LocationZcursor" Width="55" TextAlignment="Right">
94+
<TextBlock.ToolTip>
95+
<TextBlock Text="Z-coordinate (without tileZ) at the mouse pointer"/>
96+
</TextBlock.ToolTip>
97+
</TextBlock>
11098
</StatusBarItem>
99+
<Separator Grid.Column="11"/>
111100
<Separator Grid.Column="13"/>
112101
<StatusBarItem Grid.Column="14">
113102
<TextBlock Name="statusAdditional" ToolTip="Any other relevant information. Make your choice via Statusbar menu"/>

Source/ORTS.Common/Coordinates.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ public override string ToString()
181181
{
182182
return WorldLocation.ToString();
183183
}
184+
185+
public void CopyFrom(WorldPosition copy)
186+
{
187+
TileX = copy.TileX;
188+
TileZ = copy.TileZ;
189+
Location = copy.Location;
190+
}
184191
}
185192

186193

Source/ORTS.Common/Input/UserCommand.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,15 @@ public enum UserCommand
252252
[GetString("Control DP Less")] ControlDPLess,
253253

254254
// Editor
255-
[GetString("Editor Unselect All")] EditorUnselectAll,
255+
[GetString("Editor Unselect All")] EditorCancel,
256256
[GetString("Editor Undo")] EditorUndo,
257257
[GetString("Editor Redo")] EditorRedo,
258+
[GetString("Editor Move")] EditorMove,
259+
[GetString("Editor Move Handle")] EditorMoveHandle,
260+
[GetString("Editor Rotate")] EditorRotate,
261+
[GetString("Editor Rotate Handle")] EditorRotateHandle,
262+
[GetString("Editor Move X")] EditorMoveX,
263+
[GetString("Editor Move Y")] EditorMoveY,
264+
[GetString("Editor Move Z")] EditorMoveZ,
258265
}
259266
}

Source/ORTS.Settings/InputSettings.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,16 @@ static void InitializeCommands(UserCommandInput[] Commands)
539539
Commands[(int)UserCommand.GameSwitchPicked] = new UserCommandKeyInput(0x22, KeyModifiers.Alt);
540540
Commands[(int)UserCommand.GameUncoupleWithMouse] = new UserCommandKeyInput(0x16);
541541

542-
Commands[(int)UserCommand.EditorUnselectAll] = new UserCommandKeyInput(0x01);
542+
Commands[(int)UserCommand.EditorCancel] = new UserCommandKeyInput(0x01);
543543
Commands[(int)UserCommand.EditorUndo] = new UserCommandKeyInput(Keys.Z, KeyModifiers.Control); // Not assigning by scan code, because on German influenced keyboard layounts
544544
Commands[(int)UserCommand.EditorRedo] = new UserCommandKeyInput(Keys.Y, KeyModifiers.Control); // the Y and Z keys are exchanged, and we want these to match the o/s
545+
Commands[(int)UserCommand.EditorMove] = new UserCommandKeyInput(Keys.M);
546+
Commands[(int)UserCommand.EditorMoveHandle] = new UserCommandKeyInput(Keys.M, KeyModifiers.Alt);
547+
Commands[(int)UserCommand.EditorRotate] = new UserCommandKeyInput(Keys.R);
548+
Commands[(int)UserCommand.EditorRotateHandle] = new UserCommandKeyInput(Keys.R, KeyModifiers.Alt);
549+
Commands[(int)UserCommand.EditorMoveX] = new UserCommandKeyInput(Keys.X);
550+
Commands[(int)UserCommand.EditorMoveY] = new UserCommandKeyInput(Keys.Y);
551+
Commands[(int)UserCommand.EditorMoveZ] = new UserCommandKeyInput(Keys.Z);
545552
}
546553
#endregion
547554

Source/RunActivity/Viewer3D/EditorPrimitives.cs

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,23 @@ namespace Orts.Viewer3D
2828
{
2929
public class EditorShapes : StaticShape, IDisposable
3030
{
31-
public readonly MouseCrosshair MouseCrosshair;
31+
readonly MouseCrosshair MouseCrosshair;
3232
public bool MouseCrosshairEnabled { get; set; }
3333
public bool CrosshairPositionUpdateEnabled { get; set; } = true;
3434

35-
public readonly HandleX HandleX;
36-
public readonly HandleY HandleY;
37-
public readonly HandleZ HandleZ;
35+
readonly HandleX HandleX;
36+
readonly HandleY HandleY;
37+
readonly HandleZ HandleZ;
3838
public bool HandleEnabled { get; set; } = true;
39-
public WorldPosition HandleLocation;
39+
public WorldPosition HandleLocation { get; set; }
4040

41-
StaticShape _selectedObject;
41+
StaticShape PreviousSelectedObject;
4242
public StaticShape SelectedObject { get; set; }
4343

44+
public StaticShape MovedObject { get; set; }
45+
public WorldPosition MovedObjectLocation { get; set; }
46+
BoundingBoxPrimitive MovedObjectPrimitive;
47+
4448
public ConcurrentBag<StaticShape> BoundingBoxShapes = new ConcurrentBag<StaticShape>();
4549
readonly ConcurrentDictionary<(int tileX, int tileZ, int uid, Matrix matrix, int number), BoundingBoxPrimitive> BoundingBoxPrimitives = new ConcurrentDictionary<(int, int, int, Matrix, int), BoundingBoxPrimitive>();
4650
readonly ConcurrentBag<EditorPrimitive> UnusedPrimitives = new ConcurrentBag<EditorPrimitive>();
@@ -56,43 +60,43 @@ public EditorShapes(Viewer viewer) : base(viewer, "", null, ShapeFlags.None, nul
5660

5761
public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
5862
{
59-
if (_selectedObject != SelectedObject)
63+
if (PreviousSelectedObject != SelectedObject)
6064
{
61-
if (_selectedObject != null)
62-
for (var i = 0; i < 5; i++)
63-
BoundingBoxPrimitives.TryRemove((_selectedObject.Location.TileX, _selectedObject.Location.TileZ, _selectedObject.Uid, _selectedObject.Location.XNAMatrix, i), out _);
65+
if (PreviousSelectedObject?.BoundingBox != null)
66+
for (var i = 0; i < PreviousSelectedObject.BoundingBox.Length; i++)
67+
if (BoundingBoxPrimitives.TryRemove((PreviousSelectedObject.Location.TileX, PreviousSelectedObject.Location.TileZ, PreviousSelectedObject.Uid, PreviousSelectedObject.Location.XNAMatrix, i), out var primitive))
68+
UnusedPrimitives.Add(primitive);
6469

65-
_selectedObject = SelectedObject;
70+
PreviousSelectedObject = SelectedObject;
6671

67-
if (_selectedObject?.BoundingBox?.Length > 0)
72+
if (SelectedObject?.BoundingBox?.Length > 0)
6873
{
69-
for (var i = 0; i < _selectedObject.BoundingBox.Length; i++)
74+
for (var i = 0; i < SelectedObject.BoundingBox.Length; i++)
7075
{
71-
BoundingBoxPrimitives.TryAdd((_selectedObject.Location.TileX, _selectedObject.Location.TileZ, _selectedObject.Uid, _selectedObject.Location.XNAMatrix, i),
72-
new BoundingBoxPrimitive(Viewer, _selectedObject.BoundingBox[i], Color.CornflowerBlue));
76+
BoundingBoxPrimitives.TryAdd((SelectedObject.Location.TileX, SelectedObject.Location.TileZ, SelectedObject.Uid, SelectedObject.Location.XNAMatrix, i),
77+
new BoundingBoxPrimitive(Viewer, SelectedObject.BoundingBox[i], Color.CornflowerBlue));
7378
}
7479
}
7580
}
7681
for (var i = 0; i < BoundingBoxPrimitives.Count; i++)
7782
{
83+
// Sweep out the not displayable bb-s
7884
var bb = BoundingBoxPrimitives.Keys.ElementAtOrDefault(i);
7985
if (bb != default((int, int, int, Matrix, int))
80-
&& !BoundingBoxShapes.Any(s => s?.Location.TileX == bb.tileX && s?.Location.TileZ == bb.tileZ && s?.Uid == bb.uid))
86+
&& !BoundingBoxShapes.Any(s => s?.Location.TileX == bb.tileX && s?.Location.TileZ == bb.tileZ && s?.Uid == bb.uid)
87+
&& bb.tileX != SelectedObject?.Location.TileX && bb.tileZ != SelectedObject?.Location.TileZ && bb.uid != SelectedObject?.Uid)
8188
{
82-
if (bb.tileX != _selectedObject?.Location.TileX && bb.tileZ != _selectedObject?.Location.TileZ && bb.uid != _selectedObject?.Uid)
83-
{
84-
if (BoundingBoxPrimitives.TryRemove(bb, out var primitive))
85-
UnusedPrimitives.Add(primitive);
86-
}
89+
if (BoundingBoxPrimitives.TryRemove(bb, out var primitive))
90+
UnusedPrimitives.Add(primitive);
8791
}
8892
}
89-
9093
for (var j = 0; j < BoundingBoxShapes.Count; j++)
9194
{
9295
var s = BoundingBoxShapes.ElementAtOrDefault(j);
9396
if (s?.BoundingBox == null || s.BoundingBox.Length == 0)
9497
continue;
9598

99+
// Complement with all the displayable bb-s
96100
if (!BoundingBoxPrimitives.Keys.Any(bb => s.Location.TileX == bb.tileX && s.Location.TileZ == bb.tileZ && s.Uid == bb.uid))
97101
{
98102
for (var i = 0; i < s.BoundingBox.Length; i++)
@@ -102,7 +106,6 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
102106
}
103107
}
104108
}
105-
106109
if (BoundingBoxPrimitives?.Count > 0)
107110
{
108111
foreach (var boundingBox in BoundingBoxPrimitives.Keys)
@@ -116,6 +119,25 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
116119
frame.AddPrimitive(BoundingBoxPrimitives[boundingBox].Material, BoundingBoxPrimitives[boundingBox], RenderPrimitiveGroup.Labels, ref xnaDTileTranslation);
117120
}
118121
}
122+
if (MovedObject == null && MovedObjectPrimitive != null)
123+
{
124+
UnusedPrimitives.Add(MovedObjectPrimitive);
125+
MovedObjectPrimitive = null;
126+
}
127+
else if (MovedObject != null && MovedObjectPrimitive == null)
128+
{
129+
if (MovedObject.BoundingBox?.Length > 0)
130+
MovedObjectPrimitive = new BoundingBoxPrimitive(Viewer, MovedObject.BoundingBox[0], Color.MediumVioletRed);
131+
}
132+
if (MovedObjectPrimitive != null)
133+
{
134+
var dTileX = MovedObjectLocation.TileX - Viewer.Camera.TileX;
135+
var dTileZ = MovedObjectLocation.TileZ - Viewer.Camera.TileZ;
136+
var xnaDTileTranslation = MovedObjectLocation.XNAMatrix;
137+
xnaDTileTranslation.M41 += dTileX * 2048;
138+
xnaDTileTranslation.M43 -= dTileZ * 2048;
139+
frame.AddPrimitive(MovedObjectPrimitive.Material, MovedObjectPrimitive, RenderPrimitiveGroup.Labels, ref xnaDTileTranslation);
140+
}
119141
if (MouseCrosshairEnabled)
120142
{
121143
if (CrosshairPositionUpdateEnabled)
@@ -127,7 +149,7 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
127149
}
128150
if (HandleEnabled)
129151
{
130-
var handleLocation = HandleLocation ?? _selectedObject?.Location;
152+
var handleLocation = HandleLocation ?? SelectedObject?.Location;
131153
if (handleLocation != null)
132154
{
133155
var dTileX = handleLocation.TileX - Viewer.Camera.TileX;
@@ -231,10 +253,16 @@ public class BoundingBoxPrimitive : BoxPrimitive
231253
public readonly Matrix ComplexTransform;
232254

233255
public BoundingBoxPrimitive(Viewer viewer, BoundingBox boundingBox, Color color)
234-
: base(viewer, boundingBox.Min, boundingBox.Max, color)
256+
: this(viewer, boundingBox.Min, boundingBox.Max, color)
235257
{
236-
Material = viewer.MaterialManager.Load("EditorPrimitive");
237258
ComplexTransform = boundingBox.ComplexTransform;
259+
}
260+
261+
public BoundingBoxPrimitive(Viewer viewer, Vector3 min, Vector3 max, Color color)
262+
: base(viewer, min, max, color)
263+
{
264+
Material = viewer.MaterialManager.Load("EditorPrimitive");
265+
ComplexTransform = Matrix.Identity;
238266
if (BoundingBoxIndexBuffer == null)
239267
{
240268
var indexData = new short[] { 0, 1, 0, 2, 0, 4, 1, 3, 1, 5, 2, 3, 2, 6, 3, 7, 4, 5, 4, 6, 5, 7, 6, 7 };
@@ -312,12 +340,7 @@ protected VertexPositionColor[] GetVertexData(int x, int y, int z, Color color)
312340
new[] { c, +b, +b },
313341
new[] { c, -b, -b },
314342
};
315-
var vertexData = new VertexPositionColor[data.Length];
316-
for (var i = 0; i < data.Length; i++)
317-
{
318-
vertexData[i] = new VertexPositionColor(new Vector3(data[i][x], data[i][y], data[i][z]), color);
319-
}
320-
return vertexData;
343+
return data.Select(v => new VertexPositionColor(new Vector3(v[x], v[y], v[z]), color)).ToArray();
321344
}
322345
}
323346

0 commit comments

Comments
 (0)