Пример #1
0
        protected void CreateBottomVertices(FaceCoordinates frontCoords, FaceCoordinates backCoords, Vector2[] texture)
        {
            if (!Bottom)
            {
                return;
            }

            Coors.Add(new VertexPositionNormalTexture(frontCoords.BottomRight, Vector3.Zero, texture[2]));
            Coors.Add(new VertexPositionNormalTexture(backCoords.BottomRight, Vector3.Zero, texture[1]));
            Coors.Add(new VertexPositionNormalTexture(backCoords.BottomLeft, Vector3.Zero, texture[0]));
            Coors.Add(new VertexPositionNormalTexture(frontCoords.BottomLeft, Vector3.Zero, texture[3]));

            int startIndex = Coors.Count - 4;

            IndexBufferCollection.Add(startIndex);
            IndexBufferCollection.Add(startIndex + 1);
            IndexBufferCollection.Add(startIndex + 2);
            IndexBufferCollection.Add(startIndex);
            IndexBufferCollection.Add(startIndex + 2);
            IndexBufferCollection.Add(startIndex + 3);
        }
Пример #2
0
        protected void CreateLeftVertices(FaceCoordinates frontCoords, FaceCoordinates backCoords, Vector2[] texture)
        {
            if (!Left)
            {
                return;
            }

            Coors.Add(new VertexPositionNormalTexture(frontCoords.TopLeft, Vector3.Zero, texture[3]));
            Coors.Add(new VertexPositionNormalTexture(backCoords.BottomLeft, Vector3.Zero, texture[1]));
            Coors.Add(new VertexPositionNormalTexture(frontCoords.BottomLeft, Vector3.Zero, texture[2]));
            Coors.Add(new VertexPositionNormalTexture(backCoords.TopLeft, Vector3.Zero, texture[0]));

            //Left also has a strange index buffer order...
            int startIndex = Coors.Count - 4;

            IndexBufferCollection.Add(startIndex + 2);
            IndexBufferCollection.Add(startIndex + 1);
            IndexBufferCollection.Add(startIndex);
            IndexBufferCollection.Add(startIndex + 1);
            IndexBufferCollection.Add(startIndex + 3);
            IndexBufferCollection.Add(startIndex);
        }
