com.jme3.input.controls.AnalogListener Java Examples

The following examples show how to use com.jme3.input.controls.AnalogListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InputManager.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void invokeAnalogs(int hash, float value, boolean isAxis) {
    ArrayList<Mapping> maps = bindings.get(hash);
    if (maps == null) {
        return;
    }

    if (!isAxis) {
        value *= frameTPF;
    }

    int size = maps.size();
    for (int i = size - 1; i >= 0; i--) {
        Mapping mapping = maps.get(i);
        ArrayList<InputListener> listeners = mapping.listeners;
        int listenerSize = listeners.size();
        for (int j = listenerSize - 1; j >= 0; j--) {
            InputListener listener = listeners.get(j);
            if (listener instanceof AnalogListener) {
                // NOTE: multiply by TPF for any button bindings
                ((AnalogListener) listener).onAnalog(mapping.name, value, frameTPF);
            }
        }
    }
}
 
Example #2
Source File: InputManager.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void invokeAnalogsAndActions(int hash, float value, boolean applyTpf) {
    if (value < axisDeadZone) {
        invokeAnalogs(hash, value, !applyTpf);
        return;
    }

    ArrayList<Mapping> maps = bindings.get(hash);
    if (maps == null) {
        return;
    }

    boolean valueChanged = !axisValues.containsKey(hash);
    if (applyTpf) {
        value *= frameTPF;
    }

    int size = maps.size();
    for (int i = size - 1; i >= 0; i--) {
        Mapping mapping = maps.get(i);
        ArrayList<InputListener> listeners = mapping.listeners;
        int listenerSize = listeners.size();
        for (int j = listenerSize - 1; j >= 0; j--) {
            InputListener listener = listeners.get(j);

            if (listener instanceof ActionListener && valueChanged) {
                ((ActionListener) listener).onAction(mapping.name, true, frameTPF);
            }

            if (listener instanceof AnalogListener) {
                ((AnalogListener) listener).onAnalog(mapping.name, value, frameTPF);
            }

        }
    }
}
 
Example #3
Source File: BloomUI.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public BloomUI(InputManager inputManager, final BloomFilter filter) {

        System.out.println("----------------- Bloom UI Debugger --------------------");
        System.out.println("-- blur Scale : press Y to increase, H to decrease");
        System.out.println("-- exposure Power : press U to increase, J to decrease");
        System.out.println("-- exposure CutOff : press I to increase, K to decrease");
        System.out.println("-- bloom Intensity : press O to increase, P to decrease");
        System.out.println("-------------------------------------------------------");

        inputManager.addMapping("blurScaleUp", new KeyTrigger(KeyInput.KEY_Y));
        inputManager.addMapping("blurScaleDown", new KeyTrigger(KeyInput.KEY_H));
        inputManager.addMapping("exposurePowerUp", new KeyTrigger(KeyInput.KEY_U));
        inputManager.addMapping("exposurePowerDown", new KeyTrigger(KeyInput.KEY_J));
        inputManager.addMapping("exposureCutOffUp", new KeyTrigger(KeyInput.KEY_I));
        inputManager.addMapping("exposureCutOffDown", new KeyTrigger(KeyInput.KEY_K));
        inputManager.addMapping("bloomIntensityUp", new KeyTrigger(KeyInput.KEY_O));
        inputManager.addMapping("bloomIntensityDown", new KeyTrigger(KeyInput.KEY_L));


        AnalogListener anl = new AnalogListener() {

            @Override
            public void onAnalog(String name, float value, float tpf) {
                if (name.equals("blurScaleUp")) {
                    filter.setBlurScale(filter.getBlurScale() + 0.01f);
                    System.out.println("blurScale : " + filter.getBlurScale());
                }
                if (name.equals("blurScaleDown")) {
                    filter.setBlurScale(filter.getBlurScale() - 0.01f);
                    System.out.println("blurScale : " + filter.getBlurScale());
                }
                if (name.equals("exposurePowerUp")) {
                    filter.setExposurePower(filter.getExposurePower() + 0.01f);
                    System.out.println("exposurePower : " + filter.getExposurePower());
                }
                if (name.equals("exposurePowerDown")) {
                    filter.setExposurePower(filter.getExposurePower() - 0.01f);
                    System.out.println("exposurePower : " + filter.getExposurePower());
                }
                if (name.equals("exposureCutOffUp")) {
                    filter.setExposureCutOff(Math.min(1.0f, Math.max(0.0f, filter.getExposureCutOff() + 0.001f)));
                    System.out.println("exposure CutOff : " + filter.getExposureCutOff());
                }
                if (name.equals("exposureCutOffDown")) {
                    filter.setExposureCutOff(Math.min(1.0f, Math.max(0.0f, filter.getExposureCutOff() - 0.001f)));
                    System.out.println("exposure CutOff : " + filter.getExposureCutOff());
                }
                if (name.equals("bloomIntensityUp")) {
                    filter.setBloomIntensity(filter.getBloomIntensity() + 0.01f);
                    System.out.println("bloom Intensity : " + filter.getBloomIntensity());
                }
                if (name.equals("bloomIntensityDown")) {
                    filter.setBloomIntensity(filter.getBloomIntensity() - 0.01f);
                    System.out.println("bloom Intensity : " + filter.getBloomIntensity());
                }


            }
        };

        inputManager.addListener(anl, "blurScaleUp", "blurScaleDown", "exposurePowerUp", "exposurePowerDown",
                "exposureCutOffUp", "exposureCutOffDown", "bloomIntensityUp", "bloomIntensityDown");

    }
 
