public void FinishWithCicle(float Spacetime)
        {
            float time = (float)maxTime + Spacetime;

            heads.AddPoint(heads.GetPointOnCurve(0), time);
            targets.AddPoint(targets.GetPointOnCurve(0), time);
            ups.AddPoint(ups.GetPointOnCurve(0), time);
            maxTime = time;
        }
Пример #2
0
 public override void _Process(float delta)
 {
     if ((int)root.rpm != 0)
     {
         var curve = new Curve3D();
         curve.UpVectorEnabled = true;
         for (int i = 0; i < 15; i += 5)
         {
             curve.AddPoint(new Vector3(Translation.x, root.height.GetNoise2d(Translation.x, Translation.z - i) * 20, Translation.z - i));
         }
         var offset = ((root.rpm * (float)Math.PI * 2.0f) / 60.0f) * 0.60f * delta;
         Translation = curve.InterpolateBaked(offset);
         LookAt(Translation + curve.InterpolateBakedUpVector(offset).Rotated(Vector3.Right, -(float)Math.PI / 2), Vector3.Up);
     }
     else if (Input.IsKeyPressed((int)KeyList.Z))
     {
         var curve = new Curve3D();
         curve.UpVectorEnabled = true;
         for (int i = 0; i < 15; i += 5)
         {
             curve.AddPoint(new Vector3(Translation.x, root.height.GetNoise2d(Translation.x, Translation.z - i) * 20, Translation.z - i));
         }
         Translation = curve.InterpolateBaked(32 * delta);
         LookAt(Translation + curve.InterpolateBakedUpVector(16 * delta).Rotated(Vector3.Right, -(float)Math.PI / 2), Vector3.Up);
     }
 }
Пример #3
0
    public void Initialise(WaveParams waveParams)
    {
        // Instantiate the wave segments, and set the initial wave rotation

        WaveSegments = new WaveSegment[waveParams.SegmentCount];
        var waveWidth = WaveSegment.SEGMENT_WIDTH * waveParams.SegmentCount;

        var leftOrigin = new Vector3(-waveWidth / 2, 0, 0);
        var leftControlPointInOrigin  = new Vector3(-0.2f, 0, 0).Rotated(new Vector3(0, 0, 1), waveParams.LeftControlRotationRad);
        var leftControlPointOutOrigin = new Vector3(0.2f, 0, 0).Rotated(new Vector3(0, 0, 1), waveParams.LeftControlRotationRad);

        var rightOrigin = new Vector3(waveWidth / 2, 0, 0);
        var rightControlPointInOrigin  = new Vector3(0.2f, 0, 0).Rotated(new Vector3(0, 0, 1), waveParams.RightControlRotationRad);
        var rightControlPointOutOrigin = new Vector3(-0.2f, 0, 0).Rotated(new Vector3(0, 0, 1), waveParams.RightControlRotationRad);

        var curve = new Curve3D();
        var gap   = rightOrigin - leftOrigin;

        // control point locations are relative to the curve point origin (i.e not global coordinates)
        curve.AddPoint(leftOrigin,
                       SetControlPoint(gap.Length(), leftControlPointInOrigin),
                       SetControlPoint(gap.Length(), leftControlPointOutOrigin));

        curve.AddPoint(rightOrigin,
                       SetControlPoint(gap.Length(), rightControlPointInOrigin),
                       SetControlPoint(gap.Length(), rightControlPointOutOrigin));

        // instantiate wave segments
        var segmentFraction = (float)1 / waveParams.SegmentCount;

        for (var i = 0; i < waveParams.SegmentCount; i++)
        {
            var waveSegment = WaveSegmentScene.Instance() as WaveSegment;

            // xOffset moves from leftOrigin to rightOrigin in a number of steps equal to the segment count
            var xOffset = leftOrigin.x + (rightOrigin.x - leftOrigin.x) * (i * segmentFraction);
            var yOffset = curve.Interpolate(0, i * segmentFraction + (segmentFraction / 2));

            waveSegment.Translation = new Vector3(xOffset, yOffset.y, 0);

            AddChild(waveSegment);
            WaveSegments[i] = waveSegment;
        }

        Rotation        = new Vector3(0, 0, waveParams.InitialRotationRad);
        RotationRateRad = waveParams.RotationRateRad;
    }
