/* * Save whether your previous hands are opened * THIS IS USED FOR JustOpenedHandOn() & JustClosedHandOn() * @param hands Leap.Hand[] both hands */ public void SavePreviousHands(Hand[] hands) { foreach (int handId in this.handIds) { Hand hand = hands[handId]; if (hand == null) { this.existsPreviousHands[handId] = false; } else { this.existsPreviousHands[handId] = true; if (HandUtil.GetHandStatus(hand) == HandStatus.OPEN) { this.isOpenedPreviousHands[handId] = true; } else if (HandUtil.GetHandStatus(hand) == HandStatus.CLOSE) { this.isOpenedPreviousHands[handId] = false; } else { } //何も保存しない } } //Debug.Log("Left: " + this.isOpenedPreviousHands[HandUtil.LEFT]); //Debug.Log("Right: " + this.isOpenedPreviousHands[HandUtil.RIGHT]); }
public void TestNoStraight() { var cards = MakeHand(Rank.Eight, Rank.Ten, Rank.Jack, Rank.Queen, Rank.King); bool result = HandUtil.TryGetStraightOrStraightFlush(cards, out HandType handType, out Rank rank); Assert.AreEqual(false, result); }
public void TestFlush() { var cards = MakeHand(Suit.Clubs, Suit.Clubs, Suit.Clubs, Suit.Clubs, Suit.Clubs); bool result = HandUtil.TryGetFlush(cards, out Rank? rank); Assert.AreEqual(true, result); }
/* * Returns whether a hand is "just opened" or "just closed" from a state of closed or opened hand * * Called by JustOpenedHandOn or JustClosedHandOn * @param hand: LeapMotion Hand Model * @param handId: HandUtil.LEFT(=0) or HandUtil.RIGHT(=1) * @param actionType: Hand just opened action or Hand just closed action * @return whether the action is started (true or false) */ private bool JustActionedHandOn(Hand[] hands, int handId, HandActionType actionType) { Hand hand = hands[handId]; //過去手を開いていて,現在の手が存在し,その手の指が全部閉じるとき if (hand != null) { switch (actionType) { case HandActionType.JUST_OPENED: //Whether the hand is just opened if (!this.isOpenedPreviousHands[handId] && HandUtil.GetHandStatus(hand) == HandStatus.OPEN) { this.isOpenedPreviousHands[handId] = true; //hand status return(true); //Just opened } break; case HandActionType.JUST_CLOSED: //Whether the hand is just closed if (this.isOpenedPreviousHands[handId] && HandUtil.GetHandStatus(hand) == HandStatus.CLOSE) { this.isOpenedPreviousHands[handId] = false; //hand status return(true); //Just closed } break; } } return(false); //Not Actioned }
public void TestHighCard() { List <Card> hand = MakeHand(Rank.Ace, Rank.Queen, Rank.Jack, Rank.Ten, Rank.Nine); Sets sets = HandUtil.GetSets(hand, out HandType handType, out Rank rank); Assert.AreEqual(HandType.HighCard, handType); Assert.AreEqual(Rank.Ace, rank); }
public void TestLowAceStraight() { var cards = MakeHand(Rank.Two, Rank.Three, Rank.Four, Rank.Five, Rank.Ace); bool result = HandUtil.TryGetStraightOrStraightFlush(cards, out HandType handType, out Rank rank); Assert.AreEqual(true, result); Assert.AreEqual(HandType.Straight, handType); Assert.AreEqual(Rank.Five, rank); }
public void TestHighAceStraight() { var cards = MakeHand(Rank.Ten, Rank.Jack, Rank.Queen, Rank.King, Rank.Ace); bool result = HandUtil.TryGetStraightOrStraightFlush(cards, out HandType handType, out Rank rank); Assert.AreEqual(true, result); Assert.AreEqual(HandType.Straight, handType); Assert.AreEqual(Rank.Ace, rank); }
public void TestStraightFlush() { var cards = MakeHand(alsoFlush: true, Rank.Nine, Rank.Ten, Rank.Jack, Rank.Queen, Rank.King); bool result = HandUtil.TryGetStraightOrStraightFlush(cards, out HandType handType, out Rank rank); Assert.AreEqual(true, result); Assert.AreEqual(HandType.StraightFlush, handType); Assert.AreEqual(Rank.King, rank); }
public void TestInterruptedHoldemStraight() { var cards = MakeHand(Rank.Two, Rank.Three, Rank.Five, Rank.Six, Rank.Seven, Rank.Eight, Rank.Nine); bool result = HandUtil.TryGetStraightOrStraightFlush(cards, out HandType handType, out Rank rank); Assert.AreEqual(true, result); Assert.AreEqual(HandType.Straight, handType); Assert.AreEqual(Rank.Nine, rank); }
public void TestFourOfAKind() { List <Card> hand = MakeHand( Rank.Eight, Rank.Eight, Rank.Eight, Rank.Eight, Rank.Five, Rank.Five, Rank.Five); Sets sets = HandUtil.GetSets(hand, out HandType handType, out Rank rank); Assert.AreEqual(HandType.FourOfAKind, handType); Assert.AreEqual(Rank.Eight, rank); }
private void OnHandDataAppear(HandData handData) { var handProxy = HandUtil.CreateNewHand(handData); handProxy.transform.SetParent(transform); _activeHands.Add(handProxy); // -- Invoke on hand appear event events.OnHandEnter.Invoke(handProxy); }
/// <summary> /// Not currently used. Should be used in case HandTemplate (Right) or HandTemplate (Left) Have been corupted / destroyed. /// </summary> private void BuildNewTemplates() { if (_rightTemplate == null) { HandUtil.InitializeTemplateHand(HandType.Right); } if (_leftTemplate == null) { HandUtil.InitializeTemplateHand(HandType.Left); } }
//投げる動作か判定 public bool IsThrownGesture(Hand hand) { if (hand != null) { if (this.IsPalmNormalSameDirectionWith(hand, HandUtil.ToVector3(hand.PalmVelocity)) && !this.IsHandStayed(hand)) { return(true); } } return(false); }
private void Init() { this.m_Provider = this.leapProviderObj.GetComponent <LeapServiceProvider>(); this.handUtil = new HandUtil(); this.IsFingerEffector = false; this.curAttractorIndex = 0; this.attractorHandId = this.IsAttractorOnLeftHand ? HandUtil.LEFT : HandUtil.RIGHT; this.effectorHandId = this.IsAttractorOnLeftHand ? HandUtil.RIGHT : HandUtil.LEFT; for (int i = 0; i < this.attractorScales.Count; i++) { float s = this.attractorScales[i]; attractors[i].transform.localScale = new Vector3(s, s, s); } this.previousHands = new Hand[2]; }
public void TestFullHouse() { List <Card> hand = MakeHand( Rank.Ace, Rank.Ace, Rank.Ace, Rank.Eight, Rank.Eight, Rank.Eight, Rank.Two, Rank.Two); Sets sets = HandUtil.GetSets(hand, out HandType handType, out Rank rank); var expectedSets = new Sets(new List <Set>(new[] { new Set(Rank.Ace, 3), new Set(Rank.Eight, 2) })); Assert.AreEqual(expectedSets, sets); Assert.AreEqual(HandType.FullHouse, handType); Assert.AreEqual(Rank.Ace, rank); }
void Update() { Frame frame = this.m_Provider.CurrentFrame; Hand[] hands = HandUtil.GetCorrectHands(frame); //0=LEFT, 1=RIGHT if (hands[HandUtil.LEFT] != null && hands[HandUtil.RIGHT] != null) { Hand leftHand = hands[HandUtil.LEFT]; Hand rightHand = hands[HandUtil.RIGHT]; if (this.handUtil.JustOpenedHandOn(hands, HandUtil.LEFT)) { //Moment that index finger of left hand is opened if (rightHand.Fingers[(int)FingerType.TYPE_INDEX].IsExtended) { Vector3 markingPoint = HandUtil.ToVector3(rightHand.Fingers[(int)FingerType.TYPE_INDEX].TipPosition); } } else if (this.handUtil.JustOpenedHandOn(hands, HandUtil.RIGHT)) { //Moment that index finger of right hand is opened if (leftHand.Fingers[(int)FingerType.TYPE_INDEX].IsExtended) { Vector3 markingPoint = HandUtil.ToVector3(leftHand.Fingers[(int)FingerType.TYPE_INDEX].TipPosition); FingerMapper.MarkPoint(this.mappedPoints, markingPoint); Debug.Log("Marked point at " + markingPoint); } } } if (SceneManager.GetActiveScene().name == FingerMapper.sceneName) { if (Input.GetKeyUp(KeyCode.E)) { this.Save(); } else if (Input.GetKeyUp(KeyCode.D)) { //foreach (Transform t in this.mappedPoints.transform) { Destroy(t.gameObject); } } } //this.handUtil.SavePreviousFingers(hands); this.handUtil.SavePreviousHands(hands); }
void Start() { this.m_Provider = this.leapProviderObj.GetComponent <LeapServiceProvider>(); this.handUtil = new HandUtil(player); FingerMapper.Load(this.mappedPoints); this.isStartedLighting = false; this.inactivePoints = new List <Vector3>(); foreach (Transform point in mappedPoints.transform) { this.inactivePoints.Add(point.position); } //線を描画する処理に使う this.line = new Line() { currentPoint = Vector3.zero, nextPoint = Vector3.zero, progress = 0.0f, drawingSpeed = LINE_DRAWING_SPEED }; this.lineTimer = new Util.Timer(2.5f); this.light3Timer = new Util.Timer(6.0f); }
void Update() { Frame frame = this.m_Provider.CurrentFrame; Hand[] hands = HandUtil.GetCorrectHands(frame); //0=LEFT, 1=RIGHT if (this.handUtil.JustOpenedHandOn(hands, this.attractorHandId)) { Debug.Log("Just OPENED RIGHT hand"); //Show attractor this.curAttractor = this.attractors[this.curAttractorIndex]; this.curAttractor.GetComponent <VisualEffect>().enabled = true; } else if (this.handUtil.JustClosedHandOn(hands, this.attractorHandId)) { Debug.Log("Just CLOSED RIGHT hand"); //Unshow attractor this.curAttractor.GetComponent <VisualEffect>().enabled = false; this.curAttractorIndex = (this.curAttractorIndex + 1) % this.attractors.Count; //Go next attractor } if (this.handUtil.JustOpenedFingerOn(hands, this.effectorHandId, (int)Finger.FingerType.TYPE_INDEX)) { Debug.Log("Just OPENED RIGHT index finger"); this.IsFingerEffector = true; } else if (this.handUtil.JustClosedFingerOn(hands, this.effectorHandId, (int)Finger.FingerType.TYPE_INDEX)) { Debug.Log("Just CLOSED RIGHT index finger"); this.IsFingerEffector = false; } //Attractor and hand exists if (this.curAttractor != null && hands[this.attractorHandId] != null) { Hand hand = hands[this.attractorHandId]; //手の中心とアトラクターとの距離から表示位置を割り出す Vector attractorPos = hand.PalmPosition + this.attractorDistances[this.curAttractorIndex] * hand.PalmNormal; //アトラクターの位置を補正(attractorAddPositions) this.curAttractor.transform.position = HandUtil.GetVector3(attractorPos) + this.attractorAddPositions[this.curAttractorIndex]; //アトラクターの回転を補正(attractorAddQuaternions) this.curAttractor.transform.rotation = HandUtil.GetQuaternion(hand.Rotation) * Quaternion.Euler(this.attractorAddQuaternions[this.curAttractorIndex]); } //FingerEffect and hand exists if (this.IsFingerEffector && hands[this.effectorHandId] != null) { Finger indexFinger = hands[this.effectorHandId].Fingers[(int)Finger.FingerType.TYPE_INDEX]; Vector3 tipPosition = HandUtil.GetVector3(indexFinger.TipPosition); this.fingerTip.transform.position = tipPosition; //Debug.Log("tipPos: " + tipPosition); } this.handUtil.SavePreviousHands(hands); this.handUtil.SavePreviousFingers(hands); this.previousHands = hands; //if (Input.GetKeyUp(KeyCode.F)) { }
private Vector3 GetHandVelocity(Hand hand) { return(this.playerTransform.InverseTransformDirection(HandUtil.ToVector3(hand.PalmVelocity))); }
private bool IsAlmostSameDirection(Vector a, Vector b) { return(this.IsAlmostSameDirection(HandUtil.ToVector3(a), HandUtil.ToVector3(b))); }
private bool IsPalmNormalSameDirectionWith(Hand hand, Vector3 dir) { return(this.IsAlmostSameDirection(HandUtil.ToVector3(hand.PalmNormal), dir)); }
void Update() { Frame frame = this.m_Provider.CurrentFrame; Hand[] hands = HandUtil.GetCorrectHands(frame); //0=LEFT, 1=RIGHT if (hands[HandUtil.LEFT] != null || hands[HandUtil.RIGHT] != null) { Hand leftHand = hands[HandUtil.LEFT]; Hand rightHand = hands[HandUtil.RIGHT]; bool isJustOpenedLeftHand = this.handUtil.JustOpenedHandOn(hands, HandUtil.LEFT); bool isJustOpenedRightHand = this.handUtil.JustOpenedHandOn(hands, HandUtil.RIGHT); if (!this.isStartedLighting && (isJustOpenedLeftHand || isJustOpenedRightHand)) { Debug.Log("Opend a hand."); // 現在の光の位置と,次の光の位置を割り出す if (isJustOpenedLeftHand) { this.line.currentPoint = HandUtil.ToVector3(leftHand.PalmPosition); } else if (isJustOpenedRightHand) { this.line.currentPoint = HandUtil.ToVector3(rightHand.PalmPosition); } this.line.nextPoint = GetClosePoint(this.line.currentPoint); //this.TurnOnLight(1); // Light1をつける //this.TurnOnLight(2); // Light2をつける //this.light3Timer.Start(); //Light3をつけるまで待つ //this.lineTimer.Start(); //線の描画を待つ this.isStartedLighting = true; //Debug.Log(this.line.currentPoint + ", " + this.line.nextPoint); } } //時間が来たらlight3を点灯させる if (this.light3Timer.OnTime()) { this.TurnOnLight(3); // Light3をつける this.MakeLineObj(); //source pos=0, dest pos=0 } /* // ある程度光が放たれ,線を描画するタイミングが来たら,線を作成 * if (this.lineTimer.OnTime()) { * } */ if (this.line.isStarted) { if (this.line.progress < 1.0f) { //線描画が始まっていたら,線を放っていく this.ProgressLight(); } else { if (this.inactivePoints.Count > 0) { //次のポイントに変更 this.line.currentPoint = this.line.nextPoint; this.line.nextPoint = this.GetClosePoint(this.line.currentPoint); this.TurnOnLight(1); // Light1をつける this.TurnOnLight(2); // Light2をつける this.light3Timer.Start(); //Light3をつけるまで待つ this.line.progress = 0.0f; this.line.isStarted = false; } } } if (this.light3Timer.isStarted) { this.light3Timer.Clock(); } //if (this.lineTimer.isStarted) { this.lineTimer.Clock(); } }
void Start() { this.m_Provider = this.leapProviderObj.GetComponent <LeapServiceProvider>(); this.handUtil = new HandUtil(player); FingerMapper.Load(this.mappedPoints); }