mirror of https://github.com/bjornbytes/lovr.git
Re-add lovr.headset.getBoundsGeometry;
Looks like more runtimes are starting to support it.
This commit is contained in:
parent
28c56f959d
commit
e1d980a2d6
|
@ -173,6 +173,30 @@ static int l_lovrHeadsetGetBoundsDimensions(lua_State* L) {
|
|||
return 2;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetBoundsGeometry(lua_State* L) {
|
||||
int count;
|
||||
const float* points = lovrHeadsetDriver->getBoundsGeometry(&count);
|
||||
|
||||
if (!points) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (lua_type(L, 1) == LUA_TTABLE) {
|
||||
lua_settop(L, 1);
|
||||
} else {
|
||||
lua_settop(L, 0);
|
||||
lua_createtable(L, count, 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
lua_pushnumber(L, points[i]);
|
||||
lua_rawseti(L, 1, i + 1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void luax_getPose(lua_State* L, float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az) {
|
||||
if (lua_type(L, 1) == LUA_TSTRING) {
|
||||
HeadsetEye eye = luaL_checkoption(L, 1, NULL, HeadsetEyes);
|
||||
|
@ -235,7 +259,7 @@ static int l_lovrHeadsetGetAngularVelocity(lua_State* L) {
|
|||
static int l_lovrHeadsetGetControllers(lua_State* L) {
|
||||
uint8_t count;
|
||||
Controller** controllers = lovrHeadsetDriver->getControllers(&count);
|
||||
lua_newtable(L);
|
||||
lua_createtable(L, count, 0);
|
||||
for (uint8_t i = 0; i < count; i++) {
|
||||
luax_pushobject(L, controllers[i]);
|
||||
lua_rawseti(L, -2, i + 1);
|
||||
|
@ -289,6 +313,7 @@ static const luaL_Reg lovrHeadset[] = {
|
|||
{ "getBoundsWidth", l_lovrHeadsetGetBoundsWidth },
|
||||
{ "getBoundsDepth", l_lovrHeadsetGetBoundsDepth },
|
||||
{ "getBoundsDimensions", l_lovrHeadsetGetBoundsDimensions },
|
||||
{ "getBoundsGeometry", l_lovrHeadsetGetBoundsGeometry },
|
||||
{ "getPose", l_lovrHeadsetGetPose },
|
||||
{ "getPosition", l_lovrHeadsetGetPosition },
|
||||
{ "getOrientation", l_lovrHeadsetGetOrientation },
|
||||
|
|
|
@ -135,6 +135,11 @@ static void fakeGetBoundsDimensions(float* width, float* depth) {
|
|||
*width = *depth = 0.f;
|
||||
}
|
||||
|
||||
static const float* fakeGetBoundsGeometry(int* count) {
|
||||
*count = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void fakeGetPose(float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az) {
|
||||
*x = state.position[0];
|
||||
*y = state.position[1];
|
||||
|
@ -305,6 +310,7 @@ HeadsetInterface lovrHeadsetFakeDriver = {
|
|||
fakeGetClipDistance,
|
||||
fakeSetClipDistance,
|
||||
fakeGetBoundsDimensions,
|
||||
fakeGetBoundsGeometry,
|
||||
fakeGetPose,
|
||||
fakeGetEyePose,
|
||||
fakeGetVelocity,
|
||||
|
|
|
@ -77,6 +77,7 @@ typedef struct {
|
|||
void (*getClipDistance)(float* clipNear, float* clipFar);
|
||||
void (*setClipDistance)(float clipNear, float clipFar);
|
||||
void (*getBoundsDimensions)(float* width, float* depth);
|
||||
const float* (*getBoundsGeometry)(int* count);
|
||||
void (*getPose)(float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az);
|
||||
void (*getEyePose)(HeadsetEye eye, float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az);
|
||||
void (*getVelocity)(float* x, float* y, float* z);
|
||||
|
|
|
@ -189,13 +189,18 @@ static void oculusSetClipDistance(float clipNear, float clipFar) {
|
|||
state.clipFar = clipFar;
|
||||
}
|
||||
|
||||
static float oculusGetBoundsDimensions(float* width, float* depth) {
|
||||
static void oculusGetBoundsDimensions(float* width, float* depth) {
|
||||
ovrVector3f dimensions;
|
||||
ovr_GetBoundaryDimensions(state.session, ovrBoundary_PlayArea, &dimensions);
|
||||
*width = dimensions.x;
|
||||
*depth = dimensions.z;
|
||||
}
|
||||
|
||||
static const float* oculusGetBoundsGeometry(int* count) {
|
||||
*count = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void oculusGetPose(float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az) {
|
||||
ovrTrackingState *ts = refreshTracking();
|
||||
ovrVector3f pos = ts->HeadPose.ThePose.Position;
|
||||
|
@ -483,6 +488,7 @@ HeadsetInterface lovrHeadsetOculusDriver = {
|
|||
oculusGetClipDistance,
|
||||
oculusSetClipDistance,
|
||||
oculusGetBoundsDimensions,
|
||||
oculusGetBoundsGeometry,
|
||||
oculusGetPose,
|
||||
oculusGetEyePose,
|
||||
oculusGetVelocity,
|
||||
|
|
|
@ -35,6 +35,7 @@ typedef struct {
|
|||
RenderModel_t* deviceModels[16];
|
||||
RenderModel_TextureMap_t* deviceTextures[16];
|
||||
Canvas* canvas;
|
||||
vec_float_t boundsGeometry;
|
||||
vec_controller_t controllers;
|
||||
HeadsetType type;
|
||||
bool isMirrored;
|
||||
|
@ -229,6 +230,7 @@ static bool openvrInit(float offset, int msaa) {
|
|||
state.offset = state.compositor->GetTrackingSpace() == ETrackingUniverseOrigin_TrackingUniverseStanding ? 0. : offset;
|
||||
state.msaa = msaa;
|
||||
|
||||
vec_init(&state.boundsGeometry);
|
||||
vec_init(&state.controllers);
|
||||
for (uint32_t i = 0; i < k_unMaxTrackedDeviceCount; i++) {
|
||||
if (isController(i)) {
|
||||
|
@ -259,6 +261,7 @@ static void openvrDestroy() {
|
|||
vec_foreach(&state.controllers, controller, i) {
|
||||
lovrRelease(controller);
|
||||
}
|
||||
vec_deinit(&state.boundsGeometry);
|
||||
vec_deinit(&state.controllers);
|
||||
VR_ShutdownInternal();
|
||||
memset(&state, 0, sizeof(HeadsetState));
|
||||
|
@ -310,6 +313,24 @@ static void openvrGetBoundsDimensions(float* width, float* depth) {
|
|||
state.chaperone->GetPlayAreaSize(width, depth);
|
||||
}
|
||||
|
||||
static const float* openvrGetBoundsGeometry(int* count) {
|
||||
struct HmdQuad_t quad;
|
||||
if (state.chaperone->GetPlayAreaRect(&quad)) {
|
||||
vec_clear(&state.boundsGeometry);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
vec_push(&state.boundsGeometry, quad.vCorners[i].v[0]);
|
||||
vec_push(&state.boundsGeometry, quad.vCorners[i].v[1]);
|
||||
vec_push(&state.boundsGeometry, quad.vCorners[i].v[2]);
|
||||
}
|
||||
|
||||
*count = state.boundsGeometry.length;
|
||||
return state.boundsGeometry.data;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void openvrGetPose(float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az) {
|
||||
float transform[16];
|
||||
getTransform(HEADSET_INDEX, transform);
|
||||
|
@ -600,6 +621,7 @@ HeadsetInterface lovrHeadsetOpenVRDriver = {
|
|||
openvrGetClipDistance,
|
||||
openvrSetClipDistance,
|
||||
openvrGetBoundsDimensions,
|
||||
openvrGetBoundsGeometry,
|
||||
openvrGetPose,
|
||||
openvrGetEyePose,
|
||||
openvrGetVelocity,
|
||||
|
|
|
@ -16,6 +16,7 @@ extern void webvrGetDisplayDimensions(int32_t* width, int32_t* height);
|
|||
extern void webvrGetClipDistance(float* near, float* far);
|
||||
extern void webvrSetClipDistance(float near, float far);
|
||||
extern void webvrGetBoundsDimensions(float* width, float* depth);
|
||||
extern const float* webvrGetBoundsDimensions(int* count);
|
||||
extern void webvrGetPose(float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az);
|
||||
extern void webvrGetEyePose(HeadsetEye eye, float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az);
|
||||
extern void webvrGetVelocity(float* x, float* y, float* z);
|
||||
|
@ -140,6 +141,7 @@ HeadsetInterface lovrHeadsetWebVRDriver = {
|
|||
webvrGetClipDistance,
|
||||
webvrSetClipDistance,
|
||||
webvrGetBoundsDimensions,
|
||||
webvrGetBoundsGeometry,
|
||||
webvrGetPose,
|
||||
webvrGetEyePose,
|
||||
webvrGetVelocity,
|
||||
|
|
|
@ -176,6 +176,11 @@ var LibraryLOVR = {
|
|||
}
|
||||
},
|
||||
|
||||
webvrGetBoundsGeometry: function(count) {
|
||||
HEAP32[count >> 2] = 0;
|
||||
return 0;
|
||||
},
|
||||
|
||||
webvrGetPose: function(x, y, z, angle, ax, ay, az) {
|
||||
var sittingToStanding = webvr.display.stageParameters && webvr.display.stageParameters.sittingToStandingTransform;
|
||||
var pose = webvr.frameData.pose;
|
||||
|
|
Loading…
Reference in New Issue