From 01d8f36a5259f1172af4f5b1deff10be767aa08d Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Sun, 14 Jul 2013 09:18:33 +0000 Subject: [PATCH] Changed the way the walkDirection is computed in HelloCollision to avoid instatiating vector3f on each update. Also updated the wiki to reflect the change git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10714 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../jme3test/helloworld/HelloCollision.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/engine/src/test/jme3test/helloworld/HelloCollision.java b/engine/src/test/jme3test/helloworld/HelloCollision.java index d0c5f57ea..60db3b052 100644 --- a/engine/src/test/jme3test/helloworld/HelloCollision.java +++ b/engine/src/test/jme3test/helloworld/HelloCollision.java @@ -64,6 +64,11 @@ public class HelloCollision extends SimpleApplication private CharacterControl player; private Vector3f walkDirection = new Vector3f(); private boolean left = false, right = false, up = false, down = false; + + //Temporary vectors used on each frame. + //They here to avoid instanciating new vectors on each frame + private Vector3f camDir = new Vector3f(); + private Vector3f camLeft = new Vector3f(); public static void main(String[] args) { HelloCollision app = new HelloCollision(); @@ -164,15 +169,23 @@ public class HelloCollision extends SimpleApplication * We also make sure here that the camera moves with player. */ @Override - public void simpleUpdate(float tpf) { - Vector3f camDir = cam.getDirection().clone().multLocal(0.6f); - Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f); - walkDirection.set(0, 0, 0); - if (left) { walkDirection.addLocal(camLeft); } - if (right) { walkDirection.addLocal(camLeft.negate()); } - if (up) { walkDirection.addLocal(camDir); } - if (down) { walkDirection.addLocal(camDir.negate()); } - player.setWalkDirection(walkDirection); - cam.setLocation(player.getPhysicsLocation()); - } + public void simpleUpdate(float tpf) { + camDir.set(cam.getDirection()).multLocal(0.6f); + camLeft.set(cam.getLeft()).multLocal(0.4f); + walkDirection.set(0, 0, 0); + if (left) { + walkDirection.addLocal(camLeft); + } + if (right) { + walkDirection.addLocal(camLeft.negate()); + } + if (up) { + walkDirection.addLocal(camDir); + } + if (down) { + walkDirection.addLocal(camDir.negate()); + } + player.setWalkDirection(walkDirection); + cam.setLocation(player.getPhysicsLocation()); + } }