Example #4
Source File: TestColorApp.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        // Lights
        DirectionalLight sun = new DirectionalLight();
        Vector3f sunPosition = new Vector3f(1, -1, 1);
        sun.setDirection(sunPosition);
        sun.setColor(new ColorRGBA(1f,1f,1f,1f));
        rootNode.addLight(sun);
 
        //DirectionalLightShadowFilter sun_renderer = new DirectionalLightShadowFilter(assetManager, 2048, 4);
        DirectionalLightShadowRenderer sun_renderer = new DirectionalLightShadowRenderer(assetManager, 2048, 1);
        sun_renderer.setLight(sun);
        viewPort.addProcessor(sun_renderer);
        
//        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
//        fpp.addFilter(sun_renderer);
//        viewPort.addProcessor(fpp);
        
        rootNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
 
        // Camera
        viewPort.setBackgroundColor(new ColorRGBA(.6f, .6f, .6f, 1f));
        ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
 
 
        // Objects
        // Ground Object
        final Geometry groundBoxWhite = new Geometry("Box", new Box(7.5f, 7.5f, .25f));
        float[] f = {-FastMath.PI / 2, 3 * FastMath.PI / 2, 0f};
        groundBoxWhite.setLocalRotation(new Quaternion(f));
        groundBoxWhite.move(7.5f, -.75f, 7.5f);
        final Material groundMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        groundMaterial.setColor("Diffuse", new ColorRGBA(.9f, .9f, .9f, .9f));
        groundBoxWhite.setMaterial(groundMaterial);
        groundBoxWhite.addControl(chaseCam);
        rootNode.attachChild(groundBoxWhite);
 
        // Planter
        Geometry planterBox = new Geometry("Box", new Box(.5f, .5f, .5f));
        final Material planterMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        planterMaterial.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
        planterBox.setMaterial(groundMaterial);
        planterBox.setLocalTranslation(10, 0, 9);
        rootNode.attachChild(planterBox);
 
        // Action!
        inputManager.addMapping("on", new KeyTrigger(KeyInput.KEY_Z));
        inputManager.addMapping("off", new KeyTrigger(KeyInput.KEY_X));
 
        inputManager.addListener(new AnalogListener() {
            @Override
            public void onAnalog(String s, float v, float v1) {
                if (s.equals("on")) {
                    groundBoxWhite.setMaterial(planterMaterial);
                }
                if (s.equals("off")) {
                    groundBoxWhite.setMaterial(groundMaterial);
                }
            }
        }, "on", "off");
 
        inputEnabled = true;
    }
 
