Jump to content
  • entries
    940
  • comments
    5,894
  • views
    863,945

Oculus Rift support now available [beta]


Josh

4,722 views

 Share

As described earlier, Oculus Rift support is now enabled on the beta branch on Steam!

 

blogentry-1364-0-58594800-1417029861_thumb.jpg

Enabling VR

To enable VR in any game, just add the Window::VRDisplay flag in the creation flags in the Window::Create() function:

Window* window = Window::Create("My VR Game",0,0,1024,768,Window::Titlebar|Window::VRDisplay);

 

Or in Lua:

local window = Window:Create("My VR Game",0,0,1024,768,Window.Titlebar + Window.VRDisplay)

 

(If you are using a Lua project, you must update the project to get the new executables.)

 

It was very easy to add VR to my asteroids game. You can play it here:

http://www.leadwerks.com/werkspace/topic/11112-asteroidsvr/#entry80913

New Commands

There are only a few new commands to learn:

Vec3 VR::GetHeadRotation()

Use this to modify the way your controls work. For example, use the player's head rotation to change the direction they move in when a key is pressed. You do not need to rotate the camera yourself, as this is done automatically.

 

Vec3 VR::GetHeadPosition()

I can't really think of any good use for this command, since it is all automatic. If you do any line of sight tests I suppose it would be useful.

 

void VR::Recenter()

Recenters the headset orientation according to the current position and rotation.

 

void VR::HideWarning()

Disable the Oculus warning popup, typically by pressing space or another key.

Updating Existing C++ Projects

Because this involves an additional C++ library, you must modify any existing C++ projects to compile with the beta build. To do this, right-click on the project name in the solution explorer and select Properties to open the properties window. Go to the linker settings and edit the Additional Dependencies value. Add the following line to the release build settings:
libovr.lib

 

Apply the changes and then add the following line to the debug build settings, in the same place:

libovrd.lib

 

You must also modify the file main.cpp. Open this file and find the line that looks like this:

System::SaveSettings(settingsfile);

 

Add this line right after it:

System::Shutdown();

 

Your entire main,cpp will look like this:

#ifndef OS_IOS
#ifndef _DLL
#ifndef BUILD_STATICLIB
#include "App.h"
#endif
#endif

using namespace Leadwerks;

void DebugErrorHook(char* c)
{
Leadwerks::System::Print(c);
//=========================================================================================
//=========================================================================================

exit(1);//<--------------------------- Add a breakpoint here to catch errors

//=========================================================================================
//=========================================================================================
}

#ifdef __APPLE__
int main_(int argc,const char *argv[])
{
#else
int main(int argc,const char *argv[])
{
#endif

//Load saved settings
std::string settingsfile = std::string(argv[0]);
settingsfile = FileSystem::StripAll(settingsfile);
if (String::Right(settingsfile, 6) == ".debug") settingsfile = String::Left(settingsfile, settingsfile.length() - 6);
std::string settingsdir = FileSystem::GetAppDataPath();
#ifdef __linux__
#ifndef __ANDROID__
settingsdir = settingsdir + "/." + String::Lower(settingsfile);
#else
settingsdir = settingsdir + "/" + settingsfile;
#endif
#else
settingsdir = settingsdir + "/" + settingsfile;
#endif
if (FileSystem::GetFileType(settingsdir) == 0) FileSystem::CreateDir(settingsdir);
settingsfile = settingsdir + "/" + settingsfile + ".cfg";
System::LoadSettings(settingsfile);

//Load command-line parameters
System::ParseCommandLine(argc, argv);

//Add debug hook for catching errors
Leadwerks::System::AddHook(System::DebugErrorHook,(void*)DebugErrorHook);

//Load any zip files in main directory
Leadwerks::Directory* dir = Leadwerks::FileSystem::LoadDir(".");
if (dir)
{
for (int i=0; i<dir->files.size(); i++)
{
std::string file = dir->files[i];
if (Leadwerks::String::Lower(Leadwerks::FileSystem::ExtractExt(file))=="zip")
{
Leadwerks::Package::Load(file);
}
}
delete dir;
}

#ifdef DEBUG
std::string debuggerhostname = System::GetProperty("debuggerhostname");
if (debuggerhostname!="")
{
//Connect to the debugger
int debuggerport = String::Int(System::GetProperty("debuggerport"));
if (!Interpreter::Connect(debuggerhostname,debuggerport))
{
Print("Error: Failed to connect to debugger with hostname \""+debuggerhostname+"\" and port "+String(debuggerport)+".");
return false;
}
Print("Successfully connected to debugger.");
std::string breakpointsfile = System::GetProperty("breakpointsfile");
if (breakpointsfile!="")
{
if (!Interpreter::LoadBreakpoints(breakpointsfile))
{
Print("Error: Failed to load breakpoints file \""+breakpointsfile+"\".");
}
}
}
else
{
// Print("No debugger hostname supplied in command line.");
}
#endif
App* app = new App;
if (app->Start())
{
while (app->Loop()) {}
#ifdef DEBUG
Interpreter::Disconnect();
#endif
//Save settings
delete app;
System::SaveSettings(settingsfile);
System::Shutdown();
return 0;
}
else
{
#ifdef DEBUG
Interpreter::Disconnect();
#endif
return 1;
}
}
#endif

 

That's it! Have fun and let me know what you come up with!

  • Upvote 5
 Share

4 Comments


Recommended Comments

I haven't done it on Linux yet because they haven't added the direct rendering mode yet, and I don't want to have to go back and change it when they do. The commands are all implemented, they just don't do anything on Linux yet, but your code is still cross-platform compatible at least.

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...