use of com.jme3.input.controls.ActionListener in project jmonkeyengine by jMonkeyEngine.
the class TestCinematic method initInputs.
private void initInputs() {
inputManager.addMapping("togglePause", new KeyTrigger(keyInput.KEY_RETURN));
inputManager.addMapping("navFwd", new KeyTrigger(keyInput.KEY_RIGHT));
inputManager.addMapping("navBack", new KeyTrigger(keyInput.KEY_LEFT));
ActionListener acl = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("togglePause") && keyPressed) {
if (cinematic.getPlayState() == PlayState.Playing) {
cinematic.pause();
time = cinematic.getTime();
} else {
cinematic.play();
}
}
if (cinematic.getPlayState() != PlayState.Playing) {
if (name.equals("navFwd") && keyPressed) {
time += 0.25;
FastMath.clamp(time, 0, cinematic.getInitialDuration());
cinematic.setTime(time);
}
if (name.equals("navBack") && keyPressed) {
time -= 0.25;
FastMath.clamp(time, 0, cinematic.getInitialDuration());
cinematic.setTime(time);
}
}
}
};
inputManager.addListener(acl, "togglePause", "navFwd", "navBack");
}
use of com.jme3.input.controls.ActionListener in project jmonkeyengine by jMonkeyEngine.
the class TestBatchNodeTower method simpleInitApp.
@Override
public void simpleInitApp() {
timer = new NanoTimer();
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
// bulletAppState.setEnabled(false);
stateManager.attach(bulletAppState);
bullet = new Sphere(32, 32, 0.4f, true, false);
bullet.setTextureMode(TextureMode.Projected);
bulletCollisionShape = new SphereCollisionShape(0.4f);
brick = new Box(brickWidth, brickHeight, brickDepth);
brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
//bulletAppState.getPhysicsSpace().enableDebug(assetManager);
initMaterial();
initTower();
initFloor();
initCrossHairs();
this.cam.setLocation(new Vector3f(0, 25f, 8f));
cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
cam.setFrustumFar(80);
inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(actionListener, "shoot");
rootNode.setShadowMode(ShadowMode.Off);
batchNode.batch();
batchNode.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(batchNode);
shadowRenderer = new DirectionalLightShadowFilter(assetManager, 1024, 2);
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
shadowRenderer.setLight(dl);
shadowRenderer.setLambda(0.55f);
shadowRenderer.setShadowIntensity(0.6f);
shadowRenderer.setShadowCompareMode(CompareMode.Hardware);
shadowRenderer.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(shadowRenderer);
viewPort.addProcessor(fpp);
}
use of com.jme3.input.controls.ActionListener in project jmonkeyengine by jMonkeyEngine.
the class TestIK method simpleInitApp.
@Override
public void simpleInitApp() {
super.simpleInitApp();
final KinematicRagdollControl ikControl = model.getControl(KinematicRagdollControl.class);
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("stop") && isPressed) {
ikControl.setEnabled(!ikControl.isEnabled());
ikControl.setIKMode();
}
if (name.equals("one") && isPressed) {
//ragdoll.setKinematicMode();
targetPoint = model.getWorldTranslation().add(new Vector3f(0, 2, 4));
targetNode.setLocalTranslation(targetPoint);
ikControl.setIKTarget(ikControl.getBone("Hand.L"), targetPoint, 2);
ikControl.setIKMode();
}
if (name.equals("two") && isPressed) {
//ragdoll.setKinematicMode();
targetPoint = model.getWorldTranslation().add(new Vector3f(-3, 3, 0));
targetNode.setLocalTranslation(targetPoint);
ikControl.setIKTarget(ikControl.getBone("Hand.R"), targetPoint, 3);
ikControl.setIKMode();
}
}
}, "one", "two");
inputManager.addMapping("one", new KeyTrigger(KeyInput.KEY_1));
inputManager.addMapping("two", new KeyTrigger(KeyInput.KEY_2));
inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_H));
}
use of com.jme3.input.controls.ActionListener in project jmonkeyengine by jMonkeyEngine.
the class SimpleApplication method initialize.
@Override
public void initialize() {
super.initialize();
// Several things rely on having this
guiFont = loadGuiFont();
guiNode.setQueueBucket(Bucket.Gui);
guiNode.setCullHint(CullHint.Never);
viewPort.attachScene(rootNode);
guiViewPort.attachScene(guiNode);
if (inputManager != null) {
// the app state is added.
if (stateManager.getState(FlyCamAppState.class) != null) {
flyCam = new FlyByCamera(cam);
// odd to set this here but it did it before
flyCam.setMoveSpeed(1f);
stateManager.getState(FlyCamAppState.class).setCamera(flyCam);
}
if (context.getType() == Type.Display) {
inputManager.addMapping(INPUT_MAPPING_EXIT, new KeyTrigger(KeyInput.KEY_ESCAPE));
}
if (stateManager.getState(StatsAppState.class) != null) {
inputManager.addMapping(INPUT_MAPPING_HIDE_STATS, new KeyTrigger(KeyInput.KEY_F5));
inputManager.addListener(actionListener, INPUT_MAPPING_HIDE_STATS);
}
inputManager.addListener(actionListener, INPUT_MAPPING_EXIT);
}
if (stateManager.getState(StatsAppState.class) != null) {
// Some of the tests rely on having access to fpsText
// for quick display. Maybe a different way would be better.
stateManager.getState(StatsAppState.class).setFont(guiFont);
fpsText = stateManager.getState(StatsAppState.class).getFpsText();
}
// call user code
simpleInitApp();
}
use of com.jme3.input.controls.ActionListener in project jmonkeyengine by jMonkeyEngine.
the class MaterialDebugAppState method bind.
private void bind(final Binding binding) {
if (binding.getTrigger() instanceof FileChangedTrigger) {
FileChangedTrigger t = (FileChangedTrigger) binding.getTrigger();
List<Binding> b = fileTriggers.get(t);
if (b == null) {
t.init();
b = new ArrayList<Binding>();
fileTriggers.put(t, b);
}
b.add(binding);
} else {
final String actionName = binding.getActionName();
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (actionName.equals(name) && isPressed) {
//reloading the material
binding.reload();
}
}
}, actionName);
inputManager.addMapping(actionName, binding.getTrigger());
}
}
Aggregations