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
This commit is contained in:
parent
7c5571070c
commit
01d8f36a52
@ -64,6 +64,11 @@ public class HelloCollision extends SimpleApplication
|
|||||||
private CharacterControl player;
|
private CharacterControl player;
|
||||||
private Vector3f walkDirection = new Vector3f();
|
private Vector3f walkDirection = new Vector3f();
|
||||||
private boolean left = false, right = false, up = false, down = false;
|
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) {
|
public static void main(String[] args) {
|
||||||
HelloCollision app = new HelloCollision();
|
HelloCollision app = new HelloCollision();
|
||||||
@ -164,15 +169,23 @@ public class HelloCollision extends SimpleApplication
|
|||||||
* We also make sure here that the camera moves with player.
|
* We also make sure here that the camera moves with player.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void simpleUpdate(float tpf) {
|
public void simpleUpdate(float tpf) {
|
||||||
Vector3f camDir = cam.getDirection().clone().multLocal(0.6f);
|
camDir.set(cam.getDirection()).multLocal(0.6f);
|
||||||
Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f);
|
camLeft.set(cam.getLeft()).multLocal(0.4f);
|
||||||
walkDirection.set(0, 0, 0);
|
walkDirection.set(0, 0, 0);
|
||||||
if (left) { walkDirection.addLocal(camLeft); }
|
if (left) {
|
||||||
if (right) { walkDirection.addLocal(camLeft.negate()); }
|
walkDirection.addLocal(camLeft);
|
||||||
if (up) { walkDirection.addLocal(camDir); }
|
}
|
||||||
if (down) { walkDirection.addLocal(camDir.negate()); }
|
if (right) {
|
||||||
player.setWalkDirection(walkDirection);
|
walkDirection.addLocal(camLeft.negate());
|
||||||
cam.setLocation(player.getPhysicsLocation());
|
}
|
||||||
}
|
if (up) {
|
||||||
|
walkDirection.addLocal(camDir);
|
||||||
|
}
|
||||||
|
if (down) {
|
||||||
|
walkDirection.addLocal(camDir.negate());
|
||||||
|
}
|
||||||
|
player.setWalkDirection(walkDirection);
|
||||||
|
cam.setLocation(player.getPhysicsLocation());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user