Exemplo n.º 1
0
        public static GeometryModel Cube(string texLeft, string texBottom, string texFront,
                                         string texRight, string texTop, string texBack)
        {
            GeometryModel cube = new GeometryModel();

            cube.AddFace(new ModelFace(texLeft, new float[]
            {
                0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
                0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
                0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
            }), Face.Left);
            cube.AddFace(new ModelFace(texBottom, new float[]
            {
                0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
                1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
                1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
                0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
            }), Face.Bottom);
            cube.AddFace(new ModelFace(texFront, new float[]
            {
                0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
                0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
                1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
            }), Face.Front);
            cube.AddFace(new ModelFace(texRight, new float[]
            {
                1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
                1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
            }), Face.Right);
            cube.AddFace(new ModelFace(texTop, new float[]
            {
                0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
                0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
            }), Face.Top);
            cube.AddFace(new ModelFace(texBack, new float[]
            {
                1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
                1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                0.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
            }), Face.Back);

            return(cube);
        }
Exemplo n.º 2
0
        public static GeometryModel Terrain( TerrainCorner highCorners, string texTop, string texTopTri, string texWall, string texWallTri,
            string texBottom)
        {
            Vector2 pfl = new Vector2( 0.0f, 0.0f );
            Vector2 pfr = new Vector2( 1.0f, 0.0f );
            Vector2 pbl = new Vector2( 0.0f, 1.0f );
            Vector2 pbr = new Vector2( 1.0f, 1.0f );

            bool bfl = ( highCorners & TerrainCorner.FrontLeft  ) != 0;
            bool bfr = ( highCorners & TerrainCorner.FrontRight ) != 0;
            bool bbl = ( highCorners & TerrainCorner.BackLeft   ) != 0;
            bool bbr = ( highCorners & TerrainCorner.BackRight  ) != 0;

            float hfl = bfl ? 1.0f : 0.0f;
            float hfr = bfr ? 1.0f : 0.0f;
            float hbl = bbl ? 1.0f : 0.0f;
            float hbr = bbr ? 1.0f : 0.0f;

            Tuple<Face,Vector2,Vector2,float,float>[] faces = new Tuple<Face,Vector2,Vector2,float,float>[]
            {
                new Tuple<Face,Vector2,Vector2,float,float>
                ( Face.Left, pbl, pfl, hbl, hfl ),
                new Tuple<Face,Vector2,Vector2,float,float>
                ( Face.Front, pfl, pfr, hfl, hfr ),
                new Tuple<Face,Vector2,Vector2,float,float>
                ( Face.Right, pfr, pbr, hfr, hbr ),
                new Tuple<Face,Vector2,Vector2,float,float>
                ( Face.Back, pbr, pbl, hbr, hbl )
            };

            GeometryModel mdl = new GeometryModel();

            foreach( Tuple<Face,Vector2,Vector2,float,float> face in faces )
            {
                if( face.Item4 == 0.0f && face.Item5 == 0.0f )
                    continue;

                ModelFace mf;
                if( face.Item4 == 0.0f || face.Item5 == 0.0f )
                {
                    Vector2 corner = face.Item4 == 0.0f ? face.Item3 : face.Item2;

                    mf = new ModelFace( texWallTri, new float[]
                    {
                        face.Item2.X, face.Item4, face.Item2.Y, 0.0f, face.Item4,
                        face.Item3.X, face.Item5, face.Item3.Y, 1.0f, face.Item5,
                        corner.X, 0.0f, corner.Y, face.Item4 == 0.0f ? 1.0f : 0.0f, 0.0f
                    } );
                }
                else
                {
                    mf = new ModelFace( texWall, new float[]
                    {
                        face.Item2.X, face.Item4, face.Item2.Y, 0.0f, face.Item4,
                        face.Item3.X, face.Item5, face.Item3.Y, 1.0f, face.Item5,
                        face.Item3.X, 0.0f, face.Item3.Y, 1.0f, 0.0f,
                        face.Item2.X, 0.0f, face.Item2.Y, 0.0f, 0.0f
                    } );
                }
                mdl.AddFace( mf, face.Item1 );
            }

            bool tri = (int) highCorners % 3 > 0;

            if ( !( !bfr && !bbl && ( bfl ^ bbr ) )
                && !( bfr && bbl && ( !bfl || !bbr ) ) )
            {
                mdl.AddFace( new ModelFace( tri ? texTopTri : texTop, new float[]
                {
                    pbl.X, hbl, pbl.Y, 0.0f, 0.0f,
                    pbr.X, hbr, pbr.Y, 1.0f, 0.0f,
                    pfr.X, hfr, pfr.Y, 1.0f, 1.0f,
                } ), bbl && bbr && bfr ? Face.Top : Face.All );
                mdl.AddFace( new ModelFace( tri ? texTopTri : texTop, new float[]
                {
                    pbl.X, hbl, pbl.Y, 0.0f, 0.0f,
                    pfr.X, hfr, pfr.Y, 1.0f, 1.0f,
                    pfl.X, hfl, pfl.Y, 0.0f, 1.0f
                } ), bbl && bfl && bfr ? Face.Top : Face.All );
            }
            else
            {
                mdl.AddFace( new ModelFace( tri ? texTopTri : texTop, new float[]
                {
                    pbr.X, hbr, pbr.Y, 0.0f, 0.0f,
                    pfr.X, hfr, pfr.Y, 1.0f, 0.0f,
                    pfl.X, hfl, pfl.Y, 1.0f, 1.0f,
                } ), bbr && bfr && bfl ? Face.Top : Face.All );
                mdl.AddFace( new ModelFace( tri ? texTopTri : texTop, new float[]
                {
                    pbr.X, hbr, pbr.Y, 0.0f, 0.0f,
                    pfl.X, hfl, pfl.Y, 1.0f, 1.0f,
                    pbl.X, hbl, pbl.Y, 0.0f, 1.0f
                } ), bbr && bfl && bbl ? Face.Top : Face.All );
            }

            return mdl;
        }
