chrisdenham / osgopenvrviewer Goto Github PK
View Code? Open in Web Editor NEWAn OpenSceneGraph/OSG viewer for VR devices compatible with OpenVR / SteamVR
License: BSD 3-Clause "New" or "Revised" License
An OpenSceneGraph/OSG viewer for VR devices compatible with OpenVR / SteamVR
License: BSD 3-Clause "New" or "Revised" License
Good day!
I used your app and found some stuttering in rendering to Vive with GTX 970 and latest SteamVR, OpenVR and OSG from git. hellovr_opengl example works fine without missed frames.
Also I found that at line 715 in hellovr_opengl_main.cpp there is some hack with glFinish();
maybe we need to insert this hack to osgopenvrviewer.
You can add as an example ? Add Controllers and Buttons.....
void OpenVRDevice::updatePose()
{
vr::VRCompositor()->SetTrackingSpace(vr::TrackingUniverseSeated);
vr::TrackedDevicePose_t poses[vr::k_unMaxTrackedDeviceCount];
for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; ++i) poses[i].bPoseIsValid = false;
vr::VRCompositor()->WaitGetPoses(poses, vr::k_unMaxTrackedDeviceCount, NULL, 0);
// Not sure why, but the openvr hellovr_opengl example only seems interested in the
// pose transform from the first pose tracking device in the array.
// i.e. this seems to be the only one that is used to affect the view transform matrix.
// So, here we do the same.
m_position.clear();
m_orientation.clear();
for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; i++)
{
const vr::TrackedDevicePose_t& pose = poses[i];
if (pose.bPoseIsValid)
{
if ((m_vrSystem->GetTrackedDeviceClass( i ) != vr::TrackedDeviceClass_HMD ) && (m_vrSystem->GetTrackedDeviceClass( i ) != vr::TrackedDeviceClass_Controller )) continue;
osg::Matrix matrix = convertMatrix34(pose.mDeviceToAbsoluteTracking);
/*
pose.mDeviceToAbsoluteTracking
vr::HmdMatrix34_t
you'll get the position from the [0][3], [1][3] and [2][3] matrix positions.
*/
osg::Vec3 __pos (pose.mDeviceToAbsoluteTracking.m[0][3],pose.mDeviceToAbsoluteTracking.m[1][3],pose.mDeviceToAbsoluteTracking.m[2][3]);
m_position.push_back ( __pos );
osg::Matrix poseTransform = osg::Matrix::inverse(matrix);
//m_position.push_back ( poseTransform.getTrans() * m_worldUnitsPerMetre );
m_orientation.push_back ( poseTransform.getRotate());
}
}
ButtonsAndAnalog.clear();
// Process SteamVR controller state
for (vr::TrackedDeviceIndex_t unDevice = 0; unDevice < vr::k_unMaxTrackedDeviceCount; unDevice++)
{
if (m_vrSystem->GetTrackedDeviceClass( unDevice ) != vr::TrackedDeviceClass_Controller ) continue;
buttons_and_analog temp;
temp.k_EButton_ApplicationMenu=false;
temp.k_EButton_Grip=false;
temp.k_EButton_SteamVR_Touchpad=false;
temp.k_EButton_SteamVR_Trigger=false;
temp.TrackPad_x=0;
temp.TrackPad_y=0;
temp.Joystick_x=0;
temp.Joystick_y=0;
temp.Trigger_x=0;
temp.Trigger_y=0;
vr::VRControllerState_t state;
if (m_vrSystem->GetControllerState(unDevice, &state))
{
if (state.ulButtonPressed & vr::ButtonMaskFromId(vr::k_EButton_ApplicationMenu)) temp.k_EButton_ApplicationMenu = true;
if (state.ulButtonPressed & vr::ButtonMaskFromId(vr::k_EButton_SteamVR_Trigger)) temp.k_EButton_SteamVR_Trigger = true;
if (state.ulButtonPressed & vr::ButtonMaskFromId(vr::k_EButton_Grip)) temp.k_EButton_Grip = true;
if (state.ulButtonTouched & vr::ButtonMaskFromId(vr::k_EButton_SteamVR_Touchpad)) temp.k_EButton_SteamVR_Touchpad = true;
// Convert the axes
for (int j = 0; j < vr::k_unControllerStateAxisCount; j++)
{
vr::ETrackedDeviceProperty prop = (vr::ETrackedDeviceProperty)(vr::Prop_Axis0Type_Int32 + j);
vr::EVRControllerAxisType type = (vr::EVRControllerAxisType)vr::VRSystem()->GetInt32TrackedDeviceProperty(unDevice, prop);
vr::VRControllerAxis_t axis = state.rAxis[j];
if (type == vr::k_eControllerAxis_TrackPad)
{
temp.TrackPad_x = axis.x ;
temp.TrackPad_y = axis.y ;
}
if (type == vr::k_eControllerAxis_Trigger)
{
temp.Trigger_x = axis.x ;
temp.Trigger_y = axis.y ;
}
if (type == vr::k_eControllerAxis_Joystick)
{
temp.Joystick_x = axis.x ;
temp.Joystick_y = axis.y ;
}
}
//
}
ButtonsAndAnalog.push_back(temp);
}
class buttons_and_analog
{
public:
bool k_EButton_ApplicationMenu;
bool k_EButton_SteamVR_Trigger;
bool k_EButton_Grip;
bool k_EButton_SteamVR_Touchpad;
float TrackPad_x;
float TrackPad_y;
float Trigger_x;
float Trigger_y;
float Joystick_x;
float Joystick_y;
};
std::vector osg::Vec3 position() const { return m_position; }
std::vector osg::Quat orientation() const { return m_orientation; }
std::vector <buttons_and_analog> buttonsAndAnalogs() const { return ButtonsAndAnalog; }
Hello Chris,
this is an exciting development.
I am trying to integrate openvrviewer with osgearth viewer ... can you help me in this regard ?
thanks ,
Jai
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.