示例#1
0
        public SkyBox(IBitmap neg_x, IBitmap pos_x, IBitmap neg_y, IBitmap pos_y, IBitmap neg_z, IBitmap pos_z)
        {
            _config = Constants.Kernel.Get<RenderConfig>();
			
            ITextureAtlasFactory atlasFactory = Constants.Kernel.Get<ITextureAtlasFactory>();
            _atlas = atlasFactory.CreateTextureAtlas(new Size(_config.MaxTextureSize,_config.MaxTextureSize/2), new Size(_config.MaxTextureSize / 4, _config.MaxTextureSize / 4), 1);
            _neg_x = _atlas.AddSubImage(neg_x);
            _pos_x = _atlas.AddSubImage(pos_x);
            _pos_y = _atlas.AddSubImage(pos_y);
            _neg_y = _atlas.AddSubImage(neg_y);
            _pos_z = _atlas.AddSubImage(pos_z);
            _neg_z = _atlas.AddSubImage(neg_z);
        }
 /*
                  _________________________ (1,1,0)
                 / _________Top_________  /|
                / / ___________________/ / |   
               / / /| |               / /  |  /|\
              / / / | |              / / . |   |
             / / /| | |             / / /| |   |
            / / / | | |            / / / | |   |
           / / /  | | |           / / /| | |   | +Y axis
          / /_/__________________/ / / | | |   |
         /________________________/ /  | | |   |
 Left--> | ______________________ | |  | | |   | 
         | | |    | | |_________| | |__| | |   |
         | | |    | |___________| | |____| |   |
         | | |   / / ___________| | |_  / /    
         | | |  / / /           | | |/ / /     /
         | | | / / /            | | | / /     /
         | | |/ / /             | | |/ /     /
         | | | / /              | | ' /     /  +Z axis
         | | |/_/_______________| |  /     /
         | |____________________| | /     /
         |________Front___________|/    \/
      (0,0,1)
           ---------------------->
                 +X axis
 */
 public static void createCubeSide(ref IList<VertexPositionColorTexture> vertexes, ref IList<short> indices, Vector3 frontBottomLeftOfCube, BlockSides sideType, ITextureReference texture)
 {
     //Create vertexes
     float x = frontBottomLeftOfCube.X;
     float y = frontBottomLeftOfCube.Y;
     float z = frontBottomLeftOfCube.Z;
     RectangleF textLoc = texture.TextureLocation;
     switch (sideType)
     {
         case BlockSides.Front:
             appendIndiciesForSideOfCube(ref vertexes, ref indices);
             vertexes.Add(new VertexPositionColorTexture(x - 0.0f, y - 0.0f, z - 0.0f, Color.Gray, textLoc.X, textLoc.Y));
             vertexes.Add(new VertexPositionColorTexture(x + 1.0f, y - 0.0f, z - 0.0f, Color.Gray, textLoc.X + textLoc.Width, textLoc.Y));
             vertexes.Add(new VertexPositionColorTexture(x + 1.0f, y + 1.0f, z - 0.0f, Color.White, textLoc.X + textLoc.Width, textLoc.Y + textLoc.Height));
             vertexes.Add(new VertexPositionColorTexture(x - 0.0f, y + 1.0f, z - 0.0f, Color.White, textLoc.X, textLoc.Y + textLoc.Height));
             break;
         case BlockSides.Back:
             appendIndiciesForSideOfCube(ref vertexes, ref indices);
             vertexes.Add(new VertexPositionColorTexture(x - 0.0f, y + 1.0f, z + 1.0f, Color.White, textLoc.X, textLoc.Y));
             vertexes.Add(new VertexPositionColorTexture(x + 1.0f, y + 1.0f, z + 1.0f, Color.White, textLoc.X + textLoc.Width, textLoc.Y));
             vertexes.Add(new VertexPositionColorTexture(x + 1.0f, y - 0.0f, z + 1.0f, Color.Gray, textLoc.X + textLoc.Width, textLoc.Y + textLoc.Height));
             vertexes.Add(new VertexPositionColorTexture(x - 0.0f, y - 0.0f, z + 1.0f, Color.Gray, textLoc.X, textLoc.Y + textLoc.Height));
             break;
         case BlockSides.Left:
             appendIndiciesForSideOfCube(ref vertexes, ref indices);
             vertexes.Add(new VertexPositionColorTexture(x - 0.0f, y - 0.0f, z + 1.0f, Color.Gray, textLoc.X, textLoc.Y));
             vertexes.Add(new VertexPositionColorTexture(x - 0.0f, y - 0.0f, z - 0.0f, Color.Gray, textLoc.X + textLoc.Width, textLoc.Y));
             vertexes.Add(new VertexPositionColorTexture(x - 0.0f, y + 1.0f, z - 0.0f, Color.White, textLoc.X + textLoc.Width, textLoc.Y + textLoc.Height));
             vertexes.Add(new VertexPositionColorTexture(x - 0.0f, y + 1.0f, z + 1.0f, Color.White, textLoc.X, textLoc.Y + textLoc.Height));
             break;
         case BlockSides.Right:
             appendIndiciesForSideOfCube(ref vertexes, ref indices);
             vertexes.Add(new VertexPositionColorTexture(x + 1.0f, y + 1.0f, z + 1.0f, Color.White, textLoc.X, textLoc.Y));
             vertexes.Add(new VertexPositionColorTexture(x + 1.0f, y + 1.0f, z - 0.0f, Color.White, textLoc.X + textLoc.Width, textLoc.Y));
             vertexes.Add(new VertexPositionColorTexture(x + 1.0f, y - 0.0f, z - 0.0f, Color.Gray, textLoc.X + textLoc.Width, textLoc.Y + textLoc.Height));
             vertexes.Add(new VertexPositionColorTexture(x + 1.0f, y - 0.0f, z + 1.0f, Color.Gray, textLoc.X, textLoc.Y + textLoc.Height));
             break;
         case BlockSides.Top:
             appendIndiciesForSideOfCube(ref vertexes, ref indices);
             vertexes.Add(new VertexPositionColorTexture(x - 0.0f, y + 1.0f, z - 0.0f, Color.White, textLoc.X, textLoc.Y));
             vertexes.Add(new VertexPositionColorTexture(x + 1.0f, y + 1.0f, z - 0.0f, Color.White, textLoc.X + textLoc.Width, textLoc.Y));
             vertexes.Add(new VertexPositionColorTexture(x + 1.0f, y + 1.0f, z + 1.0f, Color.White, textLoc.X + textLoc.Width, textLoc.Y + textLoc.Height));
             vertexes.Add(new VertexPositionColorTexture(x - 0.0f, y + 1.0f, z + 1.0f, Color.White, textLoc.X, textLoc.Y + textLoc.Height));
             break;
         case BlockSides.Bottom:
             appendIndiciesForSideOfCube(ref vertexes, ref indices);
             vertexes.Add(new VertexPositionColorTexture(x - 0.0f, y - 0.0f, z + 1.0f, Color.Gray, textLoc.X, textLoc.Y));
             vertexes.Add(new VertexPositionColorTexture(x + 1.0f, y - 0.0f, z + 1.0f, Color.Gray, textLoc.X + textLoc.Width, textLoc.Y));
             vertexes.Add(new VertexPositionColorTexture(x + 1.0f, y - 0.0f, z - 0.0f, Color.Gray, textLoc.X + textLoc.Width, textLoc.Y + textLoc.Height));
             vertexes.Add(new VertexPositionColorTexture(x - 0.0f, y - 0.0f, z - 0.0f, Color.Gray, textLoc.X, textLoc.Y + textLoc.Height));
             break;
     }
 }