Example #5
Source File: WaterUI.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public WaterUI(InputManager inputManager, SimpleWaterProcessor proc) {
        processor=proc;


        System.out.println("----------------- SSAO UI Debugger --------------------");
        System.out.println("-- Water transparency : press Y to increase, H to decrease");
        System.out.println("-- Water depth : press U to increase, J to decrease");
//        System.out.println("-- AO scale : press I to increase, K to decrease");
//        System.out.println("-- AO bias : press O to increase, P to decrease");
//        System.out.println("-- Toggle AO on/off : press space bar");
//        System.out.println("-- Use only AO : press Num pad 0");
//        System.out.println("-- Output config declaration : press P");
        System.out.println("-------------------------------------------------------");
    
        inputManager.addMapping("transparencyUp", new KeyTrigger(KeyInput.KEY_Y));
        inputManager.addMapping("transparencyDown", new KeyTrigger(KeyInput.KEY_H));
        inputManager.addMapping("depthUp", new KeyTrigger(KeyInput.KEY_U));
        inputManager.addMapping("depthDown", new KeyTrigger(KeyInput.KEY_J));
//        inputManager.addMapping("scaleUp", new KeyTrigger(KeyInput.KEY_I));
//        inputManager.addMapping("scaleDown", new KeyTrigger(KeyInput.KEY_K));
//        inputManager.addMapping("biasUp", new KeyTrigger(KeyInput.KEY_O));
//        inputManager.addMapping("biasDown", new KeyTrigger(KeyInput.KEY_L));
//        inputManager.addMapping("outputConfig", new KeyTrigger(KeyInput.KEY_P));
//        inputManager.addMapping("toggleUseAO", new KeyTrigger(KeyInput.KEY_SPACE));
//        inputManager.addMapping("toggleUseOnlyAo", new KeyTrigger(KeyInput.KEY_NUMPAD0));
        
//        ActionListener acl = new ActionListener() {
//
//            public void onAction(String name, boolean keyPressed, float tpf) {
//
//                if (name.equals("toggleUseAO") && keyPressed) {
//                    ssaoConfig.setUseAo(!ssaoConfig.isUseAo());
//                    System.out.println("use AO : "+ssaoConfig.isUseAo());
//                }
//                if (name.equals("toggleUseOnlyAo") && keyPressed) {
//                    ssaoConfig.setUseOnlyAo(!ssaoConfig.isUseOnlyAo());
//                    System.out.println("use Only AO : "+ssaoConfig.isUseOnlyAo());
//
//                }
//                if (name.equals("outputConfig") && keyPressed) {
//                    System.out.println("new SSAOConfig("+ssaoConfig.getSampleRadius()+"f,"+ssaoConfig.getIntensity()+"f,"+ssaoConfig.getScale()+"f,"+ssaoConfig.getBias()+"f,"+ssaoConfig.isUseOnlyAo()+","+ssaoConfig.isUseAo()+");");
//                }
//
//            }
//        };

         AnalogListener anl = new AnalogListener() {

            @Override
            public void onAnalog(String name, float value, float tpf) {
                if (name.equals("transparencyUp")) {
                    processor.setWaterTransparency(processor.getWaterTransparency()+0.001f);
                    System.out.println("Water transparency : "+processor.getWaterTransparency());
                }
                if (name.equals("transparencyDown")) {
                    processor.setWaterTransparency(processor.getWaterTransparency()-0.001f);
                    System.out.println("Water transparency : "+processor.getWaterTransparency());
                }
                if (name.equals("depthUp")) {
                    processor.setWaterDepth(processor.getWaterDepth()+0.001f);
                    System.out.println("Water depth : "+processor.getWaterDepth());
                }
                if (name.equals("depthDown")) {
                    processor.setWaterDepth(processor.getWaterDepth()-0.001f);
                    System.out.println("Water depth : "+processor.getWaterDepth());
                }

            }
        };
    //    inputManager.addListener(acl,"toggleUseAO","toggleUseOnlyAo","outputConfig");
        inputManager.addListener(anl, "transparencyUp","transparencyDown","depthUp","depthDown");
     
    }
 
