private void setupKeyBindings() { KeyBindingManager.getKeyBindingManager().set("g", KeyInput.KEY_G); sheepDebugText = Text.createDefaultTextLabel("Text", "hest"); sheepDebugText.setRenderQueueMode(Renderer.QUEUE_ORTHO); sheepDebugText.setLightCombineMode(Spatial.LightCombineMode.Off); sheepDebugText.setLocalTranslation(new Vector3f(0, 20, 1)); statNode.attachChild(sheepDebugText); }
/* (non-Javadoc) * @see com.jme.input.action.MouseInputAction#performAction(float) */ public void performAction(InputActionEvent evt) { shotTime += evt.getTime(); if (MouseInput.get().isButtonDown(0) && shotTime > 0.1f) { shotTime = 0; Ray ray = new Ray( camera.getLocation(), camera.getDirection()); // camera direction is already normalized PickResults results = new BoundingPickResults(); results.setCheckDistance(true); scene.findPick(ray, results); hits += results.getNumber(); hitItems = ""; if (results.getNumber() > 0) { for (int i = 0; i < results.getNumber(); i++) { hitItems += results.getPickData(i).getTargetMesh().getName() + " " + results.getPickData(i).getDistance(); if (i != results.getNumber() - 1) { hitItems += ", "; } } } shots++; results.clear(); text.print("Hits: " + hits + " Shots: " + shots + " : " + hitItems); } }
protected void simpleUpdate() { float interpolation = timer.getTimePerFrame(); if (KeyBindingManager.getKeyBindingManager().isValidCommand("g", false)) { detachLandscape(); buildLandscape(); attachLandscape(); buildPlanting(); // update render state after replacing landscape rootNode.updateRenderState(); } // We don't want the chase camera to go below the world, so always keep // it 7 units above the level. World.SurfacePoint surfacePoint = world.getSurfacePointAt(cam.getLocation()); if (cam.getLocation().y < (surfacePoint.getHeight() + 7)) { cam.getLocation().y = (surfacePoint.getHeight() + 7); } for (int i = 0; i < sheep.length; i++) { sheep[i].update(interpolation); } collisionHandling(); // Move sheep a bit closer to each other for (int i = 0; i < sheep.length; i++) { for (int j = (i + 1); j < sheep.length; j++) { Vector3f dir = sheep[j] .getBody() .getLocalTranslation() .subtract(sheep[i].getBody().getLocalTranslation()); sheep[j].getBody().getLocalTranslation().subtractLocal(dir.mult(0.01f)); sheep[i].getBody().getLocalTranslation().addLocal(dir.mult(0.01f)); } } sky.getLocalTranslation().set(cam.getLocation()); cam.update(); // Because we are changing the scene (moving the skybox and player) we need to update // the graph. rootNode.updateGeometricState(interpolation, true); scene.updateGeometricState(interpolation, true); // update audio system gameAudioSystem.updateAudio(); // sheepDebugText.print(sheep[0].toString()); }
/** * Create a line of text. * * @param string displayed text * @return Text */ protected Text createText(final String string) { return Text.createDefaultTextLabel("text", string); }
protected void simpleInitGame() { // Setup camera cam.setFrustumPerspective( 55.0f, (float) display.getWidth() / (float) display.getHeight(), 1, 1000); // Setup lights PointLight light = new PointLight(); light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f)); light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f)); light.setLocation(new Vector3f(0, 30, 0)); light.setEnabled(true); lightState.attach(light); // Add dummy objects to rootNode rootNode.attachChild(createObjects()); try { MaxToJme C1 = new MaxToJme(); ByteArrayOutputStream BO = new ByteArrayOutputStream(); URL maxFile = TestMaxJmeWrite.class.getClassLoader().getResource("jmetest/data/model/Character.3DS"); C1.convert(new BufferedInputStream(maxFile.openStream()), BO); Node r = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray())); r.setLocalScale(.1f); if (r.getChild(0).getControllers().size() != 0) r.getChild(0).getController(0).setSpeed(20); Quaternion temp = new Quaternion(); temp.fromAngleAxis(FastMath.PI / 2, new Vector3f(-1, 0, 0)); r.setLocalRotation(temp); r.setLocalTranslation(new Vector3f(0, 3, 0)); rootNode.attachChild(r); } catch (IOException e) { logger.log(Level.SEVERE, "Error loading max file", e); } // Setup renderpasses RenderPass rootPass = new RenderPass(); rootPass.add(rootNode); pManager.add(rootPass); sketchRenderPass = new SketchRenderPass(cam, 2); if (!sketchRenderPass.isSupported()) { Text t = new Text("Text", "GLSL Not supported on this computer."); t.setRenderQueueMode(Renderer.QUEUE_ORTHO); t.setLightCombineMode(LightState.OFF); t.setLocalTranslation(new Vector3f(0, 20, 0)); fpsNode.attachChild(t); } else { sketchRenderPass.add(rootNode); pManager.add(sketchRenderPass); } if (!sketchRenderPass.isSupported()) { Text t = new Text("Text", "GLSL Not supported on this computer."); t.setRenderQueueMode(Renderer.QUEUE_ORTHO); t.setLightCombineMode(LightState.OFF); t.setLocalTranslation(new Vector3f(0, 20, 0)); fpsNode.attachChild(t); } RenderPass fpsPass = new RenderPass(); fpsPass.add(fpsNode); pManager.add(fpsPass); // Initialize keybindings KeyBindingManager.getKeyBindingManager().set("1", KeyInput.KEY_1); KeyBindingManager.getKeyBindingManager().set("2", KeyInput.KEY_2); KeyBindingManager.getKeyBindingManager().set("3", KeyInput.KEY_3); KeyBindingManager.getKeyBindingManager().set("4", KeyInput.KEY_4); KeyBindingManager.getKeyBindingManager().set("5", KeyInput.KEY_5); KeyBindingManager.getKeyBindingManager().set("6", KeyInput.KEY_6); KeyBindingManager.getKeyBindingManager().set("7", KeyInput.KEY_7); KeyBindingManager.getKeyBindingManager().set("8", KeyInput.KEY_8); KeyBindingManager.getKeyBindingManager().set("9", KeyInput.KEY_9); KeyBindingManager.getKeyBindingManager().set("0", KeyInput.KEY_0); KeyBindingManager.getKeyBindingManager().set("y", KeyInput.KEY_Y); KeyBindingManager.getKeyBindingManager().set("h", KeyInput.KEY_H); KeyBindingManager.getKeyBindingManager().set("shot", KeyInput.KEY_F4); }