private void PopulateQueue()
        {
            GTransform nextDataPoint = controller.QueryGTransform();

            dataQueue.Enqueue(nextDataPoint);
            SetLineRendererPositions(dataQueue);
        }
Example #2
0
        /// <summary>
        /// Normalizes the series of GTransforms with respect to the proportion of X / Y scale in the given data.
        /// </summary>
        /// <remarks>
        /// Works for horizontal and vertical lines in the viewing plane.
        /// </remarks>
        /// <param name="data"></param>
        /// <returns></returns>
        public List <GTransform> Normalize(List <GTransform> data)
        {
            List <GTransform> normalizedData = new List <GTransform>();

            if (data.Count == 0)
            {
                return(normalizedData);
            }

            Vector3 first = data[0].position;
            Vector3 last  = data[data.Count - 1].position;

            Vector2 percentage = (last - first).normalized;

            for (int i = 0; i < data.Count; i++)
            {
                GTransform trans = data[i].Copy();
                trans.position  -= first;
                trans.position.z = 0;

                normalizedData.Add(trans);
            }

            last = normalizedData[data.Count - 1].position;
            for (int i = 0; i < data.Count; i++)
            {
                GTransform trans = normalizedData[i];
                trans.position.x *= percentage.x * (2.0f / last.x);
                trans.position.y *= percentage.y * (2.0f / last.y);
                trans.position   -= new Vector3(1 * percentage.x, 1 * percentage.y, 0);
            }


            return(normalizedData);
        }
        /// <summary>
        /// Normalizes the GTransforms with respect to the bounding box FittedNormalizer was initialized with.
        /// </summary>
        /// <param name="data">List of GTramsforms</param>
        /// <returns></returns>
        public List <GTransform> Normalize(List <GTransform> data)
        {
            List <GTransform> normalizedData = new List <GTransform>();

            int count = data.Count;

            if (count == 0)
            {
                return(normalizedData);
            }

            Vector3 range = new Vector3(0, 0, 0);
            Vector3 min   = data[0].position;
            Vector3 max   = data[0].position;


            for (int i = 0; i < data.Count; i++)
            {
                GTransform trans = data[i].Copy();
                Vector3    pos   = trans.position;

                min = ApplyPredToVector(min, pos, Mathf.Min);
                max = ApplyPredToVector(max, pos, Mathf.Max);

                normalizedData.Add(trans);
            }

            range = max - min;

            if (maintainAspectRatio)
            {
                float xRange = (topRight.x - bottomLeft.x);
                float yRange = (topRight.y - bottomLeft.y);
                float zRange = (topRight.z - bottomLeft.z);

                if (xRange != 0)
                {
                    range.y = (yRange / xRange) * range.x;
                    range.z = (zRange / xRange) * range.x;
                }
            }

            for (int i = 0; i < data.Count; i++)
            {
                GTransform trans = normalizedData[i];

                trans.position -= min;

                Vector3 v = (topRight - bottomLeft);
                v.Scale(Inverse(range));
                trans.position.Scale(v);

                trans.position += bottomLeft;
            }

            return(normalizedData);
        }
Example #4
0
        /// <summary>
        /// Determine whether a single GTransform fits inside the area defined by the circle
        /// </summary>
        /// <param name="g">GTransform to check position against</param>
        /// <returns> Returns a float (between 0 and 1) representing the distance from the center of the circle, or -1 if the check fails </returns>
        override public float CheckPasses(GTransform gTransform)
        {
            float distance = Vector3.Distance(gTransform.position, position);

            if (distance > radius)
            {
                return(-1);
            }
            return(1);
        }
Example #5
0
        override public float CheckPasses(GTransform g)
        {
            float distance = Vector3.Distance(g.position, GetClosestPointOnLineSegment(firstPosition, secondPosition, g.position));

            if (distance > precision / 2.0f)
            {
                return(-1);
            }

            return(distance / (precision / 2.0f));
        }
        /// <summary>
        /// Rotates the GTransforms to in front of the user gameObject.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public List <GTransform> Normalize(List <GTransform> data)
        {
            Vector3           centroid       = new Vector3(0, 0, 0);
            int               count          = data.Count;
            List <GTransform> normalizedData = new List <GTransform>();

            if (count == 0)
            {
                return(normalizedData);
            }

            for (int i = 0; i < data.Count; i++)
            {
                GTransform trans = data[i].Copy();
                centroid += trans.position;
                normalizedData.Add(trans);
            }


            centroid /= count;
            Vector3 userPosition = userTransform.position;
            Vector3 direction    = (centroid - userPosition);

            float      dp       = Vector3.Dot(new Vector3(direction.x, 0, direction.z).normalized, direction.normalized);
            float      angle    = -Mathf.Sign(direction.y) * Mathf.Acos(dp);
            Quaternion rotation = Quaternion.AngleAxis(-angle * 360 / (2 * Mathf.PI), new Vector3(direction.z, 0, -direction.x).normalized);

            centroid = rotation * (centroid - userPosition) + userPosition;
            centroid = normalizedData[0].position;
            Vector3    direction2 = (centroid - userPosition).normalized;
            Quaternion rotation2  = Quaternion.FromToRotation(new Vector3(direction2.x, 0, direction2.z), forward);


            for (int i = 0; i < data.Count; i++)
            {
                GTransform trans = normalizedData[i];

                trans.position = rotation * (trans.position - userPosition) + userPosition;
                trans.position = rotation2 * (trans.position - userPosition) + userPosition;
            }

            return(normalizedData);
        }