Example #6
Source File: TestTessellationShader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    tessellationMaterial = new Material(getAssetManager(), "Materials/Tess/SimpleTess.j3md");
    tessellationMaterial.setInt("TessellationFactor", tessFactor);
    tessellationMaterial.getAdditionalRenderState().setWireframe(true);
    Quad quad = new Quad(10, 10);
    quad.clearBuffer(VertexBuffer.Type.Index);
    quad.setBuffer(VertexBuffer.Type.Index, 4, BufferUtils.createIntBuffer(0, 1, 2, 3));
    quad.setMode(Mesh.Mode.Patch);
    quad.setPatchVertexCount(4);
    Geometry geometry = new Geometry("tessTest", quad);
    geometry.setMaterial(tessellationMaterial);
    rootNode.attachChild(geometry);

    getInputManager().addMapping("TessUp", new KeyTrigger(KeyInput.KEY_O));
    getInputManager().addMapping("TessDo", new KeyTrigger(KeyInput.KEY_L));
    getInputManager().addListener(new AnalogListener() {
        @Override
        public void onAnalog(String name, float value, float tpf) {
            if(name.equals("TessUp")){
                tessFactor++;
                enqueue(new Callable<Boolean>() {
                    @Override
                    public Boolean call() throws Exception {
                        tessellationMaterial.setInt("TessellationFactor",tessFactor);
                        return true;
                    }
                });
            }
            if(name.equals("TessDo")){
                tessFactor--;
                enqueue(new Callable<Boolean>() {
                    @Override
                    public Boolean call() throws Exception {
                        tessellationMaterial.setInt("TessellationFactor",tessFactor);
                        return true;
                    }
                });
            }
        }
    },"TessUp","TessDo");
}
 
Example #7
Source File: LWJGLOpenVRMouseManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void updateAnalogAsMouse(int inputIndex, AnalogListener mouseListener, String mouseXName, String mouseYName, float tpf) {
    
	if (getVREnvironment() != null){
		if (getVREnvironment().getApplication() != null){
			// got a tracked controller to use as the "mouse"
	        if( getVREnvironment().isInVR() == false || 
	        	getVREnvironment().getVRinput() == null ||
	        	getVREnvironment().getVRinput().isInputDeviceTracking(inputIndex) == false ){
	        	return;
	        }
	        
	        Vector2f tpDelta;
	        // TODO option to use Touch joysticks
	        if( isThumbstickMode() ) {
	            tpDelta = getVREnvironment().getVRinput().getAxis(inputIndex, VRInputType.ViveTrackpadAxis);
	        } else {
	            tpDelta = getVREnvironment().getVRinput().getAxisDeltaSinceLastCall(inputIndex, VRInputType.ViveTrackpadAxis);            
	        }
	        
	        float Xamount = (float)Math.pow(Math.abs(tpDelta.x) * getSpeedSensitivity(), getSpeedAcceleration());
	        float Yamount = (float)Math.pow(Math.abs(tpDelta.y) * getSpeedSensitivity(), getSpeedAcceleration());
	        
	        if( tpDelta.x < 0f ){
	        	Xamount = -Xamount;
	        }
	        
	        if( tpDelta.y < 0f ){
	        	Yamount = -Yamount;
	        }
	        
	        Xamount *= getMouseMoveScale(); 
	        Yamount *= getMouseMoveScale();
	        
	        if( mouseListener != null ) {
	            if( tpDelta.x != 0f && mouseXName != null ) mouseListener.onAnalog(mouseXName, Xamount * 0.2f, tpf);
	            if( tpDelta.y != 0f && mouseYName != null ) mouseListener.onAnalog(mouseYName, Yamount * 0.2f, tpf);            
	        }
	        
	        if( getVREnvironment().getApplication().getInputManager().isCursorVisible() ) {
	            int index = (avgCounter+1) % AVERAGE_AMNT;
	            lastXmv[index] = Xamount * 133f;
	            lastYmv[index] = Yamount * 133f;
	            cursorPos.x -= avg(lastXmv);
	            cursorPos.y -= avg(lastYmv);
	            Vector2f maxsize = getVREnvironment().getVRGUIManager().getCanvasSize();
	            
	            if( cursorPos.x > maxsize.x ){
	            	cursorPos.x = maxsize.x;
	            }
	            
	            if( cursorPos.x < 0f ){
	            	cursorPos.x = 0f;
	            }
	            
	            if( cursorPos.y > maxsize.y ){
	            	cursorPos.y = maxsize.y;
	            }
	            
	            if( cursorPos.y < 0f ){
	            	cursorPos.y = 0f;
	            }
	        }
		} else {
			throw new IllegalStateException("This VR environment is not attached to any application.");
		}
	} else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
  	} 
}
 