Exemplo n.º 3
0
        public static GeometryModel Cube( string texLeft, string texBottom, string texFront,
            string texRight, string texTop, string texBack)
        {
            GeometryModel cube = new GeometryModel();

            cube.AddFace( new ModelFace( texLeft, new float[]
            {
                0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
                0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
                0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
            } ), Face.Left );
            cube.AddFace( new ModelFace( texBottom, new float[]
            {
                0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
                1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
                1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
                0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
            } ), Face.Bottom );
            cube.AddFace( new ModelFace( texFront, new float[]
            {
                0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
                0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
                1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
            } ), Face.Front );
            cube.AddFace( new ModelFace( texRight, new float[]
            {
                1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
                1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
            } ), Face.Right );
            cube.AddFace( new ModelFace( texTop, new float[]
            {
                0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
                0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
            } ), Face.Top );
            cube.AddFace( new ModelFace( texBack, new float[]
            {
                1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
                1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                0.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
            } ), Face.Back );

            return cube;
        }
Exemplo n.º 4
0
        public static GeometryModel Terrain(TerrainCorner highCorners, string texTop, string texTopTri, string texWall, string texWallTri,
                                            string texBottom)
        {
            Vector2 pfl = new Vector2(0.0f, 0.0f);
            Vector2 pfr = new Vector2(1.0f, 0.0f);
            Vector2 pbl = new Vector2(0.0f, 1.0f);
            Vector2 pbr = new Vector2(1.0f, 1.0f);

            bool bfl = (highCorners & TerrainCorner.FrontLeft) != 0;
            bool bfr = (highCorners & TerrainCorner.FrontRight) != 0;
            bool bbl = (highCorners & TerrainCorner.BackLeft) != 0;
            bool bbr = (highCorners & TerrainCorner.BackRight) != 0;

            float hfl = bfl ? 1.0f : 0.0f;
            float hfr = bfr ? 1.0f : 0.0f;
            float hbl = bbl ? 1.0f : 0.0f;
            float hbr = bbr ? 1.0f : 0.0f;

            Tuple <Face, Vector2, Vector2, float, float>[] faces = new Tuple <Face, Vector2, Vector2, float, float>[]
            {
                new Tuple <Face, Vector2, Vector2, float, float>
                    (Face.Left, pbl, pfl, hbl, hfl),
                new Tuple <Face, Vector2, Vector2, float, float>
                    (Face.Front, pfl, pfr, hfl, hfr),
                new Tuple <Face, Vector2, Vector2, float, float>
                    (Face.Right, pfr, pbr, hfr, hbr),
                new Tuple <Face, Vector2, Vector2, float, float>
                    (Face.Back, pbr, pbl, hbr, hbl)
            };

            GeometryModel mdl = new GeometryModel();

            foreach (Tuple <Face, Vector2, Vector2, float, float> face in faces)
            {
                if (face.Item4 == 0.0f && face.Item5 == 0.0f)
                {
                    continue;
                }

                ModelFace mf;
                if (face.Item4 == 0.0f || face.Item5 == 0.0f)
                {
                    Vector2 corner = face.Item4 == 0.0f ? face.Item3 : face.Item2;

                    mf = new ModelFace(texWallTri, new float[]
                    {
                        face.Item2.X, face.Item4, face.Item2.Y, 0.0f, face.Item4,
                        face.Item3.X, face.Item5, face.Item3.Y, 1.0f, face.Item5,
                        corner.X, 0.0f, corner.Y, face.Item4 == 0.0f ? 1.0f : 0.0f, 0.0f
                    });
                }
                else
                {
                    mf = new ModelFace(texWall, new float[]
                    {
                        face.Item2.X, face.Item4, face.Item2.Y, 0.0f, face.Item4,
                        face.Item3.X, face.Item5, face.Item3.Y, 1.0f, face.Item5,
                        face.Item3.X, 0.0f, face.Item3.Y, 1.0f, 0.0f,
                        face.Item2.X, 0.0f, face.Item2.Y, 0.0f, 0.0f
                    });
                }
                mdl.AddFace(mf, face.Item1);
            }

            bool tri = (int)highCorners % 3 > 0;

            if (!(!bfr && !bbl && (bfl ^ bbr)) &&
                !(bfr && bbl && (!bfl || !bbr)))
            {
                mdl.AddFace(new ModelFace(tri ? texTopTri : texTop, new float[]
                {
                    pbl.X, hbl, pbl.Y, 0.0f, 0.0f,
                    pbr.X, hbr, pbr.Y, 1.0f, 0.0f,
                    pfr.X, hfr, pfr.Y, 1.0f, 1.0f,
                }), bbl && bbr && bfr ? Face.Top : Face.All);
                mdl.AddFace(new ModelFace(tri ? texTopTri : texTop, new float[]
                {
                    pbl.X, hbl, pbl.Y, 0.0f, 0.0f,
                    pfr.X, hfr, pfr.Y, 1.0f, 1.0f,
                    pfl.X, hfl, pfl.Y, 0.0f, 1.0f
                }), bbl && bfl && bfr ? Face.Top : Face.All);
            }
            else
            {
                mdl.AddFace(new ModelFace(tri ? texTopTri : texTop, new float[]
                {
                    pbr.X, hbr, pbr.Y, 0.0f, 0.0f,
                    pfr.X, hfr, pfr.Y, 1.0f, 0.0f,
                    pfl.X, hfl, pfl.Y, 1.0f, 1.0f,
                }), bbr && bfr && bfl ? Face.Top : Face.All);
                mdl.AddFace(new ModelFace(tri ? texTopTri : texTop, new float[]
                {
                    pbr.X, hbr, pbr.Y, 0.0f, 0.0f,
                    pfl.X, hfl, pfl.Y, 1.0f, 1.0f,
                    pbl.X, hbl, pbl.Y, 0.0f, 1.0f
                }), bbr && bfl && bbl ? Face.Top : Face.All);
            }

            return(mdl);
        }