Unreal Action Mapping and haptics feedback for Oculus Touch


  Touch 的原型研制开始于DK1时代,在位于拇指摇杆和食指开关上,还有中指的抓取键上,都装有能感应你手指的传感器,内置的传感器阵列跟踪手指自然社交动作,比如,伸食指指着某个地方,抓东西,挥舞以及竖大拇哥等姿势。在初步原型阶段,拇指和食指的动作是离散的(0 和 1),相对于HTC VIVE(灯塔定位系统可实现亚毫米级检测)和PS MOVE,Oculus Touch能更好地模拟人类手部的运动,比如手指姿态还原,震动反馈等

 

Button Touch State

In addition to buttons, Touch controllers can detect whether user fingers are touching some buttons or are in certain positions.

 

ovrTouch_A : User in touching A button on the right controller.
ovrTouch_B : User in touching B button on the right controller.
ovrTouch_RThumb : User has a finger on the thumb stick of the right controller.
ovrTouch_RThumbRest : User has a finger on the textured thumb rest of the right controller.
ovrTouch_RIndexTrigger : User in touching the index finger trigger on the right controller.
ovrTouch_X : User in touching X button on the left controller.
ovrTouch_Y : User in touching Y button on the left controller.
ovrTouch_LThumb : User has a finger on the thumb stick of the left controller.
ovrTouch_LThumbRest : User has a finger on the textured thumb rest of the left controller.
ovrTouch_LIndexTrigger : User in touching the index finger trigger on the left controller.
ovrTouch_RIndexPointing : Users right index finger is pointing forward past the trigger.
ovrTouch_RThumbUp : Users right thumb is up and away from buttons on the controller, a gesture that can be interpreted as right thumbs up.
ovrTouch_LIndexPointing : Users left index finger is pointing forward past the trigger.
ovrTouch_LThumbUp : Users left thumb is up and away from buttons on the controller, a gesture that can be interpreted as left thumbs up.

For UE4:

A == MotionController (R) FaceButton1

B == MotionController (R) FaceButton2

Y == MotionController (L) FaceButton2

X == MotionController (L) FaceButton1

Haptic Feedback

Oculus touch controllers can provide haptic feedback through vibration.The SDK supports two types of haptics: buffered and non-buffered. Buffered haptics are designed to change rapidly (every 3.125ms) and work well for subtle effects. Non-buffered haptics are designed for simple effects that don't change often (every 33ms).

Note: The buffered and non-buffered functions should not be used together, as they will result in unpredictable haptic feedback.

buffere-based haptics

Running at 320Hz, each sample is 3.125 milliseconds. Because these samples are added to a buffer that holds 256 samples, the buffer can hold up to 800 milliseconds of samples.

To check the status of the buffer, call ovr_GetControllerVibrationState:

ovr_GetControllerVibrationState(ovrSession session, ovrControllerType controllerType, ovrHapticsPlaybackState* outState);

 To submit to the buffer, call ovr_SubmitControllerVibration:

ovr_SubmitControllerVibration(ovrSession session, ovrControllerType controllerType, const ovrHapticsBuffer* buffer);

 The following code sample shows basic haptic submission as part of a game loop:

uint8_t amplitude = (uint8_t)round(handTrigger[t] * 255);

    result = ovr_GetControllerVibrationState(Session, touchController[t], &state);
    if (result != ovrSuccess || state.SamplesQueued >= kLowLatencyBufferSizeInSamples)
    {
        DefaultChannel.LogWarningF("%s Haptics skipped. Queue size %d", kTouchStr[t], state.SamplesQueued);
        continue;
    }

    for (int32_t i = 0; i < kLowLatencyBufferSizeInSamples; ++i)
        samples.push_back(amplitude);

    if (samples.size() > 0)
    {
        ovrHapticsBuffer buffer;
        buffer.SubmitMode = ovrHapticsBufferSubmit_Enqueue;
        buffer.SamplesCount = (uint32_t)samples.size();
        buffer.Samples = samples.data();
        result = ovr_SubmitControllerVibration(Session, touchController[t], &buffer);
        if (result != ovrSuccess)
        {
            // Something bad happened
            DefaultChannel.LogErrorF("%s: Haptics submit failed %d", kTouchStr[t], result);
        }
    }

non-buffered haptics

Vibration can be enabled by calling ovr_SetControllerVibration:

ovr_SetControllerVibration( Hmd, ovrControllerType_LTouch, freq, trigger);

 Vibration is enabled by specifying the frequency. Specifying 0.0f will vibrate at 160Hz. Specifying 1.0f will vibrate at 320Hz.

 For UE4:

Play a haptic feedback curve on the player's controller, Target is Player Controlle.

void APlayerController::PlayHapticEffect(UHapticFeedbackEffect_Base* HapticEffect, EControllerHand Hand, float Scale, bool bLoop)
{
	if (HapticEffect)
	{
		switch (Hand)
		{
		case EControllerHand::Left:
			ActiveHapticEffect_Left.Reset();
			ActiveHapticEffect_Left = MakeShareable(new FActiveHapticFeedbackEffect(HapticEffect, Scale, bLoop));
			break;
		case EControllerHand::Right:
			ActiveHapticEffect_Right.Reset();
			ActiveHapticEffect_Right = MakeShareable(new FActiveHapticFeedbackEffect(HapticEffect, Scale, bLoop));
			break;
		case EControllerHand::Gun:
			ActiveHapticEffect_Gun.Reset();
			ActiveHapticEffect_Gun = MakeShareable(new FActiveHapticFeedbackEffect(HapticEffect, Scale, bLoop));
		default:
			UE_LOG(LogPlayerController, Warning, TEXT("Invalid hand specified (%d) for haptic feedback effect %s"), (int32)Hand, *HapticEffect->GetName());
			break;
		}
	}
}

void APlayerController::StopHapticEffect(EControllerHand Hand)
{
	SetHapticsByValue(0.f, 0.f, Hand);
}

猜你喜欢

转载自avi.iteye.com/blog/2368764