Oculus VR DK2 Support

- Updated to work with 0.5.x SDK
- Uses Oculus Rendering rather than PostFX
- Stereo rendering refactored so more rendering info is grabbed from the DisplayDevice
- Implements an Offscreen Canvas for in-game gui with oculus
- Message dialogs and metrics display can now go to the OffScreen Canvas (if oculus demo is setup correctly)
This commit is contained in:
James Urquhart 2015-05-06 23:07:48 +01:00
parent b3170bcddf
commit 3a457749ec
56 changed files with 2654 additions and 1426 deletions

View file

@ -62,11 +62,12 @@ function GuiCanvas::checkCursor(%this)
if ((%control.noCursor $= "") || !%control.noCursor)
{
showCursor();
return;
return true;
}
}
// If we get here, every control requested a hidden cursor, so we oblige.
hideCursor();
return false;
}
//---------------------------------------------------------------------------------------------

View file

@ -243,9 +243,9 @@ function metrics( %expr )
if( %metricsExpr !$= "" )
{
Canvas.pushDialog( FrameOverlayGui, 1000 );
$GameCanvas.pushDialog( FrameOverlayGui, 1000 );
TextOverlayControl.setValue( %metricsExpr );
}
else
Canvas.popDialog(FrameOverlayGui);
$GameCanvas.popDialog(FrameOverlayGui);
}

View file