Пример #4
0
    public void _CloseCurve()
    {
        Curve3D c = path.curve;

        if (!IsInstanceValid(c))
        {
            return;
        }
        if (c.GetPointCount() < 2)
        {
            return;
        }
        c.AddPoint(c.GetPointPosition(0), c.GetPointIn(0), c.GetPointOut(0));
    }
    public override void _PhysicsProcess(float delta)
    {
        base._PhysicsProcess(delta);

        var ribbonCurve = new Curve3D();

        // based on the gap between the two controllers, the control points move further away from the origin as the controllers are moved apart
        // without dynamically adjusting the control points, the curve would get straighter as the controllers moved apart.
        var gapWidth = (RightController.GlobalTransform.origin - LeftController.GlobalTransform.origin).Length();

        // control point locations are offset from the origin point (i.e not global coordinates)
        ribbonCurve.AddPoint(LeftController.RibbonGlobalOrigin,
                             AdjustControlPoint(LeftController.ControlPointInOffset, gapWidth),
                             AdjustControlPoint(LeftController.ControlPointOutOffset, gapWidth));

        ribbonCurve.AddPoint(RightController.RibbonGlobalOrigin,
                             AdjustControlPoint(RightController.ControlPointInOffset, gapWidth),
                             AdjustControlPoint(RightController.ControlPointOutOffset, gapWidth));


        // figure out a vector at 90 degrees to origin and control point. Vector will be used to offset one side of the ribbon, and give it a consistent width and orientation
        // need this for both controllers, and then gradually rotate from one to the other over the course of the ribbon length

        // Curve points pass through the centre of the Ribbon, as it appears on-screen.
        // To get the vertices to draw, need to offset from curvePoints for the front and back edges of the Ribbon, as below
        RibbonPoints = ribbonCurve.Tessellate();

        // will interpolate between these edges to give the ribbon a smooth "twist" over its length
        var leftRibbonFrontEdgeOffset = LeftController.RibbonFrontEdgeOffset;
        var leftRibbonBackEdgeOffset  = LeftController.RibbonBackEdgeOffset;

        var rightRibbonFrontEdgeOffset = RightController.RibbonFrontEdgeOffset;
        var rightRibbonBackEdgeOffset  = RightController.RibbonBackEdgeOffset;

        var triStripPoints        = new Vector3[RibbonPoints.Length * 2];
        var curvePointLengthFloat = (float)RibbonPoints.Length;

        for (var i = 0; i < RibbonPoints.Length; i++)
        {
            // Offset front and back from curvePoints, as curvePoints pass through the centre of the ribbon
            var frontEdgePoint = RibbonPoints[i] + leftRibbonFrontEdgeOffset.LinearInterpolate(rightRibbonFrontEdgeOffset, i / curvePointLengthFloat);
            var backEdgePoint  = RibbonPoints[i] + leftRibbonBackEdgeOffset.LinearInterpolate(rightRibbonBackEdgeOffset, i / curvePointLengthFloat);

            triStripPoints[i * 2]       = frontEdgePoint;
            triStripPoints[(i * 2) + 1] = backEdgePoint;
        }

        RibbonMesh.Clear();         // without Clear, triangles from previous loops accumulate on screen
        RibbonMesh.Begin(Mesh.PrimitiveType.TriangleStrip);
        for (var i = 0; i < triStripPoints.Length; i++)
        {
            // pass vertices to Normal function in anti-clockwise order
            // this will vary depending on which side of the ribbon the vertex is added, hence the i % 2... condition. i.e.:
            // - odd number: n, n-1, n-2
            // - even number: n-2, n-1, n
            var normal = i < 3 ? GetTriangleNormal(triStripPoints[2], triStripPoints[1], triStripPoints[0])
                                                                : (i % 2 == 0 ? GetTriangleNormal(triStripPoints[i], triStripPoints[i - 1], triStripPoints[i - 2])
                                                                        : GetTriangleNormal(triStripPoints[i - 2], triStripPoints[i - 1], triStripPoints[i]));

            RibbonMesh.SetNormal(normal);
            RibbonMesh.AddVertex(triStripPoints[i]);
        }
        RibbonMesh.End();
    }