mirror of https://github.com/bjornbytes/lovr.git
WebVR velocity functions;
This commit is contained in:
parent
065a5aa0dd
commit
ab2594b204
|
@ -13,7 +13,7 @@ if(EMSCRIPTEN)
|
|||
"-s FULL_ES3=1 "
|
||||
"-s FORCE_FILESYSTEM=1 "
|
||||
"-s ALLOW_MEMORY_GROWTH=1 "
|
||||
"-s \"EXPORTED_FUNCTIONS=['_main','_mat4_rotateQuat','_mat4_set','_mat4_transform','_quat_fromMat4','_quat_getAngleAxis']\" "
|
||||
"-s \"EXPORTED_FUNCTIONS=['_main','_mat4_rotateQuat','_mat4_set','_mat4_transform','_mat4_transformDirection','_quat_fromMat4','_quat_getAngleAxis']\" "
|
||||
"-s \"EXTRA_EXPORTED_RUNTIME_METHODS=['getValue','setValue']\" "
|
||||
"--js-library \"${CMAKE_CURRENT_SOURCE_DIR}/src/resources/lovr.js\""
|
||||
)
|
||||
|
|
|
@ -362,8 +362,7 @@ static void fakeUpdate(float dt) {
|
|||
}
|
||||
|
||||
// move
|
||||
float quat[4];
|
||||
quat_rotate(quat_fromMat4(quat, state.transform), v);
|
||||
mat4_transformDirection(state.transform, &v[0], &v[1], &v[2]);
|
||||
vec3_add(state.pos, v);
|
||||
|
||||
// update transform
|
||||
|
|
|
@ -14,6 +14,7 @@ extern void webvrSetClipDistance(float near, float far);
|
|||
extern void webvrGetBoundsDimensions(float* width, float* depth);
|
||||
extern void webvrGetPose(float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az);
|
||||
extern void webvrGetVelocity(float* x, float* y, float* z);
|
||||
extern void webvrGetAngularVelocity(float* x, float* y, float* z);
|
||||
extern void webvrRenderTo(void (*callback)(void*), void* userdata);
|
||||
|
||||
typedef struct {
|
||||
|
@ -48,7 +49,7 @@ HeadsetInterface lovrHeadsetWebVRDriver = {
|
|||
webvrGetPose,
|
||||
NULL, //void (*getEyePose)(HeadsetEye eye, float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az);
|
||||
webvrGetVelocity,
|
||||
NULL, //void (*getAngularVelocity)(float* x, float* y, float* z);
|
||||
webvrGetAngularVelocity,
|
||||
NULL, //vec_controller_t* (*getControllers)();
|
||||
NULL, //bool (*controllerIsConnected)(Controller* controller);
|
||||
NULL, //ControllerHand (*controllerGetHand)(Controller* controller);
|
||||
|
|
|
@ -335,3 +335,10 @@ void mat4_transform(mat4 m, float* x, float* y, float* z) {
|
|||
*y = tx * m[1] + ty * m[5] + tz * m[9] + m[13];
|
||||
*z = tx * m[2] + ty * m[6] + tz * m[10] + m[14];
|
||||
}
|
||||
|
||||
void mat4_transformDirection(mat4 m, float* dx, float* dy, float* dz) {
|
||||
float x = *dx, y = *dy, z = *dz;
|
||||
*dx = x * m[0] + y * m[4] + z * m[8];
|
||||
*dy = x * m[1] + y * m[5] + z * m[9];
|
||||
*dz = x * m[2] + y * m[6] + z * m[10];
|
||||
}
|
||||
|
|
|
@ -20,3 +20,4 @@ mat4 mat4_orthographic(mat4 m, float left, float right, float top, float bottom,
|
|||
mat4 mat4_perspective(mat4 m, float near, float far, float fov, float aspect);
|
||||
mat4 mat4_lookAt(mat4 m, vec3 from, vec3 to, vec3 up);
|
||||
void mat4_transform(mat4 m, float* x, float* y, float* z);
|
||||
void mat4_transformDirection(mat4 m, float* x, float* y, float* z);
|
||||
|
|
|
@ -163,13 +163,34 @@ var LibraryLOVR = {
|
|||
},
|
||||
|
||||
webvrGetVelocity: function(x, y, z) {
|
||||
var stage = lovr.WebVR.display && lovr.WebVR.display.stageParameters;
|
||||
var sittingToStanding = lovr.WebVR.display && lovr.WebVR.display.stageParameters && lovr.WebVR.display.stageParameters.sittingToStandingTransform;
|
||||
var pose = lovr.WebVR.frameData.pose;
|
||||
|
||||
if (pose.linearVelocity) {
|
||||
HEAPF32[x >> 2] = pose.linearVelocity[0];
|
||||
HEAPF32[y >> 2] = pose.linearVelocity[1];
|
||||
HEAPF32[z >> 2] = pose.linearVelocity[2];
|
||||
|
||||
if (sittingToStanding) {
|
||||
Module._mat4_transformDirection(sittingToStanding, x, y, z);
|
||||
}
|
||||
} else {
|
||||
HEAPF32[x >> 2] = HEAPF32[y >> 2] = HEAPF32[z >> 2] = 0;
|
||||
}
|
||||
},
|
||||
|
||||
webvrGetAngularVelocity: function(x, y, z) {
|
||||
var sittingToStanding = lovr.WebVR.display && lovr.WebVR.display.stageParameters && lovr.WebVR.display.stageParameters.sittingToStandingTransform;
|
||||
var pose = lovr.WebVR.frameData.pose;
|
||||
|
||||
if (pose.angularVelocity) {
|
||||
HEAPF32[x >> 2] = pose.angularVelocity[0];
|
||||
HEAPF32[y >> 2] = pose.angularVelocity[1];
|
||||
HEAPF32[z >> 2] = pose.angularVelocity[2];
|
||||
|
||||
if (sittingToStanding) {
|
||||
Module._mat4_transformDirection(sittingToStanding, x, y, z);
|
||||
}
|
||||
} else {
|
||||
HEAPF32[x >> 2] = HEAPF32[y >> 2] = HEAPF32[z >> 2] = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue