use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class VRMouseManager method updateAnalogAsMouse.
/**
* 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) {
if (environment != null) {
if (environment.getApplication() != null) {
// got a tracked controller to use as the "mouse"
if (environment.isInVR() == false || environment.getVRinput() == null || environment.getVRinput().isInputDeviceTracking(inputIndex) == false) {
return;
}
Vector2f tpDelta;
if (thumbstickMode) {
tpDelta = environment.getVRinput().getAxis(inputIndex, VRInputType.ViveTrackpadAxis);
} else {
tpDelta = environment.getVRinput().getAxisDeltaSinceLastCall(inputIndex, VRInputType.ViveTrackpadAxis);
}
float Xamount = (float) Math.pow(Math.abs(tpDelta.x) * sensitivity, acceleration);
float Yamount = (float) Math.pow(Math.abs(tpDelta.y) * sensitivity, acceleration);
if (tpDelta.x < 0f) {
Xamount = -Xamount;
}
if (tpDelta.y < 0f) {
Yamount = -Yamount;
}
Xamount *= moveScale;
Yamount *= moveScale;
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 (environment.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 = environment.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.");
}
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOSVR method prepareCameraSize.
/**
* Prepare the size of the given {@link Camera camera} to adapt it to the underlying rendering context.
* @param cam the {@link Camera camera} to prepare.
* @param xMult the camera width multiplier.
*/
private void prepareCameraSize(Camera cam, float xMult) {
if (environment != null) {
if (environment.getApplication() != null) {
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
Vector2f size = new Vector2f();
VRAPI vrhmd = environment.getVRHardware();
if (vrhmd == null) {
size.x = 1280f;
size.y = 720f;
} else {
vrhmd.getRenderSize(size);
}
if (size.x < environment.getApplication().getContext().getSettings().getWidth()) {
size.x = environment.getApplication().getContext().getSettings().getWidth();
}
if (size.y < environment.getApplication().getContext().getSettings().getHeight()) {
size.y = environment.getApplication().getContext().getSettings().getHeight();
}
if (environment.isInstanceRendering()) {
size.x *= 2f;
}
// other adjustments
size.x *= xMult;
size.x *= resMult;
size.y *= resMult;
if (cam.getWidth() != size.x || cam.getHeight() != size.y) {
cam.resize((int) size.x, (int) size.y, false);
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOSVR method initialize.
/**
* Initialize the VR view manager.
*/
public void initialize() {
logger.config("Initializing VR view manager.");
if (environment != null) {
initTextureSubmitStructs();
setupCamerasAndViews();
setupVRScene();
moveScreenProcessingToEyes();
if (environment.hasTraditionalGUIOverlay()) {
environment.getVRMouseManager().initialize();
// update the pose to position the gui correctly on start
update(0f);
environment.getVRGUIManager().positionGui();
}
if (environment.getApplication() != null) {
// if we are OSVR, our primary mirror window needs to be the same size as the render manager's output...
if (environment.getVRHardware() instanceof OSVR) {
int origWidth = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getWidth();
int origHeight = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getHeight();
long window = ((LwjglWindow) environment.getApplication().getContext()).getWindowHandle();
Vector2f windowSize = new Vector2f();
((OSVR) environment.getVRHardware()).getRenderSize(windowSize);
windowSize.x = Math.max(windowSize.x * 2f, leftCamera.getWidth());
org.lwjgl.glfw.GLFW.glfwSetWindowSize(window, (int) windowSize.x, (int) windowSize.y);
environment.getApplication().getContext().getSettings().setResolution((int) windowSize.x, (int) windowSize.y);
if (environment.getApplication().getRenderManager() != null) {
environment.getApplication().getRenderManager().notifyReshape((int) windowSize.x, (int) windowSize.y);
}
org.lwjgl.glfw.GLFW.glfwSetWindowPos(window, origWidth - (int) windowSize.x, 32);
org.lwjgl.glfw.GLFW.glfwFocusWindow(window);
org.lwjgl.glfw.GLFW.glfwSetCursorPos(window, origWidth / 2.0, origHeight / 2.0);
logger.config("Initialized VR view manager [SUCCESS]");
} else {
throw new IllegalStateException("Underlying VR hardware should be " + OSVR.class.getSimpleName());
}
} 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.");
}
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOpenVR method prepareCameraSize.
/**
* Prepare the size of the given {@link Camera camera} to adapt it to the underlying rendering context.
* @param cam the {@link Camera camera} to prepare.
* @param xMult the camera width multiplier.
*/
private void prepareCameraSize(Camera cam, float xMult) {
if (environment != null) {
if (environment.getApplication() != null) {
Vector2f size = new Vector2f();
VRAPI vrhmd = environment.getVRHardware();
if (vrhmd == null) {
size.x = 1280f;
size.y = 720f;
} else {
vrhmd.getRenderSize(size);
}
if (size.x < environment.getApplication().getContext().getSettings().getWidth()) {
size.x = environment.getApplication().getContext().getSettings().getWidth();
}
if (size.y < environment.getApplication().getContext().getSettings().getHeight()) {
size.y = environment.getApplication().getContext().getSettings().getHeight();
}
if (environment.isInstanceRendering()) {
size.x *= 2f;
}
// other adjustments
size.x *= xMult;
size.x *= getResolutionMuliplier();
size.y *= getResolutionMuliplier();
if (cam.getWidth() != size.x || cam.getHeight() != size.y) {
cam.resize((int) size.x, (int) size.y, false);
}
} 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.");
}
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class DirectionalLightShadowRendererVR method read.
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = (InputCapsule) im.getCapsule(this);
lambda = ic.readFloat("lambda", 0.65f);
zFarOverride = ic.readInt("zFarOverride", 0);
light = (DirectionalLight) ic.readSavable("light", null);
fadeInfo = (Vector2f) ic.readSavable("fadeInfo", null);
fadeLength = ic.readFloat("fadeLength", 0f);
init(nbShadowMaps, (int) shadowMapSize);
}
Aggregations