Exemplo n.º 1
0
 public ObjParser(String path)
 {
     FloatArray floatArray = new FloatArray();
     TrianglesInput input = new TrianglesInput();
     TrianglesP triP = new TrianglesP();
     Source source = new Source();
     source.mFloatArray = floatArray;
     Triangles triangles = new Triangles();
     triangles.mTriangleInputs.Add(input);
     triangles.mTrianglesP = triP;
     Vertices vertices = new Vertices();
     Mesh mesh = new Mesh();
     mesh.mSources.Add(source);
     mesh.mTriangles.Add(triangles);
     mesh.mVertices = vertices;
     Geometry geometry = new Geometry();
     geometry.mMeshes.Add(mesh);
     mGeometryLibrary.mGeometries.Add(geometry);
 }
 public override void Clear()
 {
     base.Clear();
     Triangles.Clear();
 }
Exemplo n.º 3
0
Arquivo: OsuLogo.cs Projeto: tgi74/osu
        public OsuLogo()
        {
            EarlyActivationMilliseconds = early_activation;

            Size = new Vector2(default_size);

            Anchor = Anchor.Centre;
            Origin = Anchor.Centre;

            AutoSizeAxes = Axes.Both;

            Children = new Drawable[]
            {
                logoHoverContainer = new Container
                {
                    AutoSizeAxes = Axes.Both,
                    Children     = new Drawable[]
                    {
                        logoBounceContainer = new Container
                        {
                            AutoSizeAxes = Axes.Both,
                            Children     = new Drawable[]
                            {
                                rippleContainer = new Container
                                {
                                    Anchor           = Anchor.Centre,
                                    Origin           = Anchor.Centre,
                                    RelativeSizeAxes = Axes.Both,
                                    Children         = new Drawable[]
                                    {
                                        ripple = new Sprite
                                        {
                                            Anchor       = Anchor.Centre,
                                            Origin       = Anchor.Centre,
                                            BlendingMode = BlendingMode.Additive,
                                            Alpha        = 0
                                        }
                                    }
                                },
                                logoAmplitudeContainer = new Container
                                {
                                    AutoSizeAxes = Axes.Both,
                                    Children     = new Drawable[]
                                    {
                                        logoBeatContainer = new Container
                                        {
                                            AutoSizeAxes = Axes.Both,
                                            Children     = new Drawable[]
                                            {
                                                visualizer = new LogoVisualisation
                                                {
                                                    RelativeSizeAxes = Axes.Both,
                                                    Origin           = Anchor.Centre,
                                                    Anchor           = Anchor.Centre,
                                                    Alpha            = 0.5f,
                                                    Size             = new Vector2(0.96f)
                                                },
                                                new BufferedContainer
                                                {
                                                    AutoSizeAxes = Axes.Both,
                                                    Children     = new Drawable[]
                                                    {
                                                        logoContainer = new CircularContainer
                                                        {
                                                            Anchor           = Anchor.Centre,
                                                            Origin           = Anchor.Centre,
                                                            RelativeSizeAxes = Axes.Both,
                                                            Scale            = new Vector2(0.88f),
                                                            Masking          = true,
                                                            Children         = new Drawable[]
                                                            {
                                                                colourAndTriangles = new Container
                                                                {
                                                                    RelativeSizeAxes = Axes.Both,
                                                                    Anchor           = Anchor.Centre,
                                                                    Origin           = Anchor.Centre,
                                                                    Children         = new Drawable[]
                                                                    {
                                                                        new Box
                                                                        {
                                                                            RelativeSizeAxes = Axes.Both,
                                                                            Colour           = OsuPink,
                                                                        },
                                                                        triangles = new Triangles
                                                                        {
                                                                            TriangleScale    = 4,
                                                                            ColourLight      = OsuColour.FromHex(@"ff7db7"),
                                                                            ColourDark       = OsuColour.FromHex(@"de5b95"),
                                                                            RelativeSizeAxes = Axes.Both,
                                                                        },
                                                                    }
                                                                },
                                                                flashLayer = new Box
                                                                {
                                                                    RelativeSizeAxes = Axes.Both,
                                                                    BlendingMode     = BlendingMode.Additive,
                                                                    Colour           = Color4.White,
                                                                    Alpha            = 0,
                                                                },
                                                            },
                                                        },
                                                        logo = new Sprite
                                                        {
                                                            Anchor = Anchor.Centre,
                                                            Origin = Anchor.Centre,
                                                        },
                                                    }
                                                },
                                                impactContainer = new CircularContainer
                                                {
                                                    Anchor           = Anchor.Centre,
                                                    Origin           = Anchor.Centre,
                                                    Alpha            = 0,
                                                    BorderColour     = Color4.White,
                                                    RelativeSizeAxes = Axes.Both,
                                                    BorderThickness  = 10,
                                                    Masking          = true,
                                                    Children         = new Drawable[]
                                                    {
                                                        new Box
                                                        {
                                                            RelativeSizeAxes = Axes.Both,
                                                            AlwaysPresent    = true,
                                                            Alpha            = 0,
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private string GenerateGeometry(IOMesh mesh)
        {
            // convert mesh to triangles to simplify
            mesh.MakeTriangles();

            // create a unique geometry id
            var geomID = GetUniqueID(mesh.Name + "-geometry");

            // create geometry element
            Geometry geom = new Geometry()
            {
                ID   = geomID,
                Name = mesh.Name
            };

            geom.Mesh = new Mesh();

            // generate sources
            SourceGenerator srcgen = new SourceGenerator();

            srcgen.AddSourceData(
                geomID, Input_Semantic.POSITION,
                mesh.Vertices.SelectMany(e => new float[] { e.Position.X, e.Position.Y, e.Position.Z }).ToArray());

            srcgen.AddSourceData(
                geomID, Input_Semantic.NORMAL,
                mesh.Vertices.SelectMany(e => new float[] { e.Normal.X, e.Normal.Y, e.Normal.Z }).ToArray());

            for (int i = 0; i < 7; i++)
            {
                if (mesh.HasUVSet(i))
                {
                    srcgen.AddSourceData(
                        geomID, Input_Semantic.TEXCOORD,
                        mesh.Vertices.SelectMany(e => new float[] { e.UVs[i].X, e.UVs[i].Y }).ToArray(),
                        i);
                }
            }

            for (int i = 0; i < 7; i++)
            {
                if (mesh.HasColorSet(i))
                {
                    srcgen.AddSourceData(
                        geomID, Input_Semantic.COLOR,
                        mesh.Vertices.SelectMany(e => new float[] { e.Colors[i].X, e.Colors[i].Y, e.Colors[i].Z, e.Colors[i].W }).ToArray(),
                        i);
                }
            }

            // fill in vertex info
            geom.Mesh.Vertices = new Vertices()
            {
                ID    = GetUniqueID(mesh.Name + "-vertices"),
                Input = new Input_Unshared[] {
                    new Input_Unshared()
                    {
                        Semantic = IONET.Collada.Enums.Input_Semantic.POSITION,
                        source   = "#" + srcgen.GetID(Input_Semantic.POSITION)
                    }
                }
            };

            // fill in triangles

            var polyIndex = 0;

            geom.Mesh.Triangles = new Triangles[mesh.Polygons.Count];
            foreach (var poly in mesh.Polygons)
            {
                if (poly.PrimitiveType != IOPrimitive.TRIANGLE)
                {
                    System.Diagnostics.Debug.WriteLine("Warning: " + poly.PrimitiveType + " not currently supported");
                    continue;
                }

                Triangles tri = new Triangles()
                {
                    Count    = poly.Indicies.Count / 3,
                    Material = poly.MaterialName
                };

                List <Input_Shared> inputs = new List <Input_Shared>();
                inputs.Add(new Input_Shared()
                {
                    Semantic = Input_Semantic.VERTEX,
                    Offset   = inputs.Count,
                    source   = "#" + geom.Mesh.Vertices.ID
                });

                inputs.Add(new Input_Shared()
                {
                    Semantic = Input_Semantic.NORMAL,
                    Offset   = inputs.Count,
                    source   = "#" + srcgen.GetID(Input_Semantic.NORMAL)
                });

                for (int i = 0; i < 7; i++)
                {
                    if (mesh.HasUVSet(i))
                    {
                        inputs.Add(new Input_Shared()
                        {
                            Semantic = Input_Semantic.TEXCOORD,
                            source   = "#" + srcgen.GetID(Input_Semantic.TEXCOORD, i),
                            Offset   = inputs.Count,
                            Set      = i
                        });
                    }
                }

                for (int i = 0; i < 7; i++)
                {
                    if (mesh.HasColorSet(i))
                    {
                        inputs.Add(new Input_Shared()
                        {
                            Semantic = Input_Semantic.COLOR,
                            source   = "#" + srcgen.GetID(Input_Semantic.COLOR, i),
                            Offset   = inputs.Count,
                            Set      = i
                        });
                    }
                }

                tri.Input = inputs.ToArray();

                tri.P = new IONET.Collada.Types.Int_Array_String()
                {
                    Value_As_String = string.Join(" ", srcgen.Remap(poly.Indicies))
                };

                geom.Mesh.Triangles[polyIndex++] = tri;
            }


            // generate sources
            geom.Mesh.Source = srcgen.GetSources();


            // add geometry element to document
            if (_collada.Library_Geometries == null)
            {
                _collada.Library_Geometries = new Library_Geometries();
            }

            if (_collada.Library_Geometries.Geometry == null)
            {
                _collada.Library_Geometries.Geometry = new Geometry[0];
            }

            Array.Resize(ref _collada.Library_Geometries.Geometry, _collada.Library_Geometries.Geometry.Length + 1);

            _collada.Library_Geometries.Geometry[_collada.Library_Geometries.Geometry.Length - 1] = geom;

            // return geometry id
            return(geomID);
        }
Exemplo n.º 5
0
 public void AddTriangle(DelaunayTriangle t)
 {
     Triangles.Add(t);
 }
Exemplo n.º 6
0
    //Create the mesh and the triangles for the collisions.
    void CreateShape()
    {
        //int gridSize = gridSizeNew + (gridSizeNew - 1);
        int gridSize    = gridSizeNew + gridSizeNew * (gridSizeNew - 1);
        int triangleNum = (gridSize - 1) * (gridSize - 1) * 2 * 3;

        int vertexNum = gridSize * gridSize;

        triangles = new int[triangleNum];
        vertices  = new Vector3 [vertexNum];

        triangles2 = new int[triangleNum];
        uvs        = new Vector2 [vertices.Length];

        //First I set the triangles by setting the points
        //of it: And de direction of the normal
        int xx  = 0;
        int x   = 0;
        int ind = 0;

        for (int j = 0; j < gridSize - 1; j++)
        {
            for (int i = 0; i < gridSize - 1; i++)
            {
                int i0 = j * gridSize + i;
                int i1 = j * gridSize + i + 1;
                int i2 = (j + 1) * gridSize + i;
                int i3 = (j + 1) * gridSize + i + 1;


                var p1 = new Triangles(i0, i2, i1, ind);
                ind++;
                p1.PosTriangles(_particles[i0].Position, _particles[i2].Position, _particles[i1].Position);
                _triangles.Add(p1);
                var p2 = new Triangles(i2, i3, i1, ind);
                ind++;
                p2.PosTriangles(_particles[i2].Position, _particles[i3].Position, _particles[i1].Position);
                _triangles.Add(p2);
                triangles[x] = i0;
                x++;
                triangles[x] = i2;
                x++;
                triangles[x] = i1;
                x++;
                triangles[x] = i2;
                x++;
                triangles[x] = i3;
                x++;
                triangles[x] = i1;
                x++;

                triangles2[xx] = i0;
                xx++;
                triangles2[xx] = i1;
                xx++;
                triangles2[xx] = i2;
                xx++;
                triangles2[xx] = i1;
                xx++;
                triangles2[xx] = i3;
                xx++;
                triangles2[xx] = i2;
                xx++;
            }
        }

        //Second I set the position of all the points of the mesh
        for (int i = 0; i < gridSize; i++)
        {
            for (int j = 0; j < gridSize; j++)
            {
                var pos = j * gridSize + i;
                vertices[pos] = _particles[pos].Position;
            }
        }

        for (int i = 0; i < uvs.Length; i++)
        {
            uvs[i] = new Vector2(vertices[i].x, vertices[i].z);
        }
    }
Exemplo n.º 7
0
        public void CreateMeshFromObjectFile(String filename, float scale)
        {
            List <float[]> vertices  = new List <float[]>();
            List <float[]> texCoords = new List <float[]>();
            List <float[]> normals   = new List <float[]>();
            List <int[, ]> faces     = new List <int[, ]>();

            ObjReader.Read(filename, scale, vertices, texCoords, normals, faces);
            Vertices = vertices;
            Normals  = normals;
            //loop over all faces to create the Triangle instaces
            foreach (int[,] face in faces)
            {
                float[] point;

                Vector3 p1 = Vector3.Zero;
                Vector3 p2 = Vector3.Zero;
                Vector3 p3 = Vector3.Zero;

                Vector3 n1 = Vector3.Zero;
                Vector3 n2 = Vector3.Zero;
                Vector3 n3 = Vector3.Zero;

                Vector2 t1 = Vector2.Zero;
                Vector2 t2 = Vector2.Zero;
                Vector2 t3 = Vector2.Zero;

                point = vertices[face[0, 0] - 1];
                p1    = new Vector3(point[0], point[1], point[2]);
                point = vertices[face[1, 0] - 1];
                p2    = new Vector3(point[0], point[1], point[2]);
                point = vertices[face[2, 0] - 1];
                p3    = new Vector3(point[0], point[1], point[2]);

                bool hasNormals   = normals.Count > 0;
                bool hasTexCoords = texCoords.Count > 0;

                if (hasNormals)
                {
                    float[] normal;
                    normal = normals[face[0, 2] - 1];
                    n1     = new Vector3(normal[0], normal[1], normal[2]);
                    normal = normals[face[1, 2] - 1];
                    n2     = new Vector3(normal[0], normal[1], normal[2]);
                    normal = normals[face[2, 2] - 1];
                    n3     = new Vector3(normal[0], normal[1], normal[2]);
                }
                if (hasTexCoords)
                {
                    float[] texCoord;
                    texCoord = texCoords[face[0, 1] - 1];
                    t1       = new Vector2(texCoord[0], texCoord[1]);
                    texCoord = texCoords[face[1, 1] - 1];
                    t2       = new Vector2(texCoord[0], texCoord[1]);
                    texCoord = texCoords[face[2, 1] - 1];
                    t3       = new Vector2(texCoord[0], texCoord[1]);
                }
                Triangle t;
                if (hasNormals && hasTexCoords)
                {
                    t = new Triangle(p1, n1, t1, p2, n2, t2, p3, n3, t3);
                }
                else if (hasNormals)
                {
                    t = new Triangle(p1, n1, p2, n2, p3, n3);
                }
                else
                {
                    t = new Triangle(p1, p2, p3);
                }
                t.Material = Material;
                t.BuildBoundingBox();
                Triangles.Add(t);
                Add(t);
            }
            BuildBoundingBox();
        }
Exemplo n.º 8
0
        /*-----------------------------------------------------------------------------------------
        *
        *	Some stuff
        *
        *  -----------------------------------------------------------------------------------------*/



        /// <summary>
        ///	Removes degenerate triangles
        /// </summary>
        public void RemoveDegenerateTriangles()
        {
            Triangles.RemoveAll(tri => tri.IsDegenerate());
        }
Exemplo n.º 9
0
 public void testIsosceles()
 {
     Assert.AreEqual(Triangles.isIsosceles(3, 3, 2), true);
     Assert.AreEqual(Triangles.isIsosceles(3, 3, 6), false);
     Assert.AreEqual(Triangles.isIsosceles(3, 3, 7), false);
 }
Exemplo n.º 10
0
 public void testEquilateral()
 {
     Assert.AreEqual(Triangles.isEquilateral(3, 3, 3), true);
     Assert.AreEqual(Triangles.isEquilateral(4, 3, 3), false);
 }
Exemplo n.º 11
0
    void CreateStartTriangle()      //The Room Is The Start Room, It Requires That The Points Represented Are Able To Be Connected Any Way Without Getting Weird Triangle. (Like A Square But At The Bottom There Is A Tiny Square. Then This Wont Work, That Square Needs To Be Added Later)
    {
        MapCorenerLength = CoreMapAlterations.Length - 1;

        triangle = new Triangles();
        triangle.TriangleColor = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f));
        triangle.A             = CoreMapAlterations[0];
        PreviousPoints[0]      = CoreMapAlterations[0];
        CoreMapAlterations[0]  = CoreMapAlterations[MapCorenerLength--];

        for (int j = 0; j < 2; j++)          //Finding The Two Other Points

        {
            shortestDistance = 1000;

            for (int n = 0; n < MapCorenerLength; n++)              //Iterating To Find The Other Point

            {
                if (Vector2.Distance(triangle.A, CoreMapAlterations[n]) < shortestDistance)
                {
                    shortestDistance = Vector2.Distance(triangle.A, CoreMapAlterations[n]);
                    _ClosestPoint    = n;
                }
            }

            if (j == 0)
            {
                triangle.B        = CoreMapAlterations[_ClosestPoint];
                PreviousPoints[1] = CoreMapAlterations[_ClosestPoint];
                CoreMapAlterations[_ClosestPoint] = CoreMapAlterations[MapCorenerLength--];
            }
            else
            {
                triangle.C        = CoreMapAlterations[_ClosestPoint];
                PreviousPoints[2] = CoreMapAlterations[_ClosestPoint];
                CoreMapAlterations[_ClosestPoint] = CoreMapAlterations[MapCorenerLength--];
            }
        }

        TriangleGroups.Add(triangle);


        for (int i = 0; i < CoreMapAlterations.Length - 3; i++)          //Triangles To Make. 3 Points == 1 Triangle. 4 Points == 2 Triangles
        {
            triangle = new Triangles();
            triangle.TriangleColor = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f));
            triangle.A             = PreviousPoints[2];


            shortestDistance = 1000;

            for (int n = 0; n <= MapCorenerLength; n++)              //Iterating To Find The Other Point
            {
                if (Vector2.Distance(PreviousPoints[2], CoreMapAlterations[n]) < shortestDistance)
                {
                    shortestDistance = Vector2.Distance(PreviousPoints[2], CoreMapAlterations[n]);
                    _ClosestPoint    = n;
                }
            }
            for (int n = 0; n <= MapCorenerLength; n++)              //Iterating To Find The Other Point
            {
                if (Vector2.Distance(PreviousPoints[1], CoreMapAlterations[n]) < shortestDistance)
                {
                    shortestDistance = Vector2.Distance(PreviousPoints[1], CoreMapAlterations[n]);
                    _ClosestPoint    = n;
                }
            }
            for (int n = 0; n <= MapCorenerLength; n++)              //Iterating To Find The Other Point
            {
                if (Vector2.Distance(PreviousPoints[0], CoreMapAlterations[n]) < shortestDistance)
                {
                    shortestDistance = Vector2.Distance(PreviousPoints[0], CoreMapAlterations[n]);
                    _ClosestPoint    = n;
                }
            }

            PointInLineA = ((PreviousPoints[0].x - PreviousPoints[2].x) * (CoreMapAlterations[_ClosestPoint].y - PreviousPoints[2].y) - (PreviousPoints[0].y - PreviousPoints[2].y) * (CoreMapAlterations[_ClosestPoint].x - PreviousPoints[2].x));
            PointInLineB = ((PreviousPoints[0].x - PreviousPoints[2].x) * (PreviousPoints[1].y - PreviousPoints[2].y) - (PreviousPoints[0].y - PreviousPoints[2].y) * (PreviousPoints[1].x - PreviousPoints[2].x));

            if (PointInLineA > 0)
            {
                if (PointInLineB < 0)                  //On Oposite Sides
                {
                    triangle.A = PreviousPoints[2];
                    triangle.B = PreviousPoints[0];
                    triangle.C = CoreMapAlterations[_ClosestPoint];
                    CoreMapAlterations[_ClosestPoint] = CoreMapAlterations[MapCorenerLength--];
                }
                else                    //On The Same Side.
                {
                    PointInLineA = ((PreviousPoints[1].x - PreviousPoints[2].x) * (CoreMapAlterations[_ClosestPoint].y - PreviousPoints[2].y) - (PreviousPoints[1].y - PreviousPoints[2].y) * (CoreMapAlterations[_ClosestPoint].x - PreviousPoints[2].x));
                    PointInLineB = ((PreviousPoints[1].x - PreviousPoints[2].x) * (PreviousPoints[0].y - PreviousPoints[2].y) - (PreviousPoints[1].y - PreviousPoints[2].y) * (PreviousPoints[0].x - PreviousPoints[2].x));

                    if (PointInLineA > 0)
                    {
                        if (PointInLineB < 0)                          //On Oposite Sides
                        {
                            triangle.A = PreviousPoints[2];
                            triangle.B = PreviousPoints[1];
                            triangle.C = CoreMapAlterations[_ClosestPoint];
                            CoreMapAlterations[_ClosestPoint] = CoreMapAlterations[MapCorenerLength--];
                        }
                        else
                        {
                            triangle.A = PreviousPoints[0];
                            triangle.B = PreviousPoints[1];
                            triangle.C = CoreMapAlterations[_ClosestPoint];
                            CoreMapAlterations[_ClosestPoint] = CoreMapAlterations[MapCorenerLength--];
                        }
                    }
                    else
                    {
                        if (PointInLineB > 0)                          //On Oposite Sides
                        {
                            triangle.A = PreviousPoints[2];
                            triangle.B = PreviousPoints[1];
                            triangle.C = CoreMapAlterations[_ClosestPoint];
                            CoreMapAlterations[_ClosestPoint] = CoreMapAlterations[MapCorenerLength--];
                        }
                        else
                        {
                            triangle.A = PreviousPoints[0];
                            triangle.B = PreviousPoints[1];
                            triangle.C = CoreMapAlterations[_ClosestPoint];
                            CoreMapAlterations[_ClosestPoint] = CoreMapAlterations[MapCorenerLength--];
                        }
                    }
                }
            }
            else if (PointInLineA < 0)
            {
                if (PointInLineB > 0)                  //On Oposite Sides
                {
                    triangle.A = PreviousPoints[2];
                    triangle.B = PreviousPoints[0];
                    triangle.C = CoreMapAlterations[_ClosestPoint];
                    CoreMapAlterations[_ClosestPoint] = CoreMapAlterations[MapCorenerLength--];
                }
                else                    //On The Same Side.
                {
                    PointInLineA = ((PreviousPoints[1].x - PreviousPoints[2].x) * (CoreMapAlterations[_ClosestPoint].y - PreviousPoints[2].y) - (PreviousPoints[1].y - PreviousPoints[2].y) * (CoreMapAlterations[_ClosestPoint].x - PreviousPoints[2].x));
                    PointInLineB = ((PreviousPoints[1].x - PreviousPoints[2].x) * (PreviousPoints[0].y - PreviousPoints[2].y) - (PreviousPoints[1].y - PreviousPoints[2].y) * (PreviousPoints[0].x - PreviousPoints[2].x));

                    if (PointInLineA > 0)
                    {
                        if (PointInLineB < 0)                          //On Oposite Sides
                        {
                            triangle.A = PreviousPoints[2];
                            triangle.B = PreviousPoints[1];
                            triangle.C = CoreMapAlterations[_ClosestPoint];
                            CoreMapAlterations[_ClosestPoint] = CoreMapAlterations[MapCorenerLength--];
                        }
                        else
                        {
                            triangle.A = PreviousPoints[0];
                            triangle.B = PreviousPoints[1];
                            triangle.C = CoreMapAlterations[_ClosestPoint];
                            CoreMapAlterations[_ClosestPoint] = CoreMapAlterations[MapCorenerLength--];
                        }
                    }
                    else
                    {
                        if (PointInLineB > 0)                          //On Oposite Sides
                        {
                            triangle.A = PreviousPoints[2];
                            triangle.B = PreviousPoints[1];
                            triangle.C = CoreMapAlterations[_ClosestPoint];
                            CoreMapAlterations[_ClosestPoint] = CoreMapAlterations[MapCorenerLength--];
                        }
                        else
                        {
                            triangle.A = PreviousPoints[0];
                            triangle.B = PreviousPoints[1];
                            triangle.C = CoreMapAlterations[_ClosestPoint];
                            CoreMapAlterations[_ClosestPoint] = CoreMapAlterations[MapCorenerLength--];
                        }
                    }
                }
            }
            else
            {
                Debug.Log("Hmmmm Its Zero");
            }

            PreviousPoints[0] = triangle.A;
            PreviousPoints[1] = triangle.B;
            PreviousPoints[2] = triangle.C;
            TriangleGroups.Add(triangle);
        }
    }
Exemplo n.º 12
0
        public void TestRightAngleCountsFromWireLength(Int32 length, Int32 expCount)
        {
            IEnumerable <(Int32 a, Int32 b, Int32 c)> generateRightAngleTriangles = Triangles.GenerateRightAngleTriangles(length);

            Assert.AreEqual(expCount, generateRightAngleTriangles.Count());
        }
Exemplo n.º 13
0
        public void TestRightAngleTriangle(int a, int b, int c, Boolean expected)
        {
            Boolean isValidTriangle = Triangles.IsValidRightAngleTriangle(a, b, c);

            Assert.AreEqual(expected, isValidTriangle);
        }
Exemplo n.º 14
0
 private void CreateFloor(float z)
 {
     Triangles.Add(new Triangle(new Point(100, -100, z), new Point(100, 100, z), new Point(-100, 100, z)));
     Triangles.Add(new Triangle(new Point(-100, 100, z), new Point(-100, -100, z), new Point(100, -100, z)));
     Log.WriteLog("Created floors", LogType.Console, LogLevel.Debug);
 }
Exemplo n.º 15
0
        private void load(SongSelect songSelect, BeatmapManager manager, BeatmapSetOverlay beatmapOverlay)
        {
            this.beatmapOverlay = beatmapOverlay;

            if (songSelect != null)
            {
                startRequested = b => songSelect.FinaliseSelection(b);
                editRequested  = songSelect.Edit;
            }

            if (manager != null)
            {
                hideRequested = manager.Hide;
            }

            Children = new Drawable[]
            {
                background = new Box
                {
                    RelativeSizeAxes = Axes.Both,
                },
                triangles = new Triangles
                {
                    TriangleScale    = 2,
                    RelativeSizeAxes = Axes.Both,
                    ColourLight      = OsuColour.FromHex(@"3a7285"),
                    ColourDark       = OsuColour.FromHex(@"123744")
                },
                new FillFlowContainer
                {
                    Padding      = new MarginPadding(5),
                    Direction    = FillDirection.Horizontal,
                    AutoSizeAxes = Axes.Both,
                    Anchor       = Anchor.CentreLeft,
                    Origin       = Anchor.CentreLeft,
                    Children     = new Drawable[]
                    {
                        new DifficultyIcon(beatmap)
                        {
                            Scale = new Vector2(1.8f),
                        },
                        new FillFlowContainer
                        {
                            Padding = new MarginPadding {
                                Left = 5
                            },
                            Direction    = FillDirection.Vertical,
                            AutoSizeAxes = Axes.Both,
                            Children     = new Drawable[]
                            {
                                new FillFlowContainer
                                {
                                    Direction    = FillDirection.Horizontal,
                                    Spacing      = new Vector2(4, 0),
                                    AutoSizeAxes = Axes.Both,
                                    Children     = new[]
                                    {
                                        new OsuSpriteText
                                        {
                                            Font     = @"Exo2.0-Medium",
                                            Text     = beatmap.Version,
                                            TextSize = 20,
                                            Anchor   = Anchor.BottomLeft,
                                            Origin   = Anchor.BottomLeft
                                        },
                                        new OsuSpriteText
                                        {
                                            Font     = @"Exo2.0-Medium",
                                            Text     = "mapped by",
                                            TextSize = 16,
                                            Anchor   = Anchor.BottomLeft,
                                            Origin   = Anchor.BottomLeft
                                        },
                                        new OsuSpriteText
                                        {
                                            Font     = @"Exo2.0-MediumItalic",
                                            Text     = $"{(beatmap.Metadata ?? beatmap.BeatmapSet.Metadata).Author.Username}",
                                            TextSize = 16,
                                            Anchor   = Anchor.BottomLeft,
                                            Origin   = Anchor.BottomLeft
                                        },
                                    }
                                },
                                starCounter = new StarCounter
                                {
                                    CountStars = (float)beatmap.StarDifficulty,
                                    Scale      = new Vector2(0.8f),
                                }
                            }
                        }
                    }
                }
            };
        }
Exemplo n.º 16
0
        public BeatmapPanel(BeatmapInfo beatmap)
        {
            Beatmap = beatmap;
            Height *= 0.60f;

            Children = new Drawable[]
            {
                background = new Box
                {
                    RelativeSizeAxes = Axes.Both,
                },
                triangles = new Triangles
                {
                    TriangleScale    = 2,
                    RelativeSizeAxes = Axes.Both,
                    ColourLight      = OsuColour.FromHex(@"3a7285"),
                    ColourDark       = OsuColour.FromHex(@"123744")
                },
                new FillFlowContainer
                {
                    Padding      = new MarginPadding(5),
                    Direction    = FillDirection.Horizontal,
                    AutoSizeAxes = Axes.Both,
                    Anchor       = Anchor.CentreLeft,
                    Origin       = Anchor.CentreLeft,
                    Children     = new Drawable[]
                    {
                        new DifficultyIcon(beatmap)
                        {
                            Scale = new Vector2(1.8f),
                        },
                        new FillFlowContainer
                        {
                            Padding = new MarginPadding {
                                Left = 5
                            },
                            Direction    = FillDirection.Vertical,
                            AutoSizeAxes = Axes.Both,
                            Children     = new Drawable[]
                            {
                                new FillFlowContainer
                                {
                                    Direction    = FillDirection.Horizontal,
                                    Spacing      = new Vector2(4, 0),
                                    AutoSizeAxes = Axes.Both,
                                    Children     = new[]
                                    {
                                        new OsuSpriteText
                                        {
                                            Font     = @"Exo2.0-Medium",
                                            Text     = beatmap.Version,
                                            TextSize = 20,
                                            Anchor   = Anchor.BottomLeft,
                                            Origin   = Anchor.BottomLeft
                                        },
                                        new OsuSpriteText
                                        {
                                            Font     = @"Exo2.0-Medium",
                                            Text     = "mapped by",
                                            TextSize = 16,
                                            Anchor   = Anchor.BottomLeft,
                                            Origin   = Anchor.BottomLeft
                                        },
                                        new OsuSpriteText
                                        {
                                            Font     = @"Exo2.0-MediumItalic",
                                            Text     = $"{(beatmap.Metadata ?? beatmap.BeatmapSet.Metadata).Author}",
                                            TextSize = 16,
                                            Anchor   = Anchor.BottomLeft,
                                            Origin   = Anchor.BottomLeft
                                        },
                                    }
                                },
                                starCounter = new StarCounter
                                {
                                    Count = (float)beatmap.StarDifficulty,
                                    Scale = new Vector2(0.8f),
                                }
                            }
                        }
                    }
                }
            };
        }
Exemplo n.º 17
0
 public void testScalene()
 {
     Assert.AreEqual(Triangles.isScalene(4, 2, 3), true);
     Assert.AreEqual(Triangles.isScalene(4, 2, 7), false);
 }
Exemplo n.º 18
0
        public void Rebuild(float min)
        {
            float minXnew, maxXnew, minYnew, maxYnew, minZnew, maxZnew;


            // 1, 2, 3, 4 oct
            Vector3 center = new Vector3((SpaceCube.x1.X + SpaceCube.x2.X) * 0.5f, (SpaceCube.x1.Y + SpaceCube.x4.Y) * 0.5f, (SpaceCube.x1.Z + SpaceCube.x5.Z) * 0.5f);

            minXnew = (SpaceCube.x1.X + SpaceCube.x2.X) * 0.5f;
            maxXnew = SpaceCube.x1.X;
            minYnew = (SpaceCube.x1.Y + SpaceCube.x4.Y) * 0.5f;
            maxYnew = SpaceCube.x1.Y;
            minZnew = (SpaceCube.x1.Z + SpaceCube.x5.Z) * 0.5f;
            maxZnew = SpaceCube.x1.Z;

            if (Triangles.Count() < 100 || (maxXnew - minXnew) < min)
            {
                return;
            }

            DaughterNodes[0] = new TreeNode(minXnew, maxXnew, minYnew, maxYnew, minZnew, maxZnew);

            maxXnew = (SpaceCube.x1.X + SpaceCube.x2.X) * 0.5f;
            minXnew = SpaceCube.x2.X;
            minYnew = (SpaceCube.x1.Y + SpaceCube.x4.Y) * 0.5f;
            maxYnew = SpaceCube.x1.Y;
            minZnew = (SpaceCube.x1.Z + SpaceCube.x5.Z) * 0.5f;
            maxZnew = SpaceCube.x1.Z;

            DaughterNodes[1] = new TreeNode(minXnew, maxXnew, minYnew, maxYnew, minZnew, maxZnew);

            maxXnew = (SpaceCube.x1.X + SpaceCube.x2.X) * 0.5f;
            minXnew = SpaceCube.x2.X;
            maxYnew = (SpaceCube.x2.Y + SpaceCube.x3.Y) * 0.5f;
            minYnew = SpaceCube.x3.Y;
            minZnew = (SpaceCube.x1.Z + SpaceCube.x5.Z) * 0.5f;
            maxZnew = SpaceCube.x1.Z;

            DaughterNodes[2] = new TreeNode(minXnew, maxXnew, minYnew, maxYnew, minZnew, maxZnew);

            minXnew = (SpaceCube.x3.X + SpaceCube.x4.X) * 0.5f;
            maxXnew = SpaceCube.x4.X;
            maxYnew = (SpaceCube.x1.Y + SpaceCube.x4.Y) * 0.5f;
            minYnew = SpaceCube.x4.Y;
            minZnew = (SpaceCube.x1.Z + SpaceCube.x5.Z) * 0.5f;
            maxZnew = SpaceCube.x1.Z;

            DaughterNodes[3] = new TreeNode(minXnew, maxXnew, minYnew, maxYnew, minZnew, maxZnew);

            // 5, 6, 7, 8 oct

            minXnew = (SpaceCube.x1.X + SpaceCube.x2.X) * 0.5f;
            maxXnew = SpaceCube.x1.X;
            minYnew = (SpaceCube.x1.Y + SpaceCube.x4.Y) * 0.5f;
            maxYnew = SpaceCube.x1.Y;
            maxZnew = (SpaceCube.x1.Z + SpaceCube.x5.Z) * 0.5f;
            minZnew = SpaceCube.x5.Z;

            DaughterNodes[4] = new TreeNode(minXnew, maxXnew, minYnew, maxYnew, minZnew, maxZnew);

            maxXnew = (SpaceCube.x1.X + SpaceCube.x2.X) * 0.5f;
            minXnew = SpaceCube.x2.X;
            minYnew = (SpaceCube.x1.Y + SpaceCube.x4.Y) * 0.5f;
            maxYnew = SpaceCube.x1.Y;
            maxZnew = (SpaceCube.x1.Z + SpaceCube.x5.Z) * 0.5f;
            minZnew = SpaceCube.x5.Z;

            DaughterNodes[5] = new TreeNode(minXnew, maxXnew, minYnew, maxYnew, minZnew, maxZnew);

            maxXnew = (SpaceCube.x1.X + SpaceCube.x2.X) * 0.5f;
            minXnew = SpaceCube.x2.X;
            maxYnew = (SpaceCube.x2.Y + SpaceCube.x3.Y) * 0.5f;
            minYnew = SpaceCube.x3.Y;
            maxZnew = (SpaceCube.x1.Z + SpaceCube.x5.Z) * 0.5f;
            minZnew = SpaceCube.x5.Z;

            DaughterNodes[6] = new TreeNode(minXnew, maxXnew, minYnew, maxYnew, minZnew, maxZnew);

            minXnew = (SpaceCube.x3.X + SpaceCube.x4.X) * 0.5f;
            maxXnew = SpaceCube.x4.X;
            maxYnew = (SpaceCube.x1.Y + SpaceCube.x4.Y) * 0.5f;
            minYnew = SpaceCube.x4.Y;
            maxZnew = (SpaceCube.x1.Z + SpaceCube.x5.Z) * 0.5f;
            minZnew = SpaceCube.x5.Z;

            DaughterNodes[7] = new TreeNode(minXnew, maxXnew, minYnew, maxYnew, minZnew, maxZnew);

            List <Triangle> newVectors = new List <Triangle>();

            while (Triangles.Count() != 0)
            {
                int counter1 = -1;
                int counter2 = -1;
                int counter3 = -1;

                Triangle i = Triangles.Last();
                Triangles.RemoveAt(Triangles.Count() - 1);

                counter1 = PositionFinder(i.N0, center);
                counter2 = PositionFinder(i.N1, center);
                counter3 = PositionFinder(i.N2, center);

                if (counter1 == counter2 && counter2 == counter3)
                {
                    DaughterNodes[counter1].Triangles.Add(i);
                }
                else
                {
                    newVectors.Add(i);
                }
            }

            Triangles = newVectors;

            List = false;

            DaughterNodes[0].List = true;
            DaughterNodes[0].Rebuild(min);
            DaughterNodes[1].List = true;
            DaughterNodes[1].Rebuild(min);
            DaughterNodes[2].List = true;
            DaughterNodes[2].Rebuild(min);
            DaughterNodes[3].List = true;
            DaughterNodes[3].Rebuild(min);
            DaughterNodes[4].List = true;
            DaughterNodes[4].Rebuild(min);
            DaughterNodes[5].List = true;
            DaughterNodes[5].Rebuild(min);
            DaughterNodes[6].List = true;
            DaughterNodes[6].Rebuild(min);
            DaughterNodes[7].List = true;
            DaughterNodes[7].Rebuild(min);
        }
Exemplo n.º 19
0
 public void AddTriangle(int v0, int v1, int v2)
 {
     Triangles.Add(new Triangle(Vertices[v0], Vertices[v1], Vertices[v2]));
 }
Exemplo n.º 20
0
        //"../../../../Glyph Cores/Nexus.glyc" -sr
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Usage : GlyView <filename> ");
                Console.WriteLine(" Output types:");
                Console.WriteLine("   -c : display code ");
                Console.WriteLine("   -r : display rects ");
                Console.WriteLine("  -sr : display serialized rects ");
                Console.WriteLine("   -q : display quads ");
                Console.WriteLine("   -t : display triangles ");
                Console.WriteLine("  -sg : display scenegraph");
                Console.WriteLine("  -ci : display circuit");
                return;
            }

            string  filename = args[0];
            Options options  = new Options();

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "-c")
                {
                    options.displayCode = true;
                }
                if (args[i] == "-r")
                {
                    options.displayRects = true;
                }
                if (args[i] == "-sr")
                {
                    options.displaySerializedRects = true;
                }
                if (args[i] == "-q")
                {
                    options.displayQuads = true;
                }
                if (args[i] == "-t")
                {
                    options.displayTriangles = true;
                }
                if (args[i] == "-sg")
                {
                    options.displaySceneGraph = true;
                }
                if (args[i] == "-ci")
                {
                    options.displayCircuit = true;
                }
            }
            string codeString = RasterLib.RasterApi.ReadGlyc(filename);
            Code   code       = new Code(codeString);

            if (options.displayCode)
            {
                Console.WriteLine("Code: " + codeString);
            }

            Grid grid = RasterLib.RasterApi.CodeToGrid(code);

            if (grid != null)
            {
                //string bytesDesc = RasterLib.RasterApi.BytesToString(grid.CloneData());
                //Console.WriteLine("GridBytes:\n{0}\n", bytesDesc);
            }

            RectList rects = RasterLib.RasterApi.GridToRects(grid);
            //rects
            {
                if (options.displayRects)
                {
                    Console.WriteLine("Rects: {0}\n{1}", rects.Count, rects);
                }

                RasterLib.RasterApi.BuildCircuit(rects, options.displayCircuit);

                string serialized = RasterLib.RasterApi.RectsToSerializedRectsLimit255(rects).SerializedData;
                if (options.displaySerializedRects)
                {
                    Console.WriteLine("{0}\n", serialized);
                }
                //Console.WriteLine("Serialized Rects: (len={0})\n{1}\n", serialized.Length, serialized);

                SerializedRects serializedRects = new SerializedRects(serialized);
                RectList        rectsDecoded    = RectConverter.SerializedRectsToRects(serializedRects);
            }

            //if (ctl.OutputRenderedAscii)
            {
                //Console.WriteLine("2d view:\n{0}", RasterLib.RasterApi.Renderer.GridToHexDescription(grid));
                //Console.WriteLine("3d view:\n{0}", RasterLib.RasterApi.Renderer.GridTo3DDescription(grid, 0, 0, 0));
            }

            //if (ctl.OutputSceneGraph)
            {
                Scene scene = RasterLib.RasterApi.RectsToScene(rects);
                if (options.displaySceneGraph)
                {
                    Console.WriteLine("Scene: {0}", scene);
                }

                QuadList quads = RasterLib.RasterApi.RectsToQuads(rects);
                if (options.displayQuads)
                {
                    Console.WriteLine("Quads: {0}", quads);
                }

                Triangles triangles = RasterLib.RasterApi.QuadsToTriangles(quads);
                if (options.displayTriangles)
                {
                    Console.WriteLine("Triangles: {0}", triangles);
                }
            }
        }
Exemplo n.º 21
0
        public void ParseGeometryLibrary_GeometryMeshTriangles(XmlNode TrianglesNode, Mesh CurrentMesh)
        {
            Console.WriteLine("Entered TrianglesNode");

            Triangles CurrentTriangles = new Triangles();

            for (int i = 0; i < TrianglesNode.Attributes.Count; i++)
            {
                switch(TrianglesNode.Attributes[i].Name)
                {
                    case "count":
                        CurrentTriangles.mCount = uint.Parse(TrianglesNode.Attributes[i].Value);
                        break;
                    case "material":
                        CurrentTriangles.mMaterial = TrianglesNode.Attributes[i].Value.ToString();
                        break;
                }
            }

            for (int i = 0; i < TrianglesNode.ChildNodes.Count; i++)
            {
                if (TrianglesNode.ChildNodes[i].Name.Equals("input"))
                {
                    ParseGeometryLibrary_GeometryMeshTriangles_Input(TrianglesNode.ChildNodes[i], CurrentTriangles);
                }

                if (TrianglesNode.ChildNodes[i].Name.Equals("p"))
                {
                    ParseGeometryLibrary_GeometryMeshTriangles_P(TrianglesNode.ChildNodes[i], CurrentTriangles);
                }
            }

            CurrentMesh.mTriangles.Add(CurrentTriangles);
        }
Exemplo n.º 22
0
 public override void AddTriangle(DelaunayTriangle t)
 {
     Triangles.Add(t);
 }
Exemplo n.º 23
0
        public void ParseGeometryLibrary_GeometryMeshTriangles_Input(XmlNode InputNode, Triangles CurrentTriangles)
        {
            Console.WriteLine("Entered TrianglesInputNode");
            TrianglesInput CurrentTrianglesInput = new TrianglesInput();

            for (int i = 0; i < InputNode.Attributes.Count; i++)
            {
                switch(InputNode.Attributes[i].Name)
                {
                    case "offset":
                        CurrentTrianglesInput.mOffset = uint.Parse(InputNode.Attributes[i].Value);
                        break;
                    case "semantic":
                        CurrentTrianglesInput.mSemantic = InputNode.Attributes[i].Value.ToString();
                        break;
                    case "set":
                        // Ignored
                        break;
                    case "source":
                        CurrentTrianglesInput.mSource = InputNode.Attributes[i].Value.ToString().Substring(1);
                        break;
                }
            }

            CurrentTriangles.mTriangleInputs.Add(CurrentTrianglesInput);
        }
Exemplo n.º 24
0
 public void ClearTriangles()
 {
     Triangles.Clear();
 }
Exemplo n.º 25
0
        public void ParseGeometryLibrary_GeometryMeshTriangles_P(XmlNode PNode, Triangles CurrentTriangles)
        {
            Console.WriteLine("Entered TrianglesPNode");
            TrianglesP CurrentTrianglesP = new TrianglesP();

            String PValues = PNode.InnerText;
            String[] Ps = PValues.Split(" ".ToCharArray());

            for (int i = 0; i < Ps.Length; i++)
            {
                CurrentTrianglesP.mIndices.Add(uint.Parse(Ps[i]));
            }

            CurrentTriangles.mTrianglesP = CurrentTrianglesP;
        }
Exemplo n.º 26
0
        public void TriangleS_Creation()
        {
            Triangles triangles = new Triangles();

            Assert.NotNull(triangles);
        }
Exemplo n.º 27
0
 public void RemoveFromList(DelaunayTriangle triangle)
 {
     Triangles.Remove(triangle);
 }
Exemplo n.º 28
0
        public override List <IActivityData> Process()
        {
            IDatasetElement sElement = base.SourceDatasetElement;
            IFeatureClass   sFc      = base.SourceFeatureClass;

            ActivityBase.TargetDatasetElement tElement = base.TargetDatasetElement;
            IDataset tDs = base.TargetDataset;
            //IFeatureDatabase tDatabase = base.TargetFeatureDatabase;

            GeometryDef geomDef = new GeometryDef(
                geometryType.Polyline,
                null,
                false);

            IFeatureClass    tFc       = base.CreateTargetFeatureclass(geomDef, sFc.Fields);
            IFeatureDatabase tDatabase = FeatureDatabase(tFc);

            Report.featureMax = sFc.CountFeatures;
            Report.featurePos = 0;
            ReportProgess("Query Filter: " + SourceData.FilterClause);

            Nodes nodes = new Nodes();

            using (IFeatureCursor cursor = SourceData.GetFeatures(String.Empty))
            {
                if (cursor == null)
                {
                    return(null);
                }

                IFeature feature;
                while ((feature = cursor.NextFeature) != null)
                {
                    if (Report.featurePos++ % 100 == 0)
                    {
                        ReportProgess();
                    }

                    if (feature.Shape is IPoint)
                    {
                        nodes.Add((IPoint)feature.Shape);
                    }
                }
            }

            DelaunayTriangulation triangulation = new DelaunayTriangulation();

            triangulation.Progress += new DelaunayTriangulation.ProgressEventHandler(triangulation_Progress);
            ReportProgess("Calculate Triangles");
            Triangles triangles = triangulation.Triangulate(nodes);

            ReportProgess("Extract Edges");
            Edges edges = triangulation.TriangleEdges(triangles);

            Report.featurePos = 0;
            List <IFeature> features = new List <IFeature>();

            foreach (Edge edge in edges)
            {
                Polyline pLine = new Polyline();
                Path     path  = new Path();
                path.AddPoint(nodes[edge.p1]);
                path.AddPoint(nodes[edge.p2]);
                pLine.AddPath(path);

                Feature feature = new Feature();
                feature.Shape = pLine;

                Report.featurePos++;
                features.Add(feature);
                if (features.Count >= 100)
                {
                    if (!tDatabase.Insert(tFc, features))
                    {
                        throw new Exception(tDatabase.lastErrorMsg);
                    }
                    features.Clear();
                    ReportProgess();
                }
            }

            if (features.Count > 0)
            {
                ReportProgess();
                if (!tDatabase.Insert(tFc, features))
                {
                    throw new Exception(tDatabase.lastErrorMsg);
                }
            }

            ReportProgess("Flush Features");
            base.FlushFeatureClass(tFc);

            return(base.ToProcessResult(tFc));
        }
Exemplo n.º 29
0
        private void ReadObjFile(string pathObjFile)
        {
            using (var myStream = new FileStream(pathObjFile, FileMode.Open))
            {
                var myReader = new StreamReader(myStream);
                var coord    = new double[3];
                var tri      = new int[3];
                var tex      = new int[4];
                var quad     = new int[4];

                string line;
                while ((line = myReader.ReadLine()) != null)
                {
                    if (line != "")
                    {
                        line = line.Trim(' ');

                        string[] array;
                        switch (line[0])
                        {
                        case 'v':
                        {
                            if (line[1] != 't' && line[1] != 'n')
                            {
                                line  = line.Trim('v', ' ');
                                array = line.Split(' ');
                                for (var i = 0; i < 3; i++)
                                {
                                    coord[i] = double.Parse(array[i], CultureInfo.InvariantCulture);
                                }

                                var v = new Vertex(coord[0], coord[1], coord[2]);
                                Vertices.Add(v);
                            }
                            else
                            {
                                if (line[1] == 't')
                                {
                                    line  = line.Trim('t', 'v', ' ');
                                    array = line.Split(' ');
                                    for (var i = 0; i < 2; i++)
                                    {
                                        coord[i] = double.Parse(array[i], CultureInfo.InvariantCulture);
                                    }

                                    var v = new Vertex2D(coord[0], coord[1]);
                                    TextureCoordinates.Add(v);
                                }
                            }

                            break;
                        }

                        case 'f':
                        {
                            line  = line.Trim('f', ' ');
                            array = line.Split(new[] { ' ', '/' },
                                               StringSplitOptions.RemoveEmptyEntries);
                            if (array.Length == 9)
                            {
                                for (int i = 0, j = 0; i < 3 && j < array.Length; i++, j += 3)
                                {
                                    tri[i] = int.Parse(array[j]);
                                    tex[i] = int.Parse(array[j + 1]);
                                }

                                var t = new Triangle(Vertices[tri[0] - 1], Vertices[tri[1] - 1],
                                                     Vertices[tri[2] - 1], TextureCoordinates[tex[0] - 1],
                                                     TextureCoordinates[tex[1] - 1], TextureCoordinates[tex[2] - 1]);
                                Triangles.Add(t);
                            }

                            if (array.Length == 12)
                            {
                                for (int i = 0, j = 0; i < 4 && j < array.Length; i++, j += 3)
                                {
                                    quad[i] = int.Parse(array[j]);
                                    tex[i]  = int.Parse(array[j + 1]);
                                }

                                var q = new Quad(Vertices[quad[0] - 1], Vertices[quad[1] - 1],
                                                 Vertices[quad[2] - 1],
                                                 Vertices[quad[3] - 1], TextureCoordinates[tex[0] - 1],
                                                 TextureCoordinates[tex[1] - 1], TextureCoordinates[tex[2] - 1],
                                                 TextureCoordinates[tex[3] - 1]);
                                Quads.Add(q);
                            }
                        }
                        break;
                        }
                    }
                }
            }
        }
 public void FinalizeTriangulation()
 {
     Triangulatable.AddTriangles(Triangles);
     Triangles.Clear();
 }
Exemplo n.º 31
0
 public void SinusesTheorem()
 {
     Assert.AreEqual(Math.Sqrt(2), Triangles.SinusesTheorem(Math.PI / 4, 2, Math.PI / 4), .0000000001);
 }
        private void load(BeatmapManager manager, SongSelect songSelect)
        {
            Header.Height = height;

            if (songSelect != null)
            {
                startRequested = b => songSelect.FinaliseSelection(b);
                if (songSelect.AllowEditing)
                {
                    editRequested = songSelect.Edit;
                }
            }

            if (manager != null)
            {
                hideRequested = manager.Hide;
            }

            Header.Children = new Drawable[]
            {
                background = new Box
                {
                    RelativeSizeAxes = Axes.Both,
                },
                triangles = new Triangles
                {
                    TriangleScale    = 2,
                    RelativeSizeAxes = Axes.Both,
                    ColourLight      = Color4Extensions.FromHex(@"3a7285"),
                    ColourDark       = Color4Extensions.FromHex(@"123744")
                },
                new FillFlowContainer
                {
                    Padding      = new MarginPadding(5),
                    Direction    = FillDirection.Horizontal,
                    AutoSizeAxes = Axes.Both,
                    Anchor       = Anchor.CentreLeft,
                    Origin       = Anchor.CentreLeft,
                    Children     = new Drawable[]
                    {
                        new DifficultyIcon(beatmap, shouldShowTooltip: false)
                        {
                            Scale = new Vector2(1.8f),
                        },
                        new FillFlowContainer
                        {
                            Padding = new MarginPadding {
                                Left = 5
                            },
                            Direction    = FillDirection.Vertical,
                            AutoSizeAxes = Axes.Both,
                            Children     = new Drawable[]
                            {
                                new FillFlowContainer
                                {
                                    Direction    = FillDirection.Horizontal,
                                    Spacing      = new Vector2(4, 0),
                                    AutoSizeAxes = Axes.Both,
                                    Children     = new[]
                                    {
                                        new OsuSpriteText
                                        {
                                            Text   = beatmap.Version,
                                            Font   = OsuFont.GetFont(size: 20),
                                            Anchor = Anchor.BottomLeft,
                                            Origin = Anchor.BottomLeft
                                        },
                                        new OsuSpriteText
                                        {
                                            Text   = "mapped by",
                                            Anchor = Anchor.BottomLeft,
                                            Origin = Anchor.BottomLeft
                                        },
                                        new OsuSpriteText
                                        {
                                            Text   = $"{(beatmap.Metadata ?? beatmap.BeatmapSet.Metadata).Author.Username}",
                                            Font   = OsuFont.GetFont(italics: true),
                                            Anchor = Anchor.BottomLeft,
                                            Origin = Anchor.BottomLeft
                                        },
                                    }
                                },
                                new FillFlowContainer
                                {
                                    Direction    = FillDirection.Horizontal,
                                    Spacing      = new Vector2(4, 0),
                                    AutoSizeAxes = Axes.Both,
                                    Children     = new Drawable[]
                                    {
                                        new TopLocalRank(beatmap)
                                        {
                                            Scale = new Vector2(0.8f),
                                            Size  = new Vector2(40, 20)
                                        },
                                        starCounter = new StarCounter
                                        {
                                            Scale = new Vector2(0.8f),
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };
        }
Exemplo n.º 33
0
        ///<summary>
        /// Close the line with given color
        ///</summary>
        void CloseLine(Color32 color)
        {
            if (vertices.Count == 0)
            {
                return;
            }

            int        offset        = Vertices.Count;
            int        triangleCount = vertices.Count - 2;
            List <int> triangles     = new List <int>();

            for (int i = 0; i < triangleCount / 2; i++)
            {
                triangles.Add(offset + i * 2);
                triangles.Add(offset + i * 2 + 2);
                triangles.Add(offset + i * 2 + 1);

                triangles.Add(offset + i * 2 + 2);
                triangles.Add(offset + i * 2 + 3);
                triangles.Add(offset + i * 2 + 1);
            }

            for (int i = 0; i < vertices.Count; i++)
            {
                VertexColors.Add(color);
            }

            if (mode_3d)
            {
                List <Vector3> v2 = new List <Vector3>();
                List <int>     t2 = new List <int>();

                for (int i = 0; i < vertices.Count; i++)
                {
                    v2.Add(new Vector3(vertices[i].x, vertices[i].y, z1));
                    VertexColors.Add(color);
                }

                for (int i = 0; i < triangleCount * 3; i += 3)
                {
                    t2.Add(triangles[i] + vertices.Count);
                    t2.Add(triangles[i + 2] + vertices.Count);
                    t2.Add(triangles[i + 1] + vertices.Count);
                }

                for (int i = 0; i < triangles.Count; i += 6)
                {
                    t2.Add(triangles[i + 4]);
                    t2.Add(t2[i + 1]);
                    t2.Add(triangles[i + 2]);

                    t2.Add(triangles[i + 4]);
                    t2.Add(t2[i + 5]);
                    t2.Add(t2[i + 1]);

                    t2.Add(triangles[i]);
                    t2.Add(t2[i]);
                    t2.Add(t2[i + 2]);

                    t2.Add(triangles[i + 1]);
                    t2.Add(triangles[i]);
                    t2.Add(t2[i + 2]);
                }

                t2.Add(offset);
                t2.Add(offset + 1);
                t2.Add(offset + vertices.Count);

                t2.Add(offset + vertices.Count + 1);
                t2.Add(offset + vertices.Count);
                t2.Add(offset + 1);

                t2.Add(offset + vertices.Count - 2);
                t2.Add(offset + vertices.Count * 2 - 1);
                t2.Add(offset + vertices.Count - 1);

                t2.Add(offset + vertices.Count * 2 - 1);
                t2.Add(offset + vertices.Count - 2);
                t2.Add(offset + vertices.Count * 2 - 2);

                vertices.AddRange(v2);
                triangles.AddRange(t2);
            }

            Vertices.AddRange(vertices);
            Triangles.AddRange(triangles);

            vertices.Clear();
        }
Exemplo n.º 34
0
        ///<summary>
        /// Generate a point at given location
        ///</summary>
        void CreatePoint(Vector3 center, int row, int column)
        {
            float   r     = size.x * pointSize;
            Color32 color = colors[row % colorCount, 1];

            switch (point)
            {
            case PointType.CIRCLE:
            {
                Vector3 p1 = new Vector3(r, 0, 0);
                for (int i = 0; i < 360 / 30; i++)
                {
                    Vector3 p = p1;
                    p1 = Quaternion.Euler(0, 0, 30) * p1;

                    Vertices.Add(center);
                    Vertices.Add(center + p);
                    Vertices.Add(center + p1);
                    VertexColors.Add(color);
                    VertexColors.Add(color);
                    VertexColors.Add(color);
                    Triangles.Add(Vertices.Count - 3);
                    Triangles.Add(Vertices.Count - 2);
                    Triangles.Add(Vertices.Count - 1);

                    if (mode_3d)
                    {
                        Vector3 p3 = center; p3.z = z1;
                        Vector3 p4 = center + p; p4.z = z1;
                        Vector3 p5 = center + p1; p5.z = z1;

                        AddTriangle(p3, p5, p4, color, color);

                        AddTriangle(center + p, p4, center + p1, color, color);
                        AddTriangle(center + p1, p4, p5, color, color);
                    }
                }
            }
            break;

            case PointType.RECTANGLE:
            {
                Vector3 p0 = center + new Vector3(-r, -r, 0);
                Vector3 p1 = center + new Vector3(-r, r, 0);
                Vector3 p2 = center + new Vector3(r, r, 0);
                Vector3 p3 = center + new Vector3(r, -r, 0);

                // Vector3 p = new Vector3(0, r, 0);
                // Vector3 p0 = center + Quaternion.Euler(0, 0, 45) * p;
                // Vector3 p1 = center + Quaternion.Euler(0, 0, 135) * p;
                // Vector3 p2 = center + Quaternion.Euler(0, 0, 225) * p;
                // Vector3 p3 = center + Quaternion.Euler(0, 0, 315) * p;

                AddTriangle(p0, p1, p3, color, color);
                AddTriangle(p3, p1, p2, color, color);

                if (mode_3d)
                {
                    Vector3 p4 = p0; p4.z = z1;
                    Vector3 p5 = p1; p5.z = z1;
                    Vector3 p6 = p2; p6.z = z1;
                    Vector3 p7 = p3; p7.z = z1;

                    AddTriangle(p4, p7, p5, color, color);
                    AddTriangle(p7, p6, p5, color, color);

                    AddTriangle(p0, p4, p1, color, color);
                    AddTriangle(p5, p1, p4, color, color);

                    AddTriangle(p2, p1, p5, color, color);
                    AddTriangle(p2, p5, p6, color, color);

                    AddTriangle(p2, p6, p3, color, color);
                    AddTriangle(p7, p3, p6, color, color);

                    AddTriangle(p3, p7, p0, color, color);
                    AddTriangle(p0, p7, p4, color, color);
                }
            }
            break;

            case PointType.TRIANGLE:
            {
                Vector3 p0 = center + new Vector3(0, r, 0);
                Vector3 p1 = center + new Vector3(r, -r, 0);
                Vector3 p2 = center + new Vector3(-r, -r, 0);

                // Vector3 p = new Vector3(0, r, 0);
                // Vector3 p0 = center + p;
                // Vector3 p1 = center + Quaternion.Euler(0, 0, 120) * p;
                // Vector3 p2 = center + Quaternion.Euler(0, 0, 240) * p;

                AddTriangle(p0, p1, p2, color, color);

                if (mode_3d)
                {
                    Vector3 p3 = p0; p3.z = z1;
                    Vector3 p4 = p1; p4.z = z1;
                    Vector3 p5 = p2; p5.z = z1;

                    AddTriangle(p3, p5, p4, color, color);

                    AddTriangle(p0, p4, p1, color, color);
                    AddTriangle(p0, p3, p4, color, color);

                    AddTriangle(p1, p4, p2, color, color);
                    AddTriangle(p2, p4, p5, color, color);

                    AddTriangle(p2, p5, p0, color, color);
                    AddTriangle(p5, p3, p0, color, color);
                }
            }
            break;
            }
        }
Exemplo n.º 35
0
        private void createTriangle(PhysicsSimulator pS, int i, int width, Triangles t)
        {
            Vertices vertices = new Vertices();
            Vector2 position = new Vector2(0, 0) ;
            switch(t)
            {
                case Triangles.LeftRightDown:
                    position = new Vector2((width * 50) - (i % width) * 50 - 7, (i - (i % width)) / width * 50 + 8);
                    vertices.Add(new Vector2(50, 50));
                    vertices.Add(new Vector2(0, 50));
                    vertices.Add(new Vector2(0, 0));
                    vertices.Add(new Vector2(12.5f, 12.5f));
                    vertices.Add(new Vector2(25, 25));
                    vertices.Add(new Vector2(37.5f, 37.5f));
                    break;
                case Triangles.RightLeftDown:
                    position = new Vector2((width * 50) - (i % width) * 50 + 7, (i - (i % width)) / width * 50 + 8);
                    vertices.Add(new Vector2(50, 0));
                    vertices.Add(new Vector2(50, 50));
                    vertices.Add(new Vector2(0, 50));
                    vertices.Add(new Vector2(12.5f, 37.5f));
                    vertices.Add(new Vector2(25, 25));
                    vertices.Add(new Vector2(37.5f, 12.5f));
                    break;
                case Triangles.RightLeftUp:
                    position = new Vector2((width * 50) - (i % width) * 50 - 7, (i - (i % width)) / width * 50 - 8);
                    vertices.Add(new Vector2(0, 0));
                    vertices.Add(new Vector2(50, 0));
                    vertices.Add(new Vector2(12.5f, 37.5f));
                    vertices.Add(new Vector2(25, 25));
                    vertices.Add(new Vector2(37.5f, 12.5f));
                    vertices.Add(new Vector2(0, 50));
                    break;
                case Triangles.LeftRightUp:
                    position = new Vector2((width * 50) - (i % width) * 50 + 7, (i - (i % width)) / width * 50 - 8);
                    vertices.Add(new Vector2(0, 0));
                    vertices.Add(new Vector2(50, 0));
                    vertices.Add(new Vector2(50, 50));
                    vertices.Add(new Vector2(37.5f, 37.5f));
                    vertices.Add(new Vector2(25, 25));
                    vertices.Add(new Vector2(12.5f, 12.5f));
                    break;
            }

            Body bd = BodyFactory.Instance.CreatePolygonBody(pS, vertices, 1);
            bd.Position = position;
            bd.IsStatic = true;
            pBodyList.Add(bd);
            Geom gm = GeomFactory.Instance.CreatePolygonGeom(pS, bd, vertices, 5);
            gm.FrictionCoefficient = 0.4f;
            pGeomList.Add(gm);
        }