Example #1
0
    private void CreateBlockOutline()
    {
        debugCursor.Begin(Mesh.PrimitiveType.LineStrip);
        debugCursor.SetColor(new Color(1, 0, 0));

        debugCursor.AddVertex(Renderer.CUBE_VERTICES[0] * 1.01f);
        debugCursor.AddVertex(Renderer.CUBE_VERTICES[1] * 1.01f);
        debugCursor.AddVertex(Renderer.CUBE_VERTICES[2] * 1.01f);
        debugCursor.AddVertex(Renderer.CUBE_VERTICES[3] * 0.01f);

        debugCursor.AddVertex(Renderer.CUBE_VERTICES[3] * 1.01f);
        debugCursor.AddVertex(Renderer.CUBE_VERTICES[0] * 1.01f);

        debugCursor.AddVertex(Renderer.CUBE_VERTICES[4] * 1.01f);
        debugCursor.AddVertex(Renderer.CUBE_VERTICES[5] * 1.01f);
        debugCursor.AddVertex(Renderer.CUBE_VERTICES[1] * 1.01f);

        debugCursor.AddVertex(Renderer.CUBE_VERTICES[5] * 1.01f);
        debugCursor.AddVertex(Renderer.CUBE_VERTICES[6] * 1.01f);
        debugCursor.AddVertex(Renderer.CUBE_VERTICES[2] * 1.01f);

        debugCursor.AddVertex(Renderer.CUBE_VERTICES[6] * 1.01f);
        debugCursor.AddVertex(Renderer.CUBE_VERTICES[7] * 1.01f);
        debugCursor.AddVertex(Renderer.CUBE_VERTICES[3] * 1.01f);

        debugCursor.AddVertex(Renderer.CUBE_VERTICES[7] * 1.01f);
        debugCursor.AddVertex(Renderer.CUBE_VERTICES[4] * 1.01f);
        debugCursor.End();
    }
Example #2
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;
    }
Example #3
0
        private void DrawAxis()
        {
            ImmediateGeometry xAxis = GetNode <ImmediateGeometry>("xAxis");
            ImmediateGeometry yAxis = GetNode <ImmediateGeometry>("yAxis");
            ImmediateGeometry zAxis = GetNode <ImmediateGeometry>("zAxis");

            xAxis.Begin(Mesh.PrimitiveType.LineStrip);
            xAxis.AddVertex(Vector3.Zero);
            xAxis.AddVertex(new Vector3(100, 0, 0));
            xAxis.End();

            yAxis.Begin(Mesh.PrimitiveType.LineStrip);
            yAxis.AddVertex(Vector3.Zero);
            yAxis.AddVertex(new Vector3(0, 100, 0));
            yAxis.End();

            zAxis.Begin(Mesh.PrimitiveType.LineStrip);
            zAxis.AddVertex(Vector3.Zero);
            zAxis.AddVertex(new Vector3(0, 0, 100));
            zAxis.End();
        }
Example #4
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();
    }
Example #5
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();
            }
        }
Example #6
0
 public void AddToDebugDraw()
 {
     for (int i = 0; i < stepCount; i++)
     {
         Vector3 thisStart = (Vector3)((Dictionary)stepPoints[i])["start"];
         Vector3 thisEnd   = (Vector3)((Dictionary)stepPoints[i])["end"];
         bool    isPen     = (bool)((Dictionary)stepPoints[i])["isPen"];
         GD.Print("Points: ", thisStart, thisEnd);
         if (isPen)
         {
             debugDrawNode2.Begin(Mesh.PrimitiveType.LineStrip, null);
             debugDrawNode2.AddVertex(thisStart);
             debugDrawNode2.AddVertex(thisEnd);
             debugDrawNode2.End();
         }
         else
         {
             debugDrawNode.Begin(Mesh.PrimitiveType.LineStrip, null);
             debugDrawNode.AddVertex(thisStart);
             debugDrawNode.AddVertex(thisEnd);
             debugDrawNode.End();
         }
     }
 }