Пример #3
0
        protected void SetUpSlopeDiagonal(byte rotation)
        {
            FaceCoordinates frontCoordinates;
            FaceCoordinates backCoordinates;

            PrepareCoordinates(out frontCoordinates, out backCoordinates);

            if (rotation > 0)
            {
                frontCoordinates = RotateSlope(frontCoordinates, rotation);
                backCoordinates  = RotateSlope(backCoordinates, rotation);
            }

            //
            //LID
            //
            if (Lid)
            {
                RotationType lidRotation = Lid.Rotation;
                lidRotation = RotateEnum(lidRotation, rotation);

                if (Lid.Flip) //ToDo: This is just a dirty way! Problem: rotation Bug if flipped
                {
                    if (rotation == 1 || rotation == 3)
                    {
                        switch (lidRotation)
                        {
                        case RotationType.Rotate90:
                            lidRotation = RotationType.Rotate270;
                            break;

                        case RotationType.Rotate270:
                            lidRotation = RotationType.Rotate90;
                            break;
                        }
                    }
                }

                Vector2[] texPos = textures.GetNormalTexture((UInt32)Lid.TileNumber, lidRotation, Lid.Flip);
                Coors.Add(new VertexPositionNormalTexture(frontCoordinates.TopLeft, Vector3.Zero, texPos[3]));
                Coors.Add(new VertexPositionNormalTexture(frontCoordinates.BottomRight, Vector3.Zero, texPos[1]));
                Coors.Add(new VertexPositionNormalTexture(frontCoordinates.BottomLeft, Vector3.Zero, texPos[0]));

                int startIndex = Coors.Count - 3;
                IndexBufferCollection.Add(startIndex);
                IndexBufferCollection.Add(startIndex + 1);
                IndexBufferCollection.Add(startIndex + 2);
            }

            //int TileNumber = 0;
            BlockFace diagonalFace = null;

            switch (rotation)
            {
            case 0:
                diagonalFace = Right;
                break;

            case 1:
                diagonalFace = Left;
                break;

            case 2:
                diagonalFace = Left;
                break;

            case 3:
                diagonalFace = Right;
                break;
            }

            //Diagonal face
            if (diagonalFace)
            {
                Vector2[] texPos = textures.GetNormalTexture((UInt32)diagonalFace.TileNumber, diagonalFace.Rotation, diagonalFace.Flip);
                Coors.Add(new VertexPositionNormalTexture(frontCoordinates.TopLeft, Vector3.Zero, texPos[3]));
                Coors.Add(new VertexPositionNormalTexture(frontCoordinates.BottomRight, Vector3.Zero, texPos[2]));
                Coors.Add(new VertexPositionNormalTexture(backCoordinates.BottomRight, Vector3.Zero, texPos[1]));
                Coors.Add(new VertexPositionNormalTexture(backCoordinates.TopLeft, Vector3.Zero, texPos[0]));

                var startIndex = Coors.Count - 4;
                IndexBufferCollection.Add(startIndex + 2);
                IndexBufferCollection.Add(startIndex + 1);
                IndexBufferCollection.Add(startIndex);
                IndexBufferCollection.Add(startIndex + 3);
                IndexBufferCollection.Add(startIndex + 2);
                IndexBufferCollection.Add(startIndex);
            }

            PrepareCoordinates(out frontCoordinates, out backCoordinates);
            switch (rotation)
            {
            case 0:     //Facing up right
                Vector2[] texture = textures.GetNormalTexture((UInt32)Bottom.TileNumber, Bottom.Rotation, Bottom.Flip);
                CreateBottomVertices(frontCoordinates, backCoordinates, texture);
                texture = textures.GetNormalTexture((UInt32)Left.TileNumber, Left.Rotation, Left.Flip);
                CreateLeftVertices(frontCoordinates, backCoordinates, texture);
                break;

            case 1:     //Facing up left
                texture = textures.GetNormalTexture((UInt32)Bottom.TileNumber, Bottom.Rotation, Bottom.Flip);
                CreateBottomVertices(frontCoordinates, backCoordinates, texture);
                texture = textures.GetNormalTexture((UInt32)Right.TileNumber, Right.Rotation, Right.Flip);
                CreateRightVertices(frontCoordinates, backCoordinates, texture);
                break;

            case 2:     //Facing down left --> BUG
                texture = textures.GetNormalTexture((UInt32)Top.TileNumber, Top.Rotation, Top.Flip);
                CreateTopVertices(frontCoordinates, backCoordinates, texture);
                texture = textures.GetNormalTexture((UInt32)Right.TileNumber, Right.Rotation, Right.Flip);
                CreateRightVertices(frontCoordinates, backCoordinates, texture);
                break;

            case 3:     //Facing down right --> BUG
                texture = textures.GetNormalTexture((UInt32)Top.TileNumber, Top.Rotation, Top.Flip);
                CreateTopVertices(frontCoordinates, backCoordinates, texture);
                texture = textures.GetNormalTexture((UInt32)Left.TileNumber, Left.Rotation, Left.Flip);
                CreateLeftVertices(frontCoordinates, backCoordinates, texture);
                break;
            }
        }
