Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameTime"></param>
        void DrawInternal(GameTime gameTime)
        {
            var dev = Game.GraphicsDevice;

            viewMatrix = DMatrix.LookAtRH(cameraPosition, DVector3.Zero, DVector3.UnitY);

            DMatrix vvvM = viewMatrix;

            viewMatrix.TranslationVector = DVector3.Zero;

            var camPos = cameraPosition;

            if (Game.InputDevice.IsKeyDown(Keys.LeftShift))
            {
                DVector3 cameraUp    = cameraPosition / cameraPosition.Length();
                DVector3 lookAtPoint = cameraUp * Config.earthRadius;

                double length = Config.CameraDistance - Config.earthRadius;

                var quat = DQuaternion.RotationAxis(DVector3.UnitY, FreeCamYaw) * DQuaternion.RotationAxis(DVector3.UnitX, FreeCamPitch);

                var qRot = DMatrix.RotationQuaternion(quat);
                var mat  = DMatrix.Identity;

                var xAxis = DVector3.TransformNormal(DVector3.UnitX, DMatrix.RotationAxis(DVector3.UnitY, Yaw));
                xAxis.Normalize();

                mat.Up      = cameraUp;
                mat.Right   = xAxis;
                mat.Forward = DVector3.Cross(xAxis, cameraUp);
                mat.Forward.Normalize();

                var matrix = qRot * mat;

                var c = DVector3.Transform(new DVector3(0, 0, length), matrix);

                var camPoint = new DVector3(c.X, c.Y, c.Z) + lookAtPoint;

                camPos = camPoint;

                viewMatrix = DMatrix.LookAtRH(camPoint, lookAtPoint, cameraUp);
                vvvM       = viewMatrix;
                viewMatrix.TranslationVector = DVector3.Zero;
            }

            viewMatrixFloat = DMatrix.ToFloatMatrix(viewMatrix);
            projMatrixFloat = DMatrix.ToFloatMatrix(projMatrix);

            var viewDir = cameraPosition / cameraPosition.Length();

            constBuffer.Data.ViewProj      = viewMatrixFloat * projMatrixFloat;
            constBuffer.Data.ViewPositionX = camPos.X;
            constBuffer.Data.ViewPositionY = camPos.Y;
            constBuffer.Data.ViewPositionZ = camPos.Z;
            constBuffer.Data.Temp          = new Vector4(0.0f, (float)Config.earthRadius, 0, 0);
            constBuffer.Data.ViewDir       = new Vector4((float)viewDir.X, (float)viewDir.Y, (float)viewDir.Z, 0);
            constBuffer.UpdateCBuffer();

            Game.GraphicsDevice.VertexShaderConstants[0] = constBuffer;

            Game.GraphicsDevice.PixelShaderSamplers[0]  = SamplerState.LinearClamp;
            Game.GraphicsDevice.PixelShaderResources[1] = frame;

            if (gridVertexBuffer != null)
            {
                Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
                    GlobeFlags.DRAW_POLY | GlobeFlags.DRAW_VERTEX_POLY | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_TEXTURED | (Config.ShowFrames ? GlobeFlags.SHOW_FRAMES : GlobeFlags.NONE),
                    Primitive.TriangleList,
                    BlendState.AlphaBlend,
                    RasterizerState.CullCW,
                    DepthStencilState.Readonly);

                Game.GraphicsDevice.PixelShaderResources[0] = gridTex;

                Game.GraphicsDevice.SetupVertexInput(gridVertexBuffer, gridIndexBuffer);
                dev.DrawIndexed(/*Primitive.TriangleList,*/ gridIndexBuffer.Capacity, 0, 0);
            }

            var rastState = Game.InputDevice.IsKeyDown(Keys.Tab) ? RasterizerState.Wireframe : RasterizerState.CullCW;

            Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
                GlobeFlags.DRAW_POLY | GlobeFlags.DRAW_VERTEX_POLY | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_TEXTURED | (Config.ShowFrames ? GlobeFlags.SHOW_FRAMES : GlobeFlags.NONE),
                Primitive.TriangleList,
                BlendState.AlphaBlend,
                rastState,
                DepthStencilState.Default);

            foreach (var globeTile in tilesToRender)
            {
                var tex = Game.GetService <LayerService>().MapLayer.CurrentMapSource.GetTile(globeTile.Value.X, globeTile.Value.Y, globeTile.Value.Z).Tile;
                dev.PixelShaderResources[0] = tex;

                dev.SetupVertexInput(globeTile.Value.VertexBuf, globeTile.Value.IndexBuf);
                dev.DrawIndexed(globeTile.Value.IndexBuf.Capacity, 0, 0);
            }


            dotsBuf.Data.View = viewMatrixFloat;
            dotsBuf.Data.Proj = projMatrixFloat;
            dotsBuf.UpdateCBuffer();

            //// Draw simple railroads
            //if (simpleRailroadsVB != null && Config.ShowRailroads) {
            //	Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
            //		GlobeFlags.DRAW_VERTEX_LINES | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_SEGMENTED_LINES,
            //		Primitive.LineList,
            //		BlendState.AlphaBlend,
            //		RasterizerState.CullNone,
            //		DepthStencilState.None);
            //
            //	constBuffer.Data.Temp = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
            //	constBuffer.UpdateCBuffer();
            //
            //	Game.GraphicsDevice.VertexShaderConstants[1]	= dotsBuf;
            //	Game.GraphicsDevice.GeometryShaderConstants[1]	= dotsBuf;
            //	Game.GraphicsDevice.GeometryShaderConstants[0]	= constBuffer;
            //	Game.GraphicsDevice.VertexShaderConstants[0]	= constBuffer;
            //	Game.GraphicsDevice.PixelShaderConstants[0]		= constBuffer;
            //
            //	Game.GraphicsDevice.PixelShaderResources[0] = railRoadsTex;
            //	Game.GraphicsDevice.PixelShaderSamplers[0]	= SamplerState.LinearWrap;
            //
            //	dev.SetupVertexInput(simpleRailroadsVB, null);
            //	dev.Draw(simpleRailroadsVB.Capacity, 0);
            //}


            //// Draw buildings
            //if (contourBuildingsVB != null && Config.ShowBuildingsContours) {
            //
            //	Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
            //		GlobeFlags.DRAW_POLY | GlobeFlags.DRAW_VERTEX_POLY | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_COLOR,
            //		Primitive.LineList,
            //		BlendState.AlphaBlend,
            //		RasterizerState.CullNone,
            //		DepthStencilState.None);
            //
            //
            //	constBuffer.Data.Temp = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
            //	constBuffer.UpdateCBuffer();
            //
            //	Game.GraphicsDevice.VertexShaderConstants[0]	= constBuffer;
            //	Game.GraphicsDevice.PixelShaderConstants[0]		= constBuffer;
            //
            //	dev.SetupVertexInput(contourBuildingsVB, null);
            //	dev.Draw(contourBuildingsVB.Capacity, 0);
            //}

            // Draw Lines
            if (linesBatch.Count != 0 && Config.ShowRoads)
            {
                Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
                    GlobeFlags.DRAW_POLY | GlobeFlags.DRAW_VERTEX_POLY | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_COLOR,
                    Primitive.LineList,
                    BlendState.AlphaBlend,
                    RasterizerState.CullNone,
                    DepthStencilState.None);


                constBuffer.Data.Temp = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
                constBuffer.UpdateCBuffer();

                Game.GraphicsDevice.VertexShaderConstants[0] = constBuffer;
                Game.GraphicsDevice.PixelShaderConstants[0]  = constBuffer;

                foreach (var vb in linesBatch)
                {
                    dev.SetupVertexInput(vb, null);
                    dev.Draw(vb.Capacity, 0);
                }
            }



            // Draw simple railroads
            if (linesPolyBatch.Count != 0 && Config.ShowRoads)
            {
                Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
                    GlobeFlags.DRAW_VERTEX_LINES | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_LINES,
                    Primitive.LineList,
                    BlendState.AlphaBlend,
                    RasterizerState.CullNone,
                    DepthStencilState.None);

                constBuffer.Data.Temp = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
                constBuffer.UpdateCBuffer();

                Game.GraphicsDevice.VertexShaderConstants[1]   = dotsBuf;
                Game.GraphicsDevice.GeometryShaderConstants[1] = dotsBuf;
                Game.GraphicsDevice.GeometryShaderConstants[0] = constBuffer;
                Game.GraphicsDevice.VertexShaderConstants[0]   = constBuffer;
                Game.GraphicsDevice.PixelShaderConstants[0]    = constBuffer;


                foreach (var vb in linesPolyBatch)
                {
                    dev.SetupVertexInput(vb, null);
                    dev.Draw(vb.Capacity, 0);
                }
            }



            if (Config.ShowPOI)
            {
                dotsBuf.Data.TexWHST = new Vector4(geoObjects.Width, geoObjects.Height, 164.0f, 0.05f);
                dotsBuf.UpdateCBuffer();

                Game.GraphicsDevice.VertexShaderConstants[1]   = dotsBuf;
                Game.GraphicsDevice.GeometryShaderConstants[1] = dotsBuf;
                Game.GraphicsDevice.GeometryShaderConstants[0] = constBuffer;

                Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
                    GlobeFlags.DRAW_VERTEX_LINES | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_DOTS | GlobeFlags.DOTS_WORLDSPACE,
                    Primitive.PointList,
                    BlendState.AlphaBlend,
                    RasterizerState.CullNone,
                    DepthStencilState.None);

                Game.GraphicsDevice.PixelShaderResources[0] = geoObjects;
                Game.GraphicsDevice.PixelShaderSamplers[0]  = SamplerState.LinearClamp;

                dev.SetupVertexInput(dotsVB, null);
                dev.Draw(dotsVB.Capacity - geoObjectStart, geoObjectStart);
            }



            // Draw people
            if (Config.ShowPeople)
            {
                dotsBuf.Data.TexWHST = new Vector4(socioClasses.Width, socioClasses.Height, 64.0f, 0.025f);
                dotsBuf.UpdateCBuffer();

                Game.GraphicsDevice.VertexShaderConstants[1]   = dotsBuf;
                Game.GraphicsDevice.GeometryShaderConstants[1] = dotsBuf;
                Game.GraphicsDevice.GeometryShaderConstants[0] = constBuffer;

                Game.GraphicsDevice.PixelShaderResources[0] = socioClasses;
                Game.GraphicsDevice.PixelShaderSamplers[0]  = SamplerState.LinearClamp;

                Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
                    GlobeFlags.DRAW_VERTEX_LINES | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_DOTS | GlobeFlags.DOTS_WORLDSPACE,
                    Primitive.PointList,
                    BlendState.AlphaBlend,
                    RasterizerState.CullNone,
                    DepthStencilState.None);

                dev.SetupVertexInput(dotsVB, null);
                dev.Draw(geoObjectStart - 1, 0);
            }



            //// Draw heatmap
            //if (Config.ShowHeatMap && heatVB != null) {
            //	constBuffer.Data.Temp = new Vector4((float)Config.MaxHeatMapLevel, Config.HeatMapTransparency, HeatMapDim, 0);
            //	constBuffer.UpdateCBuffer();
            //
            //	Game.GraphicsDevice.VertexShaderConstants[0]	= constBuffer;
            //	Game.GraphicsDevice.PixelShaderConstants[0]		= constBuffer;
            //
            //	Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
            //		GlobeFlags.DRAW_POLY | GlobeFlags.DRAW_VERTEX_POLY | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_HEAT,
            //		Primitive.TriangleList,
            //		BlendState.AlphaBlend,
            //		RasterizerState.CullNone,
            //		DepthStencilState.None);
            //
            //
            //	Game.GraphicsDevice.PixelShaderSamplers[0] = SamplerState.LinearClamp;
            //	Game.GraphicsDevice.PixelShaderSamplers[1] = SamplerState.AnisotropicClamp;
            //
            //	Game.GraphicsDevice.PixelShaderResources[0] = heatMap;
            //	Game.GraphicsDevice.PixelShaderResources[1] = heatMapPalette;
            //
            //	Game.GraphicsDevice.SetupVertexInput(heatVB, heatIB);
            //	Game.GraphicsDevice.DrawIndexed(heatIB.Capacity, 0, 0);
            //}

            //// Draw infection map
            //if (Config.ShowInfectHeatMap && heatVB != null) {
            //	constBuffer.Data.Temp = new Vector4((float)Config.MaxInfectLevel, 0.0f, HeatMapDim, 0);
            //	constBuffer.UpdateCBuffer();
            //
            //	Game.GraphicsDevice.VertexShaderConstants[0]	= constBuffer;
            //	Game.GraphicsDevice.PixelShaderConstants[0]		= constBuffer;
            //
            //	Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
            //		GlobeFlags.DRAW_POLY | GlobeFlags.DRAW_VERTEX_POLY | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_HEAT,
            //		Primitive.TriangleList,
            //		BlendState.AlphaBlend,
            //		RasterizerState.CullNone,
            //		DepthStencilState.None);
            //
            //	Game.GraphicsDevice.PixelShaderSamplers[0] = SamplerState.LinearClamp;
            //	Game.GraphicsDevice.PixelShaderSamplers[1] = SamplerState.AnisotropicClamp;
            //
            //	Game.GraphicsDevice.PixelShaderResources[0] = infectMap;
            //	Game.GraphicsDevice.PixelShaderResources[1] = heatMapPalette;
            //
            //	Game.GraphicsDevice.SetupVertexInput(heatVB, heatIB);
            //	Game.GraphicsDevice.DrawIndexed(/*Primitive.TriangleList,*/ heatIB.Capacity, 0, 0);
            //}


            ////Draw atmosphere
            //if (Config.ShowAtmosphere && atmosVB != null) {
            //	constBuffer.Data.Temp = new Vector4(atmosTime, Config.ArrowsScale, 0.0f, 0);
            //	constBuffer.UpdateCBuffer();
            //
            //	Game.GraphicsDevice.VertexShaderConstants[0]	= constBuffer;
            //	Game.GraphicsDevice.PixelShaderConstants[0]		= constBuffer;
            //
            //
            //	Game.GraphicsDevice.PixelShaderResources[0] = atmosTexture;
            //	Game.GraphicsDevice.PixelShaderResources[1] = heatMapPalette;
            //	Game.GraphicsDevice.PixelShaderResources[2] = atmosNextTexture;
            //	Game.GraphicsDevice.PixelShaderResources[3] = arrowTex;
            //
            //
            //	Game.GraphicsDevice.PixelShaderSamplers[0] = SamplerState.LinearClamp;
            //	Game.GraphicsDevice.PixelShaderSamplers[1] = SamplerState.AnisotropicClamp;
            //
            //	Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
            //		GlobeFlags.DRAW_VERTEX_POLY | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_ATMOSPHERE,
            //		Primitive.TriangleList,
            //		BlendState.AlphaBlend,
            //		RasterizerState.CullNone,
            //		DepthStencilState.None);
            //
            //	Game.GraphicsDevice.SetupVertexInput(atmosVB, atmosIB);
            //	Game.GraphicsDevice.DrawIndexed(atmosIB.Capacity, 0, 0);
            //}


            //Draw airlines
            if (airLinesVB != null && Config.ShowAirLines)
            {
                constBuffer.Data.Temp = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
                constBuffer.UpdateCBuffer();

                Game.GraphicsDevice.VertexShaderConstants[1]   = dotsBuf;
                Game.GraphicsDevice.GeometryShaderConstants[0] = constBuffer;
                Game.GraphicsDevice.GeometryShaderConstants[1] = dotsBuf;

                Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
                    GlobeFlags.DRAW_VERTEX_LINES | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_ARCS,
                    Primitive.LineList,
                    BlendState.Additive,
                    RasterizerState.CullNone,
                    DepthStencilState.Readonly);

                dev.SetupVertexInput(airLinesVB, null);
                dev.Draw(/*Primitive.LineList,*/ airLinesVB.Capacity, 0);
            }

            DrawDebugLines();

            //Game.GetService<DebugStrings>().Add("Cam pos     : " + Game.GetService<Camera>().CameraMatrix.TranslationVector, Color.Red);
            //Game.GetService<DebugStrings>().Add("Radius      : " + Config.earthRadius, Color.Red);
            //Game.GetService<DebugStrings>().Add("Level       : " + CurrentLevel, Color.Green);
            //Game.GetService<DebugStrings>().Add("CamDistance : " + Config.CameraDistance, Color.Green);
            //Game.GetService<DebugStrings>().Add("Pitch : " + Pitch, Color.Green);
            //Game.GetService<DebugStrings>().Add("Width : " + Game.GraphicsDevice.Viewport.Width, Color.Green);
            Game.GetService <DebugStrings>().Add("Height : " + (Config.CameraDistance - Config.earthRadius) * 1000.0, Color.Green);
        }