示例#1
0
        public VertexNormal[] ClampPoints(VertexNormal[] positions, float radius, float angleDelta)
        {
            if (positions.Length != touchPoints.Length)
            {
                return(null);
            }

            var newPoints = new VertexNormal[positions.Length];

            for (int i = 0; i < positions.Length; i++)
            {
                // https://answers.unity.com/questions/1309521/how-to-keep-an-object-within-a-circlesphere-radius.html
                // Get vertex in range
                var   newVert  = positions[i].vertex;
                float distance = Vector3.Distance(newVert, touchPoints[i].vertex);    //distance from ~green object~ to *black circle*

                if (distance > radius)                                                //If the distance is less than the radius, it is already within the circle.
                {
                    Vector3 fromOriginToObject = newVert - touchPoints[i].vertex;     //~GreenPosition~ - *BlackCenter*
                    fromOriginToObject *= radius / distance;                          //Multiply by radius //Divide by Distance
                    newVert             = touchPoints[i].vertex + fromOriginToObject; //*BlackCenter* + all that Math
                }

                // Get normal within tolerance
                var newNorm = Vector3.RotateTowards(touchPoints[i].normal, positions[i].normal, angleDelta, 0.0f);
                newNorm.Normalize();
                newPoints[i] = new VertexNormal(newVert, newNorm);
            }
            return(newPoints);
        }
示例#2
0
        bool GetNewGrip()
        {
            VertexNormal[] pads = new VertexNormal[HandObject.FingerList.Length];
            pads[0] = UnusedCloud[Mathf.RoundToInt(Random.Range(0, UnusedCloud.Count - 1))];
            // Get a grab pose
            var startList = GetSpacedPad(RegionList, pads[0]);

            try
            {
                for (int i = 1; i < HandObject.FingerList.Length; i++)
                {
                    if (startList == null)
                    {
                        return(false);
                    }
                    pads[i]   = startList.Find(pad => pad.vertex != pads[i - 1].vertex && pad.normal != pads[i - 1].normal);
                    startList = GetSpacedPad(startList, pads[i]);
                }
                for (int i = 0; i < pads.Length; i++)
                {
                    UnusedCloud.Remove(pads[i]);
                }

                PossibleHoldPoints.Add(new GripPoints(pads));
                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#3
0
 public VertexNormal[] GetGrip()
 {
     VertexNormal[] outPoint = new VertexNormal[touchPoints.Length];
     for (int i = 0; i < touchPoints.Length; i++)
     {
         outPoint[i] = touchPoints[i];
     }
     return(outPoint);
 }
示例#4
0
        public PositionRotation JointPositionFromPad(VertexNormal DesiredPadPosition)
        {
            var pos = transform.localPosition;
            //var rot = joint.transform.rotation;
            var jpos = DesiredPadPosition.vertex - transform.localPosition;
            var jrot = transform.rotation;

            jrot *= Quaternion.FromToRotation(transform.position, -DesiredPadPosition.normal);
            jrot *= Quaternion.FromToRotation(transform.position, joint.transform.position);
            //var jrot = rot * jrot;

            return(new PositionRotation(jpos, jrot));
        }
示例#5
0
 List <VertexNormal> GetSpacedPad(List <VertexNormal> padList, VertexNormal pad)
 {
     try
     {
         var list = padList.FindAll(newpoint => Vector3.Distance(newpoint.vertex, pad.vertex) <= (fingerSpace + (fingerSpace * 0.1f)) &&
                                    Vector3.Distance(newpoint.vertex, pad.vertex) >= (fingerSpace - (fingerSpace * 0.1f)));
         return(list);
     }
     catch
     {
         return(null);
     }
 }