use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class TestSoftParticles method simpleInitApp.
@Override
public void simpleInitApp() {
cam.setLocation(new Vector3f(-7.2221026f, 4.1183004f, 7.759811f));
cam.setRotation(new Quaternion(0.06152846f, 0.91236454f, -0.1492115f, 0.37621948f));
flyCam.setMoveSpeed(10);
// -------- floor
Box b = new Box(10, 0.1f, 10);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Gray);
mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
geom.setMaterial(mat);
rootNode.attachChild(geom);
Box b2 = new Box(1, 1, 1);
Geometry geom2 = new Geometry("Box", b2);
Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat2.setColor("Color", ColorRGBA.DarkGray);
geom2.setMaterial(mat2);
rootNode.attachChild(geom2);
geom2.setLocalScale(0.1f, 0.2f, 1);
fpp = new FilterPostProcessor(assetManager);
tbf = new TranslucentBucketFilter(true);
fpp.addFilter(tbf);
int samples = context.getSettings().getSamples();
if (samples > 0) {
fpp.setNumSamples(samples);
}
viewPort.addProcessor(fpp);
particleNode = new Node("particleNode");
rootNode.attachChild(particleNode);
createParticles();
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (isPressed && name.equals("toggle")) {
// tbf.setEnabled(!tbf.isEnabled());
softParticles = !softParticles;
if (softParticles) {
viewPort.addProcessor(fpp);
} else {
viewPort.removeProcessor(fpp);
}
}
}
}, "toggle");
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
// emit again
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (isPressed && name.equals("refire")) {
//fpp.removeFilter(tbf); // <-- add back in to fix
particleNode.detachAllChildren();
createParticles();
//fpp.addFilter(tbf);
}
}
}, "refire");
inputManager.addMapping("refire", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
}
use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class CubeField method Keys.
/**
* Sets up the keyboard bindings
*/
private void Keys() {
inputManager.addMapping("START", new KeyTrigger(KeyInput.KEY_RETURN));
inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_LEFT));
inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_RIGHT));
inputManager.addListener(this, "START", "Left", "Right");
}
use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class TestBitmapFont method simpleInitApp.
@Override
public void simpleInitApp() {
inputManager.addMapping("WordWrap", new KeyTrigger(KeyInput.KEY_TAB));
inputManager.addListener(keyListener, "WordWrap");
inputManager.addRawInputListener(textListener);
BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
txt = new BitmapText(fnt, false);
txt.setBox(new Rectangle(0, 0, settings.getWidth(), settings.getHeight()));
txt.setSize(fnt.getPreferredSize() * 2f);
txt.setText(txtB);
txt.setLocalTranslation(0, txt.getHeight(), 0);
guiNode.attachChild(txt);
txt2 = new BitmapText(fnt, false);
txt2.setSize(fnt.getPreferredSize() * 1.2f);
txt2.setText("Text without restriction. \nText without restriction. Text without restriction. Text without restriction");
txt2.setLocalTranslation(0, txt2.getHeight(), 0);
guiNode.attachChild(txt2);
txt3 = new BitmapText(fnt, false);
txt3.setBox(new Rectangle(0, 0, settings.getWidth(), 0));
txt3.setText("Press Tab to toggle word-wrap. type text and enter to input text");
txt3.setLocalTranslation(0, settings.getHeight() / 2, 0);
guiNode.attachChild(txt3);
}
use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class TestWalkingChar method setupKeys.
private void setupKeys() {
inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
inputManager.addListener(this, "wireframe");
inputManager.addMapping("CharLeft", new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping("CharRight", new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping("CharUp", new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("CharDown", new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping("CharSpace", new KeyTrigger(KeyInput.KEY_RETURN));
inputManager.addMapping("CharShoot", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(this, "CharLeft");
inputManager.addListener(this, "CharRight");
inputManager.addListener(this, "CharUp");
inputManager.addListener(this, "CharDown");
inputManager.addListener(this, "CharSpace");
inputManager.addListener(this, "CharShoot");
}
use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class TestManyLightsSingle method simpleInitApp.
@Override
public void simpleInitApp() {
renderManager.setPreferredLightMode(lm);
renderManager.setSinglePassLightBatchSize(6);
flyCam.setMoveSpeed(10);
Node scene = (Node) assetManager.loadModel("Scenes/ManyLights/Main.scene");
rootNode.attachChild(scene);
Node n = (Node) rootNode.getChild(0);
final LightList lightList = n.getWorldLightList();
final Geometry g = (Geometry) n.getChild("Grid-geom-1");
g.getMaterial().setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
/* A colored lit cube. Needs light source! */
Box boxMesh = new Box(1f, 1f, 1f);
final Geometry boxGeo = new Geometry("Colored Box", boxMesh);
Material boxMat = g.getMaterial().clone();
boxMat.clearParam("DiffuseMap");
boxMat.setBoolean("UseMaterialColors", true);
boxMat.setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
boxMat.setColor("Diffuse", ColorRGBA.Blue);
boxGeo.setMaterial(boxMat);
final Node cubeNodes = new Node();
n.attachChild(cubeNodes);
int nb = 0;
for (Light light : lightList) {
nb++;
PointLight p = (PointLight) light;
if (nb > 60) {
n.removeLight(light);
} else {
LightNode ln = new LightNode("l", light);
n.attachChild(ln);
ln.setLocalTranslation(p.getPosition());
int rand = FastMath.nextRandomInt(0, 3);
switch(rand) {
case 0:
light.setColor(ColorRGBA.Red);
// ln.addControl(new MoveControl(5f));
break;
case 1:
light.setColor(ColorRGBA.Yellow);
// ln.addControl(new MoveControl(5f));
break;
case 2:
light.setColor(ColorRGBA.Green);
//ln.addControl(new MoveControl(-5f));
break;
case 3:
light.setColor(ColorRGBA.Orange);
//ln.addControl(new MoveControl(-5f));
break;
}
}
Geometry b = boxGeo.clone(false);
cubeNodes.attachChild(b);
b.setLocalTranslation(p.getPosition().x, 2, p.getPosition().z);
}
// cam.setLocation(new Vector3f(3.1893547f, 17.977385f, 30.8378f));
// cam.setRotation(new Quaternion(0.14317635f, 0.82302624f, -0.23777823f, 0.49557027f));
cam.setLocation(new Vector3f(-1.8901939f, 29.34097f, 73.07533f));
cam.setRotation(new Quaternion(0.0021000702f, 0.971012f, -0.23886925f, 0.008527749f));
BasicProfilerState profiler = new BasicProfilerState(true);
profiler.setGraphScale(1000f);
// getStateManager().attach(profiler);
// guiNode.setCullHint(CullHint.Always);
flyCam.setDragToRotate(true);
flyCam.setMoveSpeed(50);
final MaterialDebugAppState debug = new MaterialDebugAppState();
stateManager.attach(debug);
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("toggle") && isPressed) {
if (lm == TechniqueDef.LightMode.SinglePass) {
lm = TechniqueDef.LightMode.MultiPass;
helloText.setText("(Multi pass)");
} else {
lm = TechniqueDef.LightMode.SinglePass;
helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
}
renderManager.setPreferredLightMode(lm);
reloadScene(g, boxGeo, cubeNodes);
}
if (name.equals("lightsUp") && isPressed) {
renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() + 1);
helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
}
if (name.equals("lightsDown") && isPressed) {
renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() - 1);
helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
}
if (name.equals("toggleOnOff") && isPressed) {
for (final Light light : lightList) {
if (light instanceof AmbientLight) {
continue;
}
light.setEnabled(!light.isEnabled());
}
}
}
}, "toggle", "lightsUp", "lightsDown", "toggleOnOff");
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping("lightsUp", new KeyTrigger(KeyInput.KEY_UP));
inputManager.addMapping("lightsDown", new KeyTrigger(KeyInput.KEY_DOWN));
inputManager.addMapping("toggleOnOff", new KeyTrigger(KeyInput.KEY_L));
SpotLight spot = new SpotLight();
spot.setDirection(new Vector3f(-1f, -1f, -1f).normalizeLocal());
spot.setColor(ColorRGBA.Blue.mult(5));
spot.setSpotOuterAngle(FastMath.DEG_TO_RAD * 20);
spot.setSpotInnerAngle(FastMath.DEG_TO_RAD * 5);
spot.setPosition(new Vector3f(10, 10, 20));
rootNode.addLight(spot);
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, 1));
rootNode.addLight(dl);
AmbientLight al = new AmbientLight();
al.setColor(new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
rootNode.addLight(al);
/**
* Write text on the screen (HUD)
*/
guiNode.detachAllChildren();
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
helloText = new BitmapText(guiFont, false);
helloText.setSize(guiFont.getCharSet().getRenderedSize());
helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
guiNode.attachChild(helloText);
}
Aggregations