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 WorldNavigationTracker 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 public void trackKeys(final long millisecondsSinceLastFrame,
52 final ViewPanel viewContext) {
54 final UserInputTracker inputTracker = viewContext.getUserInputTracker();
56 final Avatar avatar = viewContext.getAvatar();
58 final double actualAcceleration = millisecondsSinceLastFrame
59 * avatar.avatarAcceleration
60 * (1 + (avatar.getMovementSpeed() / 10));
62 if (inputTracker.isKeyPressed(KeyboardHelper.UP))
63 avatar.getMovementVector().z += actualAcceleration;
65 if (inputTracker.isKeyPressed(KeyboardHelper.DOWN))
66 avatar.getMovementVector().z -= actualAcceleration;
68 if (inputTracker.isKeyPressed(KeyboardHelper.RIGHT))
69 avatar.getMovementVector().x += actualAcceleration;
71 if (inputTracker.isKeyPressed(KeyboardHelper.LEFT))
72 avatar.getMovementVector().x -= actualAcceleration;
74 avatar.enforceSpeedLimit();