2 * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public License
6 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.sixth.e3d.gui.humaninput;
12 import eu.svjatoslav.sixth.e3d.gui.Avatar;
13 import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
14 import eu.svjatoslav.sixth.e3d.gui.textEditorComponent.KeyboardHelper;
16 import java.awt.event.KeyEvent;
18 public class WorldNavigationUserInputTracker implements UserInputHandler {
21 public boolean beforeRender(final ViewPanel viewPanel,
22 final int millisecondsSinceLastFrame) {
24 trackKeys(millisecondsSinceLastFrame, viewPanel);
29 public boolean focusLost(final ViewPanel viewPanel) {
34 public boolean focusReceived(final ViewPanel viewContext) {
39 public boolean keyPressed(final KeyEvent event, final ViewPanel viewContext) {
44 public boolean keyReleased(final KeyEvent event, final ViewPanel viewContext) {
49 * interpret currently pressed keys
51 private void trackKeys(final long millisecondsSinceLastFrame,
52 final ViewPanel viewPanel) {
54 System.out.println("Track keys!");
56 final HIDInputTracker inputTracker = viewPanel.getHIDInputTracker();
58 final Avatar avatar = viewPanel.getAvatar();
60 final double actualAcceleration = millisecondsSinceLastFrame
61 * avatar.avatarAcceleration
62 * (1 + (avatar.getMovementSpeed() / 10));
64 if (inputTracker.isKeyPressed(KeyboardHelper.UP))
65 avatar.getMovementVector().z += actualAcceleration;
67 if (inputTracker.isKeyPressed(KeyboardHelper.DOWN))
68 avatar.getMovementVector().z -= actualAcceleration;
70 if (inputTracker.isKeyPressed(KeyboardHelper.RIGHT))
71 avatar.getMovementVector().x += actualAcceleration;
73 if (inputTracker.isKeyPressed(KeyboardHelper.LEFT))
74 avatar.getMovementVector().x -= actualAcceleration;
76 avatar.enforceSpeedLimit();