use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class HelloAnimation method initKeys.
/** Custom Keybindings: Mapping a named action to a key input. */
private void initKeys() {
inputManager.addMapping("Walk", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(actionListener, "Walk");
}
use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class TestBoneRagdoll method simpleInitApp.
public void simpleInitApp() {
initCrossHairs();
initMaterial();
cam.setLocation(new Vector3f(0.26924422f, 6.646658f, 22.265987f));
cam.setRotation(new Quaternion(-2.302544E-4f, 0.99302495f, -0.117888905f, -0.0019395084f));
bulletAppState = new BulletAppState();
bulletAppState.setEnabled(true);
stateManager.attach(bulletAppState);
bullet = new Sphere(32, 32, 1.0f, true, false);
bullet.setTextureMode(TextureMode.Projected);
bulletCollisionShape = new SphereCollisionShape(1.0f);
// bulletAppState.getPhysicsSpace().enableDebug(assetManager);
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
setupLight();
model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
// model.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_X));
//debug view
AnimControl control = model.getControl(AnimControl.class);
SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton", control.getSkeleton());
Material mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
mat2.getAdditionalRenderState().setWireframe(true);
mat2.setColor("Color", ColorRGBA.Green);
mat2.getAdditionalRenderState().setDepthTest(false);
skeletonDebug.setMaterial(mat2);
skeletonDebug.setLocalTranslation(model.getLocalTranslation());
//Note: PhysicsRagdollControl is still TODO, constructor will change
ragdoll = new KinematicRagdollControl(0.5f);
setupSinbad(ragdoll);
ragdoll.addCollisionListener(this);
model.addControl(ragdoll);
float eighth_pi = FastMath.PI * 0.125f;
ragdoll.setJointLimit("Waist", eighth_pi, eighth_pi, eighth_pi, eighth_pi, eighth_pi, eighth_pi);
ragdoll.setJointLimit("Chest", eighth_pi, eighth_pi, 0, 0, eighth_pi, eighth_pi);
//Oto's head is almost rigid
// ragdoll.setJointLimit("head", 0, 0, eighth_pi, -eighth_pi, 0, 0);
getPhysicsSpace().add(ragdoll);
speed = 1.3f;
rootNode.attachChild(model);
// rootNode.attachChild(skeletonDebug);
flyCam.setMoveSpeed(50);
animChannel = control.createChannel();
animChannel.setAnim("Dance");
control.addListener(this);
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("toggle") && isPressed) {
Vector3f v = new Vector3f();
v.set(model.getLocalTranslation());
v.y = 0;
model.setLocalTranslation(v);
Quaternion q = new Quaternion();
float[] angles = new float[3];
model.getLocalRotation().toAngles(angles);
q.fromAngleAxis(angles[1], Vector3f.UNIT_Y);
model.setLocalRotation(q);
if (angles[0] < 0) {
animChannel.setAnim("StandUpBack");
ragdoll.blendToKinematicMode(0.5f);
} else {
animChannel.setAnim("StandUpFront");
ragdoll.blendToKinematicMode(0.5f);
}
}
if (name.equals("bullet+") && isPressed) {
bulletSize += 0.1f;
}
if (name.equals("bullet-") && isPressed) {
bulletSize -= 0.1f;
}
if (name.equals("stop") && isPressed) {
ragdoll.setEnabled(!ragdoll.isEnabled());
ragdoll.setRagdollMode();
}
if (name.equals("shoot") && !isPressed) {
Geometry bulletg = new Geometry("bullet", bullet);
bulletg.setMaterial(matBullet);
bulletg.setLocalTranslation(cam.getLocation());
bulletg.setLocalScale(bulletSize);
bulletCollisionShape = new SphereCollisionShape(bulletSize);
RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, bulletSize * 10);
bulletNode.setCcdMotionThreshold(0.001f);
bulletNode.setLinearVelocity(cam.getDirection().mult(80));
bulletg.addControl(bulletNode);
rootNode.attachChild(bulletg);
getPhysicsSpace().add(bulletNode);
}
if (name.equals("boom") && !isPressed) {
Geometry bulletg = new Geometry("bullet", bullet);
bulletg.setMaterial(matBullet);
bulletg.setLocalTranslation(cam.getLocation());
bulletg.setLocalScale(bulletSize);
bulletCollisionShape = new SphereCollisionShape(bulletSize);
BombControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1);
bulletNode.setForceFactor(8);
bulletNode.setExplosionRadius(20);
bulletNode.setCcdMotionThreshold(0.001f);
bulletNode.setLinearVelocity(cam.getDirection().mult(180));
bulletg.addControl(bulletNode);
rootNode.attachChild(bulletg);
getPhysicsSpace().add(bulletNode);
}
}
}, "toggle", "shoot", "stop", "bullet+", "bullet-", "boom");
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addMapping("boom", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_H));
inputManager.addMapping("bullet-", new KeyTrigger(KeyInput.KEY_COMMA));
inputManager.addMapping("bullet+", new KeyTrigger(KeyInput.KEY_PERIOD));
}
use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class TestBrickWall method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);
bullet = new Sphere(32, 32, 0.4f, true, false);
bullet.setTextureMode(TextureMode.Projected);
bulletCollisionShape = new SphereCollisionShape(0.4f);
brick = new Box(bLength, bHeight, bWidth);
brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
initMaterial();
initWall();
initFloor();
initCrossHairs();
this.cam.setLocation(new Vector3f(0, 6f, 6f));
cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
cam.setFrustumFar(15);
inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(actionListener, "shoot");
inputManager.addMapping("gc", new KeyTrigger(KeyInput.KEY_X));
inputManager.addListener(actionListener, "gc");
rootNode.setShadowMode(ShadowMode.Off);
bsr = new BasicShadowRenderer(assetManager, 256);
bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
viewPort.addProcessor(bsr);
}
use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class TestAttachDriver method setupKeys.
private void setupKeys() {
inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_H));
inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_K));
inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_U));
inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_J));
inputManager.addMapping("Space", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping("Reset", new KeyTrigger(KeyInput.KEY_RETURN));
inputManager.addListener(this, "Lefts");
inputManager.addListener(this, "Rights");
inputManager.addListener(this, "Ups");
inputManager.addListener(this, "Downs");
inputManager.addListener(this, "Space");
inputManager.addListener(this, "Reset");
}
use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.
the class TestAttachGhostObject method setupKeys.
private void setupKeys() {
inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_H));
inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_K));
inputManager.addMapping("Space", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(this, "Lefts", "Rights", "Space");
}
Aggregations