Commit f8ee8c5c authored by Lubosz Sarnecki's avatar Lubosz Sarnecki

Initial commit.

Move files from openvr-glib and rename build to Xrd namespace.
parents
The MIT License (MIT)
Copyright 2018 Collabora Ltd.
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.
================================================================================
Asset Licenses
================================================================================
res/cat.jpg
Copyright 2007 Keith Kissel
SPDX-License-Identifier: CC-BY-2.0
Source: https://en.wikipedia.org/wiki/File:June_odd-eyed-cat.jpg
res/hawk.jpg
Copyright 2015 Charles J Sharp
SPDX-License-Identifier: CC-BY-SA-4.0
Source: https://en.wikipedia.org/wiki/File:Roadside_hawk_(Rupornis_magnirostris)_immature_2.jpg
# xrdesktop
A library for XR interaction with classical desktop compositors.
## Build
#### Configure the project
```
$ meson build
```
#### Compile the project
```
$ ninja -C build
```
## Run
#### Run the examples
```
$ ./build/examples/overlay_management
$ ./build/examples/scene
```
#### Run the tests
```
$ ninja -C build test
```
executable(
'overlay_paint', ['overlay_paint.c', test_resources],
dependencies: [gtk3_dep, openvr_dep, cairo_dep, graphene_dep, gulkan_dep, openvr_glib_dep],
link_with: xrdesktop_lib,
include_directories: xrdesktop_inc,
install: false)
executable(
'overlay_models', ['overlay_models.c', test_resources],
dependencies: [gtk3_dep, openvr_dep, cairo_dep, graphene_dep, gulkan_dep, openvr_glib_dep],
link_with: xrdesktop_lib,
include_directories: xrdesktop_inc,
install: false)
executable(
'overlay_management', ['overlay_management.c', test_resources],
dependencies: [gtk3_dep, openvr_dep, cairo_dep, graphene_dep, m_dep,
gulkan_dep, openvr_glib_dep],
link_with: xrdesktop_lib,
include_directories: xrdesktop_inc,
install: false)
executable(
'scene', ['scene.c', test_resources, shader_resources],
dependencies: [gdk_pixbuf_dep, gio_dep, glfw_dep,
graphene_dep, gulkan_dep, cairo_dep, openvr_glib_dep],
include_directories: [xrdesktop_inc],
link_with: xrdesktop_lib,
install: false)
This diff is collapsed.
/*
* OpenVR GLib
* Copyright 2018 Collabora Ltd.
* Author: Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
* Author: Christoph Haag <christoph.haag@collabora.com>
* SPDX-License-Identifier: MIT
*/
#include <glib-unix.h>
#include "openvr-context.h"
#include "openvr-overlay.h"
#include "openvr-io.h"
#include "openvr-action-set.h"
#include "xrd-overlay-model.h"
typedef struct Example
{
GSList *controllers;
XrdOverlayModel *model_overlay;
GMainLoop *loop;
guint current_model_list_index;
GSList *models;
OpenVRActionSet *action_set;
} Example;
gboolean
_sigint_cb (gpointer _self)
{
Example *self = (Example*) _self;
g_main_loop_quit (self->loop);
return TRUE;
}
static void
_pose_cb (OpenVRAction *action,
OpenVRPoseEvent *event,
Example *self)
{
(void) action;
graphene_point3d_t translation_point;
graphene_point3d_init (&translation_point, .0f, .1f, -.1f);
graphene_matrix_t transformation_matrix;
graphene_matrix_init_translate (&transformation_matrix, &translation_point);
graphene_matrix_scale (&transformation_matrix, 1.0f, 1.0f, 0.5f);
graphene_matrix_t transformed;
graphene_matrix_multiply (&transformation_matrix,
&event->pose,
&transformed);
openvr_overlay_set_transform_absolute (OPENVR_OVERLAY (self->model_overlay),
&transformed);
free (event);
}
gboolean
_update_model (Example *self)
{
struct HmdColor_t color = {
.r = 1.0f,
.g = 1.0f,
.b = 1.0f,
.a = 1.0f
};
GSList* name = g_slist_nth (self->models, self->current_model_list_index);
g_print ("Setting Model '%s' [%d/%d]\n",
(gchar *) name->data,
self->current_model_list_index + 1,
g_slist_length (self->models));
if (!xrd_overlay_model_set_model (self->model_overlay,
(gchar *) name->data, &color))
return FALSE;
return TRUE;
}
gboolean
_next_model (Example *self)
{
if (self->current_model_list_index == g_slist_length (self->models) - 1)
self->current_model_list_index = 0;
else
self->current_model_list_index++;
if (!_update_model (self))
return FALSE;
return TRUE;
}
gboolean
_previous_model (Example *self)
{
if (self->current_model_list_index == 0)
self->current_model_list_index = g_slist_length (self->models) - 1;
else
self->current_model_list_index--;
if (!_update_model (self))
return FALSE;
return TRUE;
}
static void
_next_cb (OpenVRAction *action,
OpenVRDigitalEvent *event,
Example *self)
{
(void) action;
(void) event;
if (event->active && event->changed && event->state)
_next_model (self);
}
static void
_previous_cb (OpenVRAction *action,
OpenVRDigitalEvent *event,
Example *self)
{
(void) action;
(void) event;
if (event->active && event->changed && event->state)
_previous_model (self);
}
gboolean
_poll_events_cb (gpointer _self)
{
Example *self = (Example*) _self;
if (!openvr_action_set_poll (self->action_set))
return FALSE;
return TRUE;
}
gboolean
_init_model_overlay (Example *self)
{
self->model_overlay = xrd_overlay_model_new ("model", "A 3D model overlay");
struct HmdColor_t color = {
.r = 1.0f,
.g = 1.0f,
.b = 1.0f,
.a = 1.0f
};
GSList* model_name = g_slist_nth (self->models,
self->current_model_list_index);
if (!xrd_overlay_model_set_model (self->model_overlay,
(gchar *) model_name->data, &color))
return FALSE;
char name_ret[k_unMaxPropertyStringSize];
struct HmdColor_t color_ret = {};
uint32_t id;
if (!xrd_overlay_model_get_model (self->model_overlay, name_ret, &color_ret, &id))
return FALSE;
g_print ("GetOverlayRenderModel returned id %d name: %s\n", id, name_ret);
if (!openvr_overlay_set_width_meters (OPENVR_OVERLAY (self->model_overlay),
0.5f))
return FALSE;
if (!openvr_overlay_show (OPENVR_OVERLAY (self->model_overlay)))
return FALSE;
return TRUE;
}
static void
_print_model (gpointer name, gpointer unused)
{
(void) unused;
g_print ("Model: %s\n", (gchar*) name);
}
void
_cleanup (Example *self)
{
g_print ("bye\n");
g_main_loop_unref (self->loop);
g_object_unref (self->model_overlay);
g_slist_free_full (self->models, g_free);
OpenVRContext *context = openvr_context_get_instance ();
g_object_unref (context);
}
int
main ()
{
OpenVRContext *context = openvr_context_get_instance ();
if (!openvr_context_init_overlay (context))
{
g_printerr ("Could not init OpenVR.\n");
return false;
}
if (!openvr_io_load_cached_action_manifest (
"openvr-glib",
"/res/bindings",
"example_model_actions.json",
"example_model_bindings_vive_controller.json",
NULL))
return -1;
Example self = {
.loop = g_main_loop_new (NULL, FALSE),
.current_model_list_index = 0,
.models = NULL,
.action_set = openvr_action_set_new_from_url ("/actions/model")
};
openvr_action_set_connect (self.action_set, OPENVR_ACTION_DIGITAL,
"/actions/model/in/next",
(GCallback) _next_cb, &self);
openvr_action_set_connect (self.action_set, OPENVR_ACTION_DIGITAL,
"/actions/model/in/previous",
(GCallback) _previous_cb, &self);
openvr_action_set_connect (self.action_set, OPENVR_ACTION_POSE,
"/actions/model/in/hand_primary",
(GCallback) _pose_cb, &self);
self.models = openvr_context_get_model_list (context);
g_slist_foreach (self.models, _print_model, NULL);
if (!_init_model_overlay (&self))
return -1;
g_timeout_add (20, _poll_events_cb, &self);
g_unix_signal_add (SIGINT, _sigint_cb, &self);
/* start glib main loop */
g_main_loop_run (self.loop);
_cleanup (&self);
return 0;
}
This diff is collapsed.
#include <glib.h>
#include <glib-unix.h>
#include "xrd-scene-client.h"
typedef struct Example
{
XrdSceneClient *client;
GMainLoop *loop;
} Example;
void
_cleanup (Example *self)
{
g_print ("bye\n");
g_object_unref (self->client);
}
gboolean
_sigint_cb (gpointer _self)
{
Example *self = (Example*) _self;
g_main_loop_quit (self->loop);
return TRUE;
}
gboolean
_iterate_cb (gpointer _self)
{
Example *self = (Example*) _self;
xrd_scene_client_render (self->client);
return true;
}
int
main ()
{
Example self = {
.loop = g_main_loop_new (NULL, FALSE),
.client = xrd_scene_client_new ()
};
if (!xrd_scene_client_initialize (self.client))
{
_cleanup (&self);
return 1;
}
g_timeout_add (1, _iterate_cb, &self);
g_unix_signal_add (SIGINT, _sigint_cb, &self);
/* start glib main loop */
g_main_loop_run (self.loop);
g_main_loop_unref (self.loop);
_cleanup (&self);
return 0;
}
project('xrdesktop', 'c', version: '0.8.99',
meson_version: '>= 0.42.0',
)
gnome = import('gnome')
config_h = configuration_data()
configure_file(
output: 'openvr-glib-config.h',
configuration: config_h,
)
add_project_arguments([
['-I' + meson.build_root(),
#'-Werror',
'-Wall',
'-Wextra'
],
], language: ['c'])
### Dependencies
cpp = meson.get_compiler('c')
## Required
openvr_dep = cpp.find_library('openvr_api')
# For a statically linked libopenvr_api we also need to link to the
# Standard C++ library and the implementation of dlopen()
stdcpp_dep = cpp.find_library('stdc++')
dl_dep = cpp.find_library('dl')
m_dep = cpp.find_library('m')
gulkan_dep = dependency('gulkan-0.8', version: '>= 0.8.0')
openvr_glib_dep = dependency('openvr-glib-0.9', version: '>= 0.8.0')
gio_dep = dependency('gio-2.0', version: '>= 2.50')
gtk3_dep = dependency('gtk+-3.0', version: '>= 3.22')
gdk_pixbuf_dep = dependency('gdk-pixbuf-2.0', version: '>= 2.36')
vulkan_dep = dependency('vulkan')
graphene_dep = dependency('graphene-1.0')
## Optional
x11_dep = dependency('x11', required : false)
xtst_dep = dependency('xtst', required : false)
xi_dep = dependency('xi', required : false)
clutter_gtk_dep = dependency('clutter-gtk-1.0', required : false)
clutter_dep = dependency('clutter-1.0', required : false)
cairo_dep = dependency('cairo', required : false)
libdrm_dep = dependency('libdrm', required : false)
libdrm_amdgpu_dep = dependency('libdrm_amdgpu', required : false)
glew_dep = dependency('glew', required : false)
glfw_dep = dependency('glfw3', required : false)
egl_dep = dependency('egl', required : false)
###
subdir('shaders')
subdir('src')
subdir('res')
subdir('tests')
subdir('examples')
option('introspection', type : 'boolean', value : false)
\ No newline at end of file
{
"default_bindings":[
{
"controller_type":"vive_controller",
"binding_url":"bindings_vive_controller.json"
},
{
"controller_type": "knuckles",
"binding_url": "bindings_knuckles_controller.json"
}
],
"actions":[
{
"name":"/actions/wm/in/grab_window_left",
"type":"boolean"
},
{
"name":"/actions/wm/in/grab_window_right",
"type":"boolean"
},
{
"name":"/actions/wm/in/show_keyboard_left",
"type":"boolean"
},
{
"name":"/actions/wm/in/show_keyboard_right",
"type":"boolean"
},
{
"name":"/actions/wm/in/push_pull_left",
"type": "vector2"
},
{
"name":"/actions/wm/in/push_pull_right",
"type": "vector2"
},
{
"name":"/actions/wm/in/push_pull_scale_left",
"type": "vector2"
},
{
"name":"/actions/wm/in/push_pull_scale_right",
"type": "vector2"
},
{
"name": "/actions/wm/in/hand_pose_left",
"type": "pose"
},
{
"name": "/actions/wm/in/hand_pose_right",
"type": "pose"
},
{
"name": "/actions/wm/out/haptic_left",
"type": "vibration"
},
{
"name": "/actions/wm/out/haptic_right",
"type": "vibration"
},
{
"name":"/actions/mouse_synth/in/left_click_left",
"type":"boolean"
},
{
"name":"/actions/mouse_synth/in/left_click_right",
"type":"boolean"
},
{
"name":"/actions/mouse_synth/in/right_click_left",
"type":"boolean"
},
{
"name":"/actions/mouse_synth/in/right_click_right",
"type":"boolean"
},
{
"name":"/actions/mouse_synth/in/scroll_left",
"type": "vector3"
},
{
"name":"/actions/mouse_synth/in/scroll_right",
"type": "vector3"
}
],
"action_sets": [
{
"name": "/actions/wm",
"usage": "leftright"
},
{
"name": "/actions/mouse_synth",
"usage": "leftright"
}
],
"localization":[
{
"language_tag":"en_US",
"/actions/wm/in/grab_window_left":"Grab Window Left Controller",
"/actions/wm/in/show_keyboard_left":"Show On Screen Keyboard Left Controller",
"/actions/wm/in/push_pull_left":"Move window along Z axis Left Controller",
"/actions/wm/in/push_pull_scale_left":"Scale Window Left Controller",
"/actions/wm/in/hand_pose_left" : "Pose Left Controller",
"/actions/wm/out/haptic_left" : "Haptic Feedback Left Controller",
"/actions/mouse_synth/in/left_click_left" : "Left Click Left Controller",
"/actions/mouse_synth/in/right_click_left" : "Right Click Left Controller",
"/actions/mouse_synth/in/scroll_left" : "Scroll Left Controller",
"/actions/wm/in/grab_window_right":"Grab Window Right Controller",
"/actions/wm/in/show_keyboard_right":"Show On Screen Keyboard Right Controller",
"/actions/wm/in/push_pull_right":"Move Window along Z axis Right Controller",
"/actions/wm/in/push_pull_scale_right":"Scale Window Right Controller",
"/actions/wm/in/hand_pose_right" : "Pose Right Controller",
"/actions/wm/out/haptic_right" : "Haptic Feedback Right Controller",
"/actions/mouse_synth/in/left_click_right" : "Left Click Right Controller",
"/actions/mouse_synth/in/right_click_right" : "Right Click Right Controller",
"/actions/mouse_synth/in/scroll_right" : "Scroll Right Controller"
}
]
}
\ No newline at end of file
{
"bindings" : {
"/actions/mouse_synth": {
"sources": [
{
"path": "/user/hand/right/input/a",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/mouse_synth/in/left_click_right"
}
}
},
{
"path": "/user/hand/right/input/b",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/mouse_synth/in/right_click_right"
}
}
},
{
"path": "/user/hand/left/input/a",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/mouse_synth/in/left_click_left"
}
}
},
{
"path": "/user/hand/left/input/b",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/mouse_synth/in/right_click_left"
}
}
},
{
"path": "/user/hand/left/input/trackpad",
"mode": "trackpad",
"inputs": {
"scroll": {
"output": "/actions/mouse_synth/in/scroll_left"
}
}
},
{
"path": "/user/hand/right/input/trackpad",
"mode": "trackpad",
"inputs": {
"scroll": {
"output": "/actions/mouse_synth/in/scroll_right"
}
}
}
]
},
"/actions/wm": {
"poses": [
{
"output": "/actions/wm/in/hand_pose_right",
"path": "/user/hand/right/pose/tip"
},
{
"output": "/actions/wm/in/hand_pose_left",
"path": "/user/hand/left/pose/tip"
}
],
"haptics": [
{
"output": "/actions/wm/out/haptic_right",
"path": "/user/hand/right/output/haptic"
},
{
"output": "/actions/wm/out/haptic_left",
"path": "/user/hand/left/output/haptic"
}
],
"sources": [
{
"path": "/user/hand/right/input/trigger",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/wm/in/grab_window_right"
}
}
},
{
"path": "/user/hand/right/input/trackpad",
"mode": "trackpad",
"inputs": {
"scroll": {
"output": "/actions/wm/in/push_pull_right"
}
}
},
{
"path": "/user/hand/left/input/trigger",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/wm/in/grab_window_left"
}
}
},
{
"path": "/user/hand/left/input/trackpad",
"mode": "trackpad",
"inputs": {
"scroll": {
"output": "/actions/wm/in/push_pull_left"
}
}
},
{