Ejemplo n.º 1
0
    public void AddTorch(GameData d_Data, Game d_TerainRenderer, ModelData m, int x, int y, int z, TorchType type)
    {
        float one         = 1;
        int   curcolor    = Game.ColorFromArgb(255, 255, 255, 255);
        float torchsizexy = one * 16 / 100;
        float topx        = one / 2 - torchsizexy / 2;
        float topy        = one / 2 - torchsizexy / 2;
        float bottomx     = one / 2 - torchsizexy / 2;
        float bottomy     = one / 2 - torchsizexy / 2;

        topx    += x;
        topy    += y;
        bottomx += x;
        bottomy += y;

        if (type == TorchType.Front)
        {
            bottomx = x - torchsizexy;
        }
        if (type == TorchType.Back)
        {
            bottomx = x + 1;
        }
        if (type == TorchType.Left)
        {
            bottomy = y - torchsizexy;
        }
        if (type == TorchType.Right)
        {
            bottomy = y + 1;
        }

        Vector3Ref top00 = Vector3Ref.Create(topx, z + (one * 9 / 10), topy);
        Vector3Ref top01 = Vector3Ref.Create(topx, z + (one * 9 / 10), topy + torchsizexy);
        Vector3Ref top10 = Vector3Ref.Create(topx + torchsizexy, z + (one * 9 / 10), topy);
        Vector3Ref top11 = Vector3Ref.Create(topx + torchsizexy, z + (one * 9 / 10), topy + torchsizexy);

        if (type == TorchType.Left)
        {
            top01.Y += -(one * 1 / 10);
            top11.Y += -(one * 1 / 10);
        }

        if (type == TorchType.Right)
        {
            top10.Y += -(one * 1 / 10);
            top00.Y += -(one * 1 / 10);
        }

        if (type == TorchType.Front)
        {
            top10.Y += -(one * 1 / 10);
            top11.Y += -(one * 1 / 10);
        }

        if (type == TorchType.Back)
        {
            top01.Y += -(one * 1 / 10);
            top00.Y += -(one * 1 / 10);
        }

        Vector3Ref bottom00 = Vector3Ref.Create(bottomx, z + 0, bottomy);
        Vector3Ref bottom01 = Vector3Ref.Create(bottomx, z + 0, bottomy + torchsizexy);
        Vector3Ref bottom10 = Vector3Ref.Create(bottomx + torchsizexy, z + 0, bottomy);
        Vector3Ref bottom11 = Vector3Ref.Create(bottomx + torchsizexy, z + 0, bottomy + torchsizexy);

        //top
        {
            int      sidetexture = TopTexture;
            RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, d_TerainRenderer.texturesPacked());
            int      lastelement = m.GetVerticesCount();
            AddVertex(m, top00.X, top00.Y, top00.Z, texrec.Left(), texrec.Top(), curcolor);
            AddVertex(m, top01.X, top01.Y, top01.Z, texrec.Left(), texrec.Bottom(), curcolor);
            AddVertex(m, top10.X, top10.Y, top10.Z, texrec.Right(), texrec.Top(), curcolor);
            AddVertex(m, top11.X, top11.Y, top11.Z, texrec.Right(), texrec.Bottom(), curcolor);
            m.indices[m.indicesCount++] = (lastelement + 0);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 2);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 3);
            m.indices[m.indicesCount++] = (lastelement + 2);
        }

        //bottom - same as top, but z is 1 less.
        {
            int      sidetexture = SideTexture;
            RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, d_TerainRenderer.texturesPacked());
            int      lastelement = m.GetVerticesCount();
            AddVertex(m, bottom00.X, bottom00.Y, bottom00.Z, texrec.Left(), texrec.Top(), curcolor);
            AddVertex(m, bottom01.X, bottom01.Y, bottom01.Z, texrec.Left(), texrec.Bottom(), curcolor);
            AddVertex(m, bottom10.X, bottom10.Y, bottom10.Z, texrec.Right(), texrec.Top(), curcolor);
            AddVertex(m, bottom11.X, bottom11.Y, bottom11.Z, texrec.Right(), texrec.Bottom(), curcolor);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 0);
            m.indices[m.indicesCount++] = (lastelement + 2);
            m.indices[m.indicesCount++] = (lastelement + 3);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 2);
        }

        //front
        {
            int      sidetexture = SideTexture;
            RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, d_TerainRenderer.texturesPacked());
            int      lastelement = m.GetVerticesCount();
            AddVertex(m, bottom00.X, bottom00.Y, bottom00.Z, texrec.Left(), texrec.Bottom(), curcolor);
            AddVertex(m, bottom01.X, bottom01.Y, bottom01.Z, texrec.Right(), texrec.Bottom(), curcolor);
            AddVertex(m, top00.X, top00.Y, top00.Z, texrec.Left(), texrec.Top(), curcolor);
            AddVertex(m, top01.X, top01.Y, top01.Z, texrec.Right(), texrec.Top(), curcolor);
            m.indices[m.indicesCount++] = (lastelement + 0);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 2);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 3);
            m.indices[m.indicesCount++] = (lastelement + 2);
        }

        //back - same as front, but x is 1 greater.
        {
            int      sidetexture = SideTexture;
            RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, d_TerainRenderer.texturesPacked());
            int      lastelement = m.GetVerticesCount();
            AddVertex(m, bottom10.X, bottom10.Y, bottom10.Z, texrec.Right(), texrec.Bottom(), curcolor);
            AddVertex(m, bottom11.X, bottom11.Y, bottom11.Z, texrec.Left(), texrec.Bottom(), curcolor);
            AddVertex(m, top10.X, top10.Y, top10.Z, texrec.Right(), texrec.Top(), curcolor);
            AddVertex(m, top11.X, top11.Y, top11.Z, texrec.Left(), texrec.Top(), curcolor);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 0);
            m.indices[m.indicesCount++] = (lastelement + 2);
            m.indices[m.indicesCount++] = (lastelement + 3);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 2);
        }

        {
            int      sidetexture = SideTexture;
            RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, d_TerainRenderer.texturesPacked());
            int      lastelement = m.GetVerticesCount();
            AddVertex(m, bottom00.X, bottom00.Y, bottom00.Z, texrec.Right(), texrec.Bottom(), curcolor);
            AddVertex(m, top00.X, top00.Y, top00.Z, texrec.Right(), texrec.Top(), curcolor);
            AddVertex(m, bottom10.X, bottom10.Y, bottom10.Z, texrec.Left(), texrec.Bottom(), curcolor);
            AddVertex(m, top10.X, top10.Y, top10.Z, texrec.Left(), texrec.Top(), curcolor);
            m.indices[m.indicesCount++] = (lastelement + 0);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 2);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 3);
            m.indices[m.indicesCount++] = (lastelement + 2);
        }

        //right - same as left, but y is 1 greater.
        {
            int      sidetexture = SideTexture;
            RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, d_TerainRenderer.texturesPacked());
            int      lastelement = m.GetVerticesCount();
            AddVertex(m, bottom01.X, bottom01.Y, bottom01.Z, texrec.Left(), texrec.Bottom(), curcolor);
            AddVertex(m, top01.X, top01.Y, top01.Z, texrec.Left(), texrec.Top(), curcolor);
            AddVertex(m, bottom11.X, bottom11.Y, bottom11.Z, texrec.Right(), texrec.Bottom(), curcolor);
            AddVertex(m, top11.X, top11.Y, top11.Z, texrec.Right(), texrec.Top(), curcolor);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 0);
            m.indices[m.indicesCount++] = (lastelement + 2);
            m.indices[m.indicesCount++] = (lastelement + 3);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 2);
        }
    }
