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.ViewContext;
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 ViewContext viewContext,
22 final int millisecondsSinceLastFrame) {
24 trackKeys(millisecondsSinceLastFrame, viewContext);
29 public void focusLost(final ViewContext viewContext) {
33 public void focusReceived(final ViewContext viewContext) {
37 public void keyPressed(final KeyEvent event, final ViewContext viewContext) {
41 public void keyReleased(final KeyEvent event, final ViewContext viewContext) {
45 * interpret currently pressed keys
47 public void trackKeys(final long millisecondsSinceLastFrame,
48 final ViewContext viewContext) {
50 final UserInputTracker inputTracker = viewContext.getUserInputTracker();
52 final Avatar avatar = viewContext.getAvatar();
54 final double actualAcceleration = millisecondsSinceLastFrame
55 * avatar.avatarAcceleration
56 * (1 + (avatar.getMovementSpeed() / 10));
58 if (inputTracker.isKeyPressed(KeyboardHelper.UP))
59 avatar.getMovementVector().z += actualAcceleration;
61 if (inputTracker.isKeyPressed(KeyboardHelper.DOWN))
62 avatar.getMovementVector().z -= actualAcceleration;
64 if (inputTracker.isKeyPressed(KeyboardHelper.RIGHT))
65 avatar.getMovementVector().x += actualAcceleration;
67 if (inputTracker.isKeyPressed(KeyboardHelper.LEFT))
68 avatar.getMovementVector().x -= actualAcceleration;
70 avatar.enforceSpeedLimit();