diff --git a/Projects/Android/AndroidManifest.xml b/Projects/Android/AndroidManifest.xml index 4996d30..a85c660 100644 --- a/Projects/Android/AndroidManifest.xml +++ b/Projects/Android/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:versionName="1.2.0" android:installLocation="auto" > diff --git a/Projects/Android/jni/src/Lambda1VR/L1VR_SurfaceView.c b/Projects/Android/jni/src/Lambda1VR/L1VR_SurfaceView.c index 4a10ff2..c9d4f7d 100644 --- a/Projects/Android/jni/src/Lambda1VR/L1VR_SurfaceView.c +++ b/Projects/Android/jni/src/Lambda1VR/L1VR_SurfaceView.c @@ -1327,6 +1327,33 @@ void Android_MessageBox(const char *title, const char *text) ALOGE("%s %s", title, text); } + +/* +======================== +Android_Vibrate +======================== +*/ + +//0 = left, 1 = right +float vibration_channel_duration[2] = {0.0f, 0.0f}; +float vibration_channel_intensity[2] = {0.0f, 0.0f}; +extern convar_t *vibration_enable; + +void Android_Vibrate( float duration, int channel, float intensity ) +{ + if( !vibration_enable->integer ) + return; + + if (vibration_channel_duration[channel] > 0.0f) + return; + + if (vibration_channel_duration[channel] == -1.0f && duration != 0.0f) + return; + + vibration_channel_duration[channel] = duration; + vibration_channel_intensity[channel] = intensity; +} + void initialize_gl4es(); void VR_Init() @@ -1532,6 +1559,31 @@ void * AppThreadFunction( void * parm ) vrapi_SubmitFrame2( appState.Ovr, &frameDesc ); } + //Handle haptics + static float lastFrameTime = 0.0f; + float timestamp = (float)(GetTimeInMilliSeconds()); + float frametime = timestamp - lastFrameTime; + lastFrameTime = timestamp; + + for (int i = 0; i < 2; ++i) { + if (vibration_channel_duration[i] > 0.0f || + vibration_channel_duration[i] == -1.0f) { + vrapi_SetHapticVibrationSimple(appState.Ovr, controllerIDs[i], + vibration_channel_intensity[i]); + + if (vibration_channel_duration[i] != -1.0f) { + vibration_channel_duration[i] -= frametime; + + if (vibration_channel_duration[i] < 0.0f) { + vibration_channel_duration[i] = 0.0f; + vibration_channel_intensity[i] = 0.0f; + } + } + } else { + vrapi_SetHapticVibrationSimple(appState.Ovr, controllerIDs[i], 0.0f); + } + } + if (runStatus == -1) { #ifndef NDEBUG if (appState.FrameIndex > 10800) diff --git a/Projects/Android/jni/src/Lambda1VR/VrCommon.h b/Projects/Android/jni/src/Lambda1VR/VrCommon.h index ae32457..0af7bb1 100644 --- a/Projects/Android/jni/src/Lambda1VR/VrCommon.h +++ b/Projects/Android/jni/src/Lambda1VR/VrCommon.h @@ -64,4 +64,4 @@ void rotateAboutOrigin(float v1, float v2, float rotation, vec2_t out); void QuatToYawPitchRoll(ovrQuatf q, float pitchAdjust, vec3_t out); bool useScreenLayer(); void handleTrackedControllerButton(ovrInputStateTrackedRemote * trackedRemoteState, ovrInputStateTrackedRemote * prevTrackedRemoteState, uint32_t button, int key); - +void Android_Vibrate( float duration, int channel, float intensity ); diff --git a/Projects/Android/jni/src/Lambda1VR/VrInput.h b/Projects/Android/jni/src/Lambda1VR/VrInput.h index 077857a..940aa87 100644 --- a/Projects/Android/jni/src/Lambda1VR/VrInput.h +++ b/Projects/Android/jni/src/Lambda1VR/VrInput.h @@ -12,6 +12,8 @@ ovrInputStateTrackedRemote rightTrackedRemoteState_old; ovrInputStateTrackedRemote rightTrackedRemoteState_new; ovrTracking rightRemoteTracking_new; +ovrDeviceID controllerIDs[2]; + float remote_movementSideways; float remote_movementForward; float positional_movementSideways; diff --git a/Projects/Android/jni/src/Lambda1VR/VrInputCommon.c b/Projects/Android/jni/src/Lambda1VR/VrInputCommon.c index 7bb6325..0085b6a 100644 --- a/Projects/Android/jni/src/Lambda1VR/VrInputCommon.c +++ b/Projects/Android/jni/src/Lambda1VR/VrInputCommon.c @@ -135,9 +135,11 @@ void acquireTrackedRemotesData(const ovrMobile *Ovr, double displayTime) {//The if (remoteCapabilities.ControllerCapabilities & ovrControllerCaps_RightHand) { rightTrackedRemoteState_new = trackedRemoteState; rightRemoteTracking_new = remoteTracking; + controllerIDs[1] = cap.DeviceID; } else{ leftTrackedRemoteState_new = trackedRemoteState; leftRemoteTracking_new = remoteTracking; + controllerIDs[0] = cap.DeviceID; } } } diff --git a/Projects/Android/jni/src/Lambda1VR/VrInputLeft.c b/Projects/Android/jni/src/Lambda1VR/VrInputLeft.c index ca22a9a..1ee7201 100644 --- a/Projects/Android/jni/src/Lambda1VR/VrInputLeft.c +++ b/Projects/Android/jni/src/Lambda1VR/VrInputLeft.c @@ -197,6 +197,7 @@ void HandleInput_Left( ovrMobile * Ovr, double displayTime ) if (dominantGripPushed) { //Initiate crowbar from backpack mode sendButtonActionSimple("weapon_crowbar"); + Android_Vibrate(80, 0, 0.8); // vibrate to let user know they switched grabMeleeWeapon = 1; } } diff --git a/Projects/Android/jni/src/Lambda1VR/VrInputRight.c b/Projects/Android/jni/src/Lambda1VR/VrInputRight.c index 8ca26e8..18ed58f 100644 --- a/Projects/Android/jni/src/Lambda1VR/VrInputRight.c +++ b/Projects/Android/jni/src/Lambda1VR/VrInputRight.c @@ -194,6 +194,7 @@ void HandleInput_Right(ovrMobile * Ovr, double displayTime ) if (dominantGripPushed) { //Initiate crowbar from backpack mode sendButtonActionSimple("weapon_crowbar"); + Android_Vibrate(80, 1, 0.8); // vibrate to let user know they switched grabMeleeWeapon = 1; } } diff --git a/Projects/Android/jni/src/Xash3D/xash3d/engine/client/cl_mobile.c b/Projects/Android/jni/src/Xash3D/xash3d/engine/client/cl_mobile.c index 8e9634a..6362b17 100644 --- a/Projects/Android/jni/src/Xash3D/xash3d/engine/client/cl_mobile.c +++ b/Projects/Android/jni/src/Xash3D/xash3d/engine/client/cl_mobile.c @@ -28,37 +28,27 @@ GNU General Public License for more details. mobile_engfuncs_t *gMobileEngfuncs; -convar_t *vibration_length; convar_t *vibration_enable; -static void pfnVibrate( float life, char flags ) +static void pfnVibrate( float duration, int channel, float intensity ) { - if( !vibration_enable->integer ) - return; - - if( life < 0.0f ) - { - MsgDev( D_WARN, "Negative vibrate time: %f\n", life ); - return; - } - //MsgDev( D_NOTE, "Vibrate: %f %d\n", life, flags ); // here goes platform-specific backends #ifdef __ANDROID__ - Android_Vibrate( life * vibration_length->value, flags ); + Android_Vibrate( duration, channel, intensity ); #endif } static void Vibrate_f() { - if( Cmd_Argc() != 2 ) + if( Cmd_Argc() != 4 ) { - Msg( "Usage: vibrate