Example #7
0
        override public float CheckPasses(GTransform g)
        {
            Vector3 rotation = new Vector3(
                (orientation == ARC_ORIENTATION.YZ) ? 1 : 0,
                (orientation == ARC_ORIENTATION.XZ) ? 1 : 0,
                (orientation == ARC_ORIENTATION.XY) ? 1 : 0);
            Quaternion qrot = Quaternion.Euler(-degrees * rotation);

            Vector3 position    = g.position;
            Vector3 direction   = (position - center).normalized;
            Vector3 sectorStart = (startPosition - center).normalized;
            Vector3 sectorEnd   = (qrot * sectorStart).normalized;
            float   distance    = Vector3.Distance(position, center);

            bool inArc        = IsClockwise(sectorStart, direction) && !IsClockwise(sectorEnd, direction);
            bool prettyClose  = (Vector3.Dot(sectorStart, direction) >= (1.0f - eps)) || (Vector3.Dot(sectorEnd, direction) >= (1.0f - eps));
            bool withinRadius = (distance <radius + precision / 2.0f && distance> radius - precision / 2.0f);

            if (withinRadius && (inArc || prettyClose))
            {
                return(Mathf.Abs((distance - radius)) / (precision / 2.0f));
            }
            return(-1);
        }
Example #8
0
 /// <summary>
 /// Determine whether a single GTransform passes the Check.
 /// </summary>
 /// <param name="transform">GTransform data to compare against the specified Check</param>
 /// <returns> Returns a float (between 0 and 1) representing the distance from the center of a check, or -1 if the check fails </returns>
 public abstract float CheckPasses(GTransform transform);
Example #9
0
        public List <GTransform> Normalize(List <GTransform> data)
        {
            List <GTransform> normalizedData = new List <GTransform>();

            if (first)
            {
                first = false;
                Vector3 centroid = new Vector3(0, 0, 0);
                int     count    = data.Count;

                for (int i = 0; i < data.Count; i++)
                {
                    GTransform trans = data[i].Copy();
                    centroid += trans.position;
                    normalizedData.Add(trans);
                }


                centroid /= count;
                Vector3 userPosition = userTransform.position;
                Vector3 direction    = (centroid - userPosition);

                float dp    = Vector3.Dot(new Vector3(direction.x, 0, direction.z).normalized, direction.normalized);
                float angle = -Mathf.Sign(direction.y) * Mathf.Acos(dp);
                //Quaternion rotation = Quaternion.AngleAxis(-angle * 360 / (2 * Mathf.PI), new Vector3(direction.z, 0, -direction.x).normalized);
                original = Quaternion.LookRotation(direction.normalized);
                rotation = Quaternion.FromToRotation(direction.normalized, new Vector3(direction.x, 0, direction.z).normalized);
                //rotation = Quaternion.(original, rotation);
                //centroid = rotation * (centroid - userPosition) + userPosition;
                //centroid = normalizedData[0].position;
                //Vector3 direction2 = (centroid - userPosition).normalized;
                //Quaternion rotation2 = Quaternion.FromToRotation(new Vector3(direction2.x, 0, direction2.z), forward);
            }
            else
            {
                Vector3 centroid = new Vector3(0, 0, 0);
                int     count    = data.Count;

                for (int i = 0; i < data.Count; i++)
                {
                    GTransform trans = data[i].Copy();
                    centroid += trans.position;
                    normalizedData.Add(trans);
                }

                centroid /= count;

                Vector3 direction = (centroid - userTransform.position).normalized;

                for (int i = 0; i < data.Count; i++)
                {
                    GTransform trans = normalizedData[i];
                    Vector3    p     = trans.position;
                    Vector3    r     = centroid;
                    Vector3    q     = centroid + new Vector3(direction.z, 0, -direction.x).normalized;
                    Vector3    rq    = (r - q).normalized;
                    float      tt    = Vector3.Dot(rq, (q - p)) / Vector3.Dot(rq, rq);
                    Vector3    newC  = new Vector3(p.x, centroid.y, p.z);

                    Quaternion rotation2 = Quaternion.FromToRotation(direction, forward);

                    Vector3    dir = (newC - userTransform.position);
                    Quaternion rot = Quaternion.FromToRotation(dir.normalized, new Vector3(dir.x, 0, dir.z).normalized);

                    Quaternion rr = Quaternion.Lerp(Quaternion.identity, rot, t);
                    trans.position = rr * (trans.position - userTransform.position) + userTransform.position;
                }


                t += 0.01f;
            }

            return(normalizedData);
        }
Example #10
0
        override public float CheckPasses(GTransform gTransform)
        {
            float speed = gTransform.velocity.magnitude;

            return((speed < targetSpeed) ? 1 : -1);
        }