X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=sixth-3d.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fgui%2Fhumaninput%2FWorldNavigationUserInputTracker.java;h=68e36389471a407314ae0706415fbde204360145;hp=d80924cf3c521946d706c5fe30a5894b73a578df;hb=59baa428fb2d9e7f0fe5423f4cea47f2d6245914;hpb=70ee733b25c56bed539b89ff5507ae0af842d68a diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/WorldNavigationUserInputTracker.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/WorldNavigationUserInputTracker.java index d80924c..68e3638 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/WorldNavigationUserInputTracker.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/WorldNavigationUserInputTracker.java @@ -1,5 +1,5 @@ /* - * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * Sixth 3D engine. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License @@ -21,17 +21,40 @@ public class WorldNavigationUserInputTracker implements UserInputHandler { public boolean beforeRender(final ViewPanel viewPanel, final int millisecondsSinceLastFrame) { - trackKeys(millisecondsSinceLastFrame, viewPanel); + final HIDInputTracker inputTracker = viewPanel.getHIDInputTracker(); + + final Avatar avatar = viewPanel.getAvatar(); + + final double actualAcceleration = (long) millisecondsSinceLastFrame + * avatar.avatarAcceleration + * (1 + (avatar.getMovementSpeed() / 10)); + + if (inputTracker.isKeyPressed(KeyboardHelper.UP)) + avatar.getMovementVector().z += actualAcceleration; + + if (inputTracker.isKeyPressed(KeyboardHelper.DOWN)) + avatar.getMovementVector().z -= actualAcceleration; + + if (inputTracker.isKeyPressed(KeyboardHelper.RIGHT)) + avatar.getMovementVector().x += actualAcceleration; + + if (inputTracker.isKeyPressed(KeyboardHelper.LEFT)) + avatar.getMovementVector().x -= actualAcceleration; + + avatar.enforceSpeedLimit(); + return false; } @Override public boolean focusLost(final ViewPanel viewPanel) { + viewPanel.removeViewRenderListener(this); return false; } @Override - public boolean focusReceived(final ViewPanel viewContext) { + public boolean focusReceived(final ViewPanel viewPanel) { + viewPanel.addViewRenderListener(this); return false; } @@ -45,34 +68,4 @@ public class WorldNavigationUserInputTracker implements UserInputHandler { return false; } - /** - * interpret currently pressed keys - */ - private void trackKeys(final long millisecondsSinceLastFrame, - final ViewPanel viewPanel) { - - System.out.println("Track keys!"); - - final HIDInputTracker inputTracker = viewPanel.getHIDInputTracker(); - - final Avatar avatar = viewPanel.getAvatar(); - - final double actualAcceleration = millisecondsSinceLastFrame - * avatar.avatarAcceleration - * (1 + (avatar.getMovementSpeed() / 10)); - - if (inputTracker.isKeyPressed(KeyboardHelper.UP)) - avatar.getMovementVector().z += actualAcceleration; - - if (inputTracker.isKeyPressed(KeyboardHelper.DOWN)) - avatar.getMovementVector().z -= actualAcceleration; - - if (inputTracker.isKeyPressed(KeyboardHelper.RIGHT)) - avatar.getMovementVector().x += actualAcceleration; - - if (inputTracker.isKeyPressed(KeyboardHelper.LEFT)) - avatar.getMovementVector().x -= actualAcceleration; - - avatar.enforceSpeedLimit(); - } }