Example #8
Source File: OpenVRMouseManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void updateAnalogAsMouse(int inputIndex, AnalogListener mouseListener, String mouseXName, String mouseYName, float tpf) {
    
	if (getVREnvironment() != null){
		if (getVREnvironment().getApplication() != null){
			// got a tracked controller to use as the "mouse"
	        if( getVREnvironment().isInVR() == false || 
	        	getVREnvironment().getVRinput() == null ||
	        	getVREnvironment().getVRinput().isInputDeviceTracking(inputIndex) == false ){
	        	return;
	        }
	        
	        Vector2f tpDelta;
	        // TODO option to use Touch joysticks
	        if( isThumbstickMode() ) {
	            tpDelta = getVREnvironment().getVRinput().getAxis(inputIndex, VRInputType.ViveTrackpadAxis);
	        } else {
	            tpDelta = getVREnvironment().getVRinput().getAxisDeltaSinceLastCall(inputIndex, VRInputType.ViveTrackpadAxis);            
	        }
	        
	        float Xamount = (float)Math.pow(Math.abs(tpDelta.x) * getSpeedSensitivity(), getSpeedAcceleration());
	        float Yamount = (float)Math.pow(Math.abs(tpDelta.y) * getSpeedSensitivity(), getSpeedAcceleration());
	        
	        if( tpDelta.x < 0f ){
	        	Xamount = -Xamount;
	        }
	        
	        if( tpDelta.y < 0f ){
	        	Yamount = -Yamount;
	        }
	        
	        Xamount *= getMouseMoveScale(); 
	        Yamount *= getMouseMoveScale();
	        
	        if( mouseListener != null ) {
	            if( tpDelta.x != 0f && mouseXName != null ) mouseListener.onAnalog(mouseXName, Xamount * 0.2f, tpf);
	            if( tpDelta.y != 0f && mouseYName != null ) mouseListener.onAnalog(mouseYName, Yamount * 0.2f, tpf);            
	        }
	        
	        if( getVREnvironment().getApplication().getInputManager().isCursorVisible() ) {
	            int index = (avgCounter+1) % AVERAGE_AMNT;
	            lastXmv[index] = Xamount * 133f;
	            lastYmv[index] = Yamount * 133f;
	            cursorPos.x -= avg(lastXmv);
	            cursorPos.y -= avg(lastYmv);
	            Vector2f maxsize = getVREnvironment().getVRGUIManager().getCanvasSize();
	            
	            if( cursorPos.x > maxsize.x ){
	            	cursorPos.x = maxsize.x;
	            }
	            
	            if( cursorPos.x < 0f ){
	            	cursorPos.x = 0f;
	            }
	            
	            if( cursorPos.y > maxsize.y ){
	            	cursorPos.y = maxsize.y;
	            }
	            
	            if( cursorPos.y < 0f ){
	            	cursorPos.y = 0f;
	            }
	        }
		} else {
			throw new IllegalStateException("This VR environment is not attached to any application.");
		}
	} else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
  	} 
}
 