Example #7
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();
         }
     }
 }
    private void LoadWAD(string WADPath, string LevelName)
    {
        byte[] buffer;
        int    i;

        GD.Print($"Opening {WADPath}...");

        File file = new File();

        file.Open(WADPath, File.ModeFlags.Read);
        if (file.Open(WADPath, File.ModeFlags.Read) != Godot.Error.Ok)
        {
            GD.Print($"Failed to open WAD file {WADPath}");
            return;
        }

        if (printDebugInfo)
        {
            GD.Print("READING HEADER...");
        }

        Header header = new Header();

        header.Type      = Decode32AsString(file);
        header.LumpNum   = file.Get32();
        header.DirOffset = file.Get32();

        GD.Print($"{this.WADPath} is {header.Type}");

        if (printDebugInfo)
        {
            GD.Print("READING LUMPS");
        }

        Lump lumpMapname    = new Lump();
        Lump lumpThings     = new Lump();
        Lump lumpLinedefs   = new Lump();
        Lump lumpSidedefs   = new Lump();
        Lump lumpVertexes   = new Lump();
        Lump lumpSegs       = new Lump();
        Lump lumpSubsectors = new Lump();
        Lump lumpNodes      = new Lump();
        Lump lumpSectors    = new Lump();
        Lump lumpReject     = new Lump();
        Lump lumpBlockmap   = new Lump();

        bool first      = true;
        bool breakAfter = false;

        file.Seek(header.DirOffset);
        for (int j = 0; j < header.LumpNum; j++)
        {
            Lump lump = ReadLump(file);
            if (first)
            {
                lumpMapname = lump;
                first       = false;
            }

            switch (lump.Name)
            {
            case "THINGS":
                lumpThings = lump;
                break;

            case "LINEDEFS":
                lumpLinedefs = lump;
                break;

            case "SIDEDEFS":
                lumpSidedefs = lump;
                break;

            case "VERTEXES":
                lumpVertexes = lump;
                break;

            case "SEGS":
                lumpSegs = lump;
                break;

            case "SSECTORS":
                lumpSubsectors = lump;
                break;

            case "NODES":
                lumpNodes = lump;
                break;

            case "SECTORS":
                lumpSectors = lump;
                break;

            case "REJECT":
                lumpReject = lump;
                break;

            case "BLOCKMAP":
                lumpBlockmap = lump;
                if (breakAfter)
                {
                    break;
                }

                break;

            default:
                if (lump.Name == levelName)
                {
                    breakAfter = true;
                }

                break;
            }
        }

        if (printDebugInfo)
        {
            GD.Print($"Internal map name: {lumpMapname.Name}");
        }

        if (printDebugInfo)
        {
            GD.Print($"READING THINGS...");
        }

        file.Seek(lumpThings.Offset);

        buffer = file.GetBuffer((int)lumpThings.Size);
        Thing[] things = new Thing[lumpThings.Size];
        i = 0;
        while (i < buffer.Length)
        {
            Thing thing = new Thing();
            thing.X       = ToShort(buffer[i], buffer[i + 1]);
            thing.Y       = ToShort(buffer[i + 2], buffer[i + 3]);
            thing.Angle   = ToShort(buffer[i + 4], buffer[i + 5]);
            thing.Type    = ToShort(buffer[i + 6], buffer[i + 7]);
            thing.Options = ToShort(buffer[i + 8], buffer[i + 9]);
            things.Append(thing);
            i += 10;
        }

        if (printDebugInfo)
        {
            GD.Print("READING LINEDEFS...");
        }

        file.Seek(lumpLinedefs.Offset);
        buffer = file.GetBuffer((int)lumpLinedefs.Size);
        Linedef[] linedefs = new Linedef[lumpLinedefs.Size];
        i = 0;
        int k = 0;

        while (i < buffer.Length)
        {
            Linedef linedef = new Linedef();
            linedef.StartVertex  = ToShort(buffer[i], buffer[i + 1]);
            linedef.EndVertex    = ToShort(buffer[i + 2], buffer[i + 3]);
            linedef.Flags        = ToShort(buffer[i + 4], buffer[i + 5]);
            linedef.Type         = ToShort(buffer[i + 6], buffer[i + 7]);
            linedef.Trigger      = ToShort(buffer[i + 8], buffer[i + 9]);
            linedef.RightSidedef = ToShort(buffer[i + 10], buffer[i + 11]);
            linedef.LeftSidedef  = ToShort(buffer[i + 12], buffer[i + 13]);
            //linedefs.Append(linedef);
            linedefs[k++] = linedef;
            i            += 14;
        }

        if (printDebugInfo)
        {
            GD.Print("READING SIDEDEFS...");
        }

        file.Seek(lumpSidedefs.Offset);
        buffer = file.GetBuffer((int)lumpSidedefs.Size);
        Sidedef[] sieddefs = new Sidedef[lumpSidedefs.Size];
        i = 0;
        while (i < buffer.Length)
        {
            Sidedef sidedef = new Sidedef();
            sidedef.XOffset      = ToShort(buffer[i], buffer[i + 1]);
            sidedef.YOffset      = ToShort(buffer[i + 2], buffer[i + 3]);
            sidedef.UpperTexture = Combine8BytesToString(buffer[i + 4], buffer[i + 5], buffer[i + 6], buffer[i + 7],
                                                         buffer[i + 8], buffer[i + 9], buffer[i + 10], buffer[i + 11]);
            sidedef.LowerTexture = Combine8BytesToString(buffer[i + 12], buffer[i + 13], buffer[i + 14], buffer[i + 15],
                                                         buffer[i + 16], buffer[i + 17], buffer[i + 18], buffer[i + 19]);
            sidedef.MiddleTexture = Combine8BytesToString(buffer[i + 20], buffer[i + 21], buffer[i + 22],
                                                          buffer[i + 23], buffer[i + 24], buffer[i + 25], buffer[i + 26], buffer[i + 27]);
            sidedef.Sector = ToShort(buffer[i + 28], buffer[i + 29]);
            sieddefs.Append(sidedef);
            i += 30;
        }

        if (printDebugInfo)
        {
            GD.Print("READING VERTEXES...");
        }

        file.Seek(lumpVertexes.Offset);
        buffer = buffer = file.GetBuffer((int)lumpVertexes.Size);
        Vertex[] vertexes = new Vertex[lumpVertexes.Size];
        i = 0;
        k = 0;
        while (i < buffer.Length)
        {
            float  x      = ToShort(buffer[i], buffer[i + 1]) * scale;
            float  y      = ToShort(buffer[i + 2], buffer[i + 3]) * scale;
            Vertex vertex = new Vertex();
            vertex.X    = x;
            vertex.Y    = y;
            vertexes[k] = vertex;
            k          += 1;
            i          += 4;
        }

        if (printDebugInfo)
        {
            GD.Print("READING SUB-SECTORS...");
        }

        file.Seek(lumpSubsectors.Offset);
        buffer = buffer = file.GetBuffer((int)lumpSubsectors.Size);
        SubSector[] subSectors = new SubSector[lumpSubsectors.Size];
        i = 0;
        while (i < buffer.Length)
        {
            SubSector subSector = new SubSector();
            subSector.SegCount = ToShort(buffer[i], buffer[i + 1]);
            subSector.SegNum   = ToShort(buffer[i + 2], buffer[i + 3]);
            subSectors.Append(subSector);
            i += 4;
        }

        if (printDebugInfo)
        {
            GD.Print("READING NODES...");
        }

        file.Seek(lumpNodes.Offset);
        buffer = buffer = file.GetBuffer((int)lumpNodes.Size);
        Node[] nodes = new Node[lumpNodes.Size];
        i = 0;
        while (i < buffer.Length)
        {
            Node node = new Node();
            node.X           = ToShort(buffer[i], buffer[i + 1]);
            node.Y           = ToShort(buffer[i + 2], buffer[i + 3]);
            node.DX          = ToShort(buffer[i + 4], buffer[i + 5]);
            node.DY          = ToShort(buffer[i + 6], buffer[i + 7]);
            node.YUpperRight = ToShort(buffer[i + 8], buffer[i + 9]);
            node.YLowerRight = ToShort(buffer[i + 10], buffer[i + 11]);
            node.XLowerRight = ToShort(buffer[i + 12], buffer[i + 13]);
            node.XUpperRight = ToShort(buffer[i + 14], buffer[i + 15]);
            node.YUpperLeft  = ToShort(buffer[i + 16], buffer[i + 17]);
            node.YLowerLeft  = ToShort(buffer[i + 18], buffer[i + 19]);
            node.XLowerLeft  = ToShort(buffer[i + 20], buffer[i + 20]);
            node.XUpperLeft  = ToShort(buffer[i + 22], buffer[i + 23]);
            node.NodeRight   = ToShort(buffer[i + 24], buffer[i + 25]);
            node.NodeLeft    = ToShort(buffer[i + 26], buffer[i + 27]);
            i += 28;
        }

        if (printDebugInfo)
        {
            GD.Print("READING SECTORS...");
        }

        file.Seek(lumpSectors.Offset);
        buffer = buffer = file.GetBuffer((int)lumpSectors.Size);
        Sector[] sectors = new Sector[lumpSectors.Size];
        i = 0;
        while (i < buffer.Length)
        {
            Sector sector = new Sector();
            sector.FloorHeight  = ToShort(buffer[i], buffer[i + 1]);
            sector.FloorHeight  = ToShort(buffer[i + 1], buffer[i + 3]);
            sector.FloorTexture = Combine8BytesToString(buffer[i + 4], buffer[i + 5], buffer[i + 6], buffer[i + 7],
                                                        buffer[i + 8], buffer[i + 9], buffer[i + 10], buffer[i + 11]);
            sector.CeilTexture = Combine8BytesToString(buffer[i + 12], buffer[i + 13], buffer[i + 14], buffer[i + 15],
                                                       buffer[i + 16], buffer[i + 17], buffer[i + 18], buffer[i + 19]);
            sector.LightLevel = ToShort(buffer[i + 20], buffer[i + 21]);
            sector.Special    = ToShort(buffer[i + 22], buffer[i + 23]);
            sector.Tag        = ToShort(buffer[i + 24], buffer[i + 25]);
            sectors.Append(sector);
            i += 26;
        }

        file.Close();

        if (printDebugInfo)
        {
            GD.Print("BUILDING GEOMETRY");
        }

        foreach (var ld in linedefs)
        {
            if (ld == null)
            {
                continue;
            }

            Vertex            vertex1  = vertexes[ld.StartVertex];
            Vertex            vertex2  = vertexes[ld.EndVertex];
            ImmediateGeometry geometry = new ImmediateGeometry();
            geometry.MaterialOverride = _surfaceMaterial;
            geometry.Begin(Mesh.PrimitiveType.Lines);
            if (ld.Type != 0)
            {
                geometry.SetColor(new Color(1, 1, 0));
            }
            else
            {
                geometry.SetColor(new Color(1, 0, 0));
            }

            geometry.AddVertex(new Vector3(vertex1.X, 0, vertex1.Y));
            geometry.AddVertex(new Vector3(vertex2.X, 0, vertex2.Y));
            geometry.End();
            AddChild(geometry);
        }
    }
    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();
    }