Skip to content

Commit ae66555

Browse files
committed
Fix the crosshair
1 parent 40f7f86 commit ae66555

File tree

5 files changed

+51
-20
lines changed

5 files changed

+51
-20
lines changed

Source/Contrib/TrackViewer/SceneViewer.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ public SceneViewer(TrackViewer trackViewer, string[] args)
103103
// Not "running" this Game, so manual init is needed
104104
Initialize();
105105
LoadContent();
106-
107-
Microsoft.Xna.Framework.Input.Mouse.WindowHandle = SwapChainWindow.Handle;
108106
}
109107

110108
/// <summary>
@@ -132,6 +130,11 @@ public void LoadContent()
132130
/// <param name="gameTime">Provides a snapshot of timing values.</param>
133131
public void Update(GameTime gameTime)
134132
{
133+
if (TrackViewer.RenderProcess?.Viewer == null)
134+
return;
135+
136+
TrackViewer.RenderProcess.Viewer.EditorShapes.MouseCrosshairEnabled = true;
137+
135138
if (UserInput.IsMouseLeftButtonPressed && UserInput.ModifiersMaskShiftCtrlAlt(false, false, false))
136139
{
137140
if (PickByMouse(out SelectedObject))
@@ -140,7 +143,8 @@ public void Update(GameTime gameTime)
140143
FillSelectedObjectData();
141144
}
142145
}
143-
SetCameraLocationStatus(TrackViewer.RenderProcess?.Viewer?.Camera?.CameraWorldLocation ?? new WorldLocation());
146+
//SetCameraLocationStatus(TrackViewer.RenderProcess?.Viewer?.Camera?.CameraWorldLocation ?? new WorldLocation());
147+
FillCursorPositionStatus((TrackViewer.RenderProcess?.Viewer?.Camera as ViewerCamera)?.CursorPoint ?? new Vector3());
144148
}
145149

146150
public void EndDraw()
@@ -175,6 +179,15 @@ private void SetCameraLocationStatus(WorldLocation cameraLocation)
175179
"{0,3:F3} ", cameraLocation.Location.Z);
176180
}
177181