Example #9
Source File: OculusMouseManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void updateAnalogAsMouse(int inputIndex, AnalogListener mouseListener, String mouseXName, String mouseYName, float tpf) {
    
	if (getVREnvironment() != null){
		if (getVREnvironment().getApplication() != null){
			// got a tracked controller to use as the "mouse"
	        if( getVREnvironment().isInVR() == false || 
	        	getVREnvironment().getVRinput() == null ||
	        	getVREnvironment().getVRinput().isInputDeviceTracking(inputIndex) == false ){
	        	return;
	        }
	        
	        Vector2f tpDelta;
	        // TODO option to use Touch joysticks
	        if( isThumbstickMode() ) {
	            tpDelta = getVREnvironment().getVRinput().getAxis(inputIndex, VRInputType.OculusThumbstickAxis);
	        } else {
	            tpDelta = getVREnvironment().getVRinput().getAxisDeltaSinceLastCall(inputIndex, VRInputType.OculusThumbstickAxis);            
	        }
	        
	        float Xamount = (float)Math.pow(Math.abs(tpDelta.x) * getSpeedSensitivity(), getSpeedAcceleration());
	        float Yamount = (float)Math.pow(Math.abs(tpDelta.y) * getSpeedSensitivity(), getSpeedAcceleration());
	        
	        if( tpDelta.x < 0f ){
	        	Xamount = -Xamount;
	        }
	        
	        if( tpDelta.y < 0f ){
	        	Yamount = -Yamount;
	        }
	        
	        Xamount *= getMouseMoveScale(); 
	        Yamount *= getMouseMoveScale();
	        
	        if( mouseListener != null ) {
	            if( tpDelta.x != 0f && mouseXName != null ) mouseListener.onAnalog(mouseXName, Xamount * 0.2f, tpf);
	            if( tpDelta.y != 0f && mouseYName != null ) mouseListener.onAnalog(mouseYName, Yamount * 0.2f, tpf);            
	        }
	        
	        if( getVREnvironment().getApplication().getInputManager().isCursorVisible() ) {
	            int index = (avgCounter+1) % AVERAGE_AMNT;
	            lastXmv[index] = Xamount * 133f;
	            lastYmv[index] = Yamount * 133f;
	            cursorPos.x -= avg(lastXmv);
	            cursorPos.y -= avg(lastYmv);
	            Vector2f maxsize = getVREnvironment().getVRGUIManager().getCanvasSize();
	            
	            if( cursorPos.x > maxsize.x ){
	            	cursorPos.x = maxsize.x;
	            }
	            
	            if( cursorPos.x < 0f ){
	            	cursorPos.x = 0f;
	            }
	            
	            if( cursorPos.y > maxsize.y ){
	            	cursorPos.y = maxsize.y;
	            }
	            
	            if( cursorPos.y < 0f ){
	            	cursorPos.y = 0f;
	            }
	        }
		} else {
			throw new IllegalStateException("This VR environment is not attached to any application.");
		}
	} else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
  	} 
}
 
Example #10
Source File: OSVRMouseManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void updateAnalogAsMouse(int inputIndex, AnalogListener mouseListener, String mouseXName, String mouseYName, float tpf) {
    
	if (getVREnvironment() != null){
		if (getVREnvironment().getApplication() != null){
			// got a tracked controller to use as the "mouse"
	        if( getVREnvironment().isInVR() == false || 
	        	getVREnvironment().getVRinput() == null ||
	        	getVREnvironment().getVRinput().isInputDeviceTracking(inputIndex) == false ){
	        	return;
	        }
	        
	        Vector2f tpDelta;
	        // TODO option to use Touch joysticks
	        if( isThumbstickMode() ) {
	            tpDelta = getVREnvironment().getVRinput().getAxis(inputIndex, VRInputType.ViveTrackpadAxis);
	        } else {
	            tpDelta = getVREnvironment().getVRinput().getAxisDeltaSinceLastCall(inputIndex, VRInputType.ViveTrackpadAxis);            
	        }
	        
	        float Xamount = (float)Math.pow(Math.abs(tpDelta.x) * getSpeedSensitivity(), getSpeedAcceleration());
	        float Yamount = (float)Math.pow(Math.abs(tpDelta.y) * getSpeedSensitivity(), getSpeedAcceleration());
	        
	        if( tpDelta.x < 0f ){
	        	Xamount = -Xamount;
	        }
	        
	        if( tpDelta.y < 0f ){
	        	Yamount = -Yamount;
	        }
	        
	        Xamount *= getMouseMoveScale(); 
	        Yamount *= getMouseMoveScale();
	        
	        if( mouseListener != null ) {
	            if( tpDelta.x != 0f && mouseXName != null ) mouseListener.onAnalog(mouseXName, Xamount * 0.2f, tpf);
	            if( tpDelta.y != 0f && mouseYName != null ) mouseListener.onAnalog(mouseYName, Yamount * 0.2f, tpf);            
	        }
	        
	        if( getVREnvironment().getApplication().getInputManager().isCursorVisible() ) {
	            int index = (avgCounter+1) % AVERAGE_AMNT;
	            lastXmv[index] = Xamount * 133f;
	            lastYmv[index] = Yamount * 133f;
	            cursorPos.x -= avg(lastXmv);
	            cursorPos.y -= avg(lastYmv);
	            Vector2f maxsize = getVREnvironment().getVRGUIManager().getCanvasSize();
	            
	            if( cursorPos.x > maxsize.x ){
	            	cursorPos.x = maxsize.x;
	            }
	            
	            if( cursorPos.x < 0f ){
	            	cursorPos.x = 0f;
	            }
	            
	            if( cursorPos.y > maxsize.y ){
	            	cursorPos.y = maxsize.y;
	            }
	            
	            if( cursorPos.y < 0f ){
	            	cursorPos.y = 0f;
	            }
	        }
		} else {
			throw new IllegalStateException("This VR environment is not attached to any application.");
		}
	} else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
  	} 
}
 
