public KinectAbsoluteScreenspaceCursor(KinectService Kinect, Handedness hand, Game1 MyGame) { myGame = MyGame; kinect = Kinect; handSelect = hand; kinect.RegisterKinectListener(this); _rect = new Rectangle(); _rect.Width = 48; _rect.Height = 48; _position = new Vector2(); bodySpace = new Rectangle(); }
/// <inheritdoc /> public HandData PostProcess(Handedness handedness, HandData handData) { if (handData.TrackingState == TrackingState.Tracked) { // Gather needed data for calculations. var palmPose = handData.Joints[(int)TrackedHandJoint.Palm]; var palmLookRotation = Quaternion.LookRotation(palmPose.Forward, palmPose.Up); var thumbMetacarpalPose = handData.Joints[(int)TrackedHandJoint.ThumbMetacarpal]; var thumbProximalPose = handData.Joints[(int)TrackedHandJoint.ThumbProximal]; var indexProximalPose = handData.Joints[(int)TrackedHandJoint.IndexProximal]; var indexIntermediatePose = handData.Joints[(int)TrackedHandJoint.IndexIntermediate]; var middleProximalPose = handData.Joints[(int)TrackedHandJoint.MiddleProximal]; var middleIntermediatePose = handData.Joints[(int)TrackedHandJoint.MiddleIntermediate]; var ringProximalPose = handData.Joints[(int)TrackedHandJoint.RingProximal]; var ringIntermediatePose = handData.Joints[(int)TrackedHandJoint.RingIntermediate]; var littleProximalPose = handData.Joints[(int)TrackedHandJoint.LittleProximal]; var littleIntermediatePose = handData.Joints[(int)TrackedHandJoint.LittleIntermediate]; // Calculate per finger curl angles. var thumbMetacarpalCurl = Quaternion.Angle(palmLookRotation, thumbMetacarpalPose.Rotation); var thumbProximalCurl = Quaternion.Angle(palmLookRotation, thumbProximalPose.Rotation); var indexProximalCurl = Quaternion.Angle(palmLookRotation, indexProximalPose.Rotation); var indexIntermediateCurl = Quaternion.Angle(palmLookRotation, indexIntermediatePose.Rotation); var middleProximalCurl = Quaternion.Angle(palmLookRotation, middleProximalPose.Rotation); var middleIntermediateCurl = Quaternion.Angle(palmLookRotation, middleIntermediatePose.Rotation); var ringProximalCurl = Quaternion.Angle(palmLookRotation, ringProximalPose.Rotation); var ringIntermediateCurl = Quaternion.Angle(palmLookRotation, ringIntermediatePose.Rotation); var littleProximalCurl = Quaternion.Angle(palmLookRotation, littleProximalPose.Rotation); var littleIntermediateCurl = Quaternion.Angle(palmLookRotation, littleIntermediatePose.Rotation); // Grip strength is defined as the total traveled curl distance for the intermediate joints // compared to the total travel curl distance for the whole hand. var totalIntermediateCurlDistance = littleIntermediateCurl - CURL_LITTLE_INTERMEDIATE_LOW_END_ANGLE + (ringIntermediateCurl - CURL_RING_INTERMEDIATE_LOW_END_ANGLE) + (middleIntermediateCurl - CURL_MIDDLE_INTERMEDIATE_LOW_END_ANGLE) + (indexIntermediateCurl - CURL_INDEX_INTERMEDIATE_LOW_END_ANGLE); // For grip strength we just use the intermediate curls. handData.GripStrength = Mathf.Clamp(totalIntermediateCurlDistance / CURL_TOTAL_INTERMEDIATE_DISTANCE, 0f, 1f); // For finger curl strengths we add the proximal curl to the equation. var thumbCurlStrength = Mathf.Clamp( (((thumbMetacarpalCurl - CURL_THUMB_METACARPAL_LOW_END_ANGLE) / CURL_THUMB_METACARPAL_DISTANCE) + (thumbProximalCurl - CURL_THUMB_PROXIMAL_LOW_END_ANGLE) / CURL_THUMB_PROXIMAL_DISTANCE) / 2, 0f, 1f); var indexCurlStrength = Mathf.Clamp( (((indexProximalCurl - CURL_INDEX_PROXIMAL_LOW_END_ANGLE) / CURL_INDEX_PROXIMAL_DISTANCE) + (indexIntermediateCurl - CURL_INDEX_INTERMEDIATE_LOW_END_ANGLE) / CURL_INDEX_INTERMEDIATE_DISTANCE) / 2, 0f, 1f); var middleCurlStrength = Mathf.Clamp( (((middleProximalCurl - CURL_MIDDLE_PROXIMAL_LOW_END_ANGLE) / CURL_MIDDLE_PROXIMAL_DISTANCE) + (middleIntermediateCurl - CURL_MIDDLE_INTERMEDIATE_LOW_END_ANGLE) / CURL_MIDDLE_INTERMEDIATE_DISTANCE) / 2, 0f, 1f); var ringCurlStrength = Mathf.Clamp( (((ringProximalCurl - CURL_RING_PROXIMAL_LOW_END_ANGLE) / CURL_RING_PROXIMAL_DISTANCE) + (ringIntermediateCurl - CURL_RING_INTERMEDIATE_LOW_END_ANGLE) / CURL_RING_INTERMEDIATE_DISTANCE) / 2, 0f, 1f); var littleCurlStrength = Mathf.Clamp( (((littleProximalCurl - CURL_LITTLE_PROXIMAL_LOW_END_ANGLE) / CURL_LITTLE_PROXIMAL_DISTANCE) + (littleIntermediateCurl - CURL_LITTLE_INTERMEDIATE_LOW_END_ANGLE) / CURL_LITTLE_INTERMEDIATE_DISTANCE) / 2, 0f, 1f); handData.FingerCurlStrengths = new float[] { thumbCurlStrength, indexCurlStrength, middleCurlStrength, ringCurlStrength, littleCurlStrength, }; // Hand is gripping if the grip strength passed the threshold. But we are also taking // the index curl into account explicitly, this helps avoiding the pinch gesture being // considered gripping as well. handData.IsGripping = handData.GripStrength >= IS_GRIPPING_CURL_THRESHOLD && indexCurlStrength >= IS_GRIPPING_INDEX_CURL_THRESHOLD; if (Debug.isDebugBuild && DEBUG_LOG_VALUES_TO_CONSOLE) { Debug.Log($"Grip Strength: {handData.GripStrength} " + $"| Thumb: {handData.FingerCurlStrengths[(int)HandFinger.Thumb]} " + $"| Index: {handData.FingerCurlStrengths[(int)HandFinger.Index]} " + $"| Middle: {handData.FingerCurlStrengths[(int)HandFinger.Middle]} " + $"| Ring: {handData.FingerCurlStrengths[(int)HandFinger.Ring]} " + $"| Little: {handData.FingerCurlStrengths[(int)HandFinger.Little]}"); } } else { // When hand is not tracked, reset all values. handData.IsGripping = false; handData.GripStrength = 0f; handData.FingerCurlStrengths = new float[] { 0f, 0f, 0f, 0f, 0f }; } return(handData); }
/// <inheritdoc /> public override void SetupDefaultInteractions(Handedness controllerHandedness) { AssignControllerMappings(controllerHandedness == Handedness.Left ? DefaultLeftHandedInteractions : DefaultRightHandedInteractions); }
private static Texture2D GetControllerTextureInternal(string fullTexturePath, Handedness handedness, bool scaled) { var handednessSuffix = string.Empty; switch (handedness) { case Handedness.Left: handednessSuffix = "_left"; break; case Handedness.Right: handednessSuffix = "_right"; break; } var themeSuffix = EditorGUIUtility.isProSkin ? "_white" : "_black"; return((Texture2D)AssetDatabase.LoadAssetAtPath($"{fullTexturePath}{handednessSuffix}{themeSuffix}{(scaled ? "_scaled" : string.Empty)}.png", typeof(Texture2D))); }
private static Texture2D GetControllerTextureCached(BaseMixedRealityControllerMappingProfile mappingProfile, SupportedControllerType controllerType, Handedness handedness, bool scaled = false) { var key = new Tuple <SupportedControllerType, Handedness, bool>(controllerType, handedness, scaled); if (CachedTextures.TryGetValue(key, out var texture)) { return(texture); } texture = GetControllerTextureInternal(mappingProfile, controllerType, handedness, scaled); CachedTextures.Add(key, texture); return(texture); }
/// <summary> /// Constructor. /// </summary> protected SimulatedHand(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null) : base(trackingState, controllerHandedness, inputSource, interactions) { }
/// <summary> /// Constructor. /// </summary> protected BaseWindowsMixedRealitySource(TrackingState trackingState, Handedness sourceHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null) : base(trackingState, sourceHandedness, inputSource, interactions) { }
public WindowsMixedRealityArticulatedHandDefinition(IMixedRealityInputSource source, Handedness handedness) : base(source, handedness) { }
/// <summary> /// Default constructor used by reflection for profiles /// </summary> /// <param name="trackingState"></param> /// <param name="controllerHandedness"></param> /// <param name="inputSource"></param> /// <param name="interactions"></param> public OculusQuestHand(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null) : base(trackingState, controllerHandedness, inputSource, interactions) { palmFilter.Reset(); indexTipFilter.Reset(); }
/// <summary> /// Default constructor used by reflection for profiles /// </summary> public OculusHand(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null) : base(trackingState, controllerHandedness, inputSource, interactions) { handDefinition = new ArticulatedHandDefinition(inputSource, controllerHandedness); }
public TestHand(Handedness handedness) { this.handedness = handedness; simulationService = PlayModeTestUtilities.GetInputSimulationService(); }
/// <summary> /// Constructor. /// </summary> /// <param name="controllerType"></param> /// <param name="handedness"></param> /// <param name="pointerPrefab"></param> public PointerOption(IMixedRealityController controllerType, Handedness handedness, GameObject pointerPrefab) { this.controllerType = new SystemType(controllerType.GetType()); this.handedness = handedness; this.pointerPrefab = pointerPrefab; }
/// <summary> /// Release this pointer. This sends pointer clicked and pointer up events across the input system. /// </summary> /// <param name="mixedRealityInputAction">The input action that corresponds to the released button or axis.</param> /// <param name="handedness">Optional handedness of the source that released the pointer.</param> public void RaisePointerUp(MixedRealityInputAction mixedRealityInputAction, Handedness handedness = Handedness.None) { InputSystem.RaisePointerClicked(this, handedness, mixedRealityInputAction, 0); InputSystem.RaisePointerUp(this, handedness, mixedRealityInputAction); }
/// <summary> /// Press this pointer. This sends a pointer down event across the input system. /// </summary> /// <param name="mixedRealityInputAction">The input action that corresponds to the pressed button or axis.</param> /// <param name="handedness">Optional handedness of the source that pressed the pointer.</param> public void RaisePointerDown(MixedRealityInputAction mixedRealityInputAction, Handedness handedness = Handedness.None) { InputSystem.RaisePointerDown(this, handedness, mixedRealityInputAction); }
/// <inheritdoc /> protected BaseOculusController(IMixedRealityControllerDataProvider controllerDataProvider, TrackingState trackingState, Handedness controllerHandedness, MixedRealityControllerMappingProfile controllerMappingProfile, OculusApi.Controller controllerType = OculusApi.Controller.None, OculusApi.Node nodeType = OculusApi.Node.None) : base(controllerDataProvider, trackingState, controllerHandedness, controllerMappingProfile) { ControllerType = controllerType; NodeType = nodeType; }
/// <summary> /// Assign the default interactions based on controller handedness if necessary. /// </summary> public abstract void SetupDefaultInteractions(Handedness controllerHandedness);
void initialize() { up_axis = UpAxis.YUp; handedness = Handedness.RightHanded; unit = 0.0f; }
public BaseOculusController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null) : base(trackingState, controllerHandedness, inputSource, interactions) { NodeType = controllerHandedness == Handedness.Left ? OculusApi.Node.HandLeft : OculusApi.Node.HandRight; }
public bool IsHandTracked(Handedness handedness) { return(handedness == Handedness.Left ? leftHand != null : handedness == Handedness.Right ? rightHand != null : false); }
public static void Show(MixedRealityControllerMapping controllerMapping, SerializedProperty interactionsList, Handedness handedness = Handedness.None) { if (window != null) { window.Close(); } window = null; window = CreateInstance <ControllerPopupWindow>(); window.thisWindow = window; window.titleContent = new GUIContent($"{controllerMapping.Description} - Input Action Assignment"); window.currentControllerMapping = controllerMapping; window.currentInteractionList = interactionsList; isMouseInRects = new bool[interactionsList.arraySize]; if (!File.Exists($"{Application.dataPath}{EditorWindowOptionsPath}")) { var empty = new ControllerInputActionOptions { Controllers = new List <ControllerInputActionOption> { new ControllerInputActionOption { Controller = SupportedControllerType.None, Handedness = Handedness.None, InputLabelPositions = new[] { new Vector2(0, 0) }, IsLabelFlipped = new [] { false } } } }; File.WriteAllText($"{Application.dataPath}{EditorWindowOptionsPath}", JsonUtility.ToJson(empty)); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); } else { controllerInputActionOptions = JsonUtility.FromJson <ControllerInputActionOptions>(File.ReadAllText($"{Application.dataPath}{EditorWindowOptionsPath}")); if (controllerInputActionOptions.Controllers.Any(option => option.Controller == controllerMapping.SupportedControllerType && option.Handedness == handedness)) { window.currentControllerOption = controllerInputActionOptions.Controllers.FirstOrDefault(option => option.Controller == controllerMapping.SupportedControllerType && option.Handedness == handedness); if (window.currentControllerOption != null && window.currentControllerOption.IsLabelFlipped == null) { window.currentControllerOption.IsLabelFlipped = new bool[interactionsList.arraySize]; } } } var windowSize = new Vector2(controllerMapping.HasCustomInteractionMappings ? 896f : 768f, 512f); window.maxSize = windowSize; window.minSize = windowSize; window.CenterOnMainWin(); window.ShowUtility(); defaultLabelWidth = EditorGUIUtility.labelWidth; defaultFieldWidth = EditorGUIUtility.fieldWidth; }
/// <summary> /// Event handler for when the Ungulate menu entry is selected. /// </summary> void HandednessMenuEntrySelected(object sender, PlayerIndexEventArgs e) { currentUngulate++; if (hand == true) hand = false; else hand = true; if (currentUngulate > Handedness.Right) currentUngulate = 0; SetMenuEntryText(); }
protected virtual void AttachToNewTrackedObject() { this.currentTrackedHandedness = Handedness.None; Transform target = null; if (TrackedTargetType == TrackedObjectType.Head) { target = CameraCache.Main.transform; } else if (TrackedTargetType == TrackedObjectType.MotionController) { if (this.TrackedHandness == Handedness.Both) { this.currentTrackedHandedness = Handedness.Left; target = GetMotionController(Handedness.Left); if (target == null) { this.currentTrackedHandedness = Handedness.Right; target = GetMotionController(Handedness.Right); if (target == null) { this.currentTrackedHandedness = Handedness.None; } } } else { this.currentTrackedHandedness = this.TrackedHandness; target = GetMotionController(this.TrackedHandness); } } else if (TrackedTargetType == TrackedObjectType.HandJoint) { if (HandJointService != null) { this.currentTrackedHandedness = this.TrackedHandness; if (currentTrackedHandedness == Handedness.Both) { if (HandJointService.IsHandTracked(Handedness.Left)) { currentTrackedHandedness = Handedness.Left; } else if (HandJointService.IsHandTracked(Handedness.Right)) { currentTrackedHandedness = Handedness.Right; } else { currentTrackedHandedness = Handedness.None; } } target = HandJointService.RequestJointTransform(this.TrackedHandJoint, currentTrackedHandedness); } } else if (TrackedTargetType == TrackedObjectType.CustomOverride) { target = this.transformOverride; } TrackTransform(target); }
/// <summary> /// Gets a scaled texture for the <see cref="SupportedControllerType"/> based on a list of the active <see cref="MixedRealityControllerMappingProfiles"/>. /// </summary> /// <param name="controllerType"></param> /// <param name="handedness"></param> /// <returns>The scaled texture for the controller type, if none found then a generic texture is returned.</returns> public static Texture2D GetControllerTextureScaled(BaseMixedRealityControllerMappingProfile mappingProfile, SupportedControllerType controllerType, Handedness handedness) { return(GetControllerTextureCached(mappingProfile, controllerType, handedness, true)); }
public static bool IsValidHandedness(Handedness hand) { return(hand <= Handedness.Both); }
private static Texture2D GetControllerTextureInternal(BaseMixedRealityControllerMappingProfile mappingProfile, SupportedControllerType controllerType, Handedness handedness, bool scaled) { if (mappingProfile != null && mappingProfile.ControllerType == controllerType) { var texture = GetControllerTextureInternal(mappingProfile.TexturePath, handedness, scaled); if (texture != null) { return(texture); } } return(GetControllerTextureInternal($"{MixedRealityEditorSettings.MixedRealityToolkit_RelativeFolderPath}/StandardAssets/Textures/Generic_controller", Handedness.None, scaled)); }
/// <summary> /// Instantiates <see cref="FingerTipKinematicBodyPrefab"/>s for all <see cref="fingerTipTypes"/>. /// </summary> /// <remarks> /// Optionally instantiates <see cref="PalmKinematicBodyPrefab"/>. /// </remarks> /// <param name="rigidBodyPrefab">The prefab to instantiate.</param> /// <param name="layer">the layer to put the prefab on.</param> /// <param name="handednessType">the specified <see cref="Handedness"/> for the joint.</param> /// <param name="jointType">the specified <see cref="TrackedHandJoint"/> to instantiate against.</param> /// <param name="parent">The root <see href="https://docs.unity3d.com/ScriptReference/GameObject.html"> for the joints.</param> /// <param name="jointKinematicBody">When successful, the generated <see cref="JointKinematicBody"/>.</param> /// <returns>True when able to successfully intantiate and create a <see cref="JointKinematicBody"/>.</returns> private static bool TryCreateJointKinematicBody(GameObject rigidBodyPrefab, int layer, Handedness handednessType, TrackedHandJoint jointType, Transform parent, out JointKinematicBody jointKinematicBody) { jointKinematicBody = null; GameObject currentGameObject = GameObject.Instantiate(rigidBodyPrefab, parent); currentGameObject.layer = layer; JointKinematicBody currentJoint = currentGameObject.GetComponent <JointKinematicBody>(); if (currentJoint == null) { Debug.LogError("The HandPhysicsService assumes the FingerTipKinematicBodyPrefab has a JointKinematicBody component."); UnityEngine.Object.Destroy(currentGameObject); return(false); } currentJoint.JointType = jointType; currentJoint.HandednessType = handednessType; currentGameObject.name = handednessType + " " + jointType; if (currentGameObject.GetComponent <Collider>() == null) { Debug.LogError("The HandPhysicsService assumes the FingerTipKinematicBodyPrefab has a Collder component."); UnityEngine.Object.Destroy(currentGameObject); return(false); } Rigidbody rigidbody = currentGameObject.GetComponent <Rigidbody>(); if (rigidbody == null) { Debug.LogError("The HandPhysicsService assumes the FingerTipKinematicBodyPrefab has a Rigidbody component."); UnityEngine.Object.Destroy(currentGameObject); return(false); } if (!rigidbody.isKinematic) { Debug.LogWarning("The HandPhysicsService FingerTipKinematicBodyPrefab rigidbody should be marked as kinematic, making kinematic."); rigidbody.isKinematic = true; } jointKinematicBody = currentJoint; return(true); }
/// <summary> /// Constructor. /// </summary> /// <param name="controllerType">Controller Type to instantiate at runtime.</param> /// <param name="handedness">The designated hand that the device is managing.</param> public MixedRealityControllerMapping(Type controllerType, Handedness handedness = Handedness.None) : this() { this.controllerType = new SystemType(controllerType); this.handedness = handedness; interactions = null; }
/// <inheritdoc /> public override void SetupDefaultInteractions(Handedness controllerHandedness) { AssignControllerMappings(DefaultInteractions); }
public GenericOpenVRController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null) : base(trackingState, controllerHandedness, inputSource, interactions) { nodeType = controllerHandedness == Handedness.Left ? XRNode.LeftHand : XRNode.RightHand; }
/// <summary> /// Constructor. /// </summary> protected BaseController( TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null, IMixedRealityInputSourceDefinition definition = null) { TrackingState = trackingState; ControllerHandedness = controllerHandedness; InputSource = inputSource; Interactions = interactions; Definition = definition; IsPositionAvailable = false; IsPositionApproximate = false; IsRotationAvailable = false; Type controllerType = GetType(); if (IsControllerMappingEnabled() && Interactions == null) { // We can only enable controller profiles if mappings exist. MixedRealityControllerMapping[] controllerMappings = GetControllerMappings(); // Have to test that a controller type has been registered in the profiles, // else its Unity input manager mappings will not have been set up by the inspector. bool profileFound = false; if (controllerMappings != null) { for (int i = 0; i < controllerMappings.Length; i++) { if (controllerMappings[i].ControllerType.Type == controllerType) { profileFound = true; // If it is an exact match, assign interaction mappings. if (controllerMappings[i].Handedness == ControllerHandedness && controllerMappings[i].Interactions.Length > 0) { MixedRealityInteractionMapping[] profileInteractions = controllerMappings[i].Interactions; MixedRealityInteractionMapping[] newInteractions = new MixedRealityInteractionMapping[profileInteractions.Length]; for (int j = 0; j < profileInteractions.Length; j++) { newInteractions[j] = new MixedRealityInteractionMapping(profileInteractions[j]); } AssignControllerMappings(newInteractions); break; } } } } // If no controller mappings found, try to use default interactions. if (Interactions == null || Interactions.Length < 1) { SetupDefaultInteractions(); // We still don't have controller mappings, so this may be a custom controller. if (Interactions == null || Interactions.Length < 1) { Debug.LogWarning($"No controller interaction mappings found for {controllerType}."); return; } } // If no profile was found, warn the user. Does not stop the project from running. if (!profileFound) { Debug.LogWarning($"No controller profile found for type {controllerType}; please ensure all controllers are defined in the configured MixedRealityControllerConfigurationProfile."); } } if (GetControllerVisualizationProfile() != null && GetControllerVisualizationProfile().RenderMotionControllers&& InputSource != null) { TryRenderControllerModel(controllerType, InputSource.SourceType); } Enabled = true; }
/// <summary> /// Constructor. /// </summary> public ViveWandController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null) : base(trackingState, controllerHandedness, inputSource, interactions) { }
public virtual void SetupDefaultInteractions(Handedness controllerHandedness) => SetupDefaultInteractions();
// Change from left- to right-handedness and back private void SetHandedness(Handedness h) { handedness = h; poserLeftHand.poseRoot = targets.leftHand; poserRightHand.poseRoot = targets.rightHand; poserLeftHand.AutoMapping(); poserRightHand.AutoMapping(); }
public ControllerItem(SupportedControllerType controllerType, Handedness handedness, MixedRealityInteractionMapping[] interactions) { ControllerType = controllerType; Handedness = handedness; Interactions = interactions; }