Java Code Examples for com.jme3.input.controls.AnalogListener#onAnalog()
The following examples show how to use
com.jme3.input.controls.AnalogListener#onAnalog() .
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: LWJGLOpenVRMouseManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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 2
Source File: OpenVRMouseManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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 3
Source File: OculusMouseManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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 4
Source File: OSVRMouseManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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."); } }