Пример #4
0
        /// <summary>
        ///     Creates a Low Slope.
        /// </summary>
        /// <param name="subType"></param>
        /// <param name="rotation"></param>
        protected void SetLowSlope(byte subType, byte rotation)
        {
            //Sample is a right slope, use it for orientation, it gets rotated to fit all other directions
            FaceCoordinates frontCoordinates;
            FaceCoordinates backCoordinates;

            PrepareCoordinates(out frontCoordinates, out backCoordinates);

            float slopeScalar = 1f;

            switch (subType)
            {
            case 26:
                slopeScalar = 0.5f;
                break;

            case 45:
                slopeScalar = 0;
                break;

            case 7:
                slopeScalar = 0.875f;
                break;
            }

            Vector3 middleTopLeft     = frontCoordinates.TopLeft;
            Vector3 middleTopRight    = frontCoordinates.TopRight;
            Vector3 middleBottomRight = frontCoordinates.BottomRight;
            Vector3 middleBottomLeft  = frontCoordinates.BottomLeft;
            var     middleCoordinates = new FaceCoordinates(middleTopLeft, middleTopRight, middleBottomRight, middleBottomLeft);

            if (rotation > 0)
            {
                frontCoordinates  = RotateSlope(frontCoordinates, rotation);
                backCoordinates   = RotateSlope(backCoordinates, rotation);
                middleCoordinates = RotateSlope(middleCoordinates, rotation);
            }

            middleCoordinates.TopLeft.Z     -= slopeScalar * GlobalScalar.Z;
            middleCoordinates.TopRight.Z    -= slopeScalar * GlobalScalar.Z;
            middleCoordinates.BottomRight.Z -= slopeScalar * GlobalScalar.Z;
            middleCoordinates.BottomLeft.Z  -= slopeScalar * GlobalScalar.Z;

            //Lid face
            if (Lid)
            {
                RotationType lidRotation = Lid.Rotation;
                lidRotation = RotateEnum(lidRotation, rotation);
                Vector2[] texPos = textures.GetNormalTexture((UInt32)Lid.TileNumber, Lid.Rotation, Lid.Flip);
                Coors.Add(new VertexPositionNormalTexture(middleCoordinates.TopRight, Vector3.Zero, texPos[2]));
                Coors.Add(new VertexPositionNormalTexture(middleCoordinates.BottomRight, Vector3.Zero, texPos[1]));
                Coors.Add(new VertexPositionNormalTexture(backCoordinates.BottomLeft, Vector3.Zero, texPos[0]));
                Coors.Add(new VertexPositionNormalTexture(backCoordinates.TopLeft, Vector3.Zero, texPos[3]));

                int startIndex = Coors.Count - 4;
                IndexBufferCollection.Add(startIndex);
                IndexBufferCollection.Add(startIndex + 1);
                IndexBufferCollection.Add(startIndex + 2);
                IndexBufferCollection.Add(startIndex);
                IndexBufferCollection.Add(startIndex + 2);
                IndexBufferCollection.Add(startIndex + 3);
            }

            BlockFace topFace    = null;
            BlockFace bottomFace = null;
            BlockFace rightFace  = null;

            switch (rotation)
            {
            case 0:     //No rotation
                topFace    = Top;
                bottomFace = Bottom;
                rightFace  = Right;
                break;

            case 1:     //
                topFace    = Left;
                bottomFace = Right;
                rightFace  = Top;
                break;

            case 2:
                topFace    = Bottom;
                bottomFace = Top;
                rightFace  = Left;
                break;

            case 3:
                topFace    = Right;
                bottomFace = Left;
                rightFace  = Bottom;
                break;
            }

            //Top face
            if (topFace)
            {
                Vector2[] texPos = textures.GetNormalTexture((UInt32)topFace.TileNumber, topFace.Rotation, topFace.Flip);
                Vector2   center = GetCenterPosition(ref texPos[3], ref texPos[0], slopeScalar);
                Coors.Add(new VertexPositionNormalTexture(middleCoordinates.TopRight, Vector3.Zero, center));
                Coors.Add(new VertexPositionNormalTexture(backCoordinates.TopRight, Vector3.Zero, texPos[0]));
                Coors.Add(new VertexPositionNormalTexture(backCoordinates.TopLeft, Vector3.Zero, texPos[1]));

                int startIndex = Coors.Count - 3;
                IndexBufferCollection.Add(startIndex + 2);
                IndexBufferCollection.Add(startIndex + 1);
                IndexBufferCollection.Add(startIndex + 0);
            }
            //Bottom face
            if (bottomFace)
            {
                Vector2[] texPos = textures.GetNormalTexture((UInt32)bottomFace.TileNumber, bottomFace.Rotation, bottomFace.Flip);
                Vector2   center = GetCenterPosition(ref texPos[2], ref texPos[1], slopeScalar);
                Coors.Add(new VertexPositionNormalTexture(middleCoordinates.BottomRight, Vector3.Zero, center));
                Coors.Add(new VertexPositionNormalTexture(backCoordinates.BottomRight, Vector3.Zero, texPos[1]));
                Coors.Add(new VertexPositionNormalTexture(backCoordinates.BottomLeft, Vector3.Zero, texPos[0]));

                int startIndex = Coors.Count - 3;
                IndexBufferCollection.Add(startIndex);
                IndexBufferCollection.Add(startIndex + 1);
                IndexBufferCollection.Add(startIndex + 2);
            }

            //Right face
            if (rightFace) //this face is not supported by GTA2, the editor removes this face.
            {
                Vector2[] texPos = textures.GetNormalTexture((UInt32)rightFace.TileNumber, rightFace.Rotation, rightFace.Flip);
                Vector2   center = GetCenterPosition(ref texPos[1], ref texPos[2], slopeScalar);
                Coors.Add(new VertexPositionNormalTexture(middleCoordinates.TopRight, Vector3.Zero, center));
                center = GetCenterPosition(ref texPos[0], ref texPos[3], slopeScalar);
                Coors.Add(new VertexPositionNormalTexture(middleCoordinates.BottomRight, Vector3.Zero, center));
                Coors.Add(new VertexPositionNormalTexture(backCoordinates.BottomRight, Vector3.Zero, texPos[3]));
                Coors.Add(new VertexPositionNormalTexture(backCoordinates.TopRight, Vector3.Zero, texPos[2]));

                int startIndex = Coors.Count - 4;
                IndexBufferCollection.Add(startIndex + 2);
                IndexBufferCollection.Add(startIndex + 1);
                IndexBufferCollection.Add(startIndex + 0);
                IndexBufferCollection.Add(startIndex);
                IndexBufferCollection.Add(startIndex + 3);
                IndexBufferCollection.Add(startIndex + 2);
            }
        }