@ -24,12 +24,103 @@
if(!isFunction(isOculusVRDeviceActive))
return;
function setupOculusActionMaps()
{
if (isObject(OculusWarningMap))
return;
new ActionMap(OculusWarningMap);
new ActionMap(OculusCanvasMap);
OculusWarningMap.bind(keyboard, space, dismissOculusVRWarnings);
OculusCanvasMap.bind( mouse, xaxis, oculusYaw );
OculusCanvasMap.bind( mouse, yaxis, oculusPitch );
OculusCanvasMap.bind( mouse, button0, oculusClick );
}
function oculusYaw(%val)
{
OculusCanvas.cursorNudge(%val * 0.10, 0);
}
function oculusPitch(%val)
{
OculusCanvas.cursorNudge(0, %val * 0.10);
}
function oculusClick(%active)
{
OculusCanvas.cursorClick(0, %active);
}
function GuiOffscreenCanvas::checkCursor(%this)
{
%count = %this.getCount();
for(%i = 0; %i < %count; %i++)
{
%control = %this.getObject(%i);
if ((%control.noCursor $= "") || !%control.noCursor)
{
%this.cursorOn();
return true;
}
}
// If we get here, every control requested a hidden cursor, so we oblige.
%this.cursorOff();
return false;
}
function GuiOffscreenCanvas::pushDialog(%this, %ctrl, %layer, %center)
{
Parent::pushDialog(%this, %ctrl, %layer, %center);
%cursorVisible = %this.checkCursor();
if (%cursorVisible)
{
echo("OffscreenCanvas visible");
OculusCanvasMap.pop();
OculusCanvasMap.push();
}
else
{
echo("OffscreenCanvas not visible");
OculusCanvasMap.pop();
}
}
function GuiOffscreenCanvas::popDialog(%this, %ctrl)
{
Parent::popDialog(%this, %ctrl);
%cursorVisible = %this.checkCursor();
if (%cursorVisible)
{
echo("OffscreenCanvas visible");
OculusCanvasMap.pop();
OculusCanvasMap.push();
}
else
{
echo("OffscreenCanvas not visible");
OculusCanvasMap.pop();
}
}
//-----------------------------------------------------------------------------
function oculusSensorMetricsCallback()
{
return " | OVR Sensor 0 |" @
" rot: " @ getOVRSensorEulerRotation(0);
return ovrDumpMetrics(0);
}
//-----------------------------------------------------------------------------
function onOculusStatusUpdate(%status)
{
$LastOculusTrackingState = %status;
}
//-----------------------------------------------------------------------------
@ -60,23 +151,34 @@ function enableOculusVRDisplay(%gameConnection, %trueStereoRendering)
{
setOVRHMDAsGameConnectionDisplayDevice(%gameConnection);
PlayGui.renderStyle = "stereo side by side";
if(%trueStereoRendering)
setOptimalOVRCanvasSize(Canvas);
if (!isObject(OculusCanvas))
{
if($pref::OculusVR::UseChromaticAberrationCorrection)
{
OVRBarrelDistortionChromaPostFX.isEnabled = true;
}
else
{
OVRBarrelDistortionPostFX.isEnabled = true;
}
new GuiOffscreenCanvas(OculusCanvas) {
targetSize = "512 512";
targetName = "oculusCanvas";
dynamicTarget = true;
};
}
else
if (!isObject(OculusVROverlay))
{
OVRBarrelDistortionMonoPostFX.isEnabled = true;
exec("./oculusVROverlay.gui");
}
OculusCanvas.setContent(OculusVROverlay);
OculusCanvas.setCursor(DefaultCursor);
PlayGui.setStereoGui(OculusCanvas);
OculusCanvas.setCursorPos("128 128");
OculusCanvas.cursorOff();
$GameCanvas = OculusCanvas;
%ext = Canvas.getExtent();
$OculusMouseScaleX = 512.0 / 1920.0;
$OculusMouseScaleY = 512.0 / 1060.0;
//$gfx::wireframe = true;
// Reset all sensors
ovrResetAllSensors();
}
@ -85,11 +187,15 @@ function enableOculusVRDisplay(%gameConnection, %trueStereoRendering)
// and barrel distortion for the Rift.
function disableOculusVRDisplay(%gameConnection)
{
%gameConnection.clearDisplayDevice();
OculusCanvas.popDialog();
OculusWarningMap.pop();
$GameCanvas = Canvas;
if (isObject(gameConnection))
{
%gameConnection.clearDisplayDevice();
}
PlayGui.renderStyle = "standard";
OVRBarrelDistortionPostFX.isEnabled = false;
OVRBarrelDistortionChromaPostFX.isEnabled = false;
OVRBarrelDistortionMonoPostFX.isEnabled = false;
}
// Helper function to set the standard Rift control scheme. You could place
@ -97,7 +203,7 @@ function disableOculusVRDisplay(%gameConnection)
// you call enableOculusVRDisplay().
function setStandardOculusVRControlScheme(%gameConnection)
{
if(isOVRHMDSimulated(0))
if($OculusVR::SimulateInput)
{
// We are simulating a HMD so allow the mouse and gamepad to control
// both yaw and pitch.
@ -131,3 +237,12 @@ function resetOculusVRSensors()
{
ovrResetAllSensors();
}
function dismissOculusVRWarnings(%value)
{
//if (%value)
//{
ovrDismissWarnings();
OculusWarningMap.pop();
//}
}

View file

@ -0,0 +1,19 @@
//--- OBJECT WRITE BEGIN ---
%guiContent = singleton GuiControl(OculusVROverlay) {
canSaveDynamicFields = "0";
Enabled = "1";
isContainer = "1";
Profile = "GuiContentProfile";
HorizSizing = "width";
VertSizing = "height";
Position = "0 0";
Extent = "512 512";
MinExtent = "8 8";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiToolTipProfile";
hovertime = "1000";
useVariable = "0";
tile = "0";
};
//--- OBJECT WRITE END ---

View file

@ -20,6 +20,7 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
$GameCanvas = 0;
// Cleanup Dialog created by 'core'
if( isObject( MessagePopupDlg ) )
@ -76,7 +77,7 @@ new SFXProfile(messageBoxBeep)
//---------------------------------------------------------------------------------------------
function messageCallback(%dlg, %callback)
{
Canvas.popDialog(%dlg);
$GameCanvas.popDialog(%dlg);
eval(%callback);
}
@ -89,7 +90,7 @@ function IOCallback(%dlg, %callback)
%callback = strreplace(%callback, "#", %text);
eval(%callback);
Canvas.popDialog(%dlg);
$GameCanvas.popDialog(%dlg);
}
//---------------------------------------------------------------------------------------------
@ -134,7 +135,7 @@ function MBSetText(%text, %frame, %msg)
function MessageBoxOK(%title, %message, %callback)
{
MBOKFrame.text = %title;
Canvas.pushDialog(MessageBoxOKDlg);
$GameCanvas.pushDialog(MessageBoxOKDlg);
MBSetText(MBOKText, MBOKFrame, %message);
MessageBoxOKDlg.callback = %callback;
}
@ -147,7 +148,7 @@ function MessageBoxOKDlg::onSleep( %this )
function MessageBoxOKCancel(%title, %message, %callback, %cancelCallback)
{
MBOKCancelFrame.text = %title;
Canvas.pushDialog(MessageBoxOKCancelDlg);
$GameCanvas.pushDialog(MessageBoxOKCancelDlg);
MBSetText(MBOKCancelText, MBOKCancelFrame, %message);
MessageBoxOKCancelDlg.callback = %callback;
MessageBoxOKCancelDlg.cancelCallback = %cancelCallback;
@ -169,7 +170,7 @@ function MessageBoxOKCancelDetails(%title, %message, %details, %callback, %cance
MBOKCancelDetailsFrame.setText( %title );
Canvas.pushDialog(MessageBoxOKCancelDetailsDlg);
$GameCanvas.pushDialog(MessageBoxOKCancelDetailsDlg);
MBSetText(MBOKCancelDetailsText, MBOKCancelDetailsFrame, %message);
MBOKCancelDetailsInfoText.setText(%details);
@ -233,7 +234,7 @@ function MessageBoxYesNo(%title, %message, %yesCallback, %noCallback)
{
MBYesNoFrame.text = %title;
MessageBoxYesNoDlg.profile = "GuiOverlayProfile";
Canvas.pushDialog(MessageBoxYesNoDlg);
$GameCanvas.pushDialog(MessageBoxYesNoDlg);
MBSetText(MBYesNoText, MBYesNoFrame, %message);
MessageBoxYesNoDlg.yesCallBack = %yesCallback;
MessageBoxYesNoDlg.noCallback = %noCallBack;
@ -243,7 +244,7 @@ function MessageBoxYesNoCancel(%title, %message, %yesCallback, %noCallback, %can
{
MBYesNoCancelFrame.text = %title;
MessageBoxYesNoDlg.profile = "GuiOverlayProfile";
Canvas.pushDialog(MessageBoxYesNoCancelDlg);
$GameCanvas.pushDialog(MessageBoxYesNoCancelDlg);
MBSetText(MBYesNoCancelText, MBYesNoCancelFrame, %message);
MessageBoxYesNoCancelDlg.yesCallBack = %yesCallback;
MessageBoxYesNoCancelDlg.noCallback = %noCallBack;
@ -264,7 +265,7 @@ function MessagePopup(%title, %message, %delay)
{
// Currently two lines max.
MessagePopFrame.setText(%title);
Canvas.pushDialog(MessagePopupDlg);
$GameCanvas.pushDialog(MessagePopupDlg);
MBSetText(MessagePopText, MessagePopFrame, %message);
if (%delay !$= "")
schedule(%delay, 0, CloseMessagePopup);
@ -279,7 +280,7 @@ function MessagePopup(%title, %message, %delay)
function IODropdown(%title, %message, %simgroup, %callback, %cancelCallback)
{
IODropdownFrame.text = %title;
Canvas.pushDialog(IODropdownDlg);
$GameCanvas.pushDialog(IODropdownDlg);
MBSetText(IODropdownText, IODropdownFrame, %message);
if(isObject(%simgroup))
@ -305,7 +306,7 @@ function IODropdownDlg::onSleep( %this )
function CloseMessagePopup()
{
Canvas.popDialog(MessagePopupDlg);
$GameCanvas.popDialog(MessagePopupDlg);
}
//---------------------------------------------------------------------------------------------

View file

@ -43,6 +43,8 @@ function createCanvas(%windowTitle)
displayWindow = $platform !$= "windows";
};
$GameCanvas = %foo;
// Set the window title
if (isObject(Canvas))
Canvas.setWindowTitle(getEngineName() @ " - " @ $appName);

View file

@ -42,6 +42,8 @@ function createCanvas(%windowTitle)
{
displayWindow = $platform !$= "windows";
};
$GameCanvas = %foo;
// Set the window title
if (isObject(Canvas))