/*
- * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- *
+ * Sixth 3D engine. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
*/
-
package eu.svjatoslav.sixth.e3d.gui.humaninput;
import eu.svjatoslav.sixth.e3d.gui.Avatar;
import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
-import eu.svjatoslav.sixth.e3d.gui.textEditorComponent.KeyboardHelper;
+import eu.svjatoslav.sixth.e3d.gui.ViewRenderListener;
import java.awt.event.KeyEvent;
-public class WorldNavigationUserInputTracker implements UserInputHandler {
+public class WorldNavigationUserInputTracker implements KeyboardInputHandler, ViewRenderListener {
@Override
public boolean beforeRender(final ViewPanel viewPanel,
final int millisecondsSinceLastFrame) {
- trackKeys(millisecondsSinceLastFrame, viewPanel);
+ final HIDInputTracker inputTracker = viewPanel.getHIDInputTracker();
+
+ final Avatar avatar = viewPanel.getAvatar();
+
+ final double actualAcceleration = (long) millisecondsSinceLastFrame
+ * avatar.avatarAcceleration
+ * (1 + (avatar.getMovementSpeed() / 10));
+
+ if (inputTracker.isKeyPressed(KeyboardHelper.UP))
+ avatar.getMovementVector().z += actualAcceleration;
+
+ if (inputTracker.isKeyPressed(KeyboardHelper.DOWN))
+ avatar.getMovementVector().z -= actualAcceleration;
+
+ if (inputTracker.isKeyPressed(KeyboardHelper.RIGHT))
+ avatar.getMovementVector().x += actualAcceleration;
+
+ if (inputTracker.isKeyPressed(KeyboardHelper.LEFT))
+ avatar.getMovementVector().x -= actualAcceleration;
+
+ avatar.enforceSpeedLimit();
+
return false;
}
@Override
public boolean focusLost(final ViewPanel viewPanel) {
+ viewPanel.removeViewRenderListener(this);
return false;
}
@Override
- public boolean focusReceived(final ViewPanel viewContext) {
+ public boolean focusReceived(final ViewPanel viewPanel) {
+ viewPanel.addViewRenderListener(this);
return false;
}
return false;
}
- /**
- * interpret currently pressed keys
- */
- private void trackKeys(final long millisecondsSinceLastFrame,
- final ViewPanel viewPanel) {
-
- System.out.println("Track keys!");
-
- final HIDInputTracker inputTracker = viewPanel.getHIDInputTracker();
-
- final Avatar avatar = viewPanel.getAvatar();
-
- final double actualAcceleration = millisecondsSinceLastFrame
- * avatar.avatarAcceleration
- * (1 + (avatar.getMovementSpeed() / 10));
-
- if (inputTracker.isKeyPressed(KeyboardHelper.UP))
- avatar.getMovementVector().z += actualAcceleration;
-
- if (inputTracker.isKeyPressed(KeyboardHelper.DOWN))
- avatar.getMovementVector().z -= actualAcceleration;
-
- if (inputTracker.isKeyPressed(KeyboardHelper.RIGHT))
- avatar.getMovementVector().x += actualAcceleration;
-
- if (inputTracker.isKeyPressed(KeyboardHelper.LEFT))
- avatar.getMovementVector().x -= actualAcceleration;
-
- avatar.enforceSpeedLimit();
- }
}