X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fgui%2FAvatar.java;h=852dc97104e917ab7bc96ae60e75f628f4c23939;hb=70ee733b25c56bed539b89ff5507ae0af842d68a;hp=7f0f698f41946e72964ba003d6d1eab6a31f9967;hpb=baab2e2c2ad89695293f3136311c585c9a5afed1;p=sixth-3d.git diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/Avatar.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/Avatar.java index 7f0f698..852dc97 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/Avatar.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/Avatar.java @@ -21,6 +21,10 @@ public class Avatar implements ViewRenderListener { * Just in case we want to adjust global speed for some reason. */ private static final double SPEED_MULTIPLIER = .02d; + /** + * Determines amount of friction user experiences every millisecond while moving around in space. + */ + private static final double MILLISECOND_FRICTION = 1.005; /** * Avatar movement speed, relative to avatar itself. When avatar coordinates * are updated within the world, avatar orientation relative to the world is @@ -32,23 +36,16 @@ public class Avatar implements ViewRenderListener { * Avatar location within the 3D world. */ private Point3D location = new Point3D(); - /** * Avatar orientation on the X-Z plane. It changes when turning left or * right. */ private double orientationXZ; - /** * Avatar orientation on the Y-Z plane. It changes when looking up or down. */ private double orientationYZ; - /** - * Determines amount of friction user experiences every millisecond while moving around in space. - */ - private static final double MILLISECOND_FRICTION = 1.005; - public Avatar() { } @@ -70,10 +67,10 @@ public class Avatar implements ViewRenderListener { } @Override - public boolean beforeRender(final ViewContext viewContext, final int millisecondsSinceLastFrame) { + public boolean beforeRender(final ViewPanel viewPanel, final int millisecondsSinceLastFrame) { final Point3D locationBeforeUpdate = new Point3D(location); - translateAvatarLocation(millisecondsSinceLastFrame); + translateAvatarLocationBasedOnMovementVector(millisecondsSinceLastFrame); applyFrictionToUserMovement(millisecondsSinceLastFrame); return isFrameRepaintNeeded(locationBeforeUpdate); } @@ -142,7 +139,7 @@ public class Avatar implements ViewRenderListener { * Therefore we take frame rendering time into account when translating * avatar between consecutive frames. */ - private void translateAvatarLocation(int millisecondsPassedSinceLastFrame) { + private void translateAvatarLocationBasedOnMovementVector(int millisecondsPassedSinceLastFrame) { location.x -= (float) sin(getAngleXZ()) * getMovementVector().z * SPEED_MULTIPLIER * millisecondsPassedSinceLastFrame;