/// <summary> /// Constructs a body adapter from a serialized version /// </summary> /// <param name="body"></param> public KinectBody(KGP.Serialization.Body.KinectBodyInternal body) { body.Validate(); //This will check preconditions to make sure we have a valid construct this.clippedEdges = body.ClippedEdges; this.handLeftConfidence = body.HandLeftConfidence; this.handLeftState = body.HandLeftState; this.handRightConfidence = body.HandRightConfidence; this.handRightState = body.HandRightState; this.isRestricted = body.IsRestricted; this.isTracked = body.IsTracked; Dictionary<JointType, JointOrientation> orientations = new Dictionary<JointType, JointOrientation>(); Dictionary<JointType, Joint> jointsDic = new Dictionary<JointType,Joint>(); for (int i = 0; i < body.Joints.Length;i++) { var joint = body.Joints[i]; orientations.Add(joint.JointType, body.JointOrientations[i]); jointsDic.Add(joint.JointType, joint); } this.joints = jointsDic; this.jointOrientations =orientations; this.lean = body.Lean; this.leanTrackingState = body.LeanTrackingState; this.trackingId = body.TrackingId; }
public void Update(TrackingConfidence leftConfidence, HandState leftHand, TrackingConfidence rightConfidence, HandState rightHand) { if ( leftConfidence == TrackingConfidence.High && leftHand == HandState.Closed ) { if (!this.HasLeftHandWeapon) { this.LeftHandWeaponIndex = this.selectRandomWeapon(); this.HasLeftHandWeapon = true; } } else { this.HasLeftHandWeapon = false; this.LeftHandWeaponIndex = -1; } if (rightConfidence == TrackingConfidence.High && rightHand == HandState.Closed) { if (!this.HasRightHandWeapon) { this.RightHandWeaponIndex = this.selectRandomWeapon(); this.HasRightHandWeapon = true; } } else { this.HasRightHandWeapon = false; this.RightHandWeaponIndex = -1; } }
/// <summary> /// Initializes a new instance of the <see cref="CustomBody"/> class. /// </summary> public CustomBody() { _clippedEdges = FrameEdges.None; _handLeftConfidence = TrackingConfidence.Low; _handLeftState = HandState.Unknown; _handRightConfidence = TrackingConfidence.Low; _handRightState = HandState.Unknown; _isDisposed = false; _isRestricted = false; _isTracked = false; _joints = new Dictionary<JointType, IJoint>(); _jointOrientations = new Dictionary<JointType, IJointOrientation>(); foreach (var jointType in CustomJointType.AllJoints) { _joints.Add(jointType, new CustomJoint(jointType)); _jointOrientations.Add(jointType, new CustomJointOrientation(jointType)); } _lean = new PointF(); _leanTrackingState = TrackingState.NotTracked; _trackingId = ulong.MaxValue; _hasMappedDepthPositions = false; _hasMappedColorPositions = false; }
public structRectangle() { rect = new Rectangle(); beginTime = new TimeSpan(); handState = new HandState(); position = ""; gestureTried = false; }
void Awake () { handState = HandState.NoAction; leapManager = (GameObject.Find ("LeapManager") as GameObject).GetComponent (typeof(LeapManager)) as LeapManager; cueStickController = (GameObject.Find ("CueStickTip") as GameObject).GetComponent (typeof(CueStickController)) as CueStickController; leapManager.leapController.EnableGesture (Gesture.GestureType.TYPE_SWIPE); leapManager.leapController.Config.SetFloat ("Gesture.Swipe.MinLength", 200.0f); leapManager.leapController.Config.SetFloat ("Gesture.Swipe.MinVelocity", 750f); leapManager.leapController.Config.Save (); gameStates.Add (GameState.CameraAutoAdjust); gameStates.Add (GameState.CameraManualAdjust); gameStates.Add (GameState.Aiming); gameStates.Add (GameState.AfterShot); gameStates.Add (GameState.TurnEnd); viewAdjustmentStateIcon = (GameObject.Find ("ViewAdjustmentStateIcon") as GameObject).GetComponent (typeof(RawImage)) as RawImage; aimingStateIcon = (GameObject.Find ("AimingStateIcon") as GameObject).GetComponent (typeof(RawImage)) as RawImage; swipeActionIcon = (GameObject.Find ("SwipeActionIcon") as GameObject).GetComponent (typeof(RawImage)) as RawImage; playerTurn = (GameObject.Find ("PlayerTurn") as GameObject).GetComponent (typeof(Text)) as Text; cueBall = GameObject.FindGameObjectWithTag ("cueBall"); cueBall = GameObject.FindGameObjectWithTag ("cueBall"); camera = GameObject.FindGameObjectWithTag ("PlayerCamera"); ballsParent = GameObject.FindGameObjectWithTag ("balls"); foreach (Transform ball in ballsParent.transform) { balls.Add (ball.gameObject); } }
private void RaiseHandStateChanged(KinectBody body, HandType handType, HandState previousState) { if (this.HandStateChanged != null) { this.HandStateChanged(this, new KinectHandStateEventArgs(body, handType, previousState)); } }
public HandOverHeadDetector(HandDetectionType handDetectionType, HandState state, int framesToRegister = 10, double headOffset = 0, bool headOffsetAutomatic = true) : base(handDetectionType, state) { FramesToRegister = framesToRegister; HeadOffset = headOffset; HeadOffsetAutomatic = headOffsetAutomatic; }
public HandSliderControl(HandDetectionType handDetectionType, HandState requirredHandState, Directions direction, CoordinateMapper mapper) : base(handDetectionType, requirredHandState) { SmoothLevel = 0; Direction = direction; _mapper = mapper; }
public RangeTrigger(string name, HandState<int> state) : base(name) { Hand = state.Hand; state.ValueChanged += OnStateValueChanged; ResistanceTime = 1000000; StickinessTime = 1000000; }
/// <summary> /// Constructor /// </summary> /// <param name="body">Kinect body</param> /// <param name="handType">Hand type</param> /// <param name="previousHandState">Previous hand state</param> public KinectHandStateEventArgs(KinectBody body, HandType handType, HandState previousHandState) { if (body == null) throw new ArgumentNullException("body"); this.body = body; this.handType = handType; this.previousHandState = previousHandState; }
public TrackerArgs(Body body, HandState left, HandState right, int yaw, int pitch, int roll) { this.body = body; LeftState = left; RightState = right; Yaw = yaw; Pitch = pitch; Roll = roll; }
public void getTrackerInfo(out Body body, out HandState left, out HandState right, out int yaw, out int pitch, out int roll) { body = eTracker.Engager; left = eTracker.LeftState; right = eTracker.RightState; yaw = eTracker.Yaw; pitch = eTracker.Pitch; roll = eTracker.Roll; }
public Person(int id) { this.id = id; this.instance = Send.getInstance (); if (instance == null) { Console.WriteLine ("Die Instanz ist null"); } leftHandState = HandState.NotTracked; rightHandState = HandState.NotTracked; message = new string[2]; }
public void Add(HandState aNext) { if (State == aNext) { Count++; } else { State = aNext; Count = 1; } }
public Cursor() { // deltaPosition = Vector2.zero; // deltaTime = 0; personId = 0; leftHand = false; rightHand = false; cursorId = -1; handState = HandState.Open; position = Vector2.zero; }
/// <summary> /// Constructs a body adapter from a kinect sdk body /// </summary> /// <param name="body">Body from Kinect SDK</param> public KinectBody(Microsoft.Kinect.Body body) { this.clippedEdges = body.ClippedEdges; this.handLeftConfidence = body.HandLeftConfidence; this.handLeftState = body.HandLeftState; this.handRightConfidence = body.HandRightConfidence; this.handRightState = body.HandRightState; this.isRestricted = body.IsRestricted; this.isTracked = body.IsTracked; this.jointOrientations = body.JointOrientations; this.joints = body.Joints; this.lean = body.Lean; this.leanTrackingState = body.LeanTrackingState; this.trackingId = body.TrackingId; }
//constructors public HandleObject() { pos = new Point(200, 200); vel = new Point(0, 0); this.radius = 20; inactiveBrush = Brushes.Red; activeBrush = Brushes.Green; pen = new Pen(); prevHandState = HandState.Unknown; isLeftHandOnObject = false; isRightHandOnObject = false; isBoundToHand = false; currentBrush = inactiveBrush; maxRadiusFactor = 1.5; minRadiusFactor = 0.75; }
private void DrawHand(HandState handState, Point handPosition) { switch (handState) { case HandState.Closed: drawingContext.DrawEllipse(this.handClosedBrush, null, handPosition, HandSize, HandSize); break; case HandState.Open: drawingContext.DrawEllipse(this.handOpenBrush, null, handPosition, HandSize, HandSize); break; case HandState.Lasso: drawingContext.DrawEllipse(this.handLassoBrush, null, handPosition, HandSize, HandSize); break; } }
public static KinectBodyInternal BodyWithRightHandState(ulong id, TrackingConfidence confidence, HandState state) { var result = new KinectBodyInternal() { ClippedEdges = FrameEdges.None, HandLeftConfidence = TrackingConfidence.High, HandLeftState = HandState.NotTracked, HandRightConfidence = confidence, HandRightState = state, IsRestricted = false, IsTracked = true, JointOrientations = new JointOrientation[Microsoft.Kinect.Body.JointCount], Joints = FakeJoints.ValidRandomJoints(), LeanTrackingState = TrackingState.NotTracked, TrackingId = id }; return result; }
// Use this for initialization void Start () { spells.Add(new VoidSpear(this.transform.position)); leftHandState = HandState.idle; rightHandState = HandState.idle; chargeProgressIndicator = ChargeIndicator.GetComponent<ProgressBar>(); chargeProgressIndicator.Min = 0; chargeProgressIndicator.Max = 100; chargeProgressIndicator.Value = 0; chargeProgressIndicator.DecimalPlaces = 0; chargeProgressIndicator.valueType = ProgressBar.ValueType.Percentage; cooldownProgressIndicator = CooldownIndicator.GetComponent<ProgressBar>(); cooldownProgressIndicator.Value = 0; cooldownProgressIndicator.DecimalPlaces = 1; cooldownProgressIndicator.valueType = ProgressBar.ValueType.Float; cooldownProgressIndicator.color = Color.red; }
public Person(string ID, Point3D location, string gesture, trackingStates trackState,Joint leftHand, Joint rightHand, HandState leftHandState, HandState rightHandState, TrackingConfidence leftHandConfidence, TrackingConfidence rightHandConfidence) { this.ID = ID; this.location = location; this.gesture = gesture; this.trackingState = (int)trackState; this.leftHandLocation = null; this.rightHandLocation = null; if (leftHand.TrackingState == TrackingState.Tracked) { this.leftHandLocation = new Point3D((double)leftHand.Position.X, (double)leftHand.Position.Y, (double)leftHand.Position.Z); this.leftHandState = leftHandState.ToString(); this.leftHandConfidence = leftHandConfidence.ToString(); this.rightHandConfidence = rightHandConfidence.ToString(); } if (rightHand.TrackingState == TrackingState.Tracked) { this.rightHandLocation = new Point3D((double)rightHand.Position.X, (double)rightHand.Position.Y, (double)rightHand.Position.Z); this.rightHandState = rightHandState.ToString(); } }
private void UpdateDragging(Hand hand, float3 handPos, ref HandState state) { _gridOrigin.x = handPos.x; _gridOrigin.z = handPos.z; var offset = handPos - state.DragOrigin - state.DragApplied; var intOffset = new int3(math.round(offset / GridSnap)) { x = 0, z = 0 }; if (math.lengthsq(intOffset) <= 0) { return; } offset = new float3(intOffset) * GridSnap; state.DragApplied += offset; HybridLevel.SetDragOffset(-state.DragApplied); var selectedEntities = _getSelectedFloorCeilings.ToEntityArray(Allocator.TempJob); var moves = new NativeArray <Move>(selectedEntities.Length, Allocator.TempJob); var move = new Move { Offset = offset }; for (var i = 0; i < moves.Length; ++i) { moves[i] = move; } EntityManager.AddComponentData(_getSelectedFloorCeilings, moves); selectedEntities.Dispose(); moves.Dispose(); }
private void OnCollisionStay(Collision collision) { collided = collision.gameObject; HandState hand = collided.GetComponent <HandState>(); if (hand != null && !triggered) { if (hand.isGrabbing && (hand.transform.childCount == 2)) { Rigidbody body = GetComponent <Rigidbody>(); if (body != null) { body.isKinematic = true; } ObjectOutline outline = GetComponent <ObjectOutline>(); if (outline != null) { outline.outline.SetActive(false); } if (transform.parent != null) { if (transform.parent.GetComponent <HandState>() == null) { originalParent = transform.parent; } else { return; } } transform.parent = collision.collider.transform; triggered = true; } } }
public void UpdateInfo() { if (rightHand != null || leftHand != null) { Hand availableHand = rightHand != null ? rightHand : leftHand; Finger finger = GetIndexFinger(availableHand); if (finger != null) { fingerPoint = GetTransformedFingerPosition(finger); fingerVector = GetTransformedFingerDirection(finger); isPointing = IsFingerStraight(finger); } handPoint = TransformPoint(availableHand.PalmPosition.ToVector3()); HandState detectedState = getState(availableHand); if (detectedState != handState) { if (nextState == detectedState) { stateChangeProgress += Time.deltaTime; if (stateChangeProgress > stateChangeDelay) { handState = detectedState; stateChangeProgress = 0; } } else { nextState = detectedState; stateChangeDelay = 0; } } else { nextState = detectedState; } isTracked = true; } }
private void MouseLeftClick(HandState handLeftState, IJoint leftHand, IJoint spineMid) { var zLeftHandBodyDistance = spineMid.Position.Z - leftHand.Position.Z; if (zLeftHandBodyDistance > 0.5f) // Right Hand Moving Cursor { if (handLeftState == HandState.Closed && startLeftHandClickGestureState == null) { startLeftHandClickGestureState = new MouseGestureState(PHelper.CurrentTimeMillis()); startLeftHandClickGestureState.oldCursorPosition = Cursor.Position; } else if (handLeftState == HandState.Closed && startLeftHandClickGestureState != null) { var cursorMoveDistance = PointDistance(Cursor.Position, startLeftHandClickGestureState.oldCursorPosition); //Console.WriteLine(cursorMoveDistance); if (cursorMoveDistance < 8) { MouseControl.DoMouseClick(); } } } }
void Start() { _provider = FindObjectOfType <Leap.Unity.LeapServiceProvider>(); if (_provider == null) { throw new System.Exception("Can't find leap motion provider"); } //_controller = _provider.GetLeapController(); //_controller.FrameReady += OnFrameReady; //if (useFixedUpdate) { _provider.OnFixedFrame += OnFrameReady; //} else { // _provider.OnUpdateFrame += OnFrameReady; //} _left = new HandState(); _right = new HandState(); _right.right = true; }
private void DrawLeftHand(JointType activeHand, HandState handState, Point3D handPosition, DrawingContext drawingContext, JointType jointType) { DrawHand(handState, handPosition, drawingContext); if (activeHand != jointType) { return; } _mouseDown = handState == HandState.Closed; //horizontal double delta; var direction = GetDirection(MovementDirection.Right, MovementDirection.Left, handPosition.X, LastLeftX, out delta); if (!_mouseDown || delta < MovementTrigger) { VarZ = 0; } if (delta >= MovementTrigger) { LastRightX = Convert.ToInt32(handPosition.X); InvokeKinectMovement(direction, delta); } //vertical direction = GetDirection(MovementDirection.Up, MovementDirection.Down, handPosition.Y, LastLeftY, out delta); if (!_mouseDown || delta < MovementTrigger) { VarX = 0; } if (delta >= MovementTrigger) { LastRightY = Convert.ToInt32(handPosition.Y); InvokeKinectMovement(direction, delta); } }
void InteractionManager_SourceReleased(InteractionSourceState state) { HandState handState = GetHandState(state); if (handState == null || !handState.IsPressed) { return; } Vector3 handPosition; if (!state.properties.location.TryGetPosition(out handPosition)) { RemoveHandState(state); return; } handState.UpdatePosition(handPosition); handState.IsPressed = false; const float minAcceleration = 0.009f; const float maxAcceleration = 0.3f; Vector3 acceleration = handState.AccumulativeVelocity / (Time.time - handState.PressedTimestamp); if (acceleration.magnitude > minAcceleration) { acceleration = acceleration.normalized * ((acceleration.magnitude / maxAcceleration) * ThrowForceMultiplier); } if (trackedGameObject != null) { trackedGameObject.GetComponent <Rigidbody>().useGravity = true; trackedGameObject.GetComponent <Collider>().enabled = true; trackedGameObject.GetComponent <Rigidbody>().velocity = acceleration; trackedGameObject = null; } }
private void OnTriggerEnter(Collider other) { HandState hand = other.gameObject.GetComponent <HandState>(); Poke poke = other.gameObject.GetComponent <Poke>(); if ((hand != null || poke != null) && !pressed) { switch (type) { case Type.Accept: rMan.UpdateServerRecording(); break; case Type.Decline: break; default: break; } pressed = true; } }
/// <summary> /// Draws a hand symbol if the hand is tracked: red circle = closed, green circle = opened; blue circle = lasso /// </summary> /// <param name="handState">state of the hand</param> /// <param name="handPosition">position of the hand</param> /// <param name="drawingContext">drawing context to draw to</param> private void DrawHand(HandState handState, Point handPosition, DrawingContext drawingContext, string hand) { switch (handState) { case HandState.Open: drawingContext.DrawEllipse(_handOpenBrush, null, handPosition, HandSize, HandSize); Image image = new Image { Width = 100, Uid = flowerCanvas.Children.Count.ToString() //Name = "X" + handPosition.X }; var bmImage = new BitmapImage(); bmImage.BeginInit(); bmImage.UriSource = new Uri("Images/growingFlower.gif", UriKind.Relative); bmImage.EndInit(); image.Source = bmImage; ImageBehavior.SetAnimatedSource(image, bmImage); ImageBehavior.SetRepeatBehavior(image, new RepeatBehavior(1)); flowerCanvas.Children.Add(image); if (flowerCanvas.Children.Count > 20) { var element = flowerCanvas.Children[flowerCanvas.Children.Count - 21]; flowerCanvas.Children.Remove(element); } Canvas.SetTop(image, handPosition.Y * 2.5); Canvas.SetLeft(image, handPosition.X * 2.5); break; case HandState.Closed: drawingContext.DrawEllipse(_handClosedBrush, null, handPosition, HandSize, HandSize); //var enume = flowerCanvas.Children.GetEnumerator(); //if (enume.MoveNext()) // BodyCoords = enume.Current.ToString(); break; } }
//Execute horizontal swipe attack public void HorizontalSwipe() { currentState = HandState.HorizontalSwipe; //Step 1: The hand lowers itself to just above the ground if (handBox.bounds.min.y > groundBox.bounds.max.y) { transform.position -= new Vector3(0, horizontalSwipeYSpeed * Time.deltaTime * timeMultiplier, 0); } //Step 2: The hand moves quickly along the floor until it reaches the other side of the arena else if (movingRight) { attacking = true; transform.position += new Vector3(horizontalSwipeXSpeed * Time.deltaTime * timeMultiplier, 0, 0); //Once the hand reaches the other side of the arena, return to moving state if (handBox.bounds.max.x >= movementZoneBox.bounds.max.x) { currentState = HandState.Move; actionTimer = 0f; attacking = false; } } else if (!movingRight) { attacking = true; transform.position -= new Vector3(horizontalSwipeXSpeed * Time.deltaTime * timeMultiplier, 0, 0); //Once the hand reaches the other side of the arena, return to moving state if (handBox.bounds.min.x <= movementZoneBox.bounds.min.x) { currentState = HandState.Move; actionTimer = 0f; attacking = false; } } }
void Grab() { anim.SetBool("Grab", true); handState = HandState.Grab; gameObject.layer = LayerMask.NameToLayer("HandGrabbed"); if (TryInteract()) { return; } IGrabbable obj = null; Collider2D[] colliders = Physics2D.OverlapCircleAll(grabPosition.position, grabRadius, grabMask); if (colliders.Length > 0) { obj = colliders[0].GetComponent <IGrabbable>(); float min = (grabPosition.position - colliders[0].transform.position).magnitude; for (int i = 1; i < colliders.Length; i++) { float d = (grabPosition.position - colliders[i].transform.position).magnitude; if (d < min) { min = d; obj = colliders[i].GetComponent <IGrabbable>(); } } } grabbedObj = obj; if (grabbedObj != null) { grabbedObj.Grab(); } }
void ExitState(ref HandData hand, HandState nextState) { switch (hand.state) { case HandState.Neutral: { // ... } break; case HandState.Pointing: { DestroyPointingLine(ref hand); } break; case HandState.Grip: { DetachFromHand(ref hand); } break; } }
public void LockHand(HandState state) { isLock = true; Hand_IdleModel.SetActive(false); Hand_GrabModel.SetActive(false); Hand_LargeGrabModel.SetActive(false); switch (state) { case HandState.Idle: Hand_IdleModel.SetActive(true); break; case HandState.Grab: Hand_GrabModel.SetActive(true); break; case HandState.LargeGrab: Hand_LargeGrabModel.SetActive(true); break; } }
internal Hand(ulong trackingID, HandState state, IList<DepthPointEx> contour, IList<DepthPointEx> fingers, CoordinateMapper coordinateMapper) { TrackingId = trackingID; if (state == HandState.Open) { Fingers = fingers.Select(f => new Finger(f, coordinateMapper)).ToList(); } else { Fingers = new List<Finger>(); } ushort[] depths = contour.Select(d => (ushort)d.Z).ToArray(); ContourDepth = contour.Select(p => new DepthSpacePoint { X = p.X, Y = p.Y }).ToArray(); ContourCamera = new CameraSpacePoint[ContourDepth.Count]; coordinateMapper.MapDepthPointsToCameraSpace((DepthSpacePoint[])ContourDepth, depths, (CameraSpacePoint[])ContourCamera); ContourColor = new ColorSpacePoint[ContourDepth.Count]; coordinateMapper.MapDepthPointsToColorSpace((DepthSpacePoint[])ContourDepth, depths, (ColorSpacePoint[])ContourColor); }
// MainWindow.DrawHand public void Add(HandState handState) { switch (handState) { case HandState.Closed: existClosed = 1; break; case HandState.Lasso: existLasso = 1; break; case HandState.Open: existOpen = 1; break; // 手がトラッキングされていない(NotTracked) // または手がグーチョキパー以外の形(Unknown) default: existUnavail = true; break; } }
internal Body( Joint[] jointData, Guid entityId, bool isTracked, HandState leftHandState, TrackingConfidence leftHandConfidence, HandState rightHandState, TrackingConfidence rightHandConfidence, Vector2 lean, TrackingState leanState, FrameEdges clippedEdges) { Joints = new EnumDictionary <Joint>(jointData); IsTracked = isTracked; EntityId = entityId; HandStateLeft = leftHandState; ConfidenceLeft = leftHandConfidence; HandStateRight = rightHandState; ConfidenceRight = rightHandConfidence; Lean = lean; LeanTrackingState = leanState; ClippedEdges = clippedEdges; }
/// <summary> /// Draws a hand symbol if the hand is tracked: red circle = closed, green circle = opened; blue circle = lasso /// </summary> /// <param name="handState">state of the hand</param> /// <param name="handPosition">position of the hand</param> /// <param name="drawingContext">drawing context to draw to</param> private void DrawHand(HandState handState, Point handPosition, DrawingContext drawingContext) { switch (handState) { case HandState.Closed: port.Write("#TEXT" + temp_1 + "A" + temp_2 + "B" + a1_sig + "C" + a2_sig + "D" + "#\n"); //Console.WriteLine("#TEXT" + temp_1 + "A" + temp_2 + "B" + a1_sig + "C" + a2_sig + "D" + "#\n"); this.StatusText = String.Format("Angulo Codo: {0:F2}\nAngulo Mano: {1:F2}", angle_1, angle_2); drawingContext.DrawEllipse(this.handClosedBrush, null, handPosition, HandSize, HandSize); break; case HandState.Open: drawingContext.DrawEllipse(this.handOpenBrush, null, handPosition, HandSize, HandSize); break; case HandState.Lasso: drawingContext.DrawEllipse(this.handLassoBrush, null, handPosition, HandSize, HandSize); break; } }
private void OnTriggerEnter(Collider other) { HandState hand = other.gameObject.GetComponent <HandState>(); Poke poke = other.gameObject.GetComponent <Poke>(); if ((hand != null || poke != null) && !pressed) { switch (type) { case Type.Next: screen.Next(); break; case Type.Back: screen.Back(); break; default: break; } pressed = true; } }
private void StartDragging(float3 handPos, ref HandState state) { if (state.HoveredFloorCeiling == Entity.Null || !EntityManager.GetSelected(state.HoveredFloorCeiling)) { EntityManager.DeselectAll(); if (state.HoveredFloorCeiling != Entity.Null) { EntityManager.SetSelected(state.HoveredFloorCeiling, true); } else { return; } } state.IsDragging = true; state.HasExtruded = false; state.DragOrigin = handPos; state.DragApplied = float3.zero; HybridLevel.SetDragOffset(-state.DragApplied); }
private void loadHandState(HandState hs) { setNodeRotation(pinky, baseNodeAngle(hs.pinky[0])); setNodeRotation(pinky.GetChild(0), middleNodeAngle(hs.pinky[1])); setNodeRotation(pinky.GetChild(0).GetChild(0), middleNodeAngle(hs.pinky[1])); setNodeRotation(ring, baseNodeAngle(hs.ring[0])); setNodeRotation(ring.GetChild(0), middleNodeAngle(hs.ring[1])); setNodeRotation(ring.GetChild(0).GetChild(0), middleNodeAngle(hs.ring[1])); setNodeRotation(middle, baseNodeAngle(hs.middle[0])); setNodeRotation(middle.GetChild(0), middleNodeAngle(hs.middle[1])); setNodeRotation(middle.GetChild(0).GetChild(0), middleNodeAngle(hs.middle[1])); setNodeRotation(index, baseNodeAngle(hs.index[0])); setNodeRotation(index.GetChild(0), middleNodeAngle(hs.index[1])); setNodeRotation(index.GetChild(0).GetChild(0), middleNodeAngle(hs.index[1])); setThumbRotation(thumb.GetChild(0), baseNodeAngle(hs.thumb[0])); setThumbRotation(thumb.GetChild(0).GetChild(0), baseNodeAngle(hs.thumb[1])); setPalmReference(hs.palm); }
// hand switch statement private double handStatusSwitch(HandState hand) { switch (hand) { case HandState.Open: return(0); case HandState.Closed: return(1); case HandState.Lasso: return(2); case HandState.Unknown: return(3); case HandState.NotTracked: return(4); default: return(-1); } }
/// <summary> /// draws the hand, according to the handstate on the body /// </summary> /// <param name="handState"></param> /// <param name="handPosition"></param> /// <param name="playerNumber"></param> /// <param name="drawingContext"></param> private void DrawHand(HandState handState, Point handPosition, int playerNumber, DrawingContext drawingContext) { Point p = handPosition; p.X -= 10; p.Y -= 20; switch (handState) { case HandState.Closed: drawingContext.DrawEllipse(handClosedBrush, null, handPosition, HandSize, HandSize); drawingContext.DrawText(new FormattedText(playerNumber.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeFace, 30, textBrush), p); break; case HandState.Open: drawingContext.DrawEllipse(handOpenBrush, null, handPosition, HandSize, HandSize); drawingContext.DrawText(new FormattedText(playerNumber.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeFace, 30, textBrush), p); break; case HandState.Lasso: drawingContext.DrawEllipse(handLassoBrush, null, handPosition, HandSize, HandSize); drawingContext.DrawText(new FormattedText(playerNumber.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeFace, 30, textBrush), p); break; } }
private bool HandStateChanged(HandState handstate) { if (handstate == HandState.Unknown) { return(false); } if (handstate != currentHandState) { if (handstate == HandState.Open) { currentHandState = handstate; handGesture = new KinectGesture(GestureType.Pinch, GestureDirection.Push); return(true); } else if (handstate == HandState.Closed) { currentHandState = handstate; handGesture = new KinectGesture(GestureType.Pinch, GestureDirection.Pull); return(true); } return(false); } return(false); }
int HandStateToValue(HandState hs) { if (hs == HandState.Open) { return(1); } if (hs == HandState.Closed) { return(2); } if (hs == HandState.Lasso) { return(3); } if (hs == HandState.Unknown) { return(4); } if (hs == HandState.NotTracked) { return(5); } return(6); }
private void UpdateInteract(Hand hand, float3 handPos, ref HandState state) { if (UseToolAction.GetStateDown(hand.handType)) { state.IsActionHeld = true; if (MultiSelectAction.GetState(hand.handType)) { StartSelecting(ref state); } else { StartDragging(handPos, ref state); } } else if (state.IsActionHeld && UseToolAction.GetState(hand.handType)) { if (state.IsDragging) { UpdateDragging(hand, handPos, ref state); return; } UpdateSelecting(ref state); } if (state.IsActionHeld && UseToolAction.GetStateUp(hand.handType)) { state.IsActionHeld = false; if (state.IsDragging) { StopDragging(ref state); } } }
public virtual void EndInteraction(NVRInteractable item) { if (item != null && CurrentlyHoveringOver.ContainsKey(item) == true) { CurrentlyHoveringOver.Remove(item); } if (CurrentlyInteracting != null) { // TODO: A more general event may be better ScenarioLogManager.Instance.LogEvent(this.gameObject, "OnRelease", CurrentlyInteracting.gameObject.name); CurrentlyInteracting.EndInteraction(); CurrentlyInteracting = null; } if (CurrentInteractionStyle == InteractionStyle.GripToggleToInteract) { if (CurrentHandState != HandState.Idle) { CurrentHandState = HandState.Idle; } } }
public virtual void EndInteraction(NVRInteractable item) { if (item != null && CurrentlyHoveringOver.ContainsKey(item)) { CurrentlyHoveringOver.Remove(item); } if (CurrentlyInteracting != null) { CurrentlyInteracting.EndInteraction(); if (OnEndInteraction != null) { OnEndInteraction.Invoke(CurrentlyInteracting); } CurrentlyInteracting = null; } if (CurrentInteractionStyle == InterationStyle.Toggle) { CurrentHandState = HandState.Idle; } }
private void HandleTwoOrMoreHands(List <Hand> hands) { foreach (Hand hand in hands) { switch (hand.IsLeft) { case true: leftHand = hand; break; default: rightHand = hand; break; } } if (!AreBothHandsNotNull() || hands.Count > 2) { handState = HandState.Invalid; return; } handState = HandState.Both; }
void InteractionManager_SourcePressed(InteractionSourceState state) { HandState handState = GetHandState(state); handState.IsPressed = true; Vector3 handPosition; if (!state.properties.location.TryGetPosition(out handPosition)) { RemoveHandState(state); return; } handState.UpdatePosition(handPosition); if (trackedGameObject == null) { trackedGameObject = Instantiate(PaperPrefab); trackedGameObject.GetComponent <Rigidbody>().useGravity = false; trackedGameObject.GetComponent <Collider>().enabled = false; trackedGameObject.transform.position = handState.Position + Camera.main.transform.TransformVector(FingertipsOffset); } }
public void Initialize() { Rigidbody = this.GetComponent <Rigidbody>(); if (Rigidbody == null) { Rigidbody = this.gameObject.AddComponent <Rigidbody>(); } Rigidbody.isKinematic = true; Rigidbody.maxAngularVelocity = float.MaxValue; Rigidbody.useGravity = false; Collider[] colliders = null; if (CustomModel == null) { colliders = InputDevice.SetupDefaultColliders(); } else { colliders = RenderModel.GetComponentsInChildren <Collider>(); //note: these should be trigger colliders } Player.RegisterHand(this); if (Player.PhysicalHands == true) { if (PhysicalController != null) { PhysicalController.Kill(); } PhysicalController = this.gameObject.AddComponent <NVRPhysicalController>(); PhysicalController.Initialize(this, false); if (Player.AutomaticallySetControllerTransparency == true) { Color transparentcolor = Color.white; transparentcolor.a = (float)VisibilityLevel.Ghost / 100f; GhostRenderers = this.GetComponentsInChildren <Renderer>(); for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++) { NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor); } } if (colliders != null) { GhostColliders = colliders; } CurrentVisibility = VisibilityLevel.Ghost; } else { if (Player.AutomaticallySetControllerTransparency == true) { Color transparentcolor = Color.white; transparentcolor.a = (float)VisibilityLevel.Ghost / 100f; GhostRenderers = this.GetComponentsInChildren <Renderer>(); for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++) { NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor); } } if (colliders != null) { GhostColliders = colliders; } CurrentVisibility = VisibilityLevel.Ghost; } CurrentHandState = HandState.Idle; }
public HandleObject(Point position, int radius, Point velocity, int displayWidth, int displayHeight, int id = -1) { this.ball = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\../../../Images\\basketball.png")); this.ID = id; this.pos = position; this.vel = velocity; this.radius = radius; this.adjRadius = radius; this.defaultPos = position; inactiveBrush = Brushes.Red; activeBrush = Brushes.Green; pen = new Pen(); prevHandState = HandState.Unknown; isLeftHandOnObject = false; isRightHandOnObject = false; isBoundToHand = false; currentBrush = inactiveBrush; this.displayWidth = displayWidth; this.displayHeight = displayHeight; averageOfPoints = new Point[5]; }
private void UpdateVisibilityAndColliders() { if (Player.PhysicalHands == true) { if (CurrentInteractionStyle == InterationStyle.Hold) { if (HoldButtonPressed == true && IsInteracting == false) { if (CurrentHandState != HandState.GripDownNotInteracting && VisibilityLocked == false) { VisibilityLocked = true; SetVisibility(VisibilityLevel.Visible); CurrentHandState = HandState.GripDownNotInteracting; } } else if (HoldButtonDown == true && IsInteracting == true) { if (CurrentHandState != HandState.GripDownInteracting && VisibilityLocked == false) { VisibilityLocked = true; if (Player.MakeControllerInvisibleOnInteraction == true) { SetVisibility(VisibilityLevel.Invisible); } else { SetVisibility(VisibilityLevel.Ghost); } CurrentHandState = HandState.GripDownInteracting; } } else if (IsInteracting == false) { if (CurrentHandState != HandState.Idle && VisibilityLocked == false) { SetVisibility(VisibilityLevel.Ghost); CurrentHandState = HandState.Idle; } } } else if (CurrentInteractionStyle == InterationStyle.Toggle) { if (CurrentHandState == HandState.Idle) { if (VisibilityLocked == false && CurrentVisibility != VisibilityLevel.Ghost) { SetVisibility(VisibilityLevel.Ghost); } else { VisibilityLocked = false; } } else if (CurrentHandState == HandState.GripToggleOnInteracting) { if (VisibilityLocked == false) { VisibilityLocked = true; SetVisibility(VisibilityLevel.Ghost); } } else if (CurrentHandState == HandState.GripToggleOnNotInteracting) { if (VisibilityLocked == false) { VisibilityLocked = true; SetVisibility(VisibilityLevel.Visible); } } } } else if (Player.PhysicalHands == false && Player.MakeControllerInvisibleOnInteraction == true) { if (IsInteracting == true) { SetVisibility(VisibilityLevel.Invisible); } else if (IsInteracting == false) { SetVisibility(VisibilityLevel.Ghost); } } }
public void update(HandState leftHand, HandState rightHand, Point leftPoint, Point rightPoint, float leftHandDepth,float rightHandDepth) { prevHandPoint = activePoint; isLeftHandOnObject = isHandOnObject(leftPoint); isRightHandOnObject = isHandOnObject(rightPoint); if (isLeftHandOnObject) { activeHandState = leftHand; activePoint = leftPoint; activeDepth = leftHandDepth; }else if(isRightHandOnObject){ activeHandState = rightHand; activePoint = rightPoint; activeDepth = rightHandDepth; } averageOfPoints[index % 5] = new Point(activePoint.X - prevHandPoint.X, activePoint.Y - prevHandPoint.Y); index += 1; if (pos.X + adjRadius>= displayWidth || pos.X - adjRadius<= 0) { vel.X = -vel.X; } this.pos.X += this.vel.X; if (!isBoundToHand) { hAcc += hAccIncrement; if (pos.Y + adjRadius >= displayHeight) { vel.Y = -vel.Y; pos.Y = displayHeight - radius * 2; } vel.Y += hAcc; this.pos.Y += this.vel.Y; } else { hAcc = 0; vel.Y = 0; } if (isLeftHandOnObject || isRightHandOnObject || isBoundToHand) { if (activeHandState == HandState.Closed || activeHandState == HandState.Open) { prevHandState = currHandState; currHandState = activeHandState; } if (IsHolding() && !isBoundToHand) return; //set color depending on the action performed if (IsGrabbed()) { if (isLeftHandOnObject || isRightHandOnObject) isBoundToHand = true; currentBrush = activeBrush; radius = radius * activeDepth; if (adjRadius > 60) adjRadius = 60; if (adjRadius < 35) adjRadius = 35; } else if (IsReleased()) { double xTotal = 0, yTotal = 0; isBoundToHand = false; foreach (Point p in averageOfPoints) { xTotal += p.X; yTotal += p.Y; } vel.X = xTotal / averageOfPoints.Length; vel.Y = yTotal / averageOfPoints.Length; currentBrush = inactiveBrush; } if ((IsGrabbed() || IsHolding()) && !isBoundToHand) { Console.WriteLine("dh"); } if ((IsGrabbed() || IsHolding()) && isBoundToHand) { this.pos = activePoint; adjRadius = radius / activeDepth; } else { radius = adjRadius; } } else { // prevHandState = HandState.Closed; //currHandState = HandState.Closed; } }
/// <summary> /// Updates hand state ellipses depending on tracking state and it's confidence. /// </summary> /// <param name="ellipse">ellipse representing handstate</param> /// <param name="handState">open, closed, or lasso</param> /// <param name="trackingConfidence">confidence of handstate</param> /// <param name="point">location of handjoint</param> private void UpdateHand(Ellipse ellipse, HandState handState, TrackingConfidence trackingConfidence, Point point) { ellipse.Fill = new SolidColorBrush(this.HandStateToColor(handState)); // draw handstate ellipse based on tracking confidence ellipse.Width = ellipse.Height = (trackingConfidence == TrackingConfidence.Low) ? LowConfidenceHandSize : HighConfidenceHandSize; ellipse.Visibility = Windows.UI.Xaml.Visibility.Visible; // don't draw handstate if hand joints are not tracked if (!Double.IsInfinity(point.X) && !Double.IsInfinity(point.Y)) { Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2); Canvas.SetTop(ellipse, point.Y - ellipse.Width / 2); } }
/// <summary> /// Draws a hand symbol if the hand is tracked: red circle = closed, green circle = opened; blue circle = lasso /// </summary> /// <param name="handState">state of the hand</param> /// <param name="handPosition">position of the hand</param> /// <param name="drawingContext">drawing context to draw to</param> private void DrawHand(HandState handState, Point handPosition, DrawingContext drawingContext) { string footerMainMenuText; Binding set; switch (handState) { case HandState.Closed: drawingContext.DrawEllipse(this.handClosedBrush, null, handPosition, HandSize, HandSize); break; case HandState.Open: drawingContext.DrawEllipse(this.handOpenBrush, null, handPosition, HandSize, HandSize); footerMainMenuText = "Paper"; set = new Binding(); set.Mode = BindingMode.OneWay; set.Source = footerMainMenuText; MessageBlock_Dumbbell.DataContext = footerMainMenuText; MessageBlock_Dumbbell.SetBinding(TextBlock.TextProperty, set); break; case HandState.Lasso: drawingContext.DrawEllipse(this.handLassoBrush, null, handPosition, HandSize, HandSize); footerMainMenuText = "Scissor"; set = new Binding(); set.Mode = BindingMode.OneWay; set.Source = footerMainMenuText; MessageBlock_Dumbbell.DataContext = footerMainMenuText; MessageBlock_Dumbbell.SetBinding(TextBlock.TextProperty, set); break; } }
private static void DrawHand(this Canvas canvas, Point handPosition, HandState handState) { double handSize = 90; switch (handState) { case HandState.Closed: canvas.DrawPoint(handPosition, Constants.HandClosedBrush, handSize); break; case HandState.Open: canvas.DrawPoint(handPosition, Constants.HandOpenBrush, handSize); break; case HandState.Lasso: canvas.DrawPoint(handPosition, Constants.HandLassoBrush, handSize); break; } }
/// <summary> /// Select color of hand state /// </summary> /// <param name="handState"></param> /// <returns></returns> private Color HandStateToColor(HandState handState) { switch (handState) { case HandState.Open: return Colors.Green; case HandState.Closed: return Colors.Red; case HandState.Lasso: return Colors.Blue; } return Colors.Transparent; }
/// <summary> /// Draws a hand symbol if the hand is tracked: red circle = closed, green circle = opened; blue circle = lasso /// </summary> /// <param name="handState">state of the hand</param> /// <param name="handPosition">position of the hand</param> /// <param name="drawingContext">drawing context to draw to</param> public void DrawHand(HandState handState, Point handPosition) { switch (handState) { case HandState.Closed: this.imageSource.DrawEllipse((int)handPosition.X, (int)handPosition.Y, (int)handPosition.X + (int)HandSize, (int)handPosition.Y + (int)HandSize, this.handClosedColor); break; case HandState.Open: this.imageSource.DrawEllipse((int)handPosition.X, (int)handPosition.Y, (int)handPosition.X + (int)HandSize, (int)handPosition.Y + (int)HandSize, this.handOpenColor); break; case HandState.Lasso: this.imageSource.DrawEllipse((int)handPosition.X, (int)handPosition.Y, (int)handPosition.X + (int)HandSize, (int)handPosition.Y + (int)HandSize, this.handLassoColor); break; } }
public OscMessage BuildHandMessage(Body body, string key, HandState state, TrackingConfidence confidence) { var address = String.Format("/bodies/{0}/hands/{1}", body.TrackingId, key); //System.Diagnostics.Debug.WriteLine(address); return new OscMessage(address, state.ToString(), confidence.ToString()); }