182+
private void FillCursorPositionStatus(Vector3 cursorPosition)
183+
{
184+
//SceneWindow.tileXZ.Text = string.Format(System.Globalization.CultureInfo.CurrentCulture,
185+
// "{0,-7} {1,-7}", cameraLocation.TileX, cameraLocation.TileZ);
186+
SceneWindow.LocationX.Text = string.Format(CultureInfo.InvariantCulture, "{0,3:F3} ", cursorPosition.X);
187+
SceneWindow.LocationY.Text = string.Format(CultureInfo.InvariantCulture, "{0,3:F3} ", cursorPosition.Y);
188+
SceneWindow.LocationZ.Text = string.Format(CultureInfo.InvariantCulture, "{0,3:F3} ", -cursorPosition.Z);
189+
}
190+
178191
public async Task SetCameraLocation()
179192
{
180193
var mouseLocation = TrackViewer.drawLabels.SetLocationMenuItem.CommandParameter as WorldLocation? ?? new WorldLocation();

Source/Contrib/TrackViewer/UserInterface/SceneWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
</StatusBar>
115115
<Border BorderThickness="2">
116116
<StackPanel Orientation="Vertical" Width="150">
117-
<TextBox Text="abcdefgh12345.s" FontWeight="Bold" Name="Filename"/>
117+
<TextBox FontWeight="Bold" Name="Filename"/>
118118
<DockPanel>
119119
<TextBlock Text="UID: " PreviewTextInput="UintValidationTextBox"/>
120120
<TextBlock Name="Uid"/>

Source/RunActivity/Viewer3D/Cameras.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ protected override void ZoomIn(float speed)
779779

780780
public class ViewerCamera : FreeRoamCamera
781781
{
782-
Vector3 CursorPoint;
782+
public Vector3 CursorPoint { get; private set; }
783783
bool CursorPointDirtyFlag = true;
784784

785785
public ViewerCamera(Viewer viewer)
@@ -795,6 +795,9 @@ public override void HandleUserInput(ElapsedTime elapsedTime)
795795
//var pick = UserInput.IsMouseLeftButtonPressed && UserInput.ModifiersMaskShiftCtrlAlt(false, false, false);
796796
var rotate = UserInput.IsMouseMiddleButtonDown && UserInput.ModifiersMaskShiftCtrlAlt(false, false, false);
797797

798+
if (UserInput.IsMouseMiddleButtonPressed && UserInput.ModifiersMaskShiftCtrlAlt(false, false, false))
799+
RotationOrigin = GetCursorTerrainIntersection();
800+
798801
if (pan) PanByMouse();
799802
else if (rotate) RotateByMouse();
800803
else ZoomByMouseWheel(GetSpeed(elapsedTime));
@@ -805,8 +808,19 @@ protected override void ZoomByMouseWheel(float speed)
805808
ZoomIn(speed * UserInput.MouseWheelChange * ZoomFactor);
806809
}
807810

811+
Vector3 RotationOrigin;
808812
protected override void RotateByMouse()
809813
{
814+
//var cl = cameraLocation.Location;
815+
//cl.Z *= -1;
816+
//var l = cl;
817+
//l = Vector3.Transform(l, Matrix.CreateTranslation(RotationOrigin - cl));
818+
//l = Vector3.Transform(l, Matrix.CreateRotationX(GetMouseDelta(UserInput.MouseMoveY)));
819+
//l = Vector3.Transform(l, Matrix.CreateRotationY(GetMouseDelta(UserInput.MouseMoveX)));
820+
//l = Vector3.Transform(l, Matrix.CreateTranslation(cl - RotationOrigin));
821+
//l.Z *= -1;
822+
//cameraLocation.Location = l;
823+
810824
// Mouse movement doesn't use 'var speed' because the MouseMove
811825
// parameters are already scaled down with increasing frame rates,
812826
RotationXRadians += GetMouseDelta(UserInput.MouseMoveY);
@@ -837,13 +851,12 @@ public Vector3 GetCursorTerrainIntersection()
837851
return CursorPoint;
838852

839853
var threshold = 0.1f;
840-
float interpolation;
841854
var nearPoint = Viewer.NearPoint;
842855
var farPoint = Viewer.FarPoint;
843856
var midPoint = farPoint;
844-
for (var i = 0; i < 8; i++)
857+
for (var i = 0; i < 16; i++)
845858
{
846-
var terrainLevel = Viewer.Tiles.GetElevation(TileX, TileZ, midPoint.X, midPoint.Z);
859+
var terrainLevel = Viewer.Tiles.GetElevation(TileX, TileZ, midPoint.X, -midPoint.Z);
847860
var delta = Math.Abs(midPoint.Y - terrainLevel);
848861
if (delta < threshold)
849862
{
@@ -853,18 +866,13 @@ public Vector3 GetCursorTerrainIntersection()
853866
if ((midPoint.Y > terrainLevel) ^ (nearPoint.Y < farPoint.Y))
854867
{
855868
nearPoint = midPoint;
856-
interpolation = farPoint.Y == midPoint.Y ? 1 : MathHelper.Clamp(delta / Math.Abs(farPoint.Y - midPoint.Y), 0, 1);
857-
midPoint += (farPoint - midPoint) * interpolation;
869+
midPoint += (farPoint - midPoint) * 0.5f;
858870
}
859871
else
860872
{
861873
farPoint = midPoint;
862-
interpolation = nearPoint.Y == midPoint.Y ? 1 : MathHelper.Clamp(delta / Math.Abs(nearPoint.Y - midPoint.Y), 0, 1);
863-
864-
865-
midPoint += (nearPoint - midPoint) * interpolation;
874+
midPoint += (nearPoint - midPoint) * 0.5f;
866875
}
867-
if (interpolation == 1) break; // bail off, no intersection
868876
}
869877
CursorPoint = midPoint;
870878
CursorPointDirtyFlag = false;

Source/RunActivity/Viewer3D/EditorPrimitives.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,19 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
5454
{
5555
var dTileX = _selectedObject.Location.TileX - Viewer.Camera.TileX;
5656
var dTileZ = _selectedObject.Location.TileZ - Viewer.Camera.TileZ;
57-
var mstsLocation = _selectedObject.Location.Location + new Vector3(dTileX * 2048, 0, dTileZ * 2048);
58-
var xnaMatrix = Matrix.CreateTranslation(mstsLocation.X, mstsLocation.Y, -mstsLocation.Z);
59-
frame.AddPrimitive(SelectedObjectBoundingBoxPrimitive.Material, SelectedObjectBoundingBoxPrimitive, RenderPrimitiveGroup.Labels, ref xnaMatrix);
57+
var xnaDTileTranslation = _selectedObject.Location.XNAMatrix;
58+
xnaDTileTranslation.M41 += dTileX * 2048;
59+
xnaDTileTranslation.M43 -= dTileZ * 2048;
60+
frame.AddPrimitive(SelectedObjectBoundingBoxPrimitive.Material, SelectedObjectBoundingBoxPrimitive, RenderPrimitiveGroup.Labels, ref xnaDTileTranslation);
6061
}
6162
if (MouseCrosshairEnabled)
6263
{
6364
var mouseCrosshairPosition = (Viewer.Camera as ViewerCamera)?.GetCursorTerrainIntersection() ?? Viewer.NearPoint;
64-
var mouseCrosshairMatrix = Matrix.CreateTranslation(mouseCrosshairPosition);
65-
frame.AddPrimitive(MouseCrosshair.Material, MouseCrosshair, RenderPrimitiveGroup.World, ref mouseCrosshairMatrix);
65+
if (mouseCrosshairPosition != Viewer.NearPoint)
66+
{
67+
var mouseCrosshairMatrix = Matrix.CreateTranslation(mouseCrosshairPosition);
68+
frame.AddPrimitive(MouseCrosshair.Material, MouseCrosshair, RenderPrimitiveGroup.World, ref mouseCrosshairMatrix);
69+
}
6670
}
6771
}
6872

Source/RunActivity/Viewer3D/Processes/GameStateViewer3D.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ internal override void BeginRender(RenderFrame frame)
6464

6565
FirstFrame = false;
6666
}
67+
if (FirstFrame && Viewer.EditorMode)
68+
{
69+
Game.IsFixedTimeStep = false;
70+
Game.InactiveSleepTime = TimeSpan.Zero;
71+
FirstFrame = false;
72+
}
6773
Viewer.BeginRender(frame);
6874
}
6975

0 commit comments

Comments
 (0)