示例#1
0
        public void Update(GameTime gameTime)
        {
            UpdateCamera();

            if (Map.CursorPositionVisible.X < 0)
            {
                Camera.CameraHeight   = 600;
                Camera.CameraDistance = 500;
                Camera.SetTarget(new Vector3(Map.TileSize.X * Map.MapSize.X / 2, Map.CursorPosition.Z * 32, Map.TileSize.Y * Map.MapSize.Y / 2));
                Camera.Update(gameTime);
                return;
            }

            Camera.CameraHeight   = 400;
            Camera.CameraDistance = 300;
            int          X               = (int)Map.CursorPositionVisible.X;
            int          Y               = (int)Map.CursorPositionVisible.Y;
            float        Z               = Map.LayerManager.ListLayer[(int)Map.CursorPosition.Z].ArrayTerrain[X, Y].Position.Z * 32 + (Map.CursorPosition.Z * 32) + 0.3f;
            Map2D        GroundLayer     = Map.LayerManager.ListLayer[(int)Map.CursorPosition.Z].LayerGrid;
            DrawableTile ActiveTerrain   = GroundLayer.GetTile(X, Y);
            Terrain3D    ActiveTerrain3D = ActiveTerrain.Terrain3DInfo;

            Cursor = ActiveTerrain3D.CreateTile3D(0, Point.Zero,
                                                  X * Map.TileSize.X, Y * Map.TileSize.Y, Z, Map.CursorPosition.Z * 32 + 0.3f, Map.TileSize, new List <Texture2D>()
            {
                sprCursor
            }, Z, Z, Z, Z, 0)[0];

            Camera.SetTarget(new Vector3(Map.TileSize.X * Map.CursorPositionVisible.X, Map.CursorPosition.Z * 32, Map.TileSize.Y * Map.CursorPositionVisible.Y));
            Camera.Update(gameTime);

            DicDrawablePointPerColor.Clear();
            ListDrawableArrowPerColor.Clear();
        }
示例#2
0
        public Map3D(DeathmatchMap Map, GraphicsDevice g)
        {
            this.Map  = Map;
            Random    = new Random();
            sprCursor = Map.sprCursor;
            Camera    = new DeathmatchCamera(g);
            Radius    = (Map.MapSize.X * Map.TileSize.X) / 2;

            PolygonEffect = new BasicEffect(g);

            PolygonEffect.VertexColorEnabled = true;
            PolygonEffect.TextureEnabled     = true;

            float aspectRatio = g.Viewport.Width / (float)g.Viewport.Height;

            Matrix Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                    aspectRatio,
                                                                    1, 10000);

            PolygonEffect.Projection = Projection;

            PolygonEffect.World = Matrix.Identity;
            PolygonEffect.View  = Matrix.Identity;

            DicDrawablePointPerColor = new Dictionary <Color, List <Tile3D> >();
            DicTile3D = new Dictionary <Texture2D, List <Tile3D> >();

            CreateMap(Map);

            Cursor = CreateCursor(Map, Map.CursorPositionVisible.X, Map.CursorPositionVisible.Y, sprCursor.Width, sprCursor.Height, Radius);
        }
