예제 #1
0
        public void ComputeHeight()
        {
            List <Vector3D> sp = new List <Vector3D>();

            for (int i = 0; i < vertices.Count; i++)
            {
                sp.Add(new Vector3D(vertices[i].Pos.x, vertices[i].Pos.y, vertices[i].Z));
            }

            if (vertices.Count == 2)
            {
                float    z             = sp[0].z;
                Line2D   line          = new Line2D(sp[0], sp[1]);
                Vector3D perpendicular = line.GetPerpendicular();

                Vector2D v = sp[0] + perpendicular;

                sp.Add(new Vector3D(v.x, v.y, z));
            }

            Plane p = new Plane(sp[0], sp[1], sp[2], true);

            float fheight = p.GetZ(GetCircumcenter(sp));

            // If something went wrong with computing the height use the height
            // of the first vertex as a workaround
            if (float.IsNaN(fheight))
            {
                height = Convert.ToInt32(sp[0].z);
            }
            else
            {
                height = Convert.ToInt32(fheight);
            }
        }
예제 #2
0
        private Vector2D GetCircumcenter(List <Vector3D> points)
        {
            float u_ray;

            Line2D line1 = new Line2D(points[0], points[1]);
            Line2D line2 = new Line2D(points[2], points[0]);

            // Perpendicular bisectors
            Line2D bisector1 = new Line2D(line1.GetCoordinatesAt(0.5f), line1.GetCoordinatesAt(0.5f) + line1.GetPerpendicular());
            Line2D bisector2 = new Line2D(line2.GetCoordinatesAt(0.5f), line2.GetCoordinatesAt(0.5f) + line2.GetPerpendicular());

            bisector1.GetIntersection(bisector2, out u_ray);

            return(bisector1.GetCoordinatesAt(u_ray));
        }
예제 #3
0
        public void UpdateSlopes(Sector s)
        {
            string[] fieldnames = new string[] { "user_floorplane_id", "user_ceilingplane_id" };

            foreach (string fn in fieldnames)
            {
                int id = s.Fields.GetValue(fn, -1);

                if (id == -1)
                {
                    if (fn == "user_floorplane_id")
                    {
                        s.FloorSlope       = new Vector3D();
                        s.FloorSlopeOffset = 0;
                    }
                    else
                    {
                        s.CeilSlope       = new Vector3D();
                        s.CeilSlopeOffset = 0;
                    }

                    continue;
                }

                List <Vector3D>  sp  = new List <Vector3D>();
                SlopeVertexGroup svg = GetSlopeVertexGroup(id);

                // If the SVG does not exist unbind the SVG info from this sector
                if (svg == null)
                {
                    s.Fields.Remove(fn);
                    continue;
                }

                for (int i = 0; i < svg.Vertices.Count; i++)
                {
                    sp.Add(new Vector3D(svg.Vertices[i].Pos.x, svg.Vertices[i].Pos.y, svg.Vertices[i].Z));
                }

                if (svg.Vertices.Count == 2)
                {
                    float    z             = sp[0].z;
                    Line2D   line          = new Line2D(sp[0], sp[1]);
                    Vector3D perpendicular = line.GetPerpendicular();

                    Vector2D v = sp[0] + perpendicular;

                    sp.Add(new Vector3D(v.x, v.y, z));
                }

                if (fn == "user_floorplane_id")
                {
                    Plane p = new Plane(sp[0], sp[1], sp[2], true);

                    s.FloorSlope       = new Vector3D(p.a, p.b, p.c);
                    s.FloorSlopeOffset = p.d;
                    s.FloorHeight      = svg.Height;
                    svg.Height         = s.FloorHeight;
                }
                else
                {
                    Plane p = new Plane(sp[0], sp[1], sp[2], false);

                    s.CeilSlope       = new Vector3D(p.a, p.b, p.c);
                    s.CeilSlopeOffset = p.d;
                    s.CeilHeight      = svg.Height;
                    svg.Height        = s.CeilHeight;
                }
            }
        }
예제 #4
0
        public void UpdateSlopes(Sector s)
        {
            string[] fieldnames = new string[] { "user_floorplane_id", "user_ceilingplane_id" };

            foreach (string fn in fieldnames)
            {
                int id = s.Fields.GetValue(fn, -1);

                if (id == -1)
                {
                    if (fn == "user_floorplane_id")
                    {
                        s.FloorSlope       = new Vector3D();
                        s.FloorSlopeOffset = 0;
                    }
                    else
                    {
                        s.CeilSlope       = new Vector3D();
                        s.CeilSlopeOffset = 0;
                    }

                    continue;
                }

                List <Vector3D>  sp  = new List <Vector3D>();
                SlopeVertexGroup svg = GetSlopeVertexGroup(id);

                // If the SVG does not exist unbind the SVG info from this sector
                if (svg == null)
                {
                    s.Fields.Remove(fn);
                    continue;
                }

                if (svg.Spline)
                {
                    Vector2D        center      = new Vector2D(s.BBox.Width / 2 + s.BBox.X, s.BBox.Height / 2 + s.BBox.Y);
                    List <Line3D>   splinelines = new List <Line3D>();
                    List <Vector3D> tangents    = new List <Vector3D>();

                    sp.Add(new Vector3D(svg.Vertices[1].Pos.x, svg.Vertices[1].Pos.y, svg.Vertices[1].Z));
                    sp.Add(new Vector3D(svg.Vertices[0].Pos.x, svg.Vertices[0].Pos.y, svg.Vertices[0].Z));
                    sp.Add(new Vector3D(svg.Vertices[2].Pos.x, svg.Vertices[2].Pos.y, svg.Vertices[2].Z));

                    sp.Add(new Vector3D(sp[2].x - 96, sp[2].y, sp[2].z - 64));
                    sp.Insert(0, new Vector3D(sp[0].x + 96, sp[0].y, sp[0].z - 64));
                    //sp.Add(new Vector3D(sp[2] + (sp[2] - sp[1])));
                    //sp.Insert(0, new Vector3D(sp[0] + (sp[0] - sp[1])));


                    // Create tangents
                    tangents.Add(new Vector3D());

                    for (int i = 1; i <= 3; i++)
                    {
                        tangents.Add(new Vector3D((sp[i + 1] - sp[i - 1]) / 2.0f));
                    }

                    tangents.Add(new Vector3D());

                    Debug.Print("----- tangents -----");
                    for (int i = 0; i < tangents.Count; i++)
                    {
                        Debug.Print(tangents[i].ToString());
                    }

                    for (float u = 0.0f; u < 1.0f; u += 0.1f)
                    {
                        splinelines.Add(new Line3D(
                                            CRS(sp[0], sp[1], sp[2], sp[3], u),
                                            CRS(sp[0], sp[1], sp[2], sp[3], u + 0.1f)
                                            ));

                        /*
                         * splinelines.Add(new Line3D(
                         *              Tools.HermiteSpline(sp[1], tangents[1], sp[2], tangents[2], u),
                         *              Tools.HermiteSpline(sp[1], tangents[1], sp[2], tangents[2], u+0.1f)
                         *      )
                         * );
                         */
                    }

                    for (float u = 0.0f; u < 1.0f; u += 0.1f)
                    {
                        splinelines.Add(new Line3D(
                                            CRS(sp[1], sp[2], sp[3], sp[4], u),
                                            CRS(sp[1], sp[2], sp[3], sp[4], u + 0.1f)
                                            ));

                        /*
                         * splinelines.Add(new Line3D(
                         *              Tools.HermiteSpline(sp[2], tangents[2], sp[3], tangents[3], u),
                         *              Tools.HermiteSpline(sp[2], tangents[2], sp[3], tangents[3], u + 0.1f)
                         *      )
                         * );
                         */
                    }

                    drawlines.Clear();
                    drawlines.AddRange(splinelines);

                    drawpoints.Clear();
                    drawpoints.AddRange(sp);

                    Line2D          sl1    = new Line2D(sp[1], sp[2]);
                    Line2D          sl2    = new Line2D(sp[2], sp[3]);
                    List <Vector3D> points = new List <Vector3D>();

                    Debug.Print("----- spline lines -----");
                    foreach (Line3D l in splinelines)
                    {
                        Debug.Print(l.Start.ToString() + " / " + l.End.ToString());
                    }

                    foreach (Sidedef sd in s.Sidedefs)
                    {
                        double u       = 0.0f;
                        Plane  ldplane = new Plane(sd.Line.Start.Position, sd.Line.End.Position, new Vector3D(sd.Line.Start.Position.x, sd.Line.Start.Position.y, 128), true);

                        foreach (Line3D l in splinelines)
                        {
                            if (ldplane.GetIntersection(l.Start, l.End, ref u))
                            {
                                if (u < 0.0f || u > 1.0f)
                                {
                                    continue;
                                }

                                Vector3D v = (l.End - l.Start) * u + l.Start;
                                points.Add(v);
                            }
                        }

                        /*
                         * if(sd.Line.Line.GetIntersection(sl1, out u))
                         *      points.Add(Tools.HermiteSpline(sp[1], tangents[1], sp[2], tangents[2], u));
                         *
                         * if (sd.Line.Line.GetIntersection(sl2, out u))
                         *      points.Add(Tools.HermiteSpline(sp[2], tangents[2], sp[3], tangents[3], u));
                         */
                    }


                    if (fn == "user_floorplane_id")
                    {
                        /*
                         * s.FloorSlope = new Vector3D(p.a, p.b, p.c);
                         * s.FloorSlopeOffset = p.d;
                         */
                    }
                    else
                    {
                        List <Vector3D> ps = new List <Vector3D>();

                        if (points.Count > 2)
                        {
                            points.RemoveAt(0);
                        }

                        Vector2D perp = new Line2D(points[0], points[1]).GetPerpendicular();

                        ps.Add(points[0]);
                        ps.Add(points[1]);
                        ps.Add(new Vector3D(points[0].x + perp.x, points[0].y + perp.y, points[0].z));

                        Debug.Print("----- points -----");
                        for (int i = 0; i < ps.Count; i++)
                        {
                            Debug.Print(ps[i].ToString());
                        }

                        /*
                         * for(int i=0; i < ps.Count; i++)
                         * {
                         *      ps[i] = new Vector3D(ps[i].x, ps[i].z, ps[i].y);
                         * }
                         */

                        Debug.Print("-----");
                        for (int i = 0; i < ps.Count; i++)
                        {
                            Debug.Print(ps[i].ToString());
                        }

                        Plane p = new Plane(ps[0], ps[1], ps[2], false);

                        s.CeilSlope       = new Vector3D(p.a, p.b, p.c);
                        s.CeilSlopeOffset = p.d;
                    }
                }
                else                 // No spline
                {
                    for (int i = 0; i < svg.Vertices.Count; i++)
                    {
                        sp.Add(new Vector3D(svg.Vertices[i].Pos.x, svg.Vertices[i].Pos.y, svg.Vertices[i].Z));
                    }

                    if (svg.Vertices.Count == 2)
                    {
                        double   z             = sp[0].z;
                        Line2D   line          = new Line2D(sp[0], sp[1]);
                        Vector3D perpendicular = line.GetPerpendicular();

                        Vector2D v = sp[0] + perpendicular;

                        sp.Add(new Vector3D(v.x, v.y, z));
                    }

                    if (fn == "user_floorplane_id")
                    {
                        Plane p = new Plane(sp[0], sp[1], sp[2], true);

                        s.FloorSlope       = new Vector3D(p.a, p.b, p.c);
                        s.FloorSlopeOffset = p.d;
                        s.FloorHeight      = svg.Height;
                        svg.Height         = s.FloorHeight;
                    }
                    else
                    {
                        Plane p = new Plane(sp[0], sp[1], sp[2], false);

                        s.CeilSlope       = new Vector3D(p.a, p.b, p.c);
                        s.CeilSlopeOffset = p.d;
                        s.CeilHeight      = svg.Height;
                        svg.Height        = s.CeilHeight;
                    }
                }
            }
        }
예제 #5
0
 public LuaVector2D GetPerpendicular()
 {
     return(new LuaVector2D(l2d.GetPerpendicular()));
 }