@@ -53,6 +53,7 @@ public class SceneViewer
5353 OrbitingCamera Camera ;
5454
5555 EditorState EditorState ;
56+ EditorMoveState EditorMoveState ;
5657 StaticShape SelectedObject ;
5758 WorldFile SelectedWorldFile ;
5859 Orts . Formats . Msts . WorldObject SelectedWorldObject ;
@@ -109,11 +110,6 @@ public void Show()
109110 SceneWindow . Activate ( ) ;
110111 }
111112
112- /// <summary>
113- /// Allows the game to run logic such as updating the world,
114- /// checking for collisions, gathering input, and playing audio.
115- /// </summary>
116- /// <param name="gameTime">Provides a snapshot of timing values.</param>
117113 public void Update ( GameTime gameTime )
118114 {
119115 Viewer = Viewer ?? Game . RenderProcess ? . Viewer ;
@@ -155,19 +151,29 @@ public void Update(GameTime gameTime)
155151 {
156152 if ( UserInput . IsPressed ( UserCommand . EditorMove ) )
157153 {
154+ EditorMoveState = EditorMoveState . Move ;
155+ StartObjectMove ( ) ;
156+ }
157+ if ( UserInput . IsPressed ( UserCommand . EditorRotate ) )
158+ {
159+ EditorMoveState = EditorMoveState . Rotate ;
158160 StartObjectMove ( ) ;
159161 }
160162 if ( UserInput . IsPressed ( UserCommand . EditorMoveHandle ) )
161163 {
164+ EditorMoveState = EditorMoveState . Move ;
162165 StartHandleMove ( ) ;
163166 }
164167 }
165168 if ( EditorState == EditorState . HandleMoving )
166169 {
167170 if ( UserInput . IsPressed ( UserCommand . EditorMove ) )
168171 {
169- CancelHandleMove ( ) ;
170- StartObjectMove ( ) ;
172+ EditorMoveState = EditorMoveState . Move ;
173+ }
174+ if ( UserInput . IsPressed ( UserCommand . EditorRotate ) )
175+ {
176+ EditorMoveState = EditorMoveState . Rotate ;
171177 }
172178 if ( UserInput . IsPressed ( UserCommand . EditorCancel ) )
173179 {
@@ -180,10 +186,13 @@ public void Update(GameTime gameTime)
180186 }
181187 if ( EditorState == EditorState . ObjectMoving )
182188 {
183- if ( UserInput . IsPressed ( UserCommand . EditorMoveHandle ) )
189+ if ( UserInput . IsPressed ( UserCommand . EditorMove ) )
184190 {
185- CancelObjectMove ( ) ;
186- StartHandleMove ( ) ;
191+ EditorMoveState = EditorMoveState . Move ;
192+ }
193+ if ( UserInput . IsPressed ( UserCommand . EditorRotate ) )
194+ {
195+ EditorMoveState = EditorMoveState . Rotate ;
187196 }
188197 if ( UserInput . IsPressed ( UserCommand . EditorCancel ) )
189198 {
@@ -315,7 +324,7 @@ Matrix GetMovingMatrix(in WorldPosition originalPosition, in WorldPosition handl
315324 var handle = handleOriginalPosition ?? originalPosition ;
316325 var xnaMatrix = originalPosition . XNAMatrix ;
317326
318- if ( UserInput . IsDown ( UserCommand . EditorLockRotation ) )
327+ if ( EditorMoveState == EditorMoveState . Rotate )
319328 {
320329 var distance = WorldLocation . GetDistance ( handle . WorldLocation , CursorLocation ) ;
321330 distance . Z *= - 1 ;
@@ -337,8 +346,12 @@ Matrix GetMovingMatrix(in WorldPosition originalPosition, in WorldPosition handl
337346 handleMatrix . Translation += translation ;
338347 handlePosition . XNAMatrix = handleMatrix ;
339348 }
349+
350+ DeltaX = 0 ;
351+ DeltaY = MathHelper . ToDegrees ( angle ) ;
352+ DeltaZ = 0 ;
340353 }
341- else
354+ else if ( EditorMoveState == EditorMoveState . Move )
342355 {
343356 var distance = WorldLocation . GetDistance ( originalPosition . WorldLocation , CursorLocation ) ;
344357 distance . Z *= - 1 ;
@@ -461,16 +474,9 @@ void UndoRedo(UndoDataSet undoDataSet, bool undo)
461474 }
462475 else if ( undoDataSet . UndoEvent == UndoEvent . WorldObjectChanged )
463476 {
464- if ( undo )
465- {
466- var newPosition = new WorldPosition ( undoDataSet . ChangedStaticShape . Location ) ;
467- undoDataSet . ChangedStaticShape . Location . CopyFrom ( undoDataSet . OldPosition ) ;
468- undoDataSet . OldPosition . CopyFrom ( newPosition ) ;
469- }
470- else
471- {
472-
473- }
477+ var newPosition = new WorldPosition ( undoDataSet . ChangedStaticShape . Location ) ;
478+ undoDataSet . ChangedStaticShape . Location . CopyFrom ( undoDataSet . OldPosition ) ;
479+ undoDataSet . OldPosition . CopyFrom ( newPosition ) ;
474480 }
475481 }
476482
@@ -500,8 +506,8 @@ void ApplyObjectMove()
500506 TileZ = MovedObject . Location . TileZ ,
501507 Uid = MovedObject . Uid ,
502508 ChangedStaticShape = MovedObject ,
503- OldPosition = MovedObjectOriginalPosition ,
504- MovedWithRespectTo = HandlePosition ?? MovedObject . Location ,
509+ OldPosition = new WorldPosition ( MovedObjectOriginalPosition ) ,
510+ MoveOrigin = HandlePosition ,
505511 } ) ;
506512 RedoStack . Clear ( ) ;
507513
@@ -593,7 +599,7 @@ public class UndoDataSet
593599 public int Uid ;
594600 public StaticShape ChangedStaticShape ;
595601 public WorldPosition OldPosition ;
596- public WorldPosition MovedWithRespectTo ;
602+ public WorldPosition MoveOrigin ;
597603 public Orts . Formats . Msts . WorldObject OldWorldObject ;
598604 public Orts . Formats . Msts . WorldObject NewWorldObject ;
599605
@@ -620,6 +626,12 @@ public enum EditorState
620626 HandleMoving ,
621627 }
622628
629+ public enum EditorMoveState
630+ {
631+ Move ,
632+ Rotate ,
633+ }
634+
623635 public class SceneViewerHwndHost : HwndHost
624636 {
625637 readonly IntPtr HwndChildHandle ;
0 commit comments