Ejemplo n.º 2
0
 void DrawCube(ModelData m, int x, int y, int z, int c)
 {
     //top
     //if (drawtop)
     {
         int      sidetexture = GetWeaponTextureId(TileSide.Top);
         RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, texturesPacked());
         int      lastelement = m.GetVerticesCount();
         AddVertex(m, x + 0, z + 1, y + 0, texrec.Left(), texrec.Top(), c);
         AddVertex(m, x + 0, z + 1, y + 1, texrec.Left(), texrec.Bottom(), c);
         AddVertex(m, x + 1, z + 1, y + 0, texrec.Right(), texrec.Top(), c);
         AddVertex(m, x + 1, z + 1, y + 1, texrec.Right(), texrec.Bottom(), c);
         m.indices[m.indicesCount++] = (lastelement + 0);
         m.indices[m.indicesCount++] = (lastelement + 1);
         m.indices[m.indicesCount++] = (lastelement + 2);
         m.indices[m.indicesCount++] = (lastelement + 1);
         m.indices[m.indicesCount++] = (lastelement + 3);
         m.indices[m.indicesCount++] = (lastelement + 2);
     }
     //bottom - same as top, but z is 1 less.
     //if (drawbottom)
     {
         int      sidetexture = GetWeaponTextureId(TileSide.Bottom);
         RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, texturesPacked());
         int      lastelement = m.GetVerticesCount();
         AddVertex(m, x + 0, z, y + 0, texrec.Left(), texrec.Top(), c);
         AddVertex(m, x + 0, z, y + 1, texrec.Left(), texrec.Bottom(), c);
         AddVertex(m, x + 1, z, y + 0, texrec.Right(), texrec.Top(), c);
         AddVertex(m, x + 1, z, y + 1, texrec.Right(), texrec.Bottom(), c);
         m.indices[m.indicesCount++] = (lastelement + 1);
         m.indices[m.indicesCount++] = (lastelement + 0);
         m.indices[m.indicesCount++] = (lastelement + 2);
         m.indices[m.indicesCount++] = (lastelement + 3);
         m.indices[m.indicesCount++] = (lastelement + 1);
         m.indices[m.indicesCount++] = (lastelement + 2);
     }
     // //front
     //if (drawfront)
     {
         int      sidetexture = GetWeaponTextureId(TileSide.Front);
         RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, texturesPacked());
         int      lastelement = m.GetVerticesCount();
         AddVertex(m, x + 0, z + 0, y + 0, texrec.Left(), texrec.Bottom(), c);
         AddVertex(m, x + 0, z + 0, y + 1, texrec.Right(), texrec.Bottom(), c);
         AddVertex(m, x + 0, z + 1, y + 0, texrec.Left(), texrec.Top(), c);
         AddVertex(m, x + 0, z + 1, y + 1, texrec.Right(), texrec.Top(), c);
         m.indices[m.indicesCount++] = (lastelement + 0);
         m.indices[m.indicesCount++] = (lastelement + 1);
         m.indices[m.indicesCount++] = (lastelement + 2);
         m.indices[m.indicesCount++] = (lastelement + 1);
         m.indices[m.indicesCount++] = (lastelement + 3);
         m.indices[m.indicesCount++] = (lastelement + 2);
     }
     //back - same as front, but x is 1 greater.
     //if (drawback)
     {//TODO: fix tcoords
         int      sidetexture = GetWeaponTextureId(TileSide.Back);
         RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, texturesPacked());
         int      lastelement = m.GetVerticesCount();
         AddVertex(m, x + 1, z + 0, y + 0, texrec.Left(), texrec.Bottom(), c);
         AddVertex(m, x + 1, z + 0, y + 1, texrec.Right(), texrec.Bottom(), c);
         AddVertex(m, x + 1, z + 1, y + 0, texrec.Left(), texrec.Top(), c);
         AddVertex(m, x + 1, z + 1, y + 1, texrec.Right(), texrec.Top(), c);
         m.indices[m.indicesCount++] = (lastelement + 1);
         m.indices[m.indicesCount++] = (lastelement + 0);
         m.indices[m.indicesCount++] = (lastelement + 2);
         m.indices[m.indicesCount++] = (lastelement + 3);
         m.indices[m.indicesCount++] = (lastelement + 1);
         m.indices[m.indicesCount++] = (lastelement + 2);
     }
     //if (drawleft)
     {
         int      sidetexture = GetWeaponTextureId(TileSide.Left);
         RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, texturesPacked());
         int      lastelement = m.GetVerticesCount();
         AddVertex(m, x + 0, z + 0, y + 0, texrec.Left(), texrec.Bottom(), c);
         AddVertex(m, x + 0, z + 1, y + 0, texrec.Left(), texrec.Top(), c);
         AddVertex(m, x + 1, z + 0, y + 0, texrec.Right(), texrec.Bottom(), c);
         AddVertex(m, x + 1, z + 1, y + 0, texrec.Right(), texrec.Top(), c);
         m.indices[m.indicesCount++] = (lastelement + 0);
         m.indices[m.indicesCount++] = (lastelement + 1);
         m.indices[m.indicesCount++] = (lastelement + 2);
         m.indices[m.indicesCount++] = (lastelement + 1);
         m.indices[m.indicesCount++] = (lastelement + 3);
         m.indices[m.indicesCount++] = (lastelement + 2);
     }
     //right - same as left, but y is 1 greater.
     //if (drawright)
     {//TODO: fix tcoords
         int      sidetexture = GetWeaponTextureId(TileSide.Right);
         RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, texturesPacked());
         int      lastelement = m.GetVerticesCount();
         AddVertex(m, x + 0, z + 0, y + 1, texrec.Left(), texrec.Bottom(), c);
         AddVertex(m, x + 0, z + 1, y + 1, texrec.Left(), texrec.Top(), c);
         AddVertex(m, x + 1, z + 0, y + 1, texrec.Right(), texrec.Bottom(), c);
         AddVertex(m, x + 1, z + 1, y + 1, texrec.Right(), texrec.Top(), c);
         m.indices[m.indicesCount++] = (lastelement + 1);
         m.indices[m.indicesCount++] = (lastelement + 0);
         m.indices[m.indicesCount++] = (lastelement + 2);
         m.indices[m.indicesCount++] = (lastelement + 3);
         m.indices[m.indicesCount++] = (lastelement + 1);
         m.indices[m.indicesCount++] = (lastelement + 2);
     }
 }