Example #1
0
        public void CalculateBorderTiles(bool recolor)
        {
            // Color for debug
            Vector3 HSV   = new Vector3(hue, 0.9f, 0.1f);
            Vector3 RGB   = Math2.HSV2RGB(HSV);
            Vector4 color = new Vector4(RGB.X, RGB.Y, RGB.Z, 1.0f);

            outerIndices.Clear();
            int plateIdx = vertexToPlate[allIndices[0]];

            foreach (int index in allIndices)
            {
                var vertexNeighbours = geometry.Topology.VertexNeighbours.GetNeighbours(index);
                foreach (int neighbourIndex in vertexNeighbours)
                {
                    if (plateIdx != vertexToPlate[neighbourIndex] && !outerIndices.Contains(index))
                    {
                        outerIndices.Add(index);
                        if (recolor)
                        {
                            geometry.Mesh.SetColor(index, ref color);
                        }
                    }
                }
            }
        }
Example #2
0
        private Vector4 NextColor(int cycleNum)
        {
            float   value = Math2.Clamp(0.2f + cycleNum / 20.0f, 0.0f, 1.0f);
            Vector3 HSV   = new Vector3(hue, 0.5f, value);
            Vector3 RGB   = Math2.HSV2RGB(HSV);
            Vector4 color = new Vector4(RGB.X, RGB.Y, RGB.Z, 1.0f);

            return(color);
        }
Example #3
0
        public Geometry <Vertex3DColor> GenerateDistanceDebugGeom()
        {
            List <Vertex3DColor> verts   = new List <Vertex3DColor>();
            List <uint>          indices = new List <uint>();

            for (int plateIndex = 0; plateIndex < GetPlates().Length; ++plateIndex)
            {
                Vector3 center      = GetPlates()[plateIndex].Traits.Center;
                int     cornerIndex = 0;
                foreach (int corner in GetPlates()[plateIndex].Corners)
                {
                    float    hue       = (float)cornerIndex / (float)GetPlates()[plateIndex].Corners.Count;
                    Vector3  color3    = Math2.HSV2RGB(new Vector3(hue, 0.7f, 0.5f));
                    Vector4  color     = new Vector4(color3.X, color3.Y, color3.Z, 1.0f);
                    Centroid centroid  = geometry.Topology.Centroids[corner];
                    Vector3  cornerPos = centroid.position;
                    Vector3  direction = cornerPos - center;
                    direction.Normalize();
                    float theta    = centroid.PlateDistances[plateIndex];
                    float distance = 2.0f * (float)Math.Sin(theta * 0.5f);
                    direction *= distance;
                    cornerPos  = center + direction;
                    cornerPos.Normalize();
                    int vertexStart = verts.Count;
                    GeometryFactory.AddArcVerts(verts, center, cornerPos, 1.001f, color);
                    for (int vertexIndex = vertexStart; vertexIndex < verts.Count - 1; ++vertexIndex)
                    {
                        indices.Add((uint)vertexIndex);
                        indices.Add((uint)vertexIndex + 1);
                    }
                    ++cornerIndex;
                }
            }
            Mesh <Vertex3DColor>     mesh = new Mesh <Vertex3DColor>(verts.ToArray());
            Geometry <Vertex3DColor> geom = new Geometry <Vertex3DColor>(mesh, indices.ToArray());

            geom.PrimitiveType = OpenTK.Graphics.OpenGL.PrimitiveType.Lines;
            return(geom);
        }
