use of com.jme3.input.InputManager 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.InputManager in project jmonkeyengine by jMonkeyEngine.
the class ScreenshotAppState method initialize.
@Override
public void initialize(AppStateManager stateManager, Application app) {
if (!super.isInitialized()) {
InputManager inputManager = app.getInputManager();
inputManager.addMapping("ScreenShot", new KeyTrigger(KeyInput.KEY_SYSRQ));
inputManager.addListener(this, "ScreenShot");
List<ViewPort> vps = app.getRenderManager().getPostViews();
ViewPort last = vps.get(vps.size() - 1);
last.addProcessor(this);
if (shotName == null) {
shotName = app.getClass().getSimpleName();
}
}
super.initialize(stateManager, app);
}
use of com.jme3.input.InputManager in project jmonkeyengine by jMonkeyEngine.
the class TestCameraMotionPath method simpleInitApp.
@Override
public void simpleInitApp() {
createScene();
cam.setLocation(new Vector3f(8.4399185f, 11.189463f, 14.267577f));
camNode = new CameraNode("Motion cam", cam);
camNode.setControlDir(ControlDirection.SpatialToCamera);
camNode.setEnabled(false);
path = new MotionPath();
path.setCycle(true);
path.addWayPoint(new Vector3f(20, 3, 0));
path.addWayPoint(new Vector3f(0, 3, 20));
path.addWayPoint(new Vector3f(-20, 3, 0));
path.addWayPoint(new Vector3f(0, 3, -20));
path.setCurveTension(0.83f);
path.enableDebugShape(assetManager, rootNode);
cameraMotionControl = new MotionEvent(camNode, path);
cameraMotionControl.setLoopMode(LoopMode.Loop);
//cameraMotionControl.setDuration(15f);
cameraMotionControl.setLookAt(teapot.getWorldTranslation(), Vector3f.UNIT_Y);
cameraMotionControl.setDirectionType(MotionEvent.Direction.LookAt);
rootNode.attachChild(camNode);
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
final BitmapText wayPointsText = new BitmapText(guiFont, false);
wayPointsText.setSize(guiFont.getCharSet().getRenderedSize());
guiNode.attachChild(wayPointsText);
path.addListener(new MotionPathListener() {
public void onWayPointReach(MotionEvent control, int wayPointIndex) {
if (path.getNbWayPoints() == wayPointIndex + 1) {
wayPointsText.setText(control.getSpatial().getName() + " Finish!!! ");
} else {
wayPointsText.setText(control.getSpatial().getName() + " Reached way point " + wayPointIndex);
}
wayPointsText.setLocalTranslation((cam.getWidth() - wayPointsText.getLineWidth()) / 2, cam.getHeight(), 0);
}
});
flyCam.setEnabled(false);
chaser = new ChaseCamera(cam, teapot);
chaser.registerWithInput(inputManager);
chaser.setSmoothMotion(true);
chaser.setMaxDistance(50);
chaser.setDefaultDistance(50);
initInputs();
}
use of com.jme3.input.InputManager in project jmonkeyengine by jMonkeyEngine.
the class TestCinematic method simpleInitApp.
@Override
public void simpleInitApp() {
//just some text
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(getAssetManager(), getInputManager(), getAudioRenderer(), getGuiViewPort());
Nifty nifty;
nifty = niftyDisplay.getNifty();
nifty.fromXmlWithoutStartScreen("Interface/Nifty/CinematicTest.xml");
getGuiViewPort().addProcessor(niftyDisplay);
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
final BitmapText text = new BitmapText(guiFont, false);
text.setSize(guiFont.getCharSet().getRenderedSize());
text.setText("Press enter to play/pause cinematic");
text.setLocalTranslation((cam.getWidth() - text.getLineWidth()) / 2, cam.getHeight(), 0);
guiNode.attachChild(text);
createScene();
cinematic = new Cinematic(rootNode, 20);
stateManager.attach(cinematic);
createCameraMotion();
//creating spatial animation for the teapot
AnimationFactory factory = new AnimationFactory(20, "teapotAnim");
factory.addTimeTranslation(0, new Vector3f(10, 0, 10));
factory.addTimeTranslation(20, new Vector3f(10, 0, -10));
factory.addTimeScale(10, new Vector3f(4, 4, 4));
factory.addTimeScale(20, new Vector3f(1, 1, 1));
factory.addTimeRotationAngles(20, 0, 4 * FastMath.TWO_PI, 0);
AnimControl control = new AnimControl();
control.addAnim(factory.buildAnimation());
teapot.addControl(control);
//fade in
cinematic.addCinematicEvent(0, new FadeEvent(true));
// cinematic.activateCamera(0, "aroundCam");
cinematic.addCinematicEvent(0, new AnimationEvent(teapot, "teapotAnim", LoopMode.DontLoop));
cinematic.addCinematicEvent(0, cameraMotionEvent);
cinematic.addCinematicEvent(0, new SoundEvent("Sound/Environment/Nature.ogg", LoopMode.Loop));
cinematic.addCinematicEvent(3f, new SoundEvent("Sound/Effects/kick.wav"));
cinematic.addCinematicEvent(3, new SubtitleTrack(nifty, "start", 3, "jMonkey engine really kicks A..."));
cinematic.addCinematicEvent(5.1f, new SoundEvent("Sound/Effects/Beep.ogg", 1));
cinematic.addCinematicEvent(2, new AnimationEvent(model, "Walk", LoopMode.Loop));
cinematic.activateCamera(0, "topView");
// cinematic.activateCamera(10, "aroundCam");
//fade out
cinematic.addCinematicEvent(19, new FadeEvent(false));
// cinematic.addCinematicEvent(19, new AbstractCinematicEvent() {
//
// @Override
// public void onPlay() {
// fade.setDuration(1f / cinematic.getSpeed());
// fade.fadeOut();
//
// }
//
// @Override
// public void onUpdate(float tpf) {
// }
//
// @Override
// public void onStop() {
// }
//
// @Override
// public void onPause() {
// }
// });
cinematic.addListener(new CinematicEventListener() {
public void onPlay(CinematicEvent cinematic) {
chaseCam.setEnabled(false);
System.out.println("play");
}
public void onPause(CinematicEvent cinematic) {
System.out.println("pause");
}
public void onStop(CinematicEvent cinematic) {
chaseCam.setEnabled(true);
fade.setValue(1);
System.out.println("stop");
}
});
//cinematic.setSpeed(2);
flyCam.setEnabled(false);
chaseCam = new ChaseCamera(cam, model, inputManager);
initInputs();
}
use of com.jme3.input.InputManager in project jmonkeyengine by jMonkeyEngine.
the class TestPointDirectionalAndSpotLightShadows method simpleInitApp.
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(10);
cam.setLocation(new Vector3f(0.040581334f, 1.7745866f, 6.155161f));
cam.setRotation(new Quaternion(4.3868728E-5f, 0.9999293f, -0.011230096f, 0.0039059948f));
Node scene = (Node) assetManager.loadModel("Models/Test/CornellBox.j3o");
scene.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
rootNode.attachChild(scene);
rootNode.getChild("Cube").setShadowMode(RenderQueue.ShadowMode.Receive);
lightNode = (Node) rootNode.getChild("Lamp");
Geometry lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
//Geometry lightMdl = new Geometry("Light", new Box(.1f,.1f,.1f));
lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
lightMdl.setShadowMode(RenderQueue.ShadowMode.Off);
lightNode.attachChild(lightMdl);
//lightMdl.setLocalTranslation(lightNode.getLocalTranslation());
Geometry box = new Geometry("box", new Box(0.2f, 0.2f, 0.2f));
//Geometry lightMdl = new Geometry("Light", new Box(.1f,.1f,.1f));
box.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
box.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
rootNode.attachChild(box);
box.setLocalTranslation(-1f, 0.5f, -2);
((PointLight) scene.getLocalLightList().get(0)).setColor(ColorRGBA.Red);
plsr = new PointLightShadowRenderer(assetManager, SHADOWMAP_SIZE);
plsr.setLight((PointLight) scene.getLocalLightList().get(0));
plsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
plsf = new PointLightShadowFilter(assetManager, SHADOWMAP_SIZE);
plsf.setLight((PointLight) scene.getLocalLightList().get(0));
plsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
plsf.setEnabled(useFilter);
//DIRECTIONAL LIGHT
DirectionalLight directionalLight = new DirectionalLight();
rootNode.addLight(directionalLight);
directionalLight.setColor(ColorRGBA.Blue);
directionalLight.setDirection(new Vector3f(-1f, -.2f, 0f));
dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE * 2, 4);
dlsr.setLight(directionalLight);
dlsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
dlsf = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE * 2, 4);
dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
dlsf.setLight(directionalLight);
dlsf.setEnabled(useFilter);
//SPOT LIGHT
spotLight = new SpotLight();
spotLight.setDirection(new Vector3f(1f, -1f, 0f));
spotLight.setPosition(new Vector3f(-1f, 3f, 0f));
spotLight.setSpotOuterAngle(0.5f);
spotLight.setColor(ColorRGBA.Green);
Sphere sphere = new Sphere(8, 8, .1f);
Geometry sphereGeometry = new Geometry("Sphere", sphere);
sphereGeometry.setLocalTranslation(-1f, 3f, 0f);
sphereGeometry.setMaterial(assetManager.loadMaterial("Common/Materials/WhiteColor.j3m"));
rootNode.attachChild(sphereGeometry);
rootNode.addLight(spotLight);
slsr = new SpotLightShadowRenderer(assetManager, SHADOWMAP_SIZE);
slsr.setLight(spotLight);
slsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
slsf = new SpotLightShadowFilter(assetManager, SHADOWMAP_SIZE);
slsf.setLight(spotLight);
slsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
slsf.setEnabled(useFilter);
if (!useFilter)
viewPort.addProcessor(slsr);
if (!useFilter)
viewPort.addProcessor(plsr);
if (!useFilter)
viewPort.addProcessor(dlsr);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(plsf);
fpp.addFilter(dlsf);
fpp.addFilter(slsf);
viewPort.addProcessor(fpp);
ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, plsr, plsf, guiNode, inputManager, viewPort);
ShadowTestUIManager uiManPls = new ShadowTestUIManager(assetManager, plsr, plsf, guiNode, inputManager, viewPort);
ShadowTestUIManager uiManDls = new ShadowTestUIManager(assetManager, dlsr, dlsf, guiNode, inputManager, viewPort);
ShadowTestUIManager uiManSls = new ShadowTestUIManager(assetManager, slsr, slsf, guiNode, inputManager, viewPort);
}
Aggregations