@@ -29,7 +29,13 @@ public class EditorCameraController extends InputAdapter implements EditorSubsys
29
29
double maxRot = 0.8 ;
30
30
31
31
int scrollAmount ;
32
-
32
+
33
+ boolean isMoving ;
34
+ float currentMoveTime ;
35
+ final float moveTime = 0.0625f ;
36
+ final Vector3 moveStart = new Vector3 ();
37
+ final Vector3 moveEnd = new Vector3 ();
38
+
33
39
public EditorCameraController () {}
34
40
35
41
@ Override
@@ -173,6 +179,20 @@ else if (scrollAmount > 0) {
173
179
position .set (cameraNewDirection .x , cameraNewDirection .z , cameraNewDirection .y );
174
180
}
175
181
182
+ // Handle smoothly lerping to a destination.
183
+ if (isMoving ) {
184
+ currentMoveTime += Gdx .graphics .getDeltaTime ();
185
+
186
+ position .set (moveStart );
187
+ position .lerp (moveEnd , currentMoveTime / moveTime );
188
+
189
+ if (currentMoveTime >= moveTime ) {
190
+ currentMoveTime = 0 ;
191
+ isMoving = false ;
192
+ position .set (moveEnd );
193
+ }
194
+ }
195
+
176
196
camera .position .set (position .x , position .z , position .y );
177
197
178
198
scrollAmount = 0 ;
@@ -239,6 +259,7 @@ public boolean scrolled(int amount) {
239
259
return false ;
240
260
}
241
261
262
+ /** Position the camera to view the current selection. */
242
263
public void viewSelected () {
243
264
PerspectiveCamera camera = Editor .app .camera ;
244
265
Level level = Editor .app .level ;
@@ -268,6 +289,14 @@ else if (Editor.app.selected) {
268
289
269
290
Vector3 cameraOffset = new Vector3 (camera .direction .x ,camera .direction .z ,camera .direction .y ).scl (orbitDistance );
270
291
Vector3 finalPosition = new Vector3 (selectedPosition ).sub (cameraOffset );
271
- position .set (finalPosition );
292
+ moveTo (finalPosition );
293
+ }
294
+
295
+ /** Smoothly move to given destination. */
296
+ public void moveTo (Vector3 destination ) {
297
+ moveStart .set (position );
298
+ moveEnd .set (destination );
299
+ isMoving = true ;
300
+ currentMoveTime = 0 ;
272
301
}
273
302
}
0 commit comments