Example #11
Source File: BloomUI.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public BloomUI(InputManager inputManager, final BloomFilter filter) {

        System.out.println("----------------- Bloom UI Debugger --------------------");
        System.out.println("-- blur Scale : press Y to increase, H to decrease");
        System.out.println("-- exposure Power : press U to increase, J to decrease");
        System.out.println("-- exposure CutOff : press I to increase, K to decrease");
        System.out.println("-- bloom Intensity : press O to increase, P to decrease");
        System.out.println("-------------------------------------------------------");

        inputManager.addMapping("blurScaleUp", new KeyTrigger(KeyInput.KEY_Y));
        inputManager.addMapping("blurScaleDown", new KeyTrigger(KeyInput.KEY_H));
        inputManager.addMapping("exposurePowerUp", new KeyTrigger(KeyInput.KEY_U));
        inputManager.addMapping("exposurePowerDown", new KeyTrigger(KeyInput.KEY_J));
        inputManager.addMapping("exposureCutOffUp", new KeyTrigger(KeyInput.KEY_I));
        inputManager.addMapping("exposureCutOffDown", new KeyTrigger(KeyInput.KEY_K));
        inputManager.addMapping("bloomIntensityUp", new KeyTrigger(KeyInput.KEY_O));
        inputManager.addMapping("bloomIntensityDown", new KeyTrigger(KeyInput.KEY_L));


        AnalogListener anl = new AnalogListener() {

            public void onAnalog(String name, float value, float tpf) {
                if (name.equals("blurScaleUp")) {
                    filter.setBlurScale(filter.getBlurScale() + 0.01f);
                    System.out.println("blurScale : " + filter.getBlurScale());
                }
                if (name.equals("blurScaleDown")) {
                    filter.setBlurScale(filter.getBlurScale() - 0.01f);
                    System.out.println("blurScale : " + filter.getBlurScale());
                }
                if (name.equals("exposurePowerUp")) {
                    filter.setExposurePower(filter.getExposurePower() + 0.01f);
                    System.out.println("exposurePower : " + filter.getExposurePower());
                }
                if (name.equals("exposurePowerDown")) {
                    filter.setExposurePower(filter.getExposurePower() - 0.01f);
                    System.out.println("exposurePower : " + filter.getExposurePower());
                }
                if (name.equals("exposureCutOffUp")) {
                    filter.setExposureCutOff(Math.min(1.0f, Math.max(0.0f, filter.getExposureCutOff() + 0.001f)));
                    System.out.println("exposure CutOff : " + filter.getExposureCutOff());
                }
                if (name.equals("exposureCutOffDown")) {
                    filter.setExposureCutOff(Math.min(1.0f, Math.max(0.0f, filter.getExposureCutOff() - 0.001f)));
                    System.out.println("exposure CutOff : " + filter.getExposureCutOff());
                }
                if (name.equals("bloomIntensityUp")) {
                    filter.setBloomIntensity(filter.getBloomIntensity() + 0.01f);
                    System.out.println("bloom Intensity : " + filter.getBloomIntensity());
                }
                if (name.equals("bloomIntensityDown")) {
                    filter.setBloomIntensity(filter.getBloomIntensity() - 0.01f);
                    System.out.println("bloom Intensity : " + filter.getBloomIntensity());
                }


            }
        };

        inputManager.addListener(anl, "blurScaleUp", "blurScaleDown", "exposurePowerUp", "exposurePowerDown",
                "exposureCutOffUp", "exposureCutOffDown", "bloomIntensityUp", "bloomIntensityDown");

    }
 
