mirror of https://github.com/bjornbytes/lovr.git
Do less work in lovr.headset.getPosition/getOrientation;
This commit is contained in:
parent
9a8b119a81
commit
965f39f834
|
@ -227,12 +227,12 @@ int l_lovrHeadsetGetPose(lua_State* L) {
|
|||
|
||||
int l_lovrHeadsetGetPosition(lua_State* L) {
|
||||
Path path = luax_optpath(L, 1, "head");
|
||||
float position[3], angle, ax, ay, az;
|
||||
float x, y, z;
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->getPose(path, &position[0], &position[1], &position[2], &angle, &ax, &ay, &az)) {
|
||||
lua_pushnumber(L, position[0]);
|
||||
lua_pushnumber(L, position[1]);
|
||||
lua_pushnumber(L, position[2]);
|
||||
if (driver->getPose(path, &x, &y, &z, NULL, NULL, NULL, NULL)) {
|
||||
lua_pushnumber(L, x);
|
||||
lua_pushnumber(L, y);
|
||||
lua_pushnumber(L, z);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
@ -241,9 +241,9 @@ int l_lovrHeadsetGetPosition(lua_State* L) {
|
|||
|
||||
int l_lovrHeadsetGetOrientation(lua_State* L) {
|
||||
Path path = luax_optpath(L, 1, "head");
|
||||
float x, y, z, angle, ax, ay, az;
|
||||
float angle, ax, ay, az;
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->getPose(path, &x, &y, &z, &angle, &ax, &ay, &az)) {
|
||||
if (driver->getPose(path, NULL, NULL, NULL, &angle, &ax, &ay, &az)) {
|
||||
lua_pushnumber(L, angle);
|
||||
lua_pushnumber(L, ax);
|
||||
lua_pushnumber(L, ay);
|
||||
|
|
|
@ -73,20 +73,25 @@ static const float* getBoundsGeometry(int* count) {
|
|||
}
|
||||
|
||||
static bool getPose(Path path, float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az) {
|
||||
if (PATH_EQ(path, P_HEAD)) {
|
||||
*x = *y = *z = 0.f;
|
||||
} else if (PATH_EQ(path, P_HAND, P_LEFT) || PATH_EQ(path, P_HAND, P_RIGHT)) {
|
||||
*x = 0.f;
|
||||
*y = 0.f;
|
||||
*z = -.75f;
|
||||
} else {
|
||||
bool head = PATH_EQ(path, P_HEAD);
|
||||
bool hand = PATH_EQ(path, P_HAND, P_LEFT) || PATH_EQ(path, P_HAND, P_RIGHT);
|
||||
|
||||
if (!head && !hand) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float q[4];
|
||||
mat4_transform(state.transform, x, y, z);
|
||||
quat_fromMat4(q, state.transform);
|
||||
quat_getAngleAxis(q, angle, ax, ay, az);
|
||||
if (x) {
|
||||
*x = *y = 0.f;
|
||||
*z = hand ? -.75f : 0.f;
|
||||
mat4_transform(state.transform, x, y, z);
|
||||
}
|
||||
|
||||
if (angle) {
|
||||
float q[4];
|
||||
quat_fromMat4(q, state.transform);
|
||||
quat_getAngleAxis(q, angle, ax, ay, az);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -169,12 +169,17 @@ static bool getPose(Path path, float* x, float* y, float* z, float* angle, float
|
|||
return false;
|
||||
}
|
||||
|
||||
*x = pose->Position.x;;
|
||||
*y = pose->Position.y + state.offset;
|
||||
*z = pose->Position.z;
|
||||
if (x) {
|
||||
*x = pose->Position.x;;
|
||||
*y = pose->Position.y + state.offset;
|
||||
*z = pose->Position.z;
|
||||
}
|
||||
|
||||
if (angle) {
|
||||
float quat[4] = { pose->Orientation.x, pose->Orientation.y, pose->Orientation.z, pose->Orientation.w };
|
||||
quat_getAngleAxis(quat, angle, ax, ay, az);
|
||||
}
|
||||
|
||||
float quat[4] = { pose->Orientation.x, pose->Orientation.y, pose->Orientation.z, pose->Orientation.w };
|
||||
quat_getAngleAxis(quat, angle, ax, ay, az);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,16 +71,28 @@ static const float* getBoundsGeometry(int* count) {
|
|||
|
||||
static bool getPose(Path path, float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az) {
|
||||
if (PATH_EQ(path, P_HEAD)) {
|
||||
*x = bridgeLovrMobileData.updateData.lastHeadPose.x;
|
||||
*y = bridgeLovrMobileData.updateData.lastHeadPose.y + state.offset; // Correct for head height
|
||||
*z = bridgeLovrMobileData.updateData.lastHeadPose.z;
|
||||
quat_getAngleAxis(bridgeLovrMobileData.updateData.lastHeadPose.q, angle, ax, ay, az);
|
||||
if (x) {
|
||||
*x = bridgeLovrMobileData.updateData.lastHeadPose.x;
|
||||
*y = bridgeLovrMobileData.updateData.lastHeadPose.y + state.offset; // Correct for head height
|
||||
*z = bridgeLovrMobileData.updateData.lastHeadPose.z;
|
||||
}
|
||||
|
||||
if (angle) {
|
||||
quat_getAngleAxis(bridgeLovrMobileData.updateData.lastHeadPose.q, angle, ax, ay, az);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (PATH_EQ(path, P_HAND)) {
|
||||
*x = bridgeLovrMobileData.updateData.goPose.x;
|
||||
*y = bridgeLovrMobileData.updateData.goPose.y + state.offset; // Correct for head height
|
||||
*z = bridgeLovrMobileData.updateData.goPose.z;
|
||||
quat_getAngleAxis(bridgeLovrMobileData.updateData.goPose.q, angle, ax, ay, az);
|
||||
if (x) {
|
||||
*x = bridgeLovrMobileData.updateData.goPose.x;
|
||||
*y = bridgeLovrMobileData.updateData.goPose.y + state.offset; // Correct for head height
|
||||
*z = bridgeLovrMobileData.updateData.goPose.z;
|
||||
}
|
||||
|
||||
if (angle) {
|
||||
quat_getAngleAxis(bridgeLovrMobileData.updateData.goPose.q, angle, ax, ay, az);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -249,7 +249,7 @@ static bool getPose(Path path, float* x, float* y, float* z, float* angle, float
|
|||
TrackedDeviceIndex_t deviceIndex = getDeviceIndexForPath(path);
|
||||
float transform[16];
|
||||
if (deviceIndex != INVALID_INDEX && getTransform(deviceIndex, transform)) {
|
||||
mat4_getPose(transform, x, y, z, angle, ax, ay, az);
|
||||
mat4_getTransform(transform, x, y, z, NULL, NULL, NULL, angle, ax, ay, az);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -491,28 +491,27 @@ mat4 mat4_scale(mat4 m, float x, float y, float z) {
|
|||
return m;
|
||||
}
|
||||
|
||||
void mat4_getPose(mat4 m, float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az) {
|
||||
*x = m[12];
|
||||
*y = m[13];
|
||||
*z = m[14];
|
||||
float quat[4];
|
||||
quat_fromMat4(quat, m);
|
||||
quat_getAngleAxis(quat, angle, ax, ay, az);
|
||||
}
|
||||
|
||||
void mat4_getTransform(mat4 m, float* x, float* y, float* z, float* sx, float* sy, float* sz, float* angle, float* ax, float* ay, float* az) {
|
||||
*x = m[12];
|
||||
*y = m[13];
|
||||
*z = m[14];
|
||||
float a[3] = { m[0], m[1], m[2] };
|
||||
float b[3] = { m[4], m[5], m[6] };
|
||||
float c[3] = { m[8], m[9], m[10] };
|
||||
*sx = vec3_length(a);
|
||||
*sy = vec3_length(b);
|
||||
*sz = vec3_length(c);
|
||||
float quat[4];
|
||||
quat_fromMat4(quat, m);
|
||||
quat_getAngleAxis(quat, angle, ax, ay, az);
|
||||
if (x) {
|
||||
*x = m[12];
|
||||
*y = m[13];
|
||||
*z = m[14];
|
||||
}
|
||||
|
||||
if (sx) {
|
||||
float a[3] = { m[0], m[1], m[2] };
|
||||
float b[3] = { m[4], m[5], m[6] };
|
||||
float c[3] = { m[8], m[9], m[10] };
|
||||
*sx = vec3_length(a);
|
||||
*sy = vec3_length(b);
|
||||
*sz = vec3_length(c);
|
||||
}
|
||||
|
||||
if (angle) {
|
||||
float quat[4];
|
||||
quat_fromMat4(quat, m);
|
||||
quat_getAngleAxis(quat, angle, ax, ay, az);
|
||||
}
|
||||
}
|
||||
|
||||
mat4 mat4_orthographic(mat4 m, float left, float right, float top, float bottom, float clipNear, float clipFar) {
|
||||
|
|
|
@ -54,7 +54,6 @@ MAF_EXPORT mat4 mat4_translate(mat4 m, float x, float y, float z);
|
|||
MAF_EXPORT mat4 mat4_rotate(mat4 m, float angle, float x, float y, float z);
|
||||
MAF_EXPORT mat4 mat4_rotateQuat(mat4 m, quat q);
|
||||
MAF_EXPORT mat4 mat4_scale(mat4 m, float x, float y, float z);
|
||||
MAF_EXPORT void mat4_getPose(mat4 m, float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az);
|
||||
MAF_EXPORT void mat4_getTransform(mat4 m, float* x, float* y, float* z, float* sx, float* sy, float* sz, float* angle, float* ax, float* ay, float* az);
|
||||
MAF_EXPORT mat4 mat4_orthographic(mat4 m, float left, float right, float top, float bottom, float near, float far);
|
||||
MAF_EXPORT mat4 mat4_perspective(mat4 m, float near, float far, float fov, float aspect);
|
||||
|
|
Loading…
Reference in New Issue