updated web site publishing script to work with latest javainspect
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / gui / humaninput / WorldNavigationUserInputTracker.java
1 /*
2  * Sixth 3D engine. Author: Svjatoslav Agejenko. 
3  * This project is released under Creative Commons Zero (CC0) license.
4  */
5 package eu.svjatoslav.sixth.e3d.gui.humaninput;
6
7 import eu.svjatoslav.sixth.e3d.gui.Avatar;
8 import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
9 import eu.svjatoslav.sixth.e3d.gui.ViewRenderListener;
10
11 import java.awt.event.KeyEvent;
12
13 public class WorldNavigationUserInputTracker implements KeyboardInputHandler, ViewRenderListener {
14
15     @Override
16     public boolean beforeRender(final ViewPanel viewPanel,
17                                 final int millisecondsSinceLastFrame) {
18
19         final HIDInputTracker inputTracker = viewPanel.getHIDInputTracker();
20
21         final Avatar avatar = viewPanel.getAvatar();
22
23         final double actualAcceleration = (long) millisecondsSinceLastFrame
24                 * avatar.avatarAcceleration
25                 * (1 + (avatar.getMovementSpeed() / 10));
26
27         if (inputTracker.isKeyPressed(KeyboardHelper.UP))
28             avatar.getMovementVector().z += actualAcceleration;
29
30         if (inputTracker.isKeyPressed(KeyboardHelper.DOWN))
31             avatar.getMovementVector().z -= actualAcceleration;
32
33         if (inputTracker.isKeyPressed(KeyboardHelper.RIGHT))
34             avatar.getMovementVector().x += actualAcceleration;
35
36         if (inputTracker.isKeyPressed(KeyboardHelper.LEFT))
37             avatar.getMovementVector().x -= actualAcceleration;
38
39         avatar.enforceSpeedLimit();
40
41         return false;
42     }
43
44     @Override
45     public boolean focusLost(final ViewPanel viewPanel) {
46         viewPanel.removeViewRenderListener(this);
47         return false;
48     }
49
50     @Override
51     public boolean focusReceived(final ViewPanel viewPanel) {
52         viewPanel.addViewRenderListener(this);
53         return false;
54     }
55
56     @Override
57     public boolean keyPressed(final KeyEvent event, final ViewPanel viewContext) {
58         return false;
59     }
60
61     @Override
62     public boolean keyReleased(final KeyEvent event, final ViewPanel viewContext) {
63         return false;
64     }
65
66 }