123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- // Only load these functions if an Oculus VR device is present
- 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 ovrDumpMetrics(0);
- }
- //-----------------------------------------------------------------------------
- function onOculusStatusUpdate(%status)
- {
- $LastOculusTrackingState = %status;
- }
- //-----------------------------------------------------------------------------
- // Call this function from createCanvas() to have the Canvas attach itself
- // to the Rift's display. The Canvas' window will still open on the primary
- // display if that is different from the Rift, but it will move to the Rift
- // when it goes full screen. If the Rift is not connected then nothing
- // will happen.
- function pointCanvasToOculusVRDisplay()
- {
- $pref::Video::displayOutputDevice = getOVRHMDDisplayDeviceName(0);
- }
- //-----------------------------------------------------------------------------
- // Call this function from GameConnection::initialControlSet() just before
- // your "Canvas.setContent(PlayGui);" call, or at any time you wish to switch
- // to a side-by-side rendering and the appropriate barrel distortion. This
- // will turn on side-by-side rendering and tell the GameConnection to use the
- // Rift as its display device.
- // Parameters:
- // %gameConnection - The client GameConnection instance
- // %trueStereoRendering - If true will enable stereo rendering with an eye
- // offset for each viewport. This will render each frame twice. If false
- // then a pseudo stereo rendering is done with only a single render per frame.
- function enableOculusVRDisplay(%gameConnection, %trueStereoRendering)
- {
- setOVRHMDAsGameConnectionDisplayDevice(%gameConnection);
- PlayGui.renderStyle = "stereo side by side";
- setOptimalOVRCanvasSize(Canvas);
- if (!isObject(OculusCanvas))
- {
- new GuiOffscreenCanvas(OculusCanvas) {
- targetSize = "512 512";
- targetName = "oculusCanvas";
- dynamicTarget = true;
- };
- }
- if (!isObject(OculusVROverlay))
- {
- exec("core/vr/guis/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();
- }
- // Call this function when ever you wish to turn off the stereo rendering
- // and barrel distortion for the Rift.
- function disableOculusVRDisplay(%gameConnection)
- {
- OculusCanvas.popDialog();
- OculusWarningMap.pop();
- $GameCanvas = Canvas;
- if (isObject(gameConnection))
- {
- %gameConnection.clearDisplayDevice();
- }
- PlayGui.renderStyle = "standard";
- }
- // Helper function to set the standard Rift control scheme. You could place
- // this function in GameConnection::initialControlSet() at the same time
- // you call enableOculusVRDisplay().
- function setStandardOculusVRControlScheme(%gameConnection)
- {
- if($OculusVR::SimulateInput)
- {
- // We are simulating a HMD so allow the mouse and gamepad to control
- // both yaw and pitch.
- %gameConnection.setControlSchemeParameters(true, true, true);
- }
- else
- {
- // A HMD is connected so have the mouse and gamepad only add to yaw
- %gameConnection.setControlSchemeParameters(true, true, false);
- }
- }
- //-----------------------------------------------------------------------------
- // Helper function to set the resolution for the Rift.
- // Parameters:
- // %fullscreen - If true then the display will be forced to full screen. If
- // pointCanvasToOculusVRDisplay() was called before the Canvas was created, then
- // the full screen display will appear on the Rift.
- function setVideoModeForOculusVRDisplay(%fullscreen)
- {
- %res = getOVRHMDResolution(0);
- Canvas.setVideoMode(%res.x, %res.y, %fullscreen, 32, 4);
- }
- //-----------------------------------------------------------------------------
- // Reset all Oculus Rift sensors. This will make the Rift's current heading
- // be considered the origin.
- function resetOculusVRSensors()
- {
- ovrResetAllSensors();
- }
- function dismissOculusVRWarnings(%value)
- {
- //if (%value)
- //{
- ovrDismissWarnings();
- OculusWarningMap.pop();
- //}
- }
|