2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.gui.humaninput;
7 import eu.svjatoslav.sixth.e3d.gui.Avatar;
8 import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
9 import eu.svjatoslav.sixth.e3d.gui.ViewRenderListener;
11 import java.awt.event.KeyEvent;
13 public class WorldNavigationUserInputTracker implements KeyboardInputHandler, ViewRenderListener {
16 public boolean beforeRender(final ViewPanel viewPanel,
17 final int millisecondsSinceLastFrame) {
19 final HIDInputTracker inputTracker = viewPanel.getHIDInputTracker();
21 final Avatar avatar = viewPanel.getAvatar();
23 final double actualAcceleration = (long) millisecondsSinceLastFrame
24 * avatar.avatarAcceleration
25 * (1 + (avatar.getMovementSpeed() / 10));
27 if (inputTracker.isKeyPressed(KeyboardHelper.UP))
28 avatar.getMovementVector().z += actualAcceleration;
30 if (inputTracker.isKeyPressed(KeyboardHelper.DOWN))
31 avatar.getMovementVector().z -= actualAcceleration;
33 if (inputTracker.isKeyPressed(KeyboardHelper.RIGHT))
34 avatar.getMovementVector().x += actualAcceleration;
36 if (inputTracker.isKeyPressed(KeyboardHelper.LEFT))
37 avatar.getMovementVector().x -= actualAcceleration;
39 avatar.enforceSpeedLimit();
45 public boolean focusLost(final ViewPanel viewPanel) {
46 viewPanel.removeViewRenderListener(this);
51 public boolean focusReceived(final ViewPanel viewPanel) {
52 viewPanel.addViewRenderListener(this);
57 public boolean keyPressed(final KeyEvent event, final ViewPanel viewContext) {
62 public boolean keyReleased(final KeyEvent event, final ViewPanel viewContext) {