use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestReadWrite method createControls.
/**
* Create the save and load actions and add them to the input listener
*/
private void createControls() {
flyCam.setMoveSpeed(50);
cam.setLocation(new Vector3f(0, 100, 0));
inputManager.addMapping("save", new KeyTrigger(KeyInput.KEY_T));
inputManager.addListener(saveActionListener, "save");
inputManager.addMapping("load", new KeyTrigger(KeyInput.KEY_Y));
inputManager.addListener(loadActionListener, "load");
inputManager.addMapping("clone", new KeyTrigger(KeyInput.KEY_C));
inputManager.addListener(cloneActionListener, "clone");
}
use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class TestLodGeneration method simpleInitApp.
public void simpleInitApp() {
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
rootNode.addLight(dl);
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(0.6f));
rootNode.addLight(al);
// model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
model = (Node) assetManager.loadModel("Models/Jaime/Jaime.j3o");
BoundingBox b = ((BoundingBox) model.getWorldBound());
model.setLocalScale(1.2f / (b.getYExtent() * 2));
// model.setLocalTranslation(0,-(b.getCenter().y - b.getYExtent())* model.getLocalScale().y, 0);
for (Spatial spatial : model.getChildren()) {
if (spatial instanceof Geometry) {
listGeoms.add((Geometry) spatial);
}
}
ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
model.addControl(chaseCam);
chaseCam.setLookAtOffset(b.getCenter());
chaseCam.setDefaultDistance(5);
chaseCam.setMinVerticalRotation(-FastMath.HALF_PI + 0.01f);
chaseCam.setZoomSensitivity(0.5f);
// ch = model.getControl(AnimControl.class).createChannel();
// ch.setAnim("Wave");
SkeletonControl c = model.getControl(SkeletonControl.class);
if (c != null) {
c.setEnabled(false);
}
reductionvalue = 0.80f;
lodLevel = 1;
for (final Geometry geometry : listGeoms) {
LodGenerator lodGenerator = new LodGenerator(geometry);
lodGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue);
geometry.setLodLevel(lodLevel);
}
rootNode.attachChild(model);
flyCam.setEnabled(false);
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
hudText = new BitmapText(guiFont, false);
hudText.setSize(guiFont.getCharSet().getRenderedSize());
hudText.setText(computeNbTri() + " tris");
hudText.setLocalTranslation(cam.getWidth() / 2, hudText.getLineHeight(), 0);
guiNode.attachChild(hudText);
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (isPressed) {
if (name.equals("plus")) {
// lodLevel++;
// for (Geometry geometry : listGeoms) {
// if (geometry.getMesh().getNumLodLevels() <= lodLevel) {
// lodLevel = 0;
// }
// geometry.setLodLevel(lodLevel);
// }
// jaimeText.setText(computeNbTri() + " tris");
reductionvalue += 0.05f;
updateLod();
}
if (name.equals("minus")) {
// lodLevel--;
// for (Geometry geometry : listGeoms) {
// if (lodLevel < 0) {
// lodLevel = geometry.getMesh().getNumLodLevels() - 1;
// }
// geometry.setLodLevel(lodLevel);
// }
// jaimeText.setText(computeNbTri() + " tris");
reductionvalue -= 0.05f;
updateLod();
}
if (name.equals("wireFrame")) {
wireFrame = !wireFrame;
for (Geometry geometry : listGeoms) {
geometry.getMaterial().getAdditionalRenderState().setWireframe(wireFrame);
}
}
}
}
private void updateLod() {
reductionvalue = FastMath.clamp(reductionvalue, 0.0f, 1.0f);
makeLod(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue, 1);
}
}, "plus", "minus", "wireFrame");
inputManager.addMapping("plus", new KeyTrigger(KeyInput.KEY_ADD));
inputManager.addMapping("minus", new KeyTrigger(KeyInput.KEY_SUBTRACT));
inputManager.addMapping("wireFrame", new KeyTrigger(KeyInput.KEY_SPACE));
}
use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class TestLineWidthRenderState method simpleInitApp.
@Override
public void simpleInitApp() {
setDisplayFps(false);
setDisplayStatView(false);
cam.setLocation(new Vector3f(5.5826545f, 3.6192513f, 8.016988f));
cam.setRotation(new Quaternion(-0.04787097f, 0.9463123f, -0.16569641f, -0.27339742f));
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry("Box", b);
mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
mat.getAdditionalRenderState().setWireframe(true);
mat.getAdditionalRenderState().setLineWidth(2);
geom.setMaterial(mat);
rootNode.attachChild(geom);
inputManager.addListener(new ActionListener() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("up") && isPressed) {
mat.getAdditionalRenderState().setLineWidth(mat.getAdditionalRenderState().getLineWidth() + 1);
}
if (name.equals("down") && isPressed) {
mat.getAdditionalRenderState().setLineWidth(Math.max(mat.getAdditionalRenderState().getLineWidth() - 1, 1));
}
}
}, "up", "down");
inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_U));
inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_J));
}
use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class TerrainTest method setupKeys.
private void setupKeys() {
flyCam.setMoveSpeed(50);
inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
inputManager.addListener(actionListener, "wireframe");
inputManager.addMapping("triPlanar", new KeyTrigger(KeyInput.KEY_P));
inputManager.addListener(actionListener, "triPlanar");
}
use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestAdvanced method setupKeys.
private void setupKeys() {
flyCam.setMoveSpeed(50);
inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
inputManager.addListener(actionListener, "wireframe");
inputManager.addMapping("triPlanar", new KeyTrigger(KeyInput.KEY_P));
inputManager.addListener(actionListener, "triPlanar");
inputManager.addMapping("WardIso", new KeyTrigger(KeyInput.KEY_9));
inputManager.addListener(actionListener, "WardIso");
inputManager.addMapping("DetachControl", new KeyTrigger(KeyInput.KEY_0));
inputManager.addListener(actionListener, "DetachControl");
}
Aggregations