public double AverageRoll(BodyPoint bodyPoint, double new_roll)
        {
            if (rollAverage.ContainsKey(bodyPoint) && rollAverage.TryGetValue(bodyPoint, out List <double> rollValues))
            {
                rollValues.Add(new_roll);

                if (rollValues.Count > RotationAveragingAmount)
                {
                    for (int i = 0; i < rollValues.Count - RotationAveragingAmount; i++)
                    {
                        rollValues.RemoveAt(0);
                    }
                }

                double averaged_roll = 0;
                foreach (double roll in rollValues)
                {
                    averaged_roll += roll;
                }

                new_roll = averaged_roll / rollValues.Count;
            }
            else
            {
                rollValues = new List <double>
                {
                    new_roll
                };

                rollAverage.Add(bodyPoint, rollValues);
            }

            return(new_roll);
        }
        public double AverageYaw(BodyPoint bodyPoint, double new_yaw)
        {
            if (yawAverage.ContainsKey(bodyPoint) && yawAverage.TryGetValue(bodyPoint, out List <double> yawValues))
            {
                yawValues.Add(new_yaw);

                if (yawValues.Count > RotationAveragingAmount)
                {
                    for (int i = 0; i < yawValues.Count - RotationAveragingAmount; i++)
                    {
                        yawValues.RemoveAt(0);
                    }
                }

                double averaged_yaw = 0;
                foreach (double yaw in yawValues)
                {
                    averaged_yaw += yaw;
                }

                new_yaw = averaged_yaw / yawValues.Count;
            }
            else
            {
                yawValues = new List <double>
                {
                    new_yaw
                };

                yawAverage.Add(bodyPoint, yawValues);
            }

            return(new_yaw);
        }
        public double AveragePitch(BodyPoint bodyPoint, double new_pitch)
        {
            if (pitchAverage.ContainsKey(bodyPoint) && pitchAverage.TryGetValue(bodyPoint, out List <double> pitchValues))
            {
                pitchValues.Add(new_pitch);

                if (pitchValues.Count > RotationAveragingAmount)
                {
                    for (int i = 0; i < pitchValues.Count - RotationAveragingAmount; i++)
                    {
                        pitchValues.RemoveAt(0);
                    }
                }

                double averaged_pitch = 0;
                foreach (double pitch in pitchValues)
                {
                    averaged_pitch += pitch;
                }

                new_pitch = averaged_pitch / pitchValues.Count;
            }
            else
            {
                pitchValues = new List <double>
                {
                    new_pitch
                };

                pitchAverage.Add(bodyPoint, pitchValues);
            }

            return(new_pitch);
        }
예제 #4
0
        public KeyPoint2D(BodyPoint bodyPoint, double x, double y, double score)
        {
            Raw_X = x;
            Raw_Y = y;
            Score = score;

            BodyPoint = bodyPoint;
        }
예제 #5
0
        public KeyPoint2D(BodyPoint bodyPoint, double x, double y, double score, double yaw, double pitch, double roll)
        {
            Raw_X = x;
            Raw_Y = y;
            Score = score;

            Yaw   = yaw;
            Pitch = pitch;
            Roll  = roll;

            BodyPoint = bodyPoint;
        }