Example #12
Source File: WaterUI.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public WaterUI(InputManager inputManager, SimpleWaterProcessor proc) {
        processor=proc;


        System.out.println("----------------- SSAO UI Debugger --------------------");
        System.out.println("-- Water transparency : press Y to increase, H to decrease");
        System.out.println("-- Water depth : press U to increase, J to decrease");
//        System.out.println("-- AO scale : press I to increase, K to decrease");
//        System.out.println("-- AO bias : press O to increase, P to decrease");
//        System.out.println("-- Toggle AO on/off : press space bar");
//        System.out.println("-- Use only AO : press Num pad 0");
//        System.out.println("-- Output config declaration : press P");
        System.out.println("-------------------------------------------------------");
    
        inputManager.addMapping("transparencyUp", new KeyTrigger(KeyInput.KEY_Y));
        inputManager.addMapping("transparencyDown", new KeyTrigger(KeyInput.KEY_H));
        inputManager.addMapping("depthUp", new KeyTrigger(KeyInput.KEY_U));
        inputManager.addMapping("depthDown", new KeyTrigger(KeyInput.KEY_J));
//        inputManager.addMapping("scaleUp", new KeyTrigger(KeyInput.KEY_I));
//        inputManager.addMapping("scaleDown", new KeyTrigger(KeyInput.KEY_K));
//        inputManager.addMapping("biasUp", new KeyTrigger(KeyInput.KEY_O));
//        inputManager.addMapping("biasDown", new KeyTrigger(KeyInput.KEY_L));
//        inputManager.addMapping("outputConfig", new KeyTrigger(KeyInput.KEY_P));
//        inputManager.addMapping("toggleUseAO", new KeyTrigger(KeyInput.KEY_SPACE));
//        inputManager.addMapping("toggleUseOnlyAo", new KeyTrigger(KeyInput.KEY_NUMPAD0));
        
//        ActionListener acl = new ActionListener() {
//
//            public void onAction(String name, boolean keyPressed, float tpf) {
//
//                if (name.equals("toggleUseAO") && keyPressed) {
//                    ssaoConfig.setUseAo(!ssaoConfig.isUseAo());
//                    System.out.println("use AO : "+ssaoConfig.isUseAo());
//                }
//                if (name.equals("toggleUseOnlyAo") && keyPressed) {
//                    ssaoConfig.setUseOnlyAo(!ssaoConfig.isUseOnlyAo());
//                    System.out.println("use Only AO : "+ssaoConfig.isUseOnlyAo());
//
//                }
//                if (name.equals("outputConfig") && keyPressed) {
//                    System.out.println("new SSAOConfig("+ssaoConfig.getSampleRadius()+"f,"+ssaoConfig.getIntensity()+"f,"+ssaoConfig.getScale()+"f,"+ssaoConfig.getBias()+"f,"+ssaoConfig.isUseOnlyAo()+","+ssaoConfig.isUseAo()+");");
//                }
//
//            }
//        };

         AnalogListener anl = new AnalogListener() {

            public void onAnalog(String name, float value, float tpf) {
                if (name.equals("transparencyUp")) {
                    processor.setWaterTransparency(processor.getWaterTransparency()+0.001f);
                    System.out.println("Water transparency : "+processor.getWaterTransparency());
                }
                if (name.equals("transparencyDown")) {
                    processor.setWaterTransparency(processor.getWaterTransparency()-0.001f);
                    System.out.println("Water transparency : "+processor.getWaterTransparency());
                }
                if (name.equals("depthUp")) {
                    processor.setWaterDepth(processor.getWaterDepth()+0.001f);
                    System.out.println("Water depth : "+processor.getWaterDepth());
                }
                if (name.equals("depthDown")) {
                    processor.setWaterDepth(processor.getWaterDepth()-0.001f);
                    System.out.println("Water depth : "+processor.getWaterDepth());
                }

            }
        };
    //    inputManager.addListener(acl,"toggleUseAO","toggleUseOnlyAo","outputConfig");
        inputManager.addListener(anl, "transparencyUp","transparencyDown","depthUp","depthDown");
     
    }
 
Example #13
Source File: VRMouseManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Update analog controller as it was a mouse controller.
 * @param inputIndex the index of the controller attached to the VR system.
 * @param mouseListener the JMonkey mouse listener to trigger.
 * @param mouseXName the mouseX identifier.
 * @param mouseYName the mouseY identifier
 * @param tpf the time per frame.
 */
public void updateAnalogAsMouse(int inputIndex, AnalogListener mouseListener, String mouseXName, String mouseYName, float tpf);