public void TransitionToArmModel(GvrArmModel armModel) { if (armModel == null) { return; } if (currentArmModel == null) { currentArmModel = armModel; return; } // Drop any old transitions that have only just begun transitioning, // since they won't impact how smooth the transition feels anyways. for (int i = transitionsList.Count - 1; i >= 0; i--) { if (transitionsList[i].transitionValue < DROP_TRANSITION_THRESHOLD) { transitionsList.RemoveAt(i); } } // If the max number of transitions is already active, drop the oldest. if (transitionsList.Count >= MAX_ACTIVE_TRANSITIONS) { transitionsList.RemoveAt(0); } transitionsList.Add(new ArmTransitionInfo(armModel)); }
public void Configure(GameObject bodyModelPrefab, bool createRay, GvrArmModel armModel) { Configure(bodyModelPrefab, createRay); _armModel = armModel; _origin = _armModel.transform.parent; }
private void SetFromArmModel(GvrArmModel arm, Transform laser) { elbowRestSliders.Vector = arm.elbowRestPosition; wristRestSliders.Vector = arm.wristRestPosition; controllerRestSliders.Vector = arm.controllerRestPosition; armExtensionSliders.Vector = arm.armExtensionOffset; elbowBendRatioSlider.Scalar = arm.elbowBendRatio; pointerTiltAngleSlider.Scalar = laser.localEulerAngles.x; }
void Awake() { if (transitionArmModel != null) { initialArmModel = transitionArmModel.CurrentArmModel; } SetupForHeldThrowable(); }
void OnDestroy() { // Unregister the controller update listener. GvrController controller = GetComponent <GvrController>(); controller.OnControllerUpdate -= OnControllerUpdate; // Reset the singleton instance. instance = null; }
public void SetArmModelFromUI(GvrArmModel arm, Transform laser) { arm.elbowRestPosition = elbowRestSliders.Vector; arm.wristRestPosition = wristRestSliders.Vector; arm.controllerRestPosition = controllerRestSliders.Vector; arm.armExtensionOffset = armExtensionSliders.Vector; arm.elbowBendRatio = elbowBendRatioSlider.Scalar; Vector3 euler = laser.localEulerAngles; euler.x = pointerTiltAngleSlider.Scalar; laser.localEulerAngles = euler; }
public override void OnActivated() { EnsureDeviceStateLength(3); if (Object.FindObjectOfType <GvrHeadset>() == null) { VRModule.Instance.gameObject.AddComponent <GvrHeadset>(); } if (Object.FindObjectOfType <GvrControllerInput>() == null) { VRModule.Instance.gameObject.AddComponent <GvrControllerInput>(); } m_rightDevice = GvrControllerInput.GetDevice(GvrControllerHand.Dominant); m_leftDevice = GvrControllerInput.GetDevice(GvrControllerHand.Dominant); var armModels = VRModule.Instance.GetComponents <GvrArmModel>(); if (armModels != null && armModels.Length >= 1) { m_rightArm = armModels[0]; } else { m_rightArm = VRModule.Instance.GetComponent <GvrArmModel>(); if (m_rightArm == null) { m_rightArm = VRModule.Instance.gameObject.AddComponent <GvrArmModel>(); } } m_rightArm.ControllerInputDevice = m_rightDevice; if (armModels != null && armModels.Length >= 2) { m_leftArm = armModels[1]; } else { m_leftArm = VRModule.Instance.GetComponent <GvrArmModel>(); if (m_leftArm == null) { m_leftArm = VRModule.Instance.gameObject.AddComponent <GvrArmModel>(); } } m_leftArm.ControllerInputDevice = m_leftDevice; }
public override void OnActivated() { EnsureDeviceStateLength(2); if (Object.FindObjectOfType <GvrHeadset>() == null) { VRModule.Instance.gameObject.AddComponent <GvrHeadset>(); } if (Object.FindObjectOfType <GvrControllerInput>() == null) { VRModule.Instance.gameObject.AddComponent <GvrControllerInput>(); } m_gvrArmModel = VRModule.Instance.GetComponent <GvrArmModel>(); if (m_gvrArmModel == null) { m_gvrArmModel = VRModule.Instance.gameObject.AddComponent <GvrArmModel>(); } }
private void OnControllerInputUpdated() { if (transitionsList.Count == 0) { // Just return early if there are no transitions right now. return; } float angularVelocity = GvrControllerInput.Gyro.magnitude; float lerpValue = Mathf.Clamp((angularVelocity - MIN_ANGULAR_VELOCITY) / ANGULAR_VELOCITY_DIVISOR, 0.0f, 0.1f); // Update each transition and detect if a transition has finished. for (int i = transitionsList.Count - 1; i >= 0; i--) { ArmTransitionInfo transitionInfo = transitionsList[i]; transitionInfo.transitionValue = Mathf.Lerp(transitionInfo.transitionValue, 1.0f, lerpValue); if (transitionInfo.transitionValue >= 0.95f) { transitionInfo.transitionValue = 1.0f; } transitionsList[i] = transitionInfo; // Transition is finished, so it should be removed. if (transitionInfo.transitionValue >= 1.0f) { // Set the current arm model to the arm model we just finished transitioning to. currentArmModel = transitionInfo.armModel; // All transitions prior to the one that finished can be removed. // That means we can mutate the list to remove all prior transitions and then break out of // the loop early. transitionsList.RemoveRange(0, i + 1); break; } } }
//datld private void OnPostClientControllerUpdated() { Vector3 shoulderPos; Vector3 elbowPos; Vector3 wristPos; Quaternion shoulderRotation; Quaternion elbowRotation; Quaternion wristRotation; GvrArmModel gvrArmModel = armModel as GvrArmModel; IArmModelVisualProvider armModelVisual = armModel as IArmModelVisualProvider; if (gvrArmModel != null) { shoulderPos = gvrArmModel.ShoulderPosition; elbowPos = gvrArmModel.ElbowPosition; wristPos = gvrArmModel.WristPosition; shoulderRotation = gvrArmModel.ShoulderRotation; elbowRotation = gvrArmModel.ElbowRotation; wristRotation = gvrArmModel.WristRotation; } else if (armModelVisual != null) { shoulderPos = correctShoulderPos; elbowPos = correctElbowPos; wristPos = correctWristPos; shoulderRotation = correctShoulderRotation; elbowRotation = correctElbowRotation; wristRotation = correctWristRotation; } else { return; } // Shoulder Joint. shoulderJoint.localPosition = shoulderPos; shoulderJoint.localRotation = shoulderRotation; UpdateAlphaForMesh(shoulderJointRenderer); // Elbow Joint. elbowJoint.localPosition = elbowPos; elbowJoint.localRotation = elbowRotation; UpdateAlphaForMesh(elbowJointRenderer); // Bicep Limb. Vector3 elbowShoulderDiff = elbowJoint.localPosition - shoulderJoint.localPosition; Vector3 bicepPosition = shoulderJoint.localPosition + (elbowShoulderDiff * 0.5f); bicepLimb.localPosition = bicepPosition; bicepLimb.LookAt(shoulderJoint, elbowJoint.forward); bicepLimb.localScale = new Vector3(1.0f, 1.0f, elbowShoulderDiff.magnitude * BICEP_SCALE_FACTOR); UpdateAlphaForMesh(bicepLimbRenderer); // Wrist Joint. wristJoint.localPosition = wristPos; wristJoint.localRotation = wristRotation; Vector3 wristDir = wristRotation * Vector3.forward; wristJoint.localPosition = wristJoint.localPosition + (wristDir * wristOffset); UpdateAlphaForMesh(wristJointRenderer); // Forearm Limb. Vector3 wristElbowDiff = wristJoint.localPosition - elbowJoint.localPosition; Vector3 forearmPosition = elbowJoint.localPosition + (wristElbowDiff * 0.5f); forearmLimb.localPosition = forearmPosition; forearmLimb.LookAt(elbowJoint, wristJoint.up); forearmLimb.localScale = new Vector3(1.0f, 1.0f, wristElbowDiff.magnitude * FOREARM_SCALE_FACTOR); UpdateAlphaForMesh(forearmLimbRenderer); if (laser != null) { if (isLaserHighlighted) { laser.startColor = laserHighlightColor; laser.enabled = true; } else { laser.startColor = laserDefaultColor; } Color color = laser.startColor; color.a *= armModel.PreferredAlpha; laser.startColor = color; laser.endColor = Color.clear; } }
public override void UpdateDeviceState(IVRModuleDeviceState[] prevState, IVRModuleDeviceStateRW[] currState) { if (m_gvrCtrlInputInstance == null) { m_gvrCtrlInputInstance = Object.FindObjectOfType <GvrControllerInput>(); if (m_gvrCtrlInputInstance == null) { m_gvrCtrlInputInstance = VRModule.Instance.gameObject.AddComponent <GvrControllerInput>(); } } if (GvrControllerInput.State == GvrConnectionState.Error) { Debug.LogError(GvrControllerInput.ErrorDetails); return; } if (m_gvrArmModelInstance == null) { m_gvrArmModelInstance = VRModule.Instance.GetComponent <GvrArmModel>(); if (m_gvrArmModelInstance == null) { m_gvrArmModelInstance = VRModule.Instance.gameObject.AddComponent <GvrArmModel>(); } } if (m_gvrHeadSetInstance == null) { m_gvrHeadSetInstance = Object.FindObjectOfType <GvrHeadset>(); if (m_gvrHeadSetInstance == null) { m_gvrHeadSetInstance = VRModule.Instance.gameObject.AddComponent <GvrHeadset>(); } } var headPrevState = prevState[VRModule.HMD_DEVICE_INDEX]; var headCurrState = currState[VRModule.HMD_DEVICE_INDEX]; headCurrState.isConnected = XRDevice.isPresent; if (headCurrState.isConnected) { if (!headPrevState.isConnected) { headCurrState.deviceClass = VRModuleDeviceClass.HMD; headCurrState.serialNumber = XRDevice.model + " HMD"; headCurrState.modelNumber = XRDevice.model + " HMD"; headCurrState.deviceModel = VRModuleDeviceModel.DaydreamHMD; headCurrState.renderModelName = string.Empty; } headCurrState.position = InputTracking.GetLocalPosition(XRNode.Head); headCurrState.rotation = InputTracking.GetLocalRotation(XRNode.Head); headCurrState.isPoseValid = headCurrState.pose != RigidPose.identity; headCurrState.pose = headCurrState.pose; } else { if (headPrevState.isConnected) { headCurrState.Reset(); } } var ctrlPrevState = prevState[CONTROLLER_DEVICE_INDEX]; var ctrlCurrState = currState[CONTROLLER_DEVICE_INDEX]; ctrlCurrState.isConnected = GvrControllerInput.State == GvrConnectionState.Connected; if (ctrlCurrState.isConnected) { if (!ctrlPrevState.isConnected) { ctrlCurrState.deviceClass = VRModuleDeviceClass.Controller; ctrlCurrState.serialNumber = XRDevice.model + " Controller"; ctrlCurrState.modelNumber = XRDevice.model + " Controller"; ctrlCurrState.deviceModel = VRModuleDeviceModel.DaydreamController; ctrlCurrState.renderModelName = string.Empty; } ctrlCurrState.pose = new RigidPose(m_gvrArmModelInstance.ControllerPositionFromHead, m_gvrArmModelInstance.ControllerRotationFromHead); ctrlCurrState.isPoseValid = GvrControllerInput.Orientation != Quaternion.identity; ctrlCurrState.velocity = GvrControllerInput.Accel; ctrlCurrState.angularVelocity = GvrControllerInput.Gyro; ctrlCurrState.SetButtonPress(VRModuleRawButton.Touchpad, GvrControllerInput.ClickButton); ctrlCurrState.SetButtonPress(VRModuleRawButton.ApplicationMenu, GvrControllerInput.AppButton); ctrlCurrState.SetButtonPress(VRModuleRawButton.System, GvrControllerInput.HomeButtonState); ctrlCurrState.SetButtonTouch(VRModuleRawButton.Touchpad, GvrControllerInput.IsTouching); if (GvrControllerInput.IsTouching) { var touchPadPosCentered = GvrControllerInput.TouchPosCentered; ctrlCurrState.SetAxisValue(VRModuleRawAxis.TouchpadX, touchPadPosCentered.x); ctrlCurrState.SetAxisValue(VRModuleRawAxis.TouchpadY, touchPadPosCentered.y); } else { ctrlCurrState.SetAxisValue(VRModuleRawAxis.TouchpadX, 0f); ctrlCurrState.SetAxisValue(VRModuleRawAxis.TouchpadY, 0f); } if (VIUSettings.daydreamSyncPadPressToTrigger) { ctrlCurrState.SetButtonPress(VRModuleRawButton.Trigger, GvrControllerInput.ClickButton); ctrlCurrState.SetButtonTouch(VRModuleRawButton.Trigger, GvrControllerInput.IsTouching); ctrlCurrState.SetAxisValue(VRModuleRawAxis.Trigger, GvrControllerInput.ClickButton ? 1f : 0f); } } else { if (ctrlPrevState.isConnected) { ctrlCurrState.Reset(); } } }
public AirVRTrackedControllerInputDevice(GvrArmModel armModel) { _armModel = armModel; }
public ArmTransitionInfo(GvrArmModel transitionArmModel) { armModel = transitionArmModel; transitionValue = 0.0f; }
void OnDestroy() { // Unregister the controller update listener. GvrController controller = GetComponent<GvrController>(); controller.OnControllerUpdate -= OnControllerUpdate; // Reset the singleton instance. instance = null; }