private void GenerateTriangles()
        {
            _triangles = new Triangle[TrianglesPerCell];

            _triangles[0] = _triangleFactory.Create(this, isBottom: true);
            _triangles[1] = _triangleFactory.Create(this, isBottom: false);
        }
Beispiel #2
0
 public IActionResult Get([FromQuery] Vertex v1, [FromQuery] Vertex v2, [FromQuery] Vertex v3)
 {
     try
     {
         var triangle = _TriangleFactory.Create(v1, v2, v3);
         return(new JsonResult(triangle.CalculateName()));
     }
     catch (Exception e)
     {
         var msg = $"Unanticipated exception, \"{e.Message}\". \nContact your administrator";
         Log.Error(e, msg);
         return(StatusCode(StatusCodes.Status500InternalServerError, msg));
     }
 }
Beispiel #3
0
        private void CreateTriangle(IList <string> lines, string line, IDictionary <string, IJoint> joints)
        {
            string[]  parts    = line.Split(' ');
            ITriangle triangle = triangleFactory.Create();

            AddTriangleVertex(triangle, joints, PopLine(lines));
            AddTriangleVertex(triangle, joints, PopLine(lines));
            AddTriangleVertex(triangle, joints, PopLine(lines));
            AddElementColors(triangle, PopLine(lines));
            triangle.ZIndex = Convert.ToSingle(PopLine(lines));
            string parentName  = GetParentName(parts[1]);
            IJoint parentJoint = joints[parentName];

            parentJoint.AddTriangle(triangle);
        }
Beispiel #4
0
        public RenderMap(uint numColumns, uint numRows, Map map,
                         ITriangleFactory triangleFactory, ISpriteFactory spriteFactory,
                         ITextureAtlas textureAtlasTiles, ITextureAtlas textureAtlasWaves,
                         DataSource dataSource)
        {
            CoordinateSpace = new CoordinateSpace(map, this);

            columnRowFactor = (map.Size % 2 == 0) ? 4 : 2;

            ScrollX                = 0;
            ScrollY                = 0;
            this.numColumns        = numColumns;
            this.numRows           = numRows;
            this.map               = map;
            this.textureAtlasTiles = textureAtlasTiles;
            this.textureAtlasWaves = textureAtlasWaves;

            // store map sprite offsets
            for (uint i = 0; i < 81; ++i)
            {
                var spriteInfo = dataSource.GetSpriteInfo(Data.Resource.MapMaskUp, i);

                if (spriteInfo != null)
                {
                    maskOffsets.Add(i, new Position(spriteInfo.OffsetX, spriteInfo.OffsetY));
                }

                spriteInfo = dataSource.GetSpriteInfo(Data.Resource.MapMaskDown, i);

                if (spriteInfo != null)
                {
                    maskOffsets.Add(81u + i, new Position(spriteInfo.OffsetX, spriteInfo.OffsetY));
                }
            }

            uint numTriangles = (numColumns + ADDITIONAL_X_TILES) * (numRows + ADDITIONAL_Y_TILES) * 2u;

            triangles = new List <ITriangle>((int)numTriangles);
            waves     = new List <IMaskedSprite>((int)numTriangles / 2);

            for (uint column = 0; column < numColumns + ADDITIONAL_X_TILES; ++column)
            {
                for (int i = 0; i < 2; ++i) // up and down row
                {
                    for (uint row = 0; row < numRows + ADDITIONAL_Y_TILES; ++row)
                    {
                        // the triangles are created with the max mask height of 41.
                        // also see comments in TextureAtlasManager.AddAll for further details.

                        var triangle = triangleFactory.Create(TILE_WIDTH, TILE_RENDER_MAX_HEIGHT, 0, 0);

                        triangle.X       = (int)(column * TILE_WIDTH) - TILE_WIDTH / 2 + i * TILE_WIDTH / 2;
                        triangle.Y       = (int)(row * TILE_HEIGHT);
                        triangle.Visible = true;

                        triangles.Add(triangle);
                    }
                }
            }

            for (uint column = 0; column < numColumns + ADDITIONAL_X_TILES; ++column)
            {
                for (uint row = 0; row < numRows + ADDITIONAL_Y_TILES; ++row)
                {
                    var wave = spriteFactory.Create(48, 19, 0, 0, true, false) as IMaskedSprite;

                    wave.X       = (int)(column * TILE_WIDTH) - TILE_WIDTH / 2;
                    wave.Y       = (int)(row * TILE_HEIGHT);
                    wave.Visible = false;

                    waves.Add(wave);
                }
            }

            UpdatePosition();
        }