Fixed in room navigation.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / gui / humaninput / WorldNavigationUserInputTracker.java
1 /*
2  * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  *
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.
7  *
8  */
9
10 package eu.svjatoslav.sixth.e3d.gui.humaninput;
11
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;
15
16 import java.awt.event.KeyEvent;
17
18 public class WorldNavigationUserInputTracker implements UserInputHandler {
19
20     @Override
21     public boolean beforeRender(final ViewPanel viewPanel,
22                                 final int millisecondsSinceLastFrame) {
23
24         final HIDInputTracker inputTracker = viewPanel.getHIDInputTracker();
25
26         final Avatar avatar = viewPanel.getAvatar();
27
28         final double actualAcceleration = (long) millisecondsSinceLastFrame
29                 * avatar.avatarAcceleration
30                 * (1 + (avatar.getMovementSpeed() / 10));
31
32         if (inputTracker.isKeyPressed(KeyboardHelper.UP))
33             avatar.getMovementVector().z += actualAcceleration;
34
35         if (inputTracker.isKeyPressed(KeyboardHelper.DOWN))
36             avatar.getMovementVector().z -= actualAcceleration;
37
38         if (inputTracker.isKeyPressed(KeyboardHelper.RIGHT))
39             avatar.getMovementVector().x += actualAcceleration;
40
41         if (inputTracker.isKeyPressed(KeyboardHelper.LEFT))
42             avatar.getMovementVector().x -= actualAcceleration;
43
44         avatar.enforceSpeedLimit();
45
46         return false;
47     }
48
49     @Override
50     public boolean focusLost(final ViewPanel viewPanel) {
51         viewPanel.removeViewRenderListener(this);
52         return false;
53     }
54
55     @Override
56     public boolean focusReceived(final ViewPanel viewPanel) {
57         viewPanel.addViewRenderListener(this);
58         return false;
59     }
60
61     @Override
62     public boolean keyPressed(final KeyEvent event, final ViewPanel viewContext) {
63         return false;
64     }
65
66     @Override
67     public boolean keyReleased(final KeyEvent event, final ViewPanel viewContext) {
68         return false;
69     }
70
71 }