@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()); }
private void addCharacter(PhysicsCharacter node) { if (physicsCharacters.containsKey(node.getObjectId())) { logger.log(Level.WARNING, "Character {0} already exists in PhysicsSpace, cannot add.", node); return; } physicsCharacters.put(node.getObjectId(), node); logger.log( Level.FINE, "Adding character {0} to physics space.", Long.toHexString(node.getObjectId())); addCharacterObject(physicsSpaceId, node.getObjectId()); addAction(physicsSpaceId, node.getControllerId()); // dynamicsWorld.addCollisionObject(node.getObjectId(), // CollisionFilterGroups.CHARACTER_FILTER, (short) (CollisionFilterGroups.STATIC_FILTER | // CollisionFilterGroups.DEFAULT_FILTER)); // dynamicsWorld.addAction(node.getControllerId()); }
private void removeCharacter(PhysicsCharacter node) { if (!physicsCharacters.containsKey(node.getObjectId())) { logger.log( Level.WARNING, "Character {0} does not exist in PhysicsSpace, cannot remove.", node); return; } physicsCharacters.remove(node.getObjectId()); logger.log( Level.FINE, "Removing character {0} from physics space.", Long.toHexString(node.getObjectId())); removeAction(physicsSpaceId, node.getControllerId()); removeCharacterObject(physicsSpaceId, node.getObjectId()); // dynamicsWorld.removeAction(node.getControllerId()); // dynamicsWorld.removeCollisionObject(node.getObjectId()); }
public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); flyCam.setMoveSpeed(100); setupKeys(); this.cam.setFrustumFar(2000); DirectionalLight dl = new DirectionalLight(); dl.setColor(ColorRGBA.White.clone().multLocal(2)); dl.setDirection(new Vector3f(-1, -1, -1).normalize()); rootNode.addLight(dl); AmbientLight am = new AmbientLight(); am.setColor(ColorRGBA.White.mult(2)); rootNode.addLight(am); // load the level from zip or http zip if (useHttp) { assetManager.registerLocator( "http://jmonkeyengine.googlecode.com/files/quake3level.zip", HttpZipLocator.class.getName()); } else { assetManager.registerLocator("basic.scene", ZipLocator.class.getName()); } // create the geometry and attach it MaterialList matList = (MaterialList) assetManager.loadAsset("Scene.material"); OgreMeshKey key = new OgreMeshKey("main.meshxml", matList); gameLevel = (Node) assetManager.loadAsset(key); gameLevel.setLocalScale(0.1f); // add a physics control, it will generate a MeshCollisionShape based on the gameLevel gameLevel.addControl(new RigidBodyControl(0)); player = new PhysicsCharacter(new SphereCollisionShape(5), .01f); player.setJumpSpeed(20); player.setFallSpeed(30); player.setGravity(30); player.setPhysicsLocation(new Vector3f(60, 10, -60)); rootNode.attachChild(gameLevel); getPhysicsSpace().addAll(gameLevel); getPhysicsSpace().add(player); }
public void onAction(String binding, boolean value, float tpf) { if (binding.equals("Lefts")) { if (value) left = true; else left = false; } else if (binding.equals("Rights")) { if (value) right = true; else right = false; } else if (binding.equals("Ups")) { if (value) up = true; else up = false; } else if (binding.equals("Downs")) { if (value) down = true; else down = false; } else if (binding.equals("Space")) { player.jump(); } }