Пример #5
0
        protected void SetUpSlopeHigh(byte subType, byte rotation)
        {
            //Sample is a right slope, use it for orientation, it gets rotated to fit all other directions
            FaceCoordinates frontCoordinates;
            FaceCoordinates backCoordinates;

            PrepareCoordinates(out frontCoordinates, out backCoordinates);

            float middleSlopeScalar = 1f;
            float frontSlopeScalar  = 0f;

            switch (subType)
            {
            case 26:
                middleSlopeScalar = 0.5f;
                frontSlopeScalar  = 0;
                break;

            case 7:
                middleSlopeScalar = 0.875f;
                frontSlopeScalar  = 0.75f;
                break;

            case 8:
                middleSlopeScalar = 0.75f;
                frontSlopeScalar  = 0.625f;
                break;

            case 9:
                middleSlopeScalar = 0.625f;
                frontSlopeScalar  = 0.5f;
                break;

            case 10:
                middleSlopeScalar = 0.5f;
                frontSlopeScalar  = 0.375f;
                break;

            case 11:
                middleSlopeScalar = 0.375f;
                frontSlopeScalar  = 0.25f;
                break;

            case 12:
                middleSlopeScalar = 0.25f;
                frontSlopeScalar  = 0.125f;
                break;

            case 13:
                middleSlopeScalar = 0.125f;
                frontSlopeScalar  = 0;
                break;
            }

            Vector3 middleTopLeft     = frontCoordinates.TopLeft;
            Vector3 middleTopRight    = frontCoordinates.TopRight;
            Vector3 middleBottomRight = frontCoordinates.BottomRight;
            Vector3 middleBottomLeft  = frontCoordinates.BottomLeft;
            var     middleCoordinates = new FaceCoordinates(middleTopLeft, middleTopRight, middleBottomRight, middleBottomLeft);

            if (rotation > 0)
            {
                frontCoordinates  = RotateSlope(frontCoordinates, rotation);
                backCoordinates   = RotateSlope(backCoordinates, rotation);
                middleCoordinates = RotateSlope(middleCoordinates, rotation);
            }

            frontCoordinates.TopLeft.Z     -= frontSlopeScalar * GlobalScalar.Z;
            frontCoordinates.TopRight.Z    -= frontSlopeScalar * GlobalScalar.Z;
            frontCoordinates.BottomRight.Z -= frontSlopeScalar * GlobalScalar.Z;
            frontCoordinates.BottomLeft.Z  -= frontSlopeScalar * GlobalScalar.Z;

            middleCoordinates.TopLeft.Z     -= middleSlopeScalar * GlobalScalar.Z;
            middleCoordinates.TopRight.Z    -= middleSlopeScalar * GlobalScalar.Z;
            middleCoordinates.BottomRight.Z -= middleSlopeScalar * GlobalScalar.Z;
            middleCoordinates.BottomLeft.Z  -= middleSlopeScalar * GlobalScalar.Z;

            //Front face (diagonal)
            if (Lid.TileNumber > 0)
            {
                RotationType lidRotation = Lid.Rotation;
                lidRotation = RotateEnum(lidRotation, rotation);
                Vector2[] texPos = textures.GetNormalTexture((UInt32)Lid.TileNumber, Lid.Rotation, Lid.Flip);
                Coors.Add(new VertexPositionNormalTexture(frontCoordinates.TopRight, Vector3.Zero, texPos[2]));
                Coors.Add(new VertexPositionNormalTexture(frontCoordinates.BottomRight, Vector3.Zero, texPos[1]));
                Coors.Add(new VertexPositionNormalTexture(middleCoordinates.BottomLeft, Vector3.Zero, texPos[0]));
                Coors.Add(new VertexPositionNormalTexture(middleCoordinates.TopLeft, Vector3.Zero, texPos[3]));

                int startIndex = Coors.Count - 4;
                IndexBufferCollection.Add(startIndex + 0);
                IndexBufferCollection.Add(startIndex + 1);
                IndexBufferCollection.Add(startIndex + 2);
                IndexBufferCollection.Add(startIndex + 0);
                IndexBufferCollection.Add(startIndex + 2);
                IndexBufferCollection.Add(startIndex + 3);
            }

            BlockFace topFace    = null;
            BlockFace bottomFace = null;
            BlockFace leftFace   = null;
            BlockFace rightFace  = null;

            switch (rotation)
            {
            case 0:
                topFace    = Top;
                bottomFace = Bottom;
                leftFace   = Left;
                rightFace  = Right;
                break;

            case 1:
                topFace    = Left;
                bottomFace = Right;
                leftFace   = Bottom;
                rightFace  = Top;
                break;

            case 2:
                topFace    = Bottom;
                bottomFace = Top;
                leftFace   = Right;
                rightFace  = Left;
                break;

            case 3:
                topFace    = Right;
                bottomFace = Left;
                leftFace   = Top;
                rightFace  = Bottom;
                break;
            }

            //Top face
            if (topFace)
            {
                Vector2[] texPos = textures.GetNormalTexture((UInt32)topFace.TileNumber, topFace.Rotation, topFace.Flip);
                Vector2   center = GetCenterPosition(ref texPos[0], ref texPos[3], frontSlopeScalar);
                Coors.Add(new VertexPositionNormalTexture(frontCoordinates.TopRight, Vector3.Zero, center)); //was 3
                Coors.Add(new VertexPositionNormalTexture(backCoordinates.TopRight, Vector3.Zero, texPos[0]));
                Coors.Add(new VertexPositionNormalTexture(backCoordinates.TopLeft, Vector3.Zero, texPos[1]));
                center = GetCenterPosition(ref texPos[1], ref texPos[2], middleSlopeScalar);
                Coors.Add(new VertexPositionNormalTexture(middleCoordinates.TopLeft, Vector3.Zero, center));

                int startIndex = Coors.Count - 4;
                IndexBufferCollection.Add(startIndex + 2);
                IndexBufferCollection.Add(startIndex + 1);
                IndexBufferCollection.Add(startIndex + 0);

                IndexBufferCollection.Add(startIndex + 3);
                IndexBufferCollection.Add(startIndex + 2);
                IndexBufferCollection.Add(startIndex + 0);
            }
            //Bottom face
            if (bottomFace)
            {
                Vector2[] texPos = textures.GetNormalTexture((UInt32)bottomFace.TileNumber, bottomFace.Rotation, bottomFace.Flip);
                Vector2   center = GetCenterPosition(ref texPos[2], ref texPos[1], frontSlopeScalar);
                Coors.Add(new VertexPositionNormalTexture(frontCoordinates.BottomRight, Vector3.Zero, center)); //was texPos[2]
                Coors.Add(new VertexPositionNormalTexture(backCoordinates.BottomRight, Vector3.Zero, texPos[1]));
                Coors.Add(new VertexPositionNormalTexture(backCoordinates.BottomLeft, Vector3.Zero, texPos[0]));
                center = GetCenterPosition(ref texPos[3], ref texPos[0], middleSlopeScalar);
                Coors.Add(new VertexPositionNormalTexture(middleCoordinates.BottomLeft, Vector3.Zero, center));

                int startIndex = Coors.Count - 4;
                IndexBufferCollection.Add(startIndex);
                IndexBufferCollection.Add(startIndex + 1);
                IndexBufferCollection.Add(startIndex + 2);

                IndexBufferCollection.Add(startIndex + 0);
                IndexBufferCollection.Add(startIndex + 2);
                IndexBufferCollection.Add(startIndex + 3);
            }

            //ToDo Left face (but probably not supported in GTA2 anyway)

            //Right face
            Vector2[] texture = textures.GetNormalTexture((UInt32)Right.TileNumber, Right.Rotation, Right.Flip);
            CreateRightVertices(frontCoordinates, backCoordinates, texture);
        }