Beispiel #1
0
        public Building(Game game)
            : base(game)
        {
            Model = CreateBuildingModelAuto(game, game.GraphicsDevice);

            effect = new BasicEffect(game.GraphicsDevice, new EffectPool());
            effect.DiffuseColor = Color.Gray.ToVector3();
            effect.EnableDefaultLighting();
            effect.PreferPerPixelLighting = true;

            vpntDec = new VertexDeclaration(game.GraphicsDevice, VertexPositionNormalTexture.VertexElements);

            this.CollisionType = EntityCollisionType.BuildingSpecial;

            //texture = new Texture2D(game.GraphicsDevice,
        }
Beispiel #2
0
        public Building(Game game)
            : base(game)
        {
            Model = CreateBuildingModelAuto(game, game.GraphicsDevice);

            effect = new BasicEffect(game.GraphicsDevice, new EffectPool());
            effect.DiffuseColor = Color.Gray.ToVector3();
            effect.EnableDefaultLighting();
            effect.PreferPerPixelLighting = true;

            vpntDec = new VertexDeclaration(game.GraphicsDevice, VertexPositionNormalTexture.VertexElements);

            this.CollisionType = EntityCollisionType.BuildingSpecial;

            //texture = new Texture2D(game.GraphicsDevice,
        }
Beispiel #3
0
        // TODO: Use a fat indexbuffer instead, or render using the same vertex buffer and different world matrices. idk...
        private static BuildingModel CreateBuildingModelAuto(Game game, GraphicsDevice gd)
        {
            List <BoundingBox> lbb = GenerateBuilding();

            BuildingModel bm = new BuildingModel();

            //BoundingBox ground = new BoundingBox(new Vector3(-384, -20, -384), new Vector3(384, 0, 384));
            //lbb.Add(ground);

            List <BuildingModelPart> lbmp = new List <BuildingModelPart>();

            VertexBuffer vb = new VertexBuffer(gd, new VertexPositionNormalTexture().GetType(), 36 * lbb.Count, BufferUsage.WriteOnly);

            int v = 0;

            foreach (BoundingBox bb in lbb)
            {
                BuildingModelPart bmp = new BuildingModelPart(game);
                bmp.BoundingBox = bb;
                bmp.StartVertex = v;
                bmp.VertexCount = 36;

                VertexPositionNormalTexture[] lvpc = new VertexPositionNormalTexture[36];

                Vector3[] vpos = new Vector3[36];

                // ccw draw -- build all triangles going counterclockwise.
                // FRONT
                vpos[0] = new Vector3(bb.Min.X, bb.Min.Y, bb.Min.Z);
                vpos[1] = vpos[4] = new Vector3(bb.Max.X, bb.Min.Y, bb.Min.Z);
                vpos[2] = vpos[3] = new Vector3(bb.Min.X, bb.Max.Y, bb.Min.Z);
                vpos[5] = new Vector3(bb.Max.X, bb.Max.Y, bb.Min.Z);

                // BACK
                vpos[6]  = vpos[11] = new Vector3(bb.Max.X, bb.Min.Y, bb.Max.Z);
                vpos[7]  = new Vector3(bb.Max.X, bb.Max.Y, bb.Max.Z);
                vpos[8]  = vpos[9] = new Vector3(bb.Min.X, bb.Max.Y, bb.Max.Z);
                vpos[10] = new Vector3(bb.Min.X, bb.Min.Y, bb.Max.Z);

                // TOP
                vpos[12] = new Vector3(bb.Min.X, bb.Max.Y, bb.Min.Z);
                vpos[13] = vpos[16] = new Vector3(bb.Max.X, bb.Max.Y, bb.Min.Z);
                vpos[14] = vpos[15] = new Vector3(bb.Min.X, bb.Max.Y, bb.Max.Z);
                vpos[17] = new Vector3(bb.Max.X, bb.Max.Y, bb.Max.Z);

                // BOTTOM
                vpos[18] = new Vector3(bb.Min.X, bb.Min.Y, bb.Min.Z);
                vpos[19] = vpos[22] = new Vector3(bb.Max.X, bb.Min.Y, bb.Min.Z);
                vpos[20] = vpos[21] = new Vector3(bb.Min.X, bb.Min.Y, bb.Max.Z);
                vpos[23] = new Vector3(bb.Max.X, bb.Min.Y, bb.Max.Z);

                // LEFT
                vpos[24] = new Vector3(bb.Min.X, bb.Min.Y, bb.Max.Z);
                vpos[25] = vpos[28] = new Vector3(bb.Min.X, bb.Min.Y, bb.Min.Z);
                vpos[26] = vpos[27] = new Vector3(bb.Min.X, bb.Max.Y, bb.Max.Z);
                vpos[29] = new Vector3(bb.Min.X, bb.Max.Y, bb.Min.Z);

                // RIGHT
                vpos[30] = new Vector3(bb.Max.X, bb.Min.Y, bb.Min.Z);
                vpos[31] = vpos[34] = new Vector3(bb.Max.X, bb.Min.Y, bb.Max.Z);
                vpos[32] = vpos[33] = new Vector3(bb.Max.X, bb.Max.Y, bb.Min.Z);
                vpos[35] = new Vector3(bb.Max.X, bb.Max.Y, bb.Max.Z);

                for (int i = 0; i < 36; i++)
                {
                    Vector3 normal;

                    switch ((i - (i % 6)) / 6)
                    {
                    case 0:     //Front!
                        normal = new Vector3(0f, 0f, -1f);
                        break;

                    case 1:     // Back!
                        normal = new Vector3(0f, 0f, 1f);
                        break;

                    case 2:     // Top!
                        normal = new Vector3(0f, 1f, 0f);
                        break;

                    case 3:     // Bottom!
                        normal = new Vector3(0f, -1f, 0f);
                        break;

                    case 4:     // Left!
                        normal = new Vector3(-1f, 0f, 0f);
                        break;

                    case 5:     // Right!
                        normal = new Vector3(1f, 0f, 0f);
                        break;

                    default:
                        throw new Exception("calc fail");
                    }

                    lvpc[i] = new VertexPositionNormalTexture(vpos[i], normal, Vector2.Zero);
                }


                vb.SetData <VertexPositionNormalTexture>(VertexPositionNormalTexture.SizeInBytes * v, lvpc, 0, lvpc.Length, VertexPositionNormalTexture.SizeInBytes);

                v += 36;

                lbmp.Add(bmp);
            }

            bm.ModelParts   = lbmp.ToArray();
            bm.VertexBuffer = vb;

            return(bm);
        }
Beispiel #4
0
        // TODO: Use a fat indexbuffer instead, or render using the same vertex buffer and different world matrices. idk...
        private static BuildingModel CreateBuildingModelAuto(Game game, GraphicsDevice gd)
        {
            List<BoundingBox> lbb = GenerateBuilding();

            BuildingModel bm = new BuildingModel();

            //BoundingBox ground = new BoundingBox(new Vector3(-384, -20, -384), new Vector3(384, 0, 384));
            //lbb.Add(ground);

            List<BuildingModelPart> lbmp = new List<BuildingModelPart>();

            VertexBuffer vb = new VertexBuffer(gd, new VertexPositionNormalTexture().GetType(), 36 * lbb.Count, BufferUsage.WriteOnly);

            int v = 0;

            foreach (BoundingBox bb in lbb)
            {
                BuildingModelPart bmp = new BuildingModelPart(game);
                bmp.BoundingBox = bb;
                bmp.StartVertex = v;
                bmp.VertexCount = 36;

                VertexPositionNormalTexture[] lvpc = new VertexPositionNormalTexture[36];

                Vector3[] vpos = new Vector3[36];

                // ccw draw -- build all triangles going counterclockwise.
                // FRONT
                vpos[0] = new Vector3(bb.Min.X, bb.Min.Y, bb.Min.Z);
                vpos[1] = vpos[4] = new Vector3(bb.Max.X, bb.Min.Y, bb.Min.Z);
                vpos[2] = vpos[3] = new Vector3(bb.Min.X, bb.Max.Y, bb.Min.Z);
                vpos[5] = new Vector3(bb.Max.X, bb.Max.Y, bb.Min.Z);

                // BACK
                vpos[6] = vpos[11] = new Vector3(bb.Max.X, bb.Min.Y, bb.Max.Z);
                vpos[7] = new Vector3(bb.Max.X, bb.Max.Y, bb.Max.Z);
                vpos[8] = vpos[9] = new Vector3(bb.Min.X, bb.Max.Y, bb.Max.Z);
                vpos[10] = new Vector3(bb.Min.X, bb.Min.Y, bb.Max.Z);

                // TOP
                vpos[12] = new Vector3(bb.Min.X, bb.Max.Y, bb.Min.Z);
                vpos[13] = vpos[16] = new Vector3(bb.Max.X, bb.Max.Y, bb.Min.Z);
                vpos[14] = vpos[15] = new Vector3(bb.Min.X, bb.Max.Y, bb.Max.Z);
                vpos[17] = new Vector3(bb.Max.X, bb.Max.Y, bb.Max.Z);

                // BOTTOM
                vpos[18] = new Vector3(bb.Min.X, bb.Min.Y, bb.Min.Z);
                vpos[19] = vpos[22] = new Vector3(bb.Max.X, bb.Min.Y, bb.Min.Z);
                vpos[20] = vpos[21] = new Vector3(bb.Min.X, bb.Min.Y, bb.Max.Z);
                vpos[23] = new Vector3(bb.Max.X, bb.Min.Y, bb.Max.Z);

                // LEFT
                vpos[24] = new Vector3(bb.Min.X, bb.Min.Y, bb.Max.Z);
                vpos[25] = vpos[28] = new Vector3(bb.Min.X, bb.Min.Y, bb.Min.Z);
                vpos[26] = vpos[27] = new Vector3(bb.Min.X, bb.Max.Y, bb.Max.Z);
                vpos[29] = new Vector3(bb.Min.X, bb.Max.Y, bb.Min.Z);

                // RIGHT
                vpos[30] = new Vector3(bb.Max.X, bb.Min.Y, bb.Min.Z);
                vpos[31] = vpos[34] = new Vector3(bb.Max.X, bb.Min.Y, bb.Max.Z);
                vpos[32] = vpos[33] = new Vector3(bb.Max.X, bb.Max.Y, bb.Min.Z);
                vpos[35] = new Vector3(bb.Max.X, bb.Max.Y, bb.Max.Z);

                for (int i = 0; i < 36; i++)
                {
                    Vector3 normal;

                    switch ((i - (i % 6)) / 6)
                    {
                        case 0: //Front!
                            normal = new Vector3(0f, 0f, -1f);
                            break;
                        case 1: // Back!
                            normal = new Vector3(0f, 0f, 1f);
                            break;
                        case 2: // Top!
                            normal = new Vector3(0f, 1f, 0f);
                            break;
                        case 3: // Bottom!
                            normal = new Vector3(0f, -1f, 0f);
                            break;
                        case 4: // Left!
                            normal = new Vector3(-1f, 0f, 0f);
                            break;
                        case 5: // Right!
                            normal = new Vector3(1f, 0f, 0f);
                            break;
                        default:
                            throw new Exception("calc fail");
                    }

                    lvpc[i] = new VertexPositionNormalTexture(vpos[i], normal, Vector2.Zero);
                }

                vb.SetData<VertexPositionNormalTexture>(VertexPositionNormalTexture.SizeInBytes * v, lvpc, 0, lvpc.Length, VertexPositionNormalTexture.SizeInBytes);

                v += 36;

                lbmp.Add(bmp);
            }

            bm.ModelParts = lbmp.ToArray();
            bm.VertexBuffer = vb;

            return bm;
        }