Example #4
0
        public Geometry <AltVertex> GenerateBorderGeometry <AltVertex>()
            where AltVertex : struct, IVertex
        {
            if (borders == null || borders.Count == 0)
            {
                return(null);
            }
            else
            {
                List <AltVertex> vertices   = new List <AltVertex>();
                List <uint>      newIndices = new List <uint>();

                const float h = 0.1f;

                foreach (var iter in borders)
                {
                    Int64  borderKey = iter.Key;
                    int    v1index   = (int)(borderKey & 0xffffffff);
                    int    v2index   = (int)((borderKey >> 32) & 0xffffffff);
                    Border border    = iter.Value;

                    // The border lies along an edge in the dual geometry.
                    int     plateIndex1 = border.plate0;
                    int     plateIndex2 = border.plate1;
                    Vector3 v1Pos       = geometry.Mesh.GetPosition(v1index);
                    Vector3 v2Pos       = geometry.Mesh.GetPosition(v2index);
                    Vector3 centroid1   = geometry.Topology.Centroids[border.c1Index].position;
                    Vector3 centroid2   = geometry.Topology.Centroids[border.c2Index].position;

                    Vector3 v1g1prime = Math2.BaseProjection(v1Pos, centroid1, centroid2, h);
                    Vector3 v1g2prime = Math2.BaseProjection(v1Pos, centroid2, centroid1, h);
                    Vector3 v2g1prime = Math2.BaseProjection(v2Pos, centroid1, centroid2, h);
                    Vector3 v2g2prime = Math2.BaseProjection(v2Pos, centroid2, centroid1, h);

                    centroid1 *= 1.01f; // Project the centroids out of the sphere slightly
                    centroid2 *= 1.01f;

                    bool edgeOrderIsAnticlockwise = false;
                    for (int i = 0; i < 3; i++)
                    {
                        if (geometry.Indices[border.c1Index * 3 + i] == v1index)
                        {
                            if (geometry.Indices[border.c1Index * 3 + (i + 1) % 3] == v2index)
                            {
                                edgeOrderIsAnticlockwise = true;
                            }
                            break;
                        }
                    }

                    int index = vertices.Count;
                    geometry.AddTriangle(ref vertices, ref newIndices, ref v1g2prime, ref centroid2, ref centroid1, edgeOrderIsAnticlockwise);
                    geometry.AddTriangle(ref vertices, ref newIndices, ref v1g2prime, ref centroid1, ref v1g1prime, edgeOrderIsAnticlockwise);
                    geometry.AddTriangle(ref vertices, ref newIndices, ref v2g1prime, ref centroid1, ref centroid2, edgeOrderIsAnticlockwise);
                    geometry.AddTriangle(ref vertices, ref newIndices, ref v2g1prime, ref centroid2, ref v2g2prime, edgeOrderIsAnticlockwise);

                    float     p1      = Math2.Clamp(Math.Abs(borderCorners[border.c1Index].stress.pressure) * 1000.0f, 0, 1.0f);
                    float     p2      = Math2.Clamp(Math.Abs(borderCorners[border.c2Index].stress.pressure) * 1000.0f, 0, 1.0f);
                    float     hue1    = borderCorners[border.c1Index].stress.pressure > 0 ? 0 : 0.5f;
                    float     hue2    = borderCorners[border.c2Index].stress.pressure > 0 ? 0 : 0.5f;
                    Vector3   rgb1    = Math2.HSV2RGB(new Vector3(hue1, p1, 1.0f - p1));
                    Vector3   rgb2    = Math2.HSV2RGB(new Vector3(hue2, p2, 1.0f - p2));
                    Vector4   c1Color = new Vector4(rgb1.X, rgb1.Y, rgb1.Z, 1);
                    Vector4   c2Color = new Vector4(rgb2.X, rgb2.Y, rgb2.Z, 1);
                    AltVertex v;
                    for (int i = 0; i < 12; ++i)
                    {
                        Vector4 color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                        if (i == 0 || i == 1 || i == 3 || i == 8 || i == 10 || i == 11)
                        {
                            color = c2Color;
                        }
                        else if (i == 2 || i == 4 || i == 5 || i == 6 || i == 7 || i == 9)
                        {
                            color = c1Color;
                        }
                        v = vertices[index + i]; MeshAttr.SetColor(ref v, ref color); vertices[index + i] = v;
                    }
                }
                Mesh <AltVertex> newMesh = new Mesh <AltVertex>(vertices.ToArray());
                return(new Geometry <AltVertex>(newMesh, newIndices.ToArray()));
            }
        }