Commit 351a2917 authored by Robert Menzel's avatar Robert Menzel

updated Rift SDK handling and support for 360 gamepad on windows

parent 3539d151
......@@ -17,6 +17,9 @@ lib/*
# QT creator:
#
*.user
*.sln
*.vcxproj.filters
*.vcxproj
#
# build files
......
#pragma once
/**
* IMPORTANT: DON'T EXPECT THIS CLASS TO HAVE A FINAL AND STABLE API!
* IMPORTANT: DON'T EXPECT THIS TO HAVE A FINAL AND STABLE API!
*
* This class needs the LibOVR version 0.3.2 or higher to work.
* This needs the LibOVR version 0.4 (or higher, unless the API breaks) to work.
* Headers of this lib need to be placed in the search path.
*
* In addition ACGL_USE_OCULUS_RIFT has to be defined.
*
* IMPORTANT:
* The order of SDK and window initialisation is important:
* 1. call initSDK();
* 2. call createHMD
* 3. create a window and a OpenGL context
* 4. ACGL::init();
* 5. build textures to render into (one for each eye), the size can be getOptimalRenderSizePerEye() or smaller
* 6. build a desription of those textures for the Rift SDK using generateEyeTextureDescription ( <EyeTexture> )
* 7. configureRendering - store the ovrEyeRenderDesc values for later, _renderTagetSize is the size of your Rift window
*
* At runtime:
* * call deactivateHealthWarning when the user presses a button
*
* Each frame:
* 1. beginFrame()
* 2. TODO: camera handling -> generates <poseOfEyes>
* 3. ovrHmd_EndFrame( <HMD> , <poseOfEyes> , (ovrTexture*) <EyeTexture> );
* IMPORTANT: if ovrHmd_EndFrame gets called, don't call any swapBuffers more on your own!
*
* clean up:
* 1. destroyHMD
* 2. shutdownSDK
*
*/
#ifdef ACGL_USE_OCULUS_RIFT
#include <OVR_Version.h>
#if ((OVR_MAJOR_VERSION > 0) || (OVR_MINOR_VERSION >= 4))
#include <ACGL/ACGL.hh>
#include <glm/glm.hpp>
#if ACGL_RIFT_SDK_VERSION >= 40
#include <OVR_CAPI.h>
//class GLFWWindow;
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
#include <GLFW/glfw3.h>
#include <OVR_CAPI_GL.h>
namespace ACGL{
namespace HardwareSupport{
namespace OVR{
// init the SDK once before calling any of the following functions:
bool initSDK();
bool initRiftSDK();
void shutdownRiftSDK();
// shut it down at the end:
void shutdownSDK();
// create a standard Rift, can be replaced with own, more specialized code:
ovrHmd createRift(bool _headTrackingIsRequired = false, bool _headTranslationTrackingIsAllowed = true);
void destroyRift(ovrHmd _hmd);
ovrHmd createHMD(bool _headTrackingIsRequired = false, bool _headTranslationTrackingIsAllowed = true);
void destroyHMD(ovrHmd _hmd);
// SDK gives different sizes per eye, return the max to make things easier:
glm::uvec2 getOptimalRenderSizePerEye(ovrHmd _hmd);
#ifdef ACGL_COMPILE_WITH_GLFW
// the Rift SDK need to know our window, this function hides the window system/OS specifics:
// returns a ovrEyeRenderDesc[2] used by the SDK in _eyeRenderDesc. The returned struct stores the size of the
// textures, so update this if the textures change in size!
// _eyeRenderDesc has to be an array with at least two elements!
void generateEyeTextureDescription(ACGL::OpenGL::SharedTexture2D _leftTexture,
ACGL::OpenGL::SharedTexture2D _rightTexture,
ovrGLTexture _eyeRenderDesc[2]);
// the Rift SDK needs to know our window, this function hides the window system/OS specifics:
// it's limited to OpenGL / no multisampling back buffers, if more flexibility is needed,
// write your own similar function:
// write your own similar function.
// _eyeRenderDesc will be set by this function!
#ifdef ACGL_COMPILE_WITH_GLFW
bool configureRendering(ovrHmd _hmd, ovrEyeRenderDesc _eyeRenderDesc[2], glm::uvec2 _renderTagetSize, GLFWwindow *_window);
#endif
......@@ -47,8 +81,12 @@ namespace HardwareSupport{
// returns true if the warning is still displayed. Can be called multiple times.
bool deactivateHealthWarning(ovrHmd _hmd);
// call at the beginning of a frame:
void beginFrame(ovrHmd _hmd);
// used only for debugging:
void printOVRDistortionCaps(unsigned int _caps);
void printDistortionCaps(unsigned int _caps);
}
}
}
......
......@@ -148,7 +148,7 @@ GamePad::GamePad( int _n )
setAxisMapping( RIGHT_ANALOG_STICK_Y , 3);
setMinAxisSensitivity( 0.05f );
} else if (mJoystickName == "Microsoft X-Box 360 pad") {
} else if (mJoystickName == "Microsoft X-Box 360 pad") { // 360 USB gamepad on Linux
// real buttons:
setButtonMapping( SELECT, 6);
......@@ -179,7 +179,37 @@ GamePad::GamePad( int _n )
setMinAxisSensitivity( 0.2f );
} else {
} else if (mJoystickName == "Microsoft PC-joystick driver") { // 360 USB gamepad on Windows
// real buttons:
setButtonMapping(SELECT, 6);
setButtonMapping(START, 7);
setButtonMapping(RIGHT_PAD_NORTH, 3);
setButtonMapping(RIGHT_PAD_EAST, 1);
setButtonMapping(RIGHT_PAD_SOUTH, 0);
setButtonMapping(RIGHT_PAD_WEST, 2);
setButtonMapping(LEFT_SHOULDER, 4);
setButtonMapping(RIGHT_SHOULDER, 5);
setButtonMapping(LEFT_PAD_NORTH, 10);
setButtonMapping(LEFT_PAD_EAST, 11);
setButtonMapping(LEFT_PAD_SOUTH, 12);
setButtonMapping(LEFT_PAD_WEST, 13);
//setButtonMapping(LEFT_TRIGGER, 2 + mNumberOfButtons); // axis 2
//setButtonMapping(RIGHT_TRIGGER, 5 + mNumberOfButtons); // axis 5
setAxisMapping(LEFT_ANALOG_TRIGGER, 2); mAxesMultiplier[2] = 0.5f; mAxesAdd[2] = 0.5f;
setAxisMapping(RIGHT_ANALOG_TRIGGER, 5); mAxesMultiplier[5] = -0.5f; mAxesAdd[5] = 0.5f;
setAxisMapping(LEFT_ANALOG_STICK_X, 0);
setAxisMapping(LEFT_ANALOG_STICK_Y, 1);
setAxisMapping(RIGHT_ANALOG_STICK_X, 3); mAxesMultiplier[3] = -1.0f;
setAxisMapping(RIGHT_ANALOG_STICK_Y, 4); mAxesMultiplier[4] = -1.0f;
setMinAxisSensitivity(0.2f);
} else {
debug() << "unknown gamepad: " << mJoystickName << " can't configure buttons" << endl;
}
}
......@@ -343,6 +373,9 @@ void GamePad::update()
float sign = ((mAxes[ i ] < 0.0f) && (tmp != 0.0f)) ? -1.0f : 1.0f;
mAxes[ i ] = tmp * sign;
}
//debug().unmute();
//printState();
//debug().mute();
}
void GamePad::printState()
......
This diff is collapsed.
......@@ -57,7 +57,7 @@ void OculusRiftCamera::connectWithRift(ovrHmd _hmd)
// both eyes are equal,
// two texture rendering, NOT side-by-side:
glm::uvec2 renderTargetSizeForOneEye = getOptimalRenderSizePerEye(_hmd);
glm::uvec2 renderTargetSizeForOneEye = OVR::getOptimalRenderSizePerEye(_hmd);
ovrSizei ovrRenderTargetSizeForOneEye;
ovrRenderTargetSizeForOneEye.w = renderTargetSizeForOneEye.x;
ovrRenderTargetSizeForOneEye.h = renderTargetSizeForOneEye.y;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment