void Update()
    {
        if (spline != null)
        {
            spline.Update(controlPoints);
            spline.Update(resolution);
            spline.DrawSpline(Color.white);

            if (drawNormal)
            {
                spline.DrawNormals(normalExtrusion, Color.red);
            }

            if (drawTangent)
            {
                spline.DrawTangents(tangentExtrusion, Color.cyan);
            }
        }
        else
        {
            spline = new CatmullRom(controlPoints, resolution);
        }


        if (globalTime <= 1)
        {
            globalTime += Time.deltaTime * UpdateProgress();
        }
        else
        {
            globalTime = .001f;
        }

        UpdatePosition(globalTime);
    }
Пример #2
0
    public override void PaintTrajectory()
    {
        Vector3[] controlPoints = new Vector3[pointList.Count];

        for (int i = 0; controlPoints.Length > i; i++)
        {
            controlPoints[i] = pointList[i].TransformVector.GetVector3();
        }

        try
        {
            if (spline != null)
            {
                spline.Update(controlPoints);
                spline.Update(resolution, closedLoop);
            }
            else
            {
                spline = new CatmullRom(controlPoints, resolution, closedLoop);
            }


            splineVectors = spline.GetPoints();
            trajectory.gameObject.GetComponent <LineRenderer>().positionCount = splineVectors.Length;
            trajectory.gameObject.GetComponent <LineRenderer>().SetPositions(splineVectors);
        }
        catch { print("Exeption PaintTrajectory()"); }
    }
Пример #3
0
    void Update()
    {
        if (spline != null)
        {
            spline.Update(controlPoints);
            spline.Update(resolution);
            spline.DrawSpline(Color.white);

            if (drawNormal)
            {
                spline.DrawNormals(normalExtrusion, Color.red);
            }

            if (drawTangent)
            {
                spline.DrawTangents(tangentExtrusion, Color.cyan);
            }
        }
        else
        {
            spline = new CatmullRom(controlPoints, resolution);
        }


        if (speed > 0)
        {
            Debug.Log(spline.GetPoints().Length);

            float distance = Vector3.Distance(spline.GetPoints()[currentWaypointID].position, transform.position);
            transform.position = Vector3.MoveTowards(transform.position, spline.GetPoints()[currentWaypointID].position, Time.deltaTime * speed);

            var rotation = Quaternion.LookRotation(spline.GetPoints()[currentWaypointID].position - transform.position);
            transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationSpeed);

            if (distance <= reachDistance)
            {
                currentWaypointID++;
            }
        }

        if (currentWaypointID >= spline.GetPoints().Length)
        {
            currentWaypointID  = 0;
            transform.position = spline.GetPoints()[currentWaypointID].position;
            transform.rotation = Quaternion.LookRotation(spline.GetPoints()[currentWaypointID].position - transform.position);
        }
    }
Пример #4
0
 void Update()
 {
     if (_catmull != null)
     {
         //_catmull.Update(_points);
         _catmull.Update(resolution, false);
         //Debug.Log( _catmull.GetPoints().Length );
         _catmull.DrawSpline(Color.white);
     }
 }
Пример #5
0
 private void UpdateSpline()
 {
     while (controlPoints.Count < controlPointCount)
     {
         frame.origin += GetFarthest(frame, farDetectionRange) * advanceFrameRatio;
         controlPoints.Enqueue(frame.origin);
     }
     spline.Update(controlPoints);
     splinePoints = spline.GetPoints();
 }
Пример #6
0
    void Update()
    {
        if (spline != null)
        {
            spline.Update(controlPoints);
            spline.Update(resolution);
            UpdateLinePoints();

            //spline.DrawSpline(Color.white);

            lineRenderer.positionCount = linePoints.Length;
            lineRenderer.SetPositions(linePoints);

            if (drawNormal)
            {
                spline.DrawNormals(normalExtrusion, Color.red);
            }

            if (drawTangent)
            {
                spline.DrawTangents(tangentExtrusion, Color.cyan);
            }
        }
        else
        {
            spline = new CatmullRom(controlPoints, resolution);
        }



        if (progress < 1)
        {
            progress += Time.deltaTime * GetTimeScale();
        }
        else
        {
            progress = .01f;
        }

        UpdatePosition(progress);
    }
Пример #7
0
    void Update()
    {
        if (spline != null)
        {
            spline.Update(controlPoints);
            spline.Update(resolution);
            spline.DrawSpline(Color.white);

            if (drawNormal)
            {
                spline.DrawNormals(normalExtrusion, Color.red);
            }

            if (drawTangent)
            {
                spline.DrawTangents(tangentExtrusion, Color.cyan);
            }
        }
        else
        {
            spline = new CatmullRom(controlPoints, resolution);
        }



        if (progress <= 1)
        {
            progress += Time.deltaTime * UpdateProgress();
            //if (!trail.emitting) {
            //trail.Clear();
            //trail.emitting = true;
            //}
        }
        else
        {
            progress = .001f;
            //trail.emitting = false;
        }

        UpdatePosition(progress);
    }
Пример #8
0
    void Update()
    {
        if (spline != null)
        {
            spline.Update(controlPoints);
            spline.Update(resolution, closedLoop);
            spline.DrawSpline(color);

            if (drawNormal)
            {
                spline.DrawNormals(normalExtrusion, Color.red);
            }

            if (drawTangent)
            {
                spline.DrawTangents(tangentExtrusion, Color.cyan);
            }
        }
        else
        {
            spline = new CatmullRom(controlPoints, resolution, closedLoop);
        }
    }
Пример #9
0
    public void UpdateLastPoint(Vector3 point)
    {
        if (_controlPoints == null)
        {
            return;
        }

        var p0 = _controlPoints[0].position;
        var dx = (point.x - p0.x);
        var dz = (point.z - p0.z);

        // _controlPoints[1].SetPositionAndRotation(p0 + new Vector3(dx / 8.0f, point.y, dz * 0.5f), Quaternion.identity);
        // _controlPoints[2].SetPositionAndRotation(p0 + new Vector3(dx * 0.5f, point.y, dz / 8.0f * 7.0f), Quaternion.identity);
        // _controlPoints[3].SetPositionAndRotation(point, Quaternion.identity);
        _controlPoints[1].SetPositionAndRotation(p0 + new Vector3(dx / 3.0f, point.y, dz / 3.0f), Quaternion.identity);
        _controlPoints[2].SetPositionAndRotation(p0 + new Vector3(dx / 3.0f * 2.0f, point.y, dz / 3.0f * 2.0f), Quaternion.identity);
        _controlPoints[3].SetPositionAndRotation(point, Quaternion.identity);

        _catmullRom.Update(_controlPoints.ToArray());

        GetComponent <RoadMeshRenderer>().TriggerUpdate();
    }
Пример #10
0
    // Update is called once per frame
    public void Update()
    {
        //Debug.Log("update!!! " + positions.Count);
        //最小のインターバルを設定する
        //if(Time.realtimeSinceStartup - _oldTime < 0.03f) return;
        _oldTime = Time.realtimeSinceStartup;

        //if( Input.GetKeyDown( KeyCode.B ) ){
        //boost2
        //left btn click
        if (Input.GetMouseButtonDown(1) && !Input.GetKey(KeyCode.LeftShift))
        {
            Vector3 kake = new Vector3(
                0.5f + 8f * (Random.value - 0.5f),
                0.5f + 8f * (Random.value - 0.5f),
                0.5f + 8f * (Random.value - 0.5f)
                );

            if (_bane.v.magnitude < 0.5f)
            {
                _bane.addV.x = _bane.v.x * kake.x;
                _bane.addV.y = _bane.v.y * kake.y;
                _bane.addV.z = _bane.v.z * kake.z;
            }
        }

        if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift))
        {
            if (_bane.v.magnitude < 0.5f)
            {
                float nn = 1.5f + 0.5f * Random.value;
                _bane.addV.x = _bane.v.x * nn;
                _bane.addV.y = _bane.v.y * nn;
                _bane.addV.z = _bane.v.z * nn;
            }
        }



        // Vector3でマウス位置座標を取得する
        var mousePos = Input.mousePosition;

        //Debug.Log("mousePos!!! " + mousePos);

        // Z軸修正
        mousePos.z = 0f;



        // マウス位置座標をスクリーン座標からワールド座標に変換する
        var screenToWorldPointPosition
            = _tgtTransform != null ? _tgtTransform.position : Camera.main.ScreenToWorldPoint(mousePos);


        // ワールド座標に変換されたマウス座標を代入
        //if(_tgtTransform==null){
        screenToWorldPointPosition.z *= Params.Instance.zMultiplier;    //mouse:0 body:1
        //}


        position = _bane.Update(screenToWorldPointPosition);
        // Debug.Log("pos!!! " + screenToWorldPointPosition);



        //if(position == oldPosition) return;
        //if(screenToWorldPointPosition == oldTargetPos) return;

        oldTargetPos = screenToWorldPointPosition;


        //positionsをためている。
        rotation = Mathf.Atan2(
            position.y - oldPosition.y,
            position.x - oldPosition.x
            );

        velocity.x = position.x - oldPosition.x;
        velocity.y = position.y - oldPosition.y;

        if (_tgtTransform != null)
        {
            velocity.z = position.z - oldPosition.z;
        }

        //Debug.Log(positions.Count);

        //どっちがいい?
        if ((velocity.magnitude > 0.1f && _isLimit) || !_isLimit)
        {
            if (positions.Count >= NUM)
            {
                positions.RemoveAt(positions.Count - 1);
            }
            positions.Insert(0, position);

            if (rotations.Count >= NUM)
            {
                rotations.RemoveAt(rotations.Count - 1);
            }
            rotations.Insert(0, rotation);
        }

        if (_isCatmull)
        {
            _catmull.Update(positions);
            //_catmull.Update( _catmullResolution, false );
        }

        oldPosition.x = position.x;
        oldPosition.y = position.y;
        oldPosition.z = position.z;
    }