public void playTutorial()
    {
        isPlayingTutorial = true;
        if(positions.Count < 2) {
            stopAnimation();
        }

        if(hand == null) {
            hand = Instantiate(handPref) as GameObject;
            hand.transform.parent = transform;
            hand.transform.position = (Vector3)positions[0];
        }
        positions.RemoveAt(0);

        Vector3 destination = (Vector3)positions[0];

        List<Vector3> points = new List<Vector3>();
        points.Add(hand.transform.position);
        points.Add(new Vector3(hand.transform.position.x, hand.transform.position.y+150F, hand.transform.position.z));
        points.Add(new Vector3(destination.x, hand.transform.position.y+150F, hand.transform.position.z));
        points.Add(new Vector3(destination.x, destination.y, transform.position.z));

        BezierPath bezierPath = new BezierPath();
        bezierPath.SetControlPoints(points);
        List<Vector3> drawingPoints = bezierPath.GetDrawingPoints2();

        Vector3[] path = new Vector3[drawingPoints.Count];

        for(int i = 0; i< drawingPoints.Count; i++) {
            path[i] = drawingPoints[i];
        }

        iTween.MoveTo(hand, iTween.Hash("path", path, "time", 1.0, "onComplete", "handMoveComplete", "oncompletetarget", gameObject, "easetype", iTween.EaseType.linear));
    }
示例#2
0
 void addPoint(BezierPath path, BezierPath.PathPoint point)
 {
     Undo.RegisterUndo(path, "create bezier point");
     // if lsat point, add new. if middle point, add point inbetween
     if(path.points.Count - 1 == path.points.IndexOf(point))
     {
         // add at end
         BezierPath.PathPoint p = new BezierPath.PathPoint();
         if(point.h1.magnitude < Mathf.Epsilon)
             p.p1 = point.p1 + (Vector3.right) * 2;
         else
             p.p1 = point.p1 + (point.h1).normalized * 2;
         p.h1 = point.h1;
         path.points.Add(p);
         selectedPoint = p;
     }
     else
     {
         // add in middle
         BezierPath.PathPoint point2 = path.points[path.points.IndexOf(point) + 1];
         Bezier b = new Bezier(point.p1, point.h1, -point2.h1, point2.p1);
         BezierPath.PathPoint p = new BezierPath.PathPoint();
         p.p1 = b.GetPointAtTime(0.5f);
         p.h1 = b.GetPointAtTime(0.6f) - p.p1;
         path.points.Insert(path.points.IndexOf(point) + 1, p);
     }
 }
示例#3
0
    // Use this for initialization
    void Start()
    {
        target = this.transform;

        if (bezierPathDrawer != null)
        {
            path = bezierPathDrawer.GetBezierPath();
        }
    }
示例#4
0
        public void UpdateMesh(BezierPath bPath)
        {
            if (mesh == null)
            {
                AssignMeshComponents();
            }
            Initalize(bPath);
            int vertIndex = 0;
            int triIndex  = 0;

            // Vertices for the top of the road are layed out:
            // 0  1
            // 2  3
            // and so on... So the triangle map 0,8,1 for example, defines a triangle from top left to bottom left to bottom right.

            for (int i = 0; i < vPath.NumPoints; i++)
            {
                Vector3 localUp    = vPath.up;
                Vector3 localRight = Vector3.Cross(localUp, vPath.GetTangent(i));

                // Find position to left and right of current path vertex
                Vector3 vertSideA = vPath.GetPoint(i) - localRight * Mathf.Abs(pathWidth);
                Vector3 vertSideB = vPath.GetPoint(i) + localRight * Mathf.Abs(pathWidth);

                // Add top of road vertices
                verts[vertIndex + 0] = vertSideA;
                verts[vertIndex + 1] = vertSideB;

                // Set uv on y axis to path time (0 at start of path, up to 1 at end of path)
                uvs[vertIndex + 0] = new Vector2(0, vPath.times[i]);
                uvs[vertIndex + 1] = new Vector2(1, vPath.times[i]);

                // Top of road normals
                normals[vertIndex + 0] = localUp;
                normals[vertIndex + 1] = localUp;

                // Set triangle indices
                if (i < vPath.NumPoints - 1 || vPath.isClosedLoop)
                {
                    for (int j = 0; j < triangleMap.Length; j++)
                    {
                        roadTriangles[triIndex + j] = (vertIndex + triangleMap[j]) % verts.Length;
                    }
                }
                vertIndex += 2;
                triIndex  += 6;
            }

            mesh.Clear();
            mesh.vertices = verts;
            mesh.uv       = uvs;
            mesh.normals  = normals;
            mesh.SetTriangles(roadTriangles, 0);
            mesh.RecalculateBounds();
            meshFilter.sharedMesh = mesh;
            UpdateMaterials();
        }
示例#5
0
    // Update is called once per frame
    void OnDrawGizmos()
    {
        List<Quaternion> rotList = new List<Quaternion> ();
        for (int i = 0; i < bPoints.Count; i++) {
            BezierPt b = bPoints [i];
            rotList.Add (b.transform.rotation);
        }

        List<Vector3> nodes = new List<Vector3> ();
        for (int i = 0; i < bPoints.Count-1; i++) {
            BezierPt start = bPoints [i];
            BezierPt end = bPoints [i + 1];

            nodes.Add (start.transform.position);
            nodes.Add (end.inTrans.position);
            nodes.Add (start.outTrans.position);
            nodes.Add (end.transform.position);
        }

        path = new BezierPath (nodes.ToArray (), rotList.ToArray ());

        // draw
        float delta = 1.0f / split;

        Gizmos.color = drawColor;
        for (int i = 0; i < split-1; i++) {
            float t0 = delta * i;
            float t1 = delta * (i + 1);
            Vector3 pos0 = this.GetPointAt (t0);
            Vector3 pos1 = this.GetPointAt (t1);

            Gizmos.DrawLine (pos0, pos1);
        }

        for (int i = 0; i < split; i++) {

        //			float v = (float)i / split;
            float v = delta * i;

            BezierPointInfo pInfo = path.GetBezierPointInfo(v);

            Vector3 pt = pInfo.point;
            Gizmos.color = drawColor;
            Gizmos.DrawWireSphere (pt, 0.25f);

            // tangent
            Gizmos.color = Color.blue;
            Vector3 tangent = pInfo.tangent;
            Gizmos.DrawRay (pt, tangent);

            Quaternion quat = pInfo.rotation;
            Gizmos.color = Color.green;
            Gizmos.DrawRay (pt, quat* Vector3.up);
            Gizmos.color = Color.red;
            Gizmos.DrawRay (pt, quat* Vector3.right);
        }
    }
示例#6
0
    private void CreateBezier()
    {
        BezierPath bezierPath = new BezierPath();

        // bezierPath.SamplePoints(controlObjects, 0.01f, 0.02f, 4f);
        bezierPath.Interpolate(controlPoints, 4f);
        drawingPoints = bezierPath.GetDrawingPoints2();
        SetLinePoints(drawingPoints);
    }
示例#7
0
 void Start()
 {
     if (waypoints.Length > 0)
     {
         // Create a new bezier path from the waypoints.
         BezierPath bezierPath = new BezierPath(waypoints, closedLoop, PathSpace.xyz);
         GetComponent <PathCreator> ().bezierPath = bezierPath;
     }
 }
示例#8
0
 void OnDrawGizmos()
 {
     if (waypoints.Length > 0 && showInEditor)
     {
         // Create a new bezier path from the waypoints.
         BezierPath bezierPath = new BezierPath(waypoints, closedLoop, PathSpace.xyz);
         GetComponent <PathCreator>().bezierPath = bezierPath;
     }
 }
示例#9
0
        /// <summary>
        /// Bezier interpolate to smooth the line's curve.
        /// </summary>
        public void BezierInterpolate()
        {
            BezierPath bezierPath = new BezierPath();

            bezierPath.Interpolate(points, 0.3f);
            bezierDrawingPoints = bezierPath.GetDrawingPoints2();
            lineRenderer.SetVertexCount(bezierDrawingPoints.Count);
            lineRenderer.SetPositions(bezierDrawingPoints.ToArray());
        }
示例#10
0
    static void RenderCustomGizmo(Transform objectTransform, GizmoType gizmoType)
    {
        BezierPath renderTarget = objectTransform.GetComponent <BezierPath>();

        if (renderTarget != null)
        {
            renderTarget.Start();
        }
    }
示例#11
0
    //takes control points and makes into curvy points
    private List <Vector3> RenderBezier(List <Vector3> points)
    {
        BezierPath bezierPath = new BezierPath();

        bezierPath.SetControlPoints(points);
        List <Vector3> drawingPoints = bezierPath.GetDrawingPoints0();

        RenderLine(drawingPoints);
        return(drawingPoints);
    }
示例#12
0
    public void CreatePath([NotNull] Vector3[] points)
    {
        if (points == null)
        {
            throw new ArgumentNullException(nameof(points));
        }
        BezierPath _bezierPath = new BezierPath(points, false, PathSpace.xy);

        Path.bezierPath = _bezierPath;
    }
示例#13
0
        private Vector2[] CalculateBezierSegmentsPoints(Vector2[] controlPoints)
        {
            BezierPath bezierPath = new BezierPath {
                SegmentsPerCurve = BEZIER_LINE_SEGMENTS
            };

            bezierPath.SetControlPoints(controlPoints);

            return(bezierPath.GetDrawingPoints0().ToArray());
        }
示例#14
0
    private void GenerateLevel(Vector3[] segments)
    {
        BezierPath bp = new BezierPath(segments, false, PathSpace.xyz);

        bp.ControlPointMode   = BezierPath.ControlMode.Automatic;
        bp.GlobalNormalsAngle = 90f;
        Path = new VertexPath(bp, transform, 0.6f, 0f);
        CreateRoad();
        CreateGround();
    }
示例#15
0
        /// <summary>
        ///     Draw all nodes in a specified <paramref name="path"/>.
        /// </summary>
        /// <param name="path">The path to render child nodes from.</param>
        /// <param name="selectedNode">
        ///     The node that is considered to be active (e.g., selected) in the specified path;
        ///     if <see langword="null"/>, no node is highlighted.
        /// </param>
        public void DrawAllNodes([NotNull] BezierPath path, [CanBeNull] BezierPathNode selectedNode = null)
        {
            var transform  = path.transform;
            var closedPath = path.Closed;

            var nodes = GetNodeList(transform);

            var lastNodeIndex = nodes.Count - 1;

            for (var i = 0; i < nodes.Count; ++i)
            {
                var currentNode = nodes[i];
                var nextNode    = DetermineNextNode(i);

                var drawIncoming = i > 0 || closedPath;
                var drawOutgoing = i < lastNodeIndex || closedPath;
                var isActive     = currentNode == selectedNode;

                // Make sure Gizmos/Handle coordinates are local to the parent.
                using (new Handles.DrawingScope(Handles.matrix))
                {
                    // Connect waypoints
                    var shouldDrawConnection = i < lastNodeIndex || (nodes.Count > 2);
                    if (nextNode != null && shouldDrawConnection)
                    {
                        using (new Handles.DrawingScope(Color.gray))
                        {
                            Handles.DrawDottedLine(currentNode.Center, nextNode.Center, DashedLineWidth);
                        }
                    }

                    // Connect current outgoing control with next incoming control.
                    if (nextNode != null)
                    {
                        using (new Handles.DrawingScope(Color.magenta))
                        {
                            Handles.DrawDottedLine(
                                currentNode.Out + currentNode.Center,
                                nextNode.In + nextNode.Center,
                                DottedLineWidth);
                        }
                    }

                    // Draw the actual handles.
                    DrawNodeSceneGui(transform, currentNode, isActive, drawIncoming, drawOutgoing);
                }
            }

            BezierPathNode DetermineNextNode(int i) =>
            i < lastNodeIndex
                    ? nodes[i + 1]
                    : closedPath
                        ? nodes[0]
                        : null;
        }
示例#16
0
    ComplexPath loadLane(Transform lane)
    {
        ComplexPath cPath = new ComplexPath();

        for (int i = 0; i < lane.childCount; i++)
        {
            Transform vec = lane.GetChild(i);
            IPath     nextPath;
            int       next = i + 1;
            if (next == lane.childCount)
            {
                next = 0;
            }

            if (vec.childCount > 1)
            {
                // bezier path
                Transform start      = vec.GetChild(0);
                Vector2   startPoint = new Vector2(start.transform.position.x, start.transform.position.y);
                //Debug.Log("startPoint - x " + startPoint.X + " y: " + startPoint.Y);

                Transform ch1      = vec.GetChild(1);
                Vector2   ch1Point = new Vector2(ch1.transform.position.x, ch1.transform.position.y);
                //Debug.Log("ch1Point  - x " + ch1Point.X + " y: " + ch1Point.Y);

                Transform ch2      = vec.GetChild(2);
                Vector2   ch2Point = new Vector2(ch2.transform.position.x, ch2.transform.position.y);
                //Debug.Log("ch2Point - x " + ch2Point.X + " y: " + ch2Point.Y);

                Transform end      = vec.GetChild(3);
                Vector2   endPoint = new Vector2(end.transform.position.x, end.transform.position.y);
                //Debug.Log("endPoint - x " + endPoint.X + " y: " + endPoint.Y);

                nextPath = new BezierPath(startPoint, ch1Point, ch2Point, endPoint);
            }
            else
            {
                //lineal path
                Transform vec2 = lane.GetChild(next);
                if (vec2.childCount > 1)
                {
                    vec2 = vec2.GetChild(0);
                }
                float x  = vec.transform.position.x;
                float y  = vec.transform.position.y;
                float x2 = vec2.transform.position.x;
                float y2 = vec2.transform.position.y;
                nextPath = new LinearPath(new Vector2(x, y), new Vector2(x2, y2));
            }


            cPath.AddPathSegment(nextPath);
        }
        return(cPath);
    }
示例#17
0
    private void OnEnable()
    {
        BezierPath path = (BezierPath)target;

        path.curveList.RemoveAll(item => item == null);
        //
        // for (int i = 1; i < path.curveList.Count; i++)
        // {
        //     path.curveList[i].BezierInfo.LastBezier = path.curveList[i - 1];
        // }
    }
示例#18
0
                protected override void OnRemovedNode(int index)
                {
                    BezierPath path = (BezierPath)target;

                    ArrayUtils.RemoveAt(ref path._controlPoints, index);

                    if (path._controlPoints.Length != path._nodes.Length)
                    {
                        throw new System.Exception();
                    }
                }
示例#19
0
    private void RenderBezier()
    {
        BezierPath bezierPath = new BezierPath();

        bezierPath.SetControlPoints(points);
        List <Vector3> drawingPoints = bezierPath.GetDrawingPoints2();

        gizmos = drawingPoints;

        SetLinePoints(drawingPoints);
    }
示例#20
0
    private void BezierInterpolate()
    {
        BezierPath bezierPath = new BezierPath();
        bezierPath.Interpolate(points, .25f);

        List<Vector3> drawingPoints = bezierPath.GetDrawingPoints2();

        gizmos = bezierPath.GetControlPoints();

        SetLinePoints(drawingPoints);
    }
示例#21
0
    // Draw the property inside the given rect
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        // Using BeginProperty / EndProperty on the parent property means that
        // prefab override logic works on the entire property.
        EditorGUI.BeginProperty(position, label, property);

        // Draw label
        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        // Don't make child fields be indented
        var indent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        // Calculate rects
        var amountRect = new Rect(position.x, position.y, 30, position.height);
        var unitRect   = new Rect(position.x + 35, position.y, 50, position.height);
        var nameRect   = new Rect(position.x + 90, position.y, position.width - 90, position.height);

        if (property != null && property.objectReferenceValue != null)
        {
            SerializedObject propObj = new SerializedObject(property.objectReferenceValue);

            BezierPath path = ((BezierPath)property.objectReferenceValue);

            EditorGUI.BeginChangeCheck();

            SerializedProperty propSelected = propObj.FindProperty("isSelected");
            SerializedProperty propPathType = propObj.FindProperty("pathType");

            EditorGUILayout.PropertyField(propSelected, true);
            EditorGUILayout.PropertyField(propPathType, true);
            if (EditorGUI.EndChangeCheck())
            {
                propObj.ApplyModifiedProperties();
            }

            //if (((BezierPath)property.objectReferenceValue).isSelected) {

            //}

            //BezierPath path = (BezierPath)property.objectReferenceValue;

            // Draw fields - passs GUIContent.none to each so they are drawn without labels
            //EditorGUI.PropertyField(amountRect, propObj.FindProperty("pathType"), GUIContent.none);
            //EditorGUI.PropertyField(unitRect, propObj.FindProperty("isSelected"), GUIContent.none);
            propObj.Update();
        }

        // Set indent back to what it was
        EditorGUI.indentLevel = indent;

        EditorGUI.EndProperty();
    }
示例#22
0
 public void GeneratePath()
 {
     FillTransforms(8);
     Debug.Log($"trying to generate path with {waypoints.Length}");
     if (waypoints.Length > 0)
     {
         // Create a new bezier path from the waypoints.
         BezierPath bezierPath = new BezierPath(waypoints, closedLoop, PathSpace.xyz);
         GetComponent <PathCreator>().bezierPath = bezierPath;
     }
 }
示例#23
0
        public void Initalize(BezierPath bPath)
        {
            vPath         = new VertexPath(bPath, transform, maxAngleError, 1);
            verts         = new Vector3[vPath.NumPoints * 8];
            uvs           = new Vector2[verts.Length];
            normals       = new Vector3[verts.Length];
            numberOfVerts = verts.Length;
            int numTris = 2 * (vPath.NumPoints - 1);

            roadTriangles = new int[numTris * 3];
        }
示例#24
0
 void Start()
 {
     if (waypoints.Length > 0)
     {
         // Create a new bezier path from the waypoints.
         // The 'true' argument specifies that the path should be a closed loop
         BezierPath bezierPath = new BezierPath(waypoints, true, PathSpace.xyz);
         // Create a vertex path from the bezier path
         path = new VertexPath(bezierPath);
     }
 }
示例#25
0
    void Start()
    {
        pc = GetComponent <PathCreator>();
        spriteSelection = GetComponent <PathSpriteSelect>();
        CreateNode();

        // Create a new bezier path from the waypoints.
        BezierPath bezierPath = new BezierPath(node, closedLoop, PathSpace.xy);

        pc.bezierPath.AutoControlLength = 0.01f;
        pc.bezierPath = bezierPath;
    }
示例#26
0
    private void BezierInterpolate()
    {
        BezierPath bezierPath = new BezierPath();

        bezierPath.Interpolate(points, 0.25f);

        List <Vector3> drawingPoints = bezierPath.GetDrawingPoints2();

        gizmos = bezierPath.GetControlPoints();

        SetLinePoints(drawingPoints);
    }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            InspectorClosedPath();
            InspectorGizmoDrawMode();
            InspectorSubdivisions();
            InspectorNodeList();

            // base.OnInspectorGUI();
            _path = (BezierPath)target;
            serializedObject.ApplyModifiedProperties();
        }
示例#28
0
    static GameObject CreateRoadPath(IEnumerable <Vector3> path)
    {
        var roadPathObj = new GameObject("RoadPath");
        var roadPath    = roadPathObj.AddComponent <RoadPath>();
        var bezierPath  = new BezierPath(path)
        {
            ControlPointMode = BezierPath.ControlMode.Free
        };

        bezierPath.ControlPointMode = BezierPath.ControlMode.Automatic;
        roadPath.bezierPath         = bezierPath;
        return(roadPathObj);
    }
示例#29
0
    private void BezierReduce()
    {
        BezierPath bezierPath = new BezierPath();

        bezierPath.SamplePoints(points, 10, 1000, 0.33f);

        List <Vector3> drawingPoints = bezierPath.GetDrawingPoints2();

        Debug.Log(gizmos.Count);

        gizmos = bezierPath.GetControlPoints();
        SetLinePoints(drawingPoints);
    }
示例#30
0
                protected override void OnNodeChangedPosition(int oldIndex, int newIndex)
                {
                    BezierPath path = (BezierPath)target;

                    BezierPath.NodeControlPoints origControlPoint = path._controlPoints[oldIndex];
                    path._controlPoints[oldIndex] = path._controlPoints[newIndex];
                    path._controlPoints[newIndex] = origControlPoint;

                    if (path._controlPoints.Length != path._nodes.Length)
                    {
                        throw new System.Exception();
                    }
                }
示例#31
0
    protected void StartAnimation(Transform p_tTweenObj, List <Vector3> p_controlPoints, float p_duration, Action p_callback)
    {
        m_bezier = new BezierPath();
        m_bezier.SetControlPoints(p_controlPoints);

        m_tTweenObj = p_tTweenObj;

        m_callback = p_callback;

        m_coroutine = StartCoroutine(TweenCoroutine(p_duration));

        m_bIsTweening = true;
    }
示例#32
0
    void deletePoint(BezierPath path, BezierPath.PathPoint point)
    {
        Undo.RegisterUndo(path, "delete bezier point");
        if (path.points.Count > 1)
        {
            path.points.Remove(point);
        }

        if (selectedPoint == point)
        {
            selectedPoint = path.points[0];
        }
    }
示例#33
0
    public void moveToPoint(Vector3 destination)
    {
        //Debug.Log("")
        iTween.Stop(bee);

        if (destination.x == transform.position.x && destination.y == transform.position.y)
        {
            moveToPointComplete();
        }

        if (destination.x < transform.position.x)
        {
            Vector3 beeScale = bee.transform.localScale;
            beeScale.x = -1;
            bee.transform.localScale = beeScale;
            bee.transform.rotation   = Quaternion.Euler(new Vector3(0, 0, 15));
        }
        else
        {
            Vector3 beeScale = bee.transform.localScale;
            beeScale.x = 1;
            bee.transform.localScale = beeScale;
            bee.transform.rotation   = Quaternion.Euler(new Vector3(0, 0, -15));
        }

        List <Vector3> points = new List <Vector3>();

        points.Add(transform.position);
        points.Add(new Vector3(transform.position.x, transform.position.y + 100, transform.position.z));
        points.Add(new Vector3(destination.x, transform.position.y + 100, transform.position.z));
        points.Add(new Vector3(destination.x, destination.y, transform.position.z));

        BezierPath bezierPath = new BezierPath();

        //	bezierPath.Interpolate(points, .25f);
        bezierPath.SetControlPoints(points);
        List <Vector3> drawingPoints = bezierPath.GetDrawingPoints2();

        Vector3[] path = new Vector3[drawingPoints.Count];

        for (int i = 0; i < drawingPoints.Count; i++)
        {
            path[i] = drawingPoints[i];
        }

        float distance = AGGameState.modFloat(destination.x - transform.position.x);
        float speed    = 1000.0f;
        float time     = distance / speed;

        iTween.MoveTo(gameObject, iTween.Hash("path", path, "time", time, "onComplete", "moveToPointComplete", "easetype", iTween.EaseType.linear));
    }
示例#34
0
        protected override void SetUpCannon()
        {
            waypointsLists = new List <MovePath>(8);
            Vector3        p0 = transform.position + Vector3.up;
            Vector3        p1 = transform.position + Vector3.up * 2;
            List <Vector3> p2 = BezierPath.EvaluatePoints(3, transform.position + Vector3.up * 2);
            List <Vector3> p3 = BezierPath.EvaluatePoints(3, transform.position);

            for (int i = 0; i < waypointsLists.Capacity; i++)
            {
                waypointsLists.Add(new BezierPath(count, p0, p1, p2[i], p3[i]).EvaluateWaypoints());
            }
            InvokeRepeating("Shoot", firerate, firerate);
        }
示例#35
0
    static void drawPathGizmos(BezierPath path, GizmoType gizmoType)
    {
        // don't draw if selected
        if(Selection.activeGameObject == path.gameObject)
            return;

        foreach(BezierPath.PathPoint p in path.points)
        {
            // draw point
            Gizmos.color = path.color;
            Gizmos.DrawCube(p.p1, Vector3.one);

            //draw handle
            //Gizmos.color = Color.blue;
            //Gizmos.DrawCube(p.p1 + p.h1, Vector3.one / 2);
        }

        Gizmos.color = path.lineColor;

        for(int i = 0; i < path.points.Count - 1; i++)
        {
            // draw line from point i to point i+1
            path.points[i].bezier.p1 = path.points[i].p1;
            path.points[i].bezier.h1 = path.points[i].h1;
            path.points[i].bezier.p2 = path.points[i + 1].p1;
            path.points[i].bezier.h2 = -path.points[i + 1].h1; // negative of this handle

            Vector3 oldPos = path.points[i].bezier.GetPointAtTime(0);
            for(float t = 0; t < 1.01; t += 0.1f)
            {
                Vector3 newPos = path.points[i].bezier.GetPointAtTime(t);
                Gizmos.DrawLine(oldPos, newPos);
                oldPos = newPos;
            }
        }
    }
示例#36
0
    void deletePoint(BezierPath path, BezierPath.PathPoint point)
    {
        Undo.RegisterUndo(path, "delete bezier point");
        if(path.points.Count > 1)
            path.points.Remove(point);

        if(selectedPoint == point)
            selectedPoint = path.points[0];
    }
示例#37
0
 /**
  * Update the length of the path and inner curves.
  */
 public static void UpdateLength(BezierPath path)
 {
     path.UpdateLength();
 }
示例#38
0
 /**
  * Get the properties
  */
 public void OnEnable()
 {
     m_path = (BezierPath)target;
 }