예제 #6
0
        public KeyPoint GetKeyPoint(BodyPoint bodyPoint)
        {
            if (bodyPoint >= 0 && (int)bodyPoint < KeyPoints.Count)
            {
                foreach (KeyPoint keyPoint in KeyPoints)
                {
                    if (keyPoint.BodyPoint == bodyPoint)
                    {
                        return(keyPoint);
                    }
                }
            }

            return(null);
        }
    private BodyPoint SpawnSnakeBodyFromPool()
    {
        BodyPoint point        = null;
        bool      isPointFound = false;

        // first look if any snake body is available
        if (bodyPointsParent != null)
        {
            if (bodyPointsParent.childCount > 0)
            {
                for (int i = 0; i < bodyPointsParent.childCount; i++)
                {
                    if (!bodyPointsParent.GetChild(i).gameObject.activeSelf)
                    {
                        if (bodyPointsParent.GetChild(i).GetComponent <BodyPoint>())
                        {
                            // assign snake body
                            point        = bodyPointsParent.GetChild(i).GetComponent <BodyPoint>();
                            isPointFound = true;
                        }
                        else
                        {
                            Debug.LogError("SnakeBodyPoint Script is Missing");
                        }
                    }
                }
            }

            //if no snake body is available
            if (!isPointFound)
            {
                point = Instantiate(bodyPointPrefab);
            }

            // basic body setup
            point.gameObject.SetActive(true);
            point.transform.SetParent(bodyPointsParent);
            point.gameObject.name    = "BodyPoint";
            point.transform.rotation = Quaternion.identity;
            point.transform.position = GetNextBodyPointPosition();
        }
        else
        {
            Debug.LogError("SnakeBodyParent is Missing");
        }

        return(point);
    }
    //TODO: Push() and Pull() /*like grab but no target on opponent's body*/

    /*
     * public bool Grab(MovePoint grabber, AttachPoint target)
     * {
     *  bool reachedTarget = Move(grabber, target.AttachObject.transform);
     *  if (reachedTarget)
     *  {
     *      //DebugLog("Reached target Player " + PlayerNumber);
     *      target.AttachedTo = grabber;
     *  }
     *  return reachedTarget;
     * }
     */

    public bool Move(BodyPoint bodyPoint, Transform target)
    {
        IKEffector effector = _ik.solver.GetEffector(bodyPoint.Effector);

        if (Vector3.Distance(effector.position, target.position) < MOVE_COMPLETE_PROXIMITY)
        {
            return(true);
        }

        float step = HAND_MOVE_SPEED * Time.deltaTime;

        bodyPoint.EffectorTargetPositionWeight = 1.0f;
        bodyPoint.EffectorTargetPosition       = Vector3.Lerp(effector.position, target.position, step);
        Debug.DrawLine(bodyPoint.EffectorTargetPosition, target.position, Color.white);

        return(false);
    }
    void Start()
    {
        // Head Setup
        BodyPoint head = SpawnSnakeBodyFromPool();

        if (head != null)
        {
            head.name = "Head";
            head.transform.SetParent(FindObjectOfType <Snake>().transform);
            head.transform.position = Vector3.zero;
            //snakeBodiesList.Add(head);
        }

        for (int i = 0; i < 10; i++)
        {
            SpawnSnakeBodyFromPool();
        }
    }
    public MovementManager(BjjPlayer bjjPlayer) //TODO: really we should be passing a subclass of BjjPlayer here
    {
        _player = bjjPlayer;
        _ik     = _player.GetComponentInChildren <FullBodyBipedIK>();
        _is     = _player.GetComponentInChildren <InteractionSystem>();
        _ik.Disable();

        leftHand      = new BodyPoint(SearchHierarchyForBone(_player.transform, "L Wrist").gameObject, FullBodyBipedEffector.LeftHand);
        rightHand     = new BodyPoint(SearchHierarchyForBone(_player.transform, "R Hand GP").gameObject, FullBodyBipedEffector.RightHand);
        leftFoot      = new BodyPoint(null, FullBodyBipedEffector.LeftFoot);
        rightFoot     = new BodyPoint(null, FullBodyBipedEffector.RightFoot);
        leftThigh     = new BodyPoint(null, FullBodyBipedEffector.LeftThigh);
        rightThigh    = new BodyPoint(null, FullBodyBipedEffector.RightThigh);
        leftShoulder  = new BodyPoint(null, FullBodyBipedEffector.LeftShoulder);
        rightShoulder = new BodyPoint(null, FullBodyBipedEffector.RightShoulder);
        body          = new BodyPoint(null, FullBodyBipedEffector.Body);

        BodyPoints = new List <BodyPoint> {
            leftHand, rightHand, leftFoot, rightFoot, leftThigh, rightThigh, leftShoulder, rightShoulder, body
        };
    }
 public void Grab(BodyPoint grabbingPoint, BodyPoint grabbedPoint, BodyPointLocation location)
 {
     if (!_is.IsInInteraction(grabbingPoint.Effector))
     {
         Debug.Log("Start interaction...");
         InteractionObject interactionObject = grabbedPoint.GetInteractionObject(location);
         grabbingPoint.MovementType = MovementType.Interaction;
         _is.StartInteraction(grabbingPoint.Effector, interactionObject, true);
         Debug.DrawLine(grabbingPoint.GameObject.transform.position, interactionObject.transform.position, Color.white);
     }
     else if (_is.IsPaused(grabbingPoint.Effector))
     {
         Debug.Log("Interaction paused...");
         grabbingPoint.MovementType = MovementType.None;
         _player.SetState(BjjState.Idle);
     }
     else
     {
         Debug.Log("Interaction update...");
     }
 }
예제 #12
0
 public KeyPoint3D GetKeyPoint3D(BodyPoint bodyPoint)
 {
     return((KeyPoint3D)base.GetKeyPoint(bodyPoint));
 }
 public void RemoveFromTheList(BodyPoint point)
 {
     snakeBodyPointList.Remove(point);
 }
 public void AddBodyToList(BodyPoint body)
 {
     snakeBodyPointList.Add(body);
     //body.transform.SetSiblingIndex(transform.parent.childCount - 1);
 }