/// <summary> /// Gets the pose of the given eye, predicted for the time when the current frame will scan out. /// </summary> public Pose GetEyePose (dpncEYE eye , dpnQuarterion pose , dpnVector3 position // position 在当前应该已经被转成左手系(Unity)了 , float interpupillary_distance ) { Quaternion rot = pose.ToQuaternion(); // 右手螺旋, 左手系 -> 左手螺旋,左手系(Unity) float eye_offset_x = 0.5f * interpupillary_distance; eye_offset_x = (eye == dpncEYE.LEFT) ? -eye_offset_x : eye_offset_x; float neck_to_eye_height = 0.0f; float eye_depth = 0.0f; // PC: head model do in native sdk, Android: for compatible old game, do here as old apps #if UNITY_ANDROID && !UNITY_EDITOR float eye_height = 1.6f; float player_height = eye_height * 1.067f; // eye should be at 15/16 of total height. neck_to_eye_height = player_height * 0.0625f * DpnManager.worldScale; //neck_to_eye_height should be 1/16 of total height. eye_depth = 0.0805f * DpnManager.worldScale; #endif Vector3 neck_model = new Vector3(0.0f, neck_to_eye_height, eye_depth); Vector3 pos = rot * (new Vector3(eye_offset_x, 0.0f, 0.0f) + neck_model); // neck-pivot space pos -= neck_model; // what it does is converting pos to initially oriented center-eye space, making the initial position of center eye (0,0,0) Pose ret = new Pose(); ret.position = pos + new Vector3(position.x, position.y, position.z); ret.orientation = rot; return(ret); }
/// <summary> /// Gets the head pose. /// </summary> /// <param name="predictionTime">The prediction time.</param> /// <returns></returns> public Pose GetHeadPose(double predictionTime = 0d) { #if UNITY_ANDROID && !UNITY_EDITOR dpnQuarterion pose = Composer.DpnuGetPredictedPose(predictionTime); dpnVector3 position = Composer.DpnuGetPredictedPosition(predictionTime); #else dpnQuarterion pose = Composer.DpnuGetPose(); dpnVector3 position = Composer.DpnuGetPosition(); #endif return(new Pose { position = new Vector3(position.x, position.y, position.z), orientation = pose.ToQuaternion(), }); }
public Quaternion GetPose() { return(pose.ToQuaternion()); }
void ReadState(DpnDaydreamControllerState outState, DpnDaydreamControllerState lastState) { outState.connectionState = (DpnConnectionState)DpnpGetDeviceCurrentStatus().device_status; outState.apiStatus = DpnControllerApiStatus.Ok; float[] pose = DpnpGetDeviceCurrentStatus().pose_state[0]; dpnQuarterion rawOri = new dpnQuarterion { s = pose[0], i = pose[1], j = pose[2], k = pose[3] }; dpnVector3 rawAccel = new dpnVector3 { x = pose[7], y = pose[8], z = pose[9] }; dpnVector3 rawGyro = new dpnVector3 { x = pose[4], y = pose[5], z = pose[6] }; outState.orientation = rawOri.ToQuaternion(); //outState.orientation = new Quaternion(pose[1], pose[2], pose[3], pose[0]); outState.accel = new Vector3(rawAccel.x, rawAccel.y, -rawAccel.z); outState.gyro = new Vector3(-rawGyro.x, -rawGyro.y, rawGyro.z); switch (DpnManager.peripheral) { case DPVRPeripheral.Flip: { float touchPos_x = DpnpGetDeviceCurrentStatus().axis_state[(int)DPNP_DAYDREAM_AXES.DPNP_DAYDREAM_AXIS_X][0]; float touchPos_y = DpnpGetDeviceCurrentStatus().axis_state[(int)DPNP_DAYDREAM_AXES.DPNP_DAYDREAM_AXIS_Y][0]; outState.touchPos = new Vector2(touchPos_x, touchPos_y); outState.isTouching = 0 != DpnpGetDeviceCurrentStatus().button_state[(int)DPNP_FLIP_BUTTONS.DPNP_FLIP_BUTTON_TOUCH][0]; outState.touchDown = !lastState.isTouching && outState.isTouching; outState.touchUp = lastState.isTouching && !outState.isTouching; outState.appButtonState = 0 != DpnpGetDeviceCurrentStatus().button_state[(int)DPNP_FLIP_BUTTONS.DPNP_FLIP_BUTTON_APP][0]; outState.appButtonDown = !lastState.appButtonState && outState.appButtonState; outState.appButtonUp = lastState.appButtonState && !outState.appButtonState; outState.clickButtonState = 0 != DpnpGetDeviceCurrentStatus().button_state[(int)DPNP_FLIP_BUTTONS.DPNP_FLIP_BUTTON_CLICK][0]; outState.clickButtonDown = !lastState.clickButtonState && outState.clickButtonState; outState.clickButtonUp = lastState.clickButtonState && !outState.clickButtonState; outState.triggerButtonState = 0 != DpnpGetDeviceCurrentStatus().button_state[(int)DPNP_FLIP_BUTTONS.DPNP_FLIP_BUTTON_TRIGGGER][0]; outState.triggerButtonDown = !lastState.triggerButtonState && outState.triggerButtonState; outState.triggerButtonUp = lastState.triggerButtonState && !outState.triggerButtonState; outState.volumeUpButtonState = false; outState.volumeUpButtonDown = false; outState.volumeUpButtonUp = false; outState.volumeDownButtonState = false; outState.volumeDownButtonDown = false; outState.volumeDownButtonUp = false; outState.recentering = 0 != DpnpGetDeviceCurrentStatus().button_state[(int)DPNP_FLIP_BUTTONS.DPNP_FLIP_BUTTON_RECENTERING][0]; outState.recentered = 0 != DpnpGetDeviceCurrentStatus().button_state[(int)DPNP_FLIP_BUTTONS.DPNP_FLIP_BUTTON_RECENTERED][0]; //Debug.Log(" DpnDaydreamControllerState GetData:" + "connectionState = " + outState.connectionState //+ " outState.accX = " + outState.accel.x + " outState.accY = " + outState.accel.y + " outState.accZ = " + outState.accel.z //+ " outState.gyroX = " + outState.gyro.x + " outState.gyroY = " + outState.gyro.y + " outState.gyroZ = " + outState.gyro.z //+ " outState.oriX = " + outState.orientation.x + " outState.oriY = " + outState.orientation.y + " outState.oriZ = " + outState.orientation.z //+ " outState.touchX = " + outState.touchPos.x + " outState.touchY = " + outState.touchPos.y //+ " outState.btnAPP = " + outState.appButtonState + " outState.btnHome = " + outState.recentering + " outState.btnClick = " + outState.clickButtonState //+ " outState.btnvolumeUp = " + outState.volumeUpButtonState + " outState.btnvolumeDown = " + outState.volumeDownButtonState); // If the controller was recentered, we may also need to request that the headset be // recentered. We should do that only if VrCore does NOT implement recentering. outState.headsetRecenterRequested = outState.recentered; if (outState.touchUp) { _touchUpPos = lastcontrollerState.touchPos; } break; } default: { float touchPos_x = DpnpGetDeviceCurrentStatus().axis_state[(int)DPNP_DAYDREAM_AXES.DPNP_DAYDREAM_AXIS_X][0]; float touchPos_y = DpnpGetDeviceCurrentStatus().axis_state[(int)DPNP_DAYDREAM_AXES.DPNP_DAYDREAM_AXIS_Y][0]; outState.touchPos = new Vector2(touchPos_x, touchPos_y); outState.isTouching = (0 != touchPos_x) && (0 != touchPos_y); outState.touchDown = !lastState.isTouching && outState.isTouching; outState.touchUp = lastState.isTouching && !outState.isTouching; outState.appButtonState = 0 != DpnpGetDeviceCurrentStatus().button_state[(int)DPNP_DAYDREAM_BUTTONS.DPNP_DAYDREAM_BUTTON_APP][0]; outState.appButtonDown = !lastState.appButtonState && outState.appButtonState; outState.appButtonUp = lastState.appButtonState && !outState.appButtonState; outState.clickButtonState = 0 != DpnpGetDeviceCurrentStatus().button_state[(int)DPNP_DAYDREAM_BUTTONS.DPNP_DAYDREAM_BUTTON_CLICK][0]; outState.clickButtonDown = !lastState.clickButtonState && outState.clickButtonState; outState.clickButtonUp = lastState.clickButtonState && !outState.clickButtonState; outState.triggerButtonState = false; outState.triggerButtonDown = false; outState.triggerButtonUp = false; outState.volumeUpButtonState = 0 != DpnpGetDeviceCurrentStatus().button_state[(int)DPNP_DAYDREAM_BUTTONS.DPNP_DAYDREAM_BUTTON_VOLUMEUP][0]; outState.volumeUpButtonDown = !lastState.volumeUpButtonState && outState.volumeUpButtonState; outState.volumeUpButtonUp = lastState.volumeUpButtonState && !outState.volumeUpButtonState; outState.volumeDownButtonState = 0 != DpnpGetDeviceCurrentStatus().button_state[(int)DPNP_DAYDREAM_BUTTONS.DPNP_DAYDREAM_BUTTON_VOLUMEDOWN][0]; outState.volumeDownButtonDown = !lastState.volumeDownButtonState && outState.volumeDownButtonState; outState.volumeDownButtonUp = lastState.volumeDownButtonState && !outState.volumeDownButtonState; outState.recentering = 0 != DpnpGetDeviceCurrentStatus().button_state[(int)DPNP_DAYDREAM_BUTTONS.DPNP_DAYDREAM_BUTTON_HOME][0]; outState.recentered = lastState.recentering && !outState.recentering; //Debug.Log(" DpnDaydreamControllerState GetData:" + "connectionState = " + outState.connectionState //+ " outState.accX = " + outState.accel.x + " outState.accY = " + outState.accel.y + " outState.accZ = " + outState.accel.z //+ " outState.gyroX = " + outState.gyro.x + " outState.gyroY = " + outState.gyro.y + " outState.gyroZ = " + outState.gyro.z //+ " outState.oriX = " + outState.orientation.x + " outState.oriY = " + outState.orientation.y + " outState.oriZ = " + outState.orientation.z //+ " outState.touchX = " + outState.touchPos.x + " outState.touchY = " + outState.touchPos.y //+ " outState.btnAPP = " + outState.appButtonState + " outState.btnHome = " + outState.recentering + " outState.btnClick = " + outState.clickButtonState //+ " outState.btnvolumeUp = " + outState.volumeUpButtonState + " outState.btnvolumeDown = " + outState.volumeDownButtonState); // If the controller was recentered, we may also need to request that the headset be // recentered. We should do that only if VrCore does NOT implement recentering. outState.headsetRecenterRequested = outState.recentered; if (outState.touchUp) { _touchUpPos = lastcontrollerState.touchPos; } break; } } }