示例#39
0
    public void moveToPoint(Vector3 destination)
    {
        //Debug.Log("")
        iTween.Stop(bee);

        if(destination.x == transform.position.x && destination.y == transform.position.y) {
            moveToPointComplete();
        }

        if(destination.x < transform.position.x) {
            Vector3 beeScale = bee.transform.localScale;
            beeScale.x = -1;
            bee.transform.localScale = beeScale;
            bee.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 15));
        } else {
            Vector3 beeScale = bee.transform.localScale;
            beeScale.x = 1;
            bee.transform.localScale = beeScale;
            bee.transform.rotation = Quaternion.Euler(new Vector3(0, 0, -15));
        }

        List<Vector3> points = new List<Vector3>();
        points.Add(transform.position);
        points.Add(new Vector3(transform.position.x, transform.position.y+100, transform.position.z));
        points.Add(new Vector3(destination.x, transform.position.y+100, transform.position.z));
        points.Add(new Vector3(destination.x, destination.y, transform.position.z));

        BezierPath bezierPath = new BezierPath();
        //	bezierPath.Interpolate(points, .25f);
        bezierPath.SetControlPoints(points);
        List<Vector3> drawingPoints = bezierPath.GetDrawingPoints2();

        Vector3[] path = new Vector3[drawingPoints.Count];

        for(int i = 0; i< drawingPoints.Count; i++) {
            path[i] = drawingPoints[i];
        }

        float distance = AGGameState.modFloat(destination.x - transform.position.x);
        float speed = 1000.0f;
        float time = distance / speed;

        iTween.MoveTo(gameObject, iTween.Hash("path", path, "time", time, "onComplete", "moveToPointComplete", "easetype", iTween.EaseType.linear));
    }
示例#40
0
    private void RenderBezier()
    {
        BezierPath bezierPath = new BezierPath();

        bezierPath.SetControlPoints(points);
        List<Vector3> drawingPoints = bezierPath.GetDrawingPoints2();

        gizmos = drawingPoints;

        SetLinePoints(drawingPoints);
    }
示例#41
0
    private void BezierReduce()
    {
        BezierPath bezierPath = new BezierPath();
        bezierPath.SamplePoints(points, 10, 1000, 0.33f);

        List<Vector3> drawingPoints = bezierPath.GetDrawingPoints2();
        Debug.Log(gizmos.Count);

        gizmos = bezierPath.GetControlPoints();
        SetLinePoints(drawingPoints);
    }
示例#42
0
    //Function that is executed at the end of a trial.
    //it draws the required graphs, clears the logs and sets up for the next trial
    void OnTouch()
    {
        currVel = Vector3.zero;
        compassNeedle.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));

        Texture2D tex;
        List<float> temp;
        float maxVel;

        //TODO: Acceleration X

        //Acceleration Y
        tex = new Texture2D(accLog.Count, 100, TextureFormat.ARGB32, false);

        //Add normalized Acceleration values to temp list
        temp = new List<float>();

        foreach (Vector3 acc in accLog)
        {
            temp.Add((acc.y / (float)assumedMax));
        }
        WriteLog(accLog, "accLog");
        //Draw acceleration graph
        DrawGraph(tex, temp, Color.black, 1);

        //Draw lines at maxima points
        DrawGraph(tex, maximaLog, Color.red, 2);
        WriteLog(maximaLog, "maximaLog");

        //Populate velList with velocity values calculated from distances between Maxima points
        List<float> velList = new List<float>();
        List<float> velXList = new List<float>();
        List<float> velYList = new List<float>();
        float dir;
        //velList.Add(0);                             //Append 0 at the beginning of velList to make sure trial starts at 0
        for (int i = 1; i < maximaLog.Count; i++)
        {
            velList.Add((1.0f*3.6f / ((maximaLog[i] - maximaLog[i - 1])*0.02f)));
            dir = rotationLog[maximaLog[i]] *(Mathf.PI/180.0f);
            velXList.Add(-(Mathf.Sin(dir)*(1.0f * 3.6f / ((maximaLog[i] - maximaLog[i - 1]) * 0.02f))));
            velYList.Add((Mathf.Cos(dir)*(1.0f * 3.6f / ((maximaLog[i] - maximaLog[i - 1]) * 0.02f))));
        }
        velList.Add(0);                             //Append 0 at the end of velList to make sure trial ends at 0
        velList.Add(0);                             //Twice

        velXList.Add(0);
        velXList.Add(0);
        velYList.Add(0);
        velYList.Add(0);

        maximaLog.Add(accLog.Count);

        BezierPath bezierPath;
        List<Vector3> drawingPoints;

        maxVel = Mathf.Max(velXList.ToArray());
        List<Vector3> points = new List<Vector3>();
        List<Vector2> points2v = new List<Vector2>();

        for (int i = 0; i < velXList.Count; i++)
        {
            points.Add(new Vector3(maximaLog[i], velXList[i], 0));
        }
        bezierPath = new BezierPath();
        bezierPath.Interpolate(points, .5f);
        drawingPoints = bezierPath.GetDrawingPoints2();
        foreach (Vector3 point in drawingPoints)
        {
            points2v.Add (new Vector2(point.x, point.y));
        }
        WriteLog(points2v, "velXLog");

        maxVel = Mathf.Max(velYList.ToArray());
        points = new List<Vector3>();
        points2v = new List<Vector2>();
        for (int i = 0; i < velYList.Count; i++)
        {
            points.Add(new Vector3(maximaLog[i], velYList[i], 0));
        }
        bezierPath = new BezierPath();
        bezierPath.Interpolate(points, .5f);
        drawingPoints = bezierPath.GetDrawingPoints2();
        foreach (Vector3 point in drawingPoints)
        {
            points2v.Add (new Vector2(point.x, point.y));
        }
        WriteLog(points2v, "velYLog");

        DrawGraph(tex, points, Color.blue, 3);

        //User Acceleration Calculation
        points2v = new List<Vector2>();
        points = new List<Vector3>();
        for (int i = 0; i < velList.Count-1; i++)
        {
            dir = rotationLog[maximaLog[i]] * (Mathf.PI / 180.0f);
            points.Add(new Vector3(maximaLog[i], (velXList[i + 1] - velXList[i]), 0));
        }
        bezierPath = new BezierPath();
        bezierPath.Interpolate(points, .5f);
        drawingPoints = bezierPath.GetDrawingPoints2();
        foreach (Vector3 point in drawingPoints)
        {
            points2v.Add (new Vector2(point.x, point.y));
        }
        WriteLog(points2v, "accXLog");

        points2v = new List<Vector2>();
        points = new List<Vector3>();
        for (int i = 0; i < velList.Count - 1; i++)
        {
            dir = rotationLog[maximaLog[i]] * (Mathf.PI / 180.0f);
            points.Add(new Vector3(maximaLog[i], (velYList[i + 1] - velYList[i]), 0));
        }
        bezierPath = new BezierPath();
        bezierPath.Interpolate(points, .5f);
        drawingPoints = bezierPath.GetDrawingPoints2();
        foreach (Vector3 point in drawingPoints)
        {
            points2v.Add (new Vector2(point.x, point.y));
        }
        WriteLog(points2v, "accYLog");

        //Draw all graphs onto the texture and convert to image
        tex.Apply();
        SaveTextureToFile(tex, "accelerationY");

        //Basic Graph to show rotation changes
        temp.Clear();
        tex = new Texture2D(accLog.Count, 100, TextureFormat.ARGB32, false);
        foreach (float rot in rotationLog)
        {
            if (rot > Mathf.PI/2)
                temp.Add((rot - Mathf.PI) / (Mathf.PI / 2));
            else
                temp.Add(rot / (Mathf.PI / 2));
        }
        DrawGraph(tex, temp, Color.black, 1);
        tex.Apply();
        SaveTextureToFile(tex, "RotationZ");

        //Clear logs
        accLog.Clear();
        velLog.Clear();
        maximaLog.Clear();
        maximaLog.Add(0);

        rotationLog.Clear();

        float time1 = regularClock.GetComponent<ClockScript>().totalTime;
        float time2 = warpedClock.GetComponent<ClockScript>().totalTime;
        WriteValues (time1, time2, "clockTimes");

        WriteLog (warpedTimeLog, "WarpedClockTimes");

        //Draw the simulation results
        simulator.SendMessage("simulationDraw");

        //Capture Screenshot
        Texture2D tex2 = new Texture2D(Screen.width, Screen.height);
        //StartCoroutine(CaptureScreenshotAfterDelay(tex2));
        tex2.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
        tex2.Apply();

        SaveTextureToFile(tex2, "GraphMakerAccY");

        //Another way to capture screenshot that doesn't seem to be working
        Application.CaptureScreenshot(Application.persistentDataPath+ "Screenshot.png");

        Application.LoadLevel(3);
    }