示例#3
0
        public void Update(GameTime gameTime)
        {
            Cursor = CreateCursor(Map, Map.CursorPositionVisible.X, Map.CursorPositionVisible.Y, sprCursor.Width, sprCursor.Height, Radius);
            Camera.TeleportCamera(new Vector3(Map.CursorPosition.X * Map.TileSize.X - Radius, Radius * 1.2f + 200, 200 - Radius * 0.9f + Map.CursorPosition.Y * Map.TileSize.Y));
            Camera.SetRotation(0, (float)-Math.PI / 4f, 0f);
            Camera.Update(gameTime);

            DicDrawablePointPerColor.Clear();
        }
        private void CreateFlatElevation(DeathmatchMap Map, Texture2D TileSet, Tile3D ActiveTile, int X, int Y)
        {
            Vector3 A = ActiveTile.ArrayVertex[0].Position;
            Vector3 B = ActiveTile.ArrayVertex[1].Position;
            Vector3 C = ActiveTile.ArrayVertex[2].Position;
            Vector3 D = ActiveTile.ArrayVertex[3].Position;

            Vector3 Normal = Vector3.Cross(C - B, B - A);

            Normal.Normalize();

            float Z = Map.GetTerrain(X, Y, Map.ActiveLayerIndex).Position.Z;

            for (int V = ActiveTile.ArrayVertex.Length - 1; V >= 0; --V)
            {
                ActiveTile.ArrayVertex[V].Position += Normal * Z;
            }

            //Create slope right
            if (X + 1 < Map.MapSize.X)
            {
                float ZRight = Map.GetTerrain(X + 1, Y, Map.ActiveLayerIndex).Position.Z;

                if (Z != ZRight)
                {
                    Vector3[] ArrayVertexPositionRight = new Vector3[4];
                    ArrayVertexPositionRight[0] = ActiveTile.ArrayVertex[1].Position;
                    ArrayVertexPositionRight[2] = ActiveTile.ArrayVertex[3].Position;
                    ArrayVertexPositionRight[1] = B + Normal * ZRight;
                    ArrayVertexPositionRight[3] = D + Normal * ZRight;

                    Tile3D NewTile = CreateTile(Map, TileSet, ArrayVertexPositionRight, X, Y);
                    CreateCubicTile(Map, TileSet, NewTile);
                }
            }

            //Create slope down
            if (Y + 1 < Map.MapSize.Y)
            {
                float ZDown = Map.GetTerrain(X, Y + 1, Map.ActiveLayerIndex).Position.Z;

                if (Z != ZDown)
                {
                    Vector3[] ArrayVertexPositionDown = new Vector3[4];
                    ArrayVertexPositionDown[0] = ActiveTile.ArrayVertex[2].Position;
                    ArrayVertexPositionDown[1] = ActiveTile.ArrayVertex[3].Position;
                    ArrayVertexPositionDown[2] = C + Normal * ZDown;
                    ArrayVertexPositionDown[3] = D + Normal * ZDown;

                    Tile3D NewTile = CreateTile(Map, TileSet, ArrayVertexPositionDown, X, Y);
                    CreateCubicTile(Map, TileSet, NewTile);
                }
            }
        }
        private Tile3D CreateTile(DeathmatchMap Map, Texture2D ActiveTileset, Vector3[] ArrayVertexPosition, int X, int Y)
        {
            //Add and remove a half pixel offset to avoid texture bleeding.
            VertexPositionColorTexture[] ArrayVertex = new VertexPositionColorTexture[4];
            Map2D        GroundLayer   = Map.ListLayer[0].OriginalLayerGrid;
            DrawableTile ActiveTerrain = GroundLayer.GetTile(X, Y);
            float        UVXValue      = ActiveTerrain.Origin.X + 0.5f;
            float        UVYValue      = ActiveTerrain.Origin.Y + 0.5f;
            Vector2      TextureSize   = new Vector2(ActiveTileset.Width, ActiveTileset.Height);

            ArrayVertex[0]                   = new VertexPositionColorTexture();
            ArrayVertex[0].Position          = ArrayVertexPosition[0];
            ArrayVertex[0].TextureCoordinate = new Vector2(UVXValue / TextureSize.X, UVYValue / TextureSize.Y);
            ArrayVertex[0].Color             = Color.White;

            UVXValue                         = ActiveTerrain.Origin.X + Map.TileSize.X - 0.5f;
            UVYValue                         = ActiveTerrain.Origin.Y + 0.5f;
            ArrayVertex[1]                   = new VertexPositionColorTexture();
            ArrayVertex[1].Position          = ArrayVertexPosition[1];
            ArrayVertex[1].TextureCoordinate = new Vector2(UVXValue / TextureSize.X, UVYValue / TextureSize.Y);
            ArrayVertex[1].Color             = Color.White;

            UVXValue                         = ActiveTerrain.Origin.X + 0.5f;
            UVYValue                         = ActiveTerrain.Origin.Y + Map.TileSize.Y - 0.5f;
            ArrayVertex[2]                   = new VertexPositionColorTexture();
            ArrayVertex[2].Position          = ArrayVertexPosition[2];
            ArrayVertex[2].TextureCoordinate = new Vector2(UVXValue / TextureSize.X, UVYValue / TextureSize.Y);
            ArrayVertex[2].Color             = Color.White;

            UVXValue                         = ActiveTerrain.Origin.X + Map.TileSize.X - 0.5f;
            UVYValue                         = ActiveTerrain.Origin.Y + Map.TileSize.Y - 0.5f;
            ArrayVertex[3]                   = new VertexPositionColorTexture();
            ArrayVertex[3].Position          = ArrayVertexPosition[3];
            ArrayVertex[3].TextureCoordinate = new Vector2(UVXValue / TextureSize.X, UVYValue / TextureSize.Y);
            ArrayVertex[3].Color             = Color.White;

            short[] ArrayIndex = new short[6];
            ArrayIndex[0] = 0;
            ArrayIndex[1] = 1;
            ArrayIndex[2] = 3;
            ArrayIndex[3] = 0;
            ArrayIndex[4] = 3;
            ArrayIndex[5] = 2;

            Tile3D NewTile = new Tile3D(ArrayVertex, ArrayIndex);

            return(NewTile);
        }
        private void MoveToSphericalCoordinates(Tile3D ActiveTile, float Radius)
        {
            for (int V = ActiveTile.ArrayVertex.Length - 1; V >= 0; --V)
            {
                double X = ActiveTile.ArrayVertex[V].Position.X / Radius;
                double Y = ActiveTile.ArrayVertex[V].Position.Y / Radius;
                double Z = ActiveTile.ArrayVertex[V].Position.Z / Radius;

                double TransformedX = X * Math.Sqrt(1.0 - (Y * Y * 0.5) - (Z * Z * 0.5) + (Y * Y * Z * Z / 3.0));
                double TransformedY = Y * Math.Sqrt(1.0 - (Z * Z * 0.5) - (X * X * 0.5) + (Z * Z * X * X / 3.0));
                double TransformedZ = Z * Math.Sqrt(1.0 - (X * X * 0.5) - (Y * Y * 0.5) + (X * X * Y * Y / 3.0));

                ActiveTile.ArrayVertex[V].Position.X = (float)(TransformedX * Radius);
                ActiveTile.ArrayVertex[V].Position.Y = (float)(TransformedY * Radius);
                ActiveTile.ArrayVertex[V].Position.Z = (float)(TransformedZ * Radius);
            }
        }
        protected override void CreateMap(DeathmatchMap Map)
        {
            DicTile3D.Clear();

            for (int X = Map.MapSize.X - 1; X >= 0; --X)
            {
                for (int Y = Map.MapSize.Y - 1; Y >= 0; --Y)
                {
                    Vector3[] ArrayVertexPosition = new Vector3[4];
                    ArrayVertexPosition[0] = new Vector3(X * Map.TileSize.X, 0, Y * Map.TileSize.Y);
                    ArrayVertexPosition[1] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, 0, Y * Map.TileSize.Y);
                    ArrayVertexPosition[2] = new Vector3(X * Map.TileSize.X, 0, Y * Map.TileSize.Y + Map.TileSize.Y);
                    ArrayVertexPosition[3] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, 0, Y * Map.TileSize.Y + Map.TileSize.Y);

                    Vector3[] ArrayTransformedVertexPosition = new Vector3[ArrayVertexPosition.Length];

                    Matrix TranslationToOriginMatrix = Matrix.CreateTranslation(-Radius, Radius, -Radius);
                    Vector3.Transform(ArrayVertexPosition, ref TranslationToOriginMatrix, ArrayTransformedVertexPosition);
                    for (int V = ArrayVertexPosition.Length - 1; V >= 0; --V)
                    {
                        ArrayVertexPosition[V] = ArrayTransformedVertexPosition[V];
                    }

                    Map2D        GroundLayer   = Map.ListLayer[0].OriginalLayerGrid;
                    DrawableTile ActiveTerrain = GroundLayer.GetTile(X, Y);
                    Texture2D    ActiveTileset = Map.ListTileSet[ActiveTerrain.Tileset];
                    if (!DicTile3D.ContainsKey(ActiveTileset))
                    {
                        DicTile3D.Add(ActiveTileset, new List <Tile3D>());
                    }
                    Tile3D NewTile = CreateTile(Map, ActiveTileset, ArrayVertexPosition, X, Y);

                    if (Spherical)
                    {
                        MoveToSphericalCoordinates(NewTile, Radius);
                        CreateSphericalElevation(Map, ActiveTileset, NewTile, X, Y);
                    }
                    else
                    {
                        CreateFlatElevation(Map, ActiveTileset, NewTile, X, Y);
                    }
                    CreateCubicTile(Map, ActiveTileset, NewTile);
                }
            }
        }
        private void CreateCubicTile(DeathmatchMap Map, Texture2D ActiveTileset, Tile3D Original)
        {
            const float DegToRag = 0.0174532925f;
            float       Radius   = (Map.MapSize.X * Map.TileSize.X) / 2f;

            Vector3[] ArrayOriginalVertexPosition = new Vector3[Original.ArrayVertex.Length];
            for (int V = Original.ArrayVertex.Length - 1; V >= 0; --V)
            {
                ArrayOriginalVertexPosition[V] = Original.ArrayVertex[V].Position;
            }
            Vector3[] ArrayTransformedVertexPosition = new Vector3[Original.ArrayVertex.Length];
            Matrix    TranslationToOriginMatrix      = Matrix.CreateTranslation(0f, -Radius, 0f);
            Matrix    RotationMatrix;
            Matrix    TranslationMatrix;
            Matrix    FinalMatrix;
            Tile3D    NewTile;

            //Top
            TranslationMatrix = Matrix.CreateTranslation(0f, Radius, 0f);
            FinalMatrix       = TranslationToOriginMatrix * TranslationMatrix;

            Vector3.Transform(ArrayOriginalVertexPosition, ref FinalMatrix, ArrayTransformedVertexPosition);
            NewTile = new Tile3D(Original);
            for (int V = Original.ArrayVertex.Length - 1; V >= 0; --V)
            {
                NewTile.ArrayVertex[V].Position = ArrayTransformedVertexPosition[V];
            }

            DicTile3D[ActiveTileset].Add(NewTile);

            //Front
            RotationMatrix    = Matrix.CreateRotationX(90 * DegToRag);
            TranslationMatrix = Matrix.CreateTranslation(0f, 0f, Radius);
            FinalMatrix       = TranslationToOriginMatrix * RotationMatrix * TranslationMatrix;

            Vector3.Transform(ArrayOriginalVertexPosition, ref FinalMatrix, ArrayTransformedVertexPosition);
            NewTile = new Tile3D(Original);
            for (int V = Original.ArrayVertex.Length - 1; V >= 0; --V)
            {
                NewTile.ArrayVertex[V].Position = ArrayTransformedVertexPosition[V];
            }

            DicTile3D[ActiveTileset].Add(NewTile);

            //Back
            RotationMatrix    = Matrix.CreateRotationX(270 * DegToRag);
            TranslationMatrix = Matrix.CreateTranslation(0f, 0f, -Radius);
            FinalMatrix       = TranslationToOriginMatrix * RotationMatrix * TranslationMatrix;

            Vector3.Transform(ArrayOriginalVertexPosition, ref FinalMatrix, ArrayTransformedVertexPosition);
            NewTile = new Tile3D(Original);
            for (int V = Original.ArrayVertex.Length - 1; V >= 0; --V)
            {
                NewTile.ArrayVertex[V].Position = ArrayTransformedVertexPosition[V];
            }

            DicTile3D[ActiveTileset].Add(NewTile);

            //Left
            RotationMatrix    = Matrix.CreateRotationX(90 * DegToRag) * Matrix.CreateRotationY(90 * DegToRag);
            TranslationMatrix = Matrix.CreateTranslation(Radius, 0f, 0f);
            FinalMatrix       = TranslationToOriginMatrix * RotationMatrix * TranslationMatrix;

            Vector3.Transform(ArrayOriginalVertexPosition, ref FinalMatrix, ArrayTransformedVertexPosition);
            NewTile = new Tile3D(Original);
            for (int V = Original.ArrayVertex.Length - 1; V >= 0; --V)
            {
                NewTile.ArrayVertex[V].Position = ArrayTransformedVertexPosition[V];
            }

            DicTile3D[ActiveTileset].Add(NewTile);

            //Right
            RotationMatrix    = Matrix.CreateRotationX(90 * DegToRag) * Matrix.CreateRotationY(270 * DegToRag);
            TranslationMatrix = Matrix.CreateTranslation(-Radius, 0f, 0f);
            FinalMatrix       = TranslationToOriginMatrix * RotationMatrix * TranslationMatrix;

            Vector3.Transform(ArrayOriginalVertexPosition, ref FinalMatrix, ArrayTransformedVertexPosition);
            NewTile = new Tile3D(Original);
            for (int V = Original.ArrayVertex.Length - 1; V >= 0; --V)
            {
                NewTile.ArrayVertex[V].Position = ArrayTransformedVertexPosition[V];
            }

            DicTile3D[ActiveTileset].Add(NewTile);

            //Bottom
            RotationMatrix    = Matrix.CreateRotationX(180 * DegToRag);
            TranslationMatrix = Matrix.CreateTranslation(0f, -Radius, 0f);
            FinalMatrix       = TranslationToOriginMatrix * RotationMatrix * TranslationMatrix;

            Vector3.Transform(ArrayOriginalVertexPosition, ref FinalMatrix, ArrayTransformedVertexPosition);
            NewTile = new Tile3D(Original);
            for (int V = Original.ArrayVertex.Length - 1; V >= 0; --V)
            {
                NewTile.ArrayVertex[V].Position = ArrayTransformedVertexPosition[V];
            }

            DicTile3D[ActiveTileset].Add(NewTile);
        }
示例#9
0
        public Map3DDrawable(DeathmatchMap Map, GraphicsDevice g)
        {
            this.Map  = Map;
            sprCursor = Map.sprCursor;
            Camera    = new DefaultCamera(g);

            effect = Map.Content.Load <Effect>("Shaders/Default Shader 3D");

            PolygonEffect = new BasicEffect(g);


            PolygonEffect.TextureEnabled = true;
            PolygonEffect.EnableDefaultLighting();

            float aspectRatio = g.Viewport.Width / (float)g.Viewport.Height;

            Matrix Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                    aspectRatio,
                                                                    1, 10000);

            PolygonEffect.Projection = Projection;

            PolygonEffect.World = Matrix.Identity;
            PolygonEffect.View  = Matrix.Identity;

            // Key light.
            effect.Parameters["DirLight0Direction"].SetValue(new Vector3(-0.5265408f, -0.5735765f, -0.6275069f));
            effect.Parameters["DirLight0DiffuseColor"].SetValue(new Vector3(1, 0.9607844f, 0.8078432f));
            effect.Parameters["DirLight0SpecularColor"].SetValue(new Vector3(1, 0.9607844f, 0.8078432f));

            // Fill light.
            effect.Parameters["DirLight1Direction"].SetValue(new Vector3(0.7198464f, 0.3420201f, 0.6040227f));
            effect.Parameters["DirLight1DiffuseColor"].SetValue(new Vector3(0.9647059f, 0.7607844f, 0.4078432f));
            effect.Parameters["DirLight1SpecularColor"].SetValue(Vector3.Zero);

            // Back light.
            effect.Parameters["DirLight2Direction"].SetValue(new Vector3(0.4545195f, -0.7660444f, 0.4545195f));
            effect.Parameters["DirLight2DiffuseColor"].SetValue(new Vector3(0.3231373f, 0.3607844f, 0.3937255f));
            effect.Parameters["DirLight2SpecularColor"].SetValue(new Vector3(0.3231373f, 0.3607844f, 0.3937255f));

            Vector3 diffuseColor      = Vector3.One;
            Vector3 emissiveColor     = Vector3.Zero;
            Vector3 ambientLightColor = new Vector3(0.05333332f, 0.09882354f, 0.1819608f);
            Vector4 diffuse           = new Vector4();
            Vector3 emissive          = new Vector3();
            float   alpha             = 1;

            diffuse.X = diffuseColor.X * alpha;
            diffuse.Y = diffuseColor.Y * alpha;
            diffuse.Z = diffuseColor.Z * alpha;
            diffuse.W = alpha;

            emissive.X = (emissiveColor.X + ambientLightColor.X * diffuseColor.X) * alpha;
            emissive.Y = (emissiveColor.Y + ambientLightColor.Y * diffuseColor.Y) * alpha;
            emissive.Z = (emissiveColor.Z + ambientLightColor.Z * diffuseColor.Z) * alpha;

            effect.Parameters["DiffuseColor"].SetValue(diffuse);
            effect.Parameters["EmissiveColor"].SetValue(emissive);
            effect.Parameters["SpecularColor"].SetValue(Vector3.One);
            effect.Parameters["SpecularPower"].SetValue(64);


            DicDrawablePointPerColor  = new Dictionary <Color, List <Tile3D> >();
            DicTile3DByTileset        = new Dictionary <int, Tile3DHolder>();
            ListDrawableArrowPerColor = new List <Tile3D>();

            for (int L = 0; L < Map.LayerManager.ListLayer.Count; L++)
            {
                CreateMap(Map, Map.LayerManager.ListLayer[L], L);
            }

            foreach (KeyValuePair <int, Tile3DHolder> ActiveTileSet in DicTile3DByTileset)
            {
                ActiveTileSet.Value.Finish(GameScreen.GraphicsDevice);
            }

            float        Z               = Map.LayerManager.ListLayer[0].ArrayTerrain[0, 0].Position.Z * 32;
            Map2D        GroundLayer     = Map.LayerManager.ListLayer[0].LayerGrid;
            DrawableTile ActiveTerrain   = GroundLayer.GetTile(0, 0);
            Terrain3D    ActiveTerrain3D = ActiveTerrain.Terrain3DInfo;

            Cursor = ActiveTerrain3D.CreateTile3D(0, Point.Zero,
                                                  0, 0, Z, 0, Map.TileSize, new List <Texture2D>()
            {
                sprCursor
            }, Z, Z, Z, Z, 0)[0];
        }
示例#10
0
 public Tile3D(Tile3D Clone)
 {
     this.ArrayVertex = (VertexPositionColorTexture[])Clone.ArrayVertex.Clone();
     this.ArrayIndex  = (short[])Clone.ArrayIndex.Clone();
     TriangleCount    = Clone.TriangleCount;
 }