示例#1
0
    // state functions
    public void roam()
    {
        var point = nav.GetClosestPoint(
            new Vector3(
                (float)rng.NextDouble() * 40 - 20,
                (float)rng.NextDouble() * 40 - 20,
                (float)rng.NextDouble() * 40 - 20)
            );
        var path = nav.GetSimplePath(Translation, point);

        GD.Print(path.Length);
        debug.Clear();
        debug.Begin(Mesh.PrimitiveType.LineStrip);
        foreach (Vector3 n in path)
        {
            debug.AddVertex(n);
        }
        debug.End();

        target_path = new List <Vector3>(path);
        move_flag   = true;
    }
示例#2
0
    public override void Draw()
    {
        base.Draw();

        geometry.Clear();
        geometry.Begin(Mesh.PrimitiveType.Triangles);

        for (int i = 0; i < numParticles; i++)
        {
            Particle particle = particles[i];
            if (!particle.alive)
            {
                continue;
            }

            geometry.SetColor(particle.color);
            DrawTrail(particle.customData["trail"] as Transform[]);
        }

        geometry.End();
    }
示例#3
0
        protected override void _DebugDraw(ImmediateGeometry ig)
        {
            if (Owner != null)
            {
                ig.Clear();
                ig.Begin(Mesh.PrimitiveType.LineStrip);
                ig.SetColor(new Color(1, 0, 0));
                if (!ig.IsSetAsToplevel())
                {
                    ig.SetAsToplevel(true);
                }
                ig.SetTranslation(new Vector3(0, 0, 0));
                ig.AddVertex(Owner.Translation);

                foreach (var p in way_points)
                {
                    ig.AddVertex(p);
                }
                ig.End();
            }
        }
示例#4
0
 public override void _Process(float delta)
 {
     if (tookDamage)
     {
         timer -= delta;
         if (timer < 0)
         {
             tookDamage = false;
             canShoot   = !canShoot;
             UpdateColor();
         }
     }
     if (Engine.EditorHint)
     {
         if (updateLine)
         {
             updateLine = false;
             tragectory.Clear();
             tragectory.Begin(Mesh.PrimitiveType.LineStrip);
             float   time = 0;
             Vector3 vect = (GlobalTransform.basis.y * strength);
             float   step = .01f;
             while (time < 2)
             {
                 tragectory.AddVertex(GlobalTransform.origin +
                                      new Vector3(
                                          vect.x * time,
                                          vect.y * time - (PlayerOptions.gravity / 2) * time * time,
                                          vect.z * time
                                          ));
                 time += step;
             }
             tragectory.End();
         }
     }
 }
示例#5
0
    public override void Draw()
    {
        base.Draw();

        geometry.Clear();
        geometry.Begin(Mesh.PrimitiveType.Triangles);

        for (int i = 0; i < numParticles - 1; i++)
        {
            Particle currParticle = particles[i];
            Particle nextParticle = particles[i + 1];

            Transform curr = currParticle.transform;
            Transform next = nextParticle.transform;

            Vector3 currPointPos = curr.origin;
            Vector3 nextPointPos = next.origin;

            //(point[i] - point[i-1]).cross(cameraPosition - point[i]).normalized() * (thickness / 2);
            Vector3 right          = (nextPointPos - currPointPos).Cross(cameraPos - nextPointPos).Normalized();
            Vector3 currPointRight = right;
            Vector3 nextPointRight = right;

            Vector3 currPointUp = (cameraPos - currPointPos).Normalized();
            Vector3 nextPointUp = (cameraPos - nextPointPos).Normalized();

            float currUVX = (i + 0) / (float)(numParticles - 1f);
            float nextUVX = (i + 1) / (float)(numParticles - 1f);

            float currWidth = curr.basis.x.Length();
            float nextWidth = next.basis.x.Length();

            Vector3[] normals = new Vector3[] {
                currPointUp,
                nextPointUp,
                currPointUp,

                nextPointUp,
                nextPointUp,
                currPointUp
            };
            Vector2[] uvs = new Vector2[] {
                new Vector2(currUVX, 0),
                new Vector2(nextUVX, 0),
                new Vector2(currUVX, 1),

                new Vector2(nextUVX, 0),
                new Vector2(nextUVX, 1),
                new Vector2(currUVX, 1),
            };
            Vector3[] vertices = new Vector3[] {
                currPointPos - currPointRight * currWidth,
                nextPointPos - nextPointRight * nextWidth,
                currPointPos + currPointRight * currWidth,

                nextPointPos - nextPointRight * nextWidth,
                nextPointPos + nextPointRight * nextWidth,
                currPointPos + currPointRight * currWidth
            };
            Color[] colors = new Color[] {
                currParticle.color,
                nextParticle.color,
                currParticle.color,

                nextParticle.color,
                nextParticle.color,
                currParticle.color
            };

            for (int j = 0; j < 6; j++)
            {
                geometry.SetColor(colors[j]);
                geometry.SetNormal(normals[j]);
                geometry.SetUv(uvs[j]);
                geometry.AddVertex(vertices[j]);
            }
        }

        geometry.End();
    }
    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();
    }