示例#1
0
 public override void Update(Camera camera, GameTime gameTime)
 {
     if (_delayBeforeStart <= 0)
         base.Update(camera, gameTime);
     else
         _delayBeforeStart -= (float) gameTime.ElapsedGameTime.TotalSeconds;
 }
示例#2
0
 public override void Update(Camera camera, GameTime gameTime)
 {
     base.Update(camera, gameTime);
     foreach (var item in Items)
         item.Age += (float) gameTime.ElapsedGameTime.TotalSeconds;
     Items.RemoveAll(_ => _.Age > _.TimeToLive);
 }
示例#3
0
        protected override bool draw(Camera camera, DrawingReason drawingReason, ShadowMap shadowMap)
        {
            var anyPartIsVisible = _slices.Aggregate(false,
                (current, slice) => current | (slice.Visible = camera.BoundingFrustum.Contains(slice.BoundingSphere) != ContainmentType.Disjoint));

            if (!anyPartIsVisible)
                return false;

            for (var i = 0; i < 9; i++)
            {
                var ep = Effect.Parameters["Texture" + (char)(48 + i)];
                if (ep != null)
                    ep.SetResource(Textures[i]);
            }

            Effect.Parameters["HeightsMap"].SetResource(HeightsMap);
            Effect.Parameters["NormalsMap"].SetResource(NormalsMap);
            Effect.Parameters["WeightsMap"].SetResource(WeightsMap);

            camera.UpdateEffect(Effect);

            foreach (var slice in _slices.Where(slice => slice.Visible))
            {
                Effect.Parameters["TexOffsetAndScale"].SetValue(slice.TexOffsetAndScale);
                VContent.TerrainPlane.Draw(camera, slice.World, drawingReason);
            }

            return true;
        }
示例#4
0
        protected override bool draw(Camera camera, DrawingReason drawingReason, ShadowMap shadowMap)
        {
            if (_vertexBuffer == null)
                return false;

            camera.UpdateEffect(Effect);
            Effect.World = _world;
            Effect.Texture = _texture;

            Effect.GraphicsDevice.SetVertexBuffer(_vertexBuffer);
            Effect.GraphicsDevice.SetVertexInputLayout(_vertexInputLayout);

            Effect.Parameters["BillboardWidth"].SetValue(_billboardWidth);
            Effect.Parameters["BillboardHeight"].SetValue(_billboardHeight);

            //pass one
            Effect.Parameters["AlphaTestDirection"].SetValue(1f);
            Effect.Effect.CurrentTechnique.Passes[0].Apply();
            Effect.GraphicsDevice.Draw(PrimitiveType.TriangleList, _vertexBuffer.ElementCount);

            if (drawingReason == DrawingReason.Normal)
            {
                //pass two
                Effect.GraphicsDevice.SetDepthStencilState(Effect.GraphicsDevice.DepthStencilStates.DepthRead);
                Effect.GraphicsDevice.SetBlendState(Effect.GraphicsDevice.BlendStates.NonPremultiplied);
                Effect.Parameters["AlphaTestDirection"].SetValue(-1f);
                Effect.Effect.CurrentTechnique.Passes[0].Apply();
                Effect.GraphicsDevice.Draw(PrimitiveType.TriangleList, _vertexBuffer.ElementCount);
                Effect.GraphicsDevice.SetDepthStencilState(Effect.GraphicsDevice.DepthStencilStates.Default);
                Effect.GraphicsDevice.SetBlendState(Effect.GraphicsDevice.BlendStates.Default);
            }

            return true;
        }
示例#5
0
 public SerpentCamera(Camera camera, BaseSerpent serpent, float tension = DefaultTension, float tensionIncreaseFactor = 1, float maxTension = DefaultTension)
     : base(camera)
 {
     _serpent = serpent;
     Tension = tension;
     TensionIncreaseFactor = tensionIncreaseFactor;
     MaxTension = maxTension;
 }
示例#6
0
        public MoveCamera(Camera camera, MovementTime time, Vector3 toPosition, Func<Vector3> toLookAt)
            : base(camera)
        {
            _path = new[] {Camera.Position, toPosition};

            EndTime = !time.UnitsPerSecond
                ? time.Time
                : (0.1f + pathLength())/time.Time;

            _toLookAt = toLookAt;
        }
示例#7
0
 protected override bool draw(Camera camera, DrawingReason drawingReason, ShadowMap shadowMap)
 {
     camera.UpdateEffect(Effect);
     Effect.World = World;
     if (drawingReason != DrawingReason.ShadowDepthMap)
     {
         Effect.Texture = _texture;
     //TODO                Effect.Parameters["BumpMap"].SetResource(_bumpMap);
     }
     _cube.Draw(Effect);
     return true;
 }
示例#8
0
        public static void DrawWaterSurfaceGrid(
            WaterSurface waterSurface,
            Camera camera,
            ShadowMap shadow,
            int nisse,
            int surfaceSize,
            int surfaceScale)
        {
            const int waterW = 64;
            const int waterH = 64;
            const int worldW = 32;
            const int worldH = 32;

            var boundingFrustum = camera.BoundingFrustum;

            waterSurface.Effect.SetShadowMapping(shadow);

            var gridStartX = (int) camera.Position.X/waterW - worldW/2;
            var gridStartY = (int) camera.Position.Z/waterH - worldH/2;

            Array.Clear(RenderedWaterPlanes, 0, RenderedWaterPlanes.Length);

            var drawDetails = camera.Position.Y < -1; // fix the sea water some time
            if (drawDetails)
                for (var y = 0; y <= worldH; y++)
                    for (var x = 0; x <= worldW; x++)
                    {
                        var pos1 = new Vector3((gridStartX + x) * waterW, 0, (gridStartY + y) * waterH);
                        var pos2 = pos1 + new Vector3(waterW, 1, waterH);
                        var bb = new BoundingBox(pos1, pos2);
                        if (boundingFrustum.Contains(bb) == ContainmentType.Disjoint)
                            continue;

                        waterSurface.Draw(
                            camera,
                            pos1,
                            Vector3.Distance(camera.Position, pos1 - new Vector3(-32, 0, -32)),
                            x % 8,
                            y % 8,
                            1 << surfaceScale);
                    }

            var raise = 0.5f + camera.Position.Y/500;
            var q = (int)camera.ZFar & ~(waterW - 1);
            var pos = new Vector3(gridStartX * waterW - q, raise, gridStartY * waterH - q);
            waterSurface.Draw(camera, pos, -1, 0, 0, 1 << surfaceScale);
        }
示例#9
0
        public void Draw(Camera camera, Matrix world, DrawingReason drawingReason)
        {
            camera.UpdateEffect(Effect);
            Effect.World = world;

            var distance = Vector3.Distance(camera.Position, world.TranslationVector)/Math.Min(world.M11, world.M33);
            var lod = 3;
            if (distance < 300)
                lod = 0;
            else if (distance < 600)
                lod = 1;
            else if (distance < 1800)
                lod = 2;
            if (drawingReason != DrawingReason.Normal)
                lod++;
            _loPlane.Draw(Effect, lod);
        }
示例#10
0
        protected override bool draw(Camera camera, DrawingReason drawingReason, ShadowMap shadowMap)
        {
            camera.UpdateEffect(Effect);
            Effect.World = World;

            //if (drawingReason != DrawingReason.ShadowDepthMap)
            //    Effect.Texture = _texture;

            //Effect.Apply();
            //foreach (var mesh in _model.Meshes)
            //    mesh.Draw(Effect.GraphicsDevice);

            //Effect.World = World*Matrix.Translation(21.68f, 0, 0);
            //foreach (var mesh in _model.Meshes)
            //    mesh.Draw(Effect.GraphicsDevice);

            return true;
        }
示例#11
0
        public MoveCameraYaw(Camera camera, MovementTime time, Vector3 toPosition, Vector3 toLookAt)
            : base(camera)
        {
            _fromPosition = camera.Position;
            _fromYaw = camera.Yaw;
            _fromPitch = camera.Pitch;

            _toPosition = toPosition;
            _toYaw = (float) Math.Atan2(toPosition.X - toLookAt.X, toPosition.Z - toLookAt.Z);
            _toPitch = -(float)Math.Asin((_toPosition.Y - toLookAt.Y) / Vector3.Distance(_toPosition, toLookAt));

            var angle = _fromYaw - _toYaw;
            if (angle > MathUtil.Pi)
                _fromYaw -= MathUtil.TwoPi;
            else if (angle < -MathUtil.Pi)
                _fromYaw += MathUtil.TwoPi;

            EndTime = time.GetTotalTime(Vector3.Distance(_fromPosition, _toPosition));
        }
示例#12
0
        protected override bool draw(Camera camera, DrawingReason drawingReason, ShadowMap shadowMap)
        {
            if (drawingReason != DrawingReason.Normal)
                return true;

            camera.UpdateEffect(Effect);
            foreach (var item in Items)
            {
                Effect.World = Matrix.BillboardRH(item.Target.Position + item.GetOffset(item), camera.Position, -camera.Up, camera.Front);
                Effect.DiffuseColor = item.GetColor(item);
                SpriteBatch.Begin(SpriteSortMode.Deferred, Effect.GraphicsDevice.BlendStates.NonPremultiplied, null, Effect.GraphicsDevice.DepthStencilStates.DepthRead, null, Effect.Effect);
                SpriteBatch.DrawString(Font, item.Text, Vector2.Zero, Color.Black, 0, Font.MeasureString(item.Text) / 2, item.GetSize(item), 0, 0);
                SpriteBatch.End();
            }

            Effect.GraphicsDevice.SetDepthStencilState(Effect.GraphicsDevice.DepthStencilStates.Default);
            Effect.GraphicsDevice.SetBlendState(Effect.GraphicsDevice.BlendStates.Opaque);

            return true;
        }
示例#13
0
        public void Draw(Camera camera, Vector3 pos, float distance, int x, int y, int lakeTextureTransformation)
        {
            var world = Matrix.Translation(pos);
            Effect.World = world;
            Effect.View = camera.View;
            Effect.Projection = camera.Projection;
            _mhWorldInv.SetValue(Matrix.Invert(world));
            _mhCameraPosition.SetValue(camera.Position);

            _mhWaveBumpMapOffset0.SetValue(_waveBumpMapOffset0);
            _mhWaveBumpMapOffset1.SetValue(_waveBumpMapOffset1);
            _mhWaveDispMapOffset0.SetValue(_waveDispMapOffset0);
            _mhWaveDispMapOffset1.SetValue(_waveDispMapOffset1);

            if ( distance < 0 )
            {
                WaterFactory.RenderedWaterPlanes[5]++;
                Effect.Parameters["LakeTextureTransformation"].SetValue(new Vector4(0, 0, lakeTextureTransformation, lakeTextureTransformation));
                Effect.Effect.CurrentTechnique = Effect.Effect.Techniques[1];
                _lakePlane.Draw(Effect);
                return;
            }

            Effect.Parameters["LakeTextureTransformation"].SetValue(new Vector4(-x, -y, 2, 2));
            Effect.Effect.CurrentTechnique = Effect.Effect.Techniques[0];

            if (distance < 80)
            {
                _hiPolyPlane.Draw(Effect);
                WaterFactory.RenderedWaterPlanes[0]++;
            }
            else if (distance < 160)
            {
                WaterFactory.RenderedWaterPlanes[1]++;
                world *= Matrix.Translation(0, -0.10f, 0);
                Effect.World = world;
                _mhWorldInv.SetValue(Matrix.Invert(world));
                _hiPolyPlane.Draw(Effect, 1);
            }
            else if (distance < 400)
            {
                WaterFactory.RenderedWaterPlanes[2]++;
                world *= Matrix.Translation(0, -0.20f, 0);
                Effect.World = world;
                _mhWorldInv.SetValue(Matrix.Invert(world));
                _hiPolyPlane.Draw(Effect, 3);
            }
            else
            {
                var lod = 5;
                if (distance > 800)
                {
                    WaterFactory.RenderedWaterPlanes[4]++;
                    Effect.Effect.CurrentTechnique = Effect.Effect.Techniques[1];
                    lod = 5;
                }
                else
                    WaterFactory.RenderedWaterPlanes[3]++;
                world *= Matrix.Translation(0, -0.30f, 0);
                Effect.World = world;
                _mhWorldInv.SetValue(Matrix.Invert(world));
                _hiPolyPlane.Draw(Effect, lod);
            }
        }
示例#14
0
 public override void Update(Camera camera, GameTime gameTime)
 {
     _time += (float)gameTime.ElapsedGameTime.TotalSeconds;
 }
示例#15
0
 public override void Update(Camera camera, GameTime gameTime)
 {
     Speed -= SpeedDecreasePerSecond*(float) gameTime.ElapsedGameTime.TotalSeconds;
     base.Update(camera, gameTime);
 }
示例#16
0
        public WaterSurface(
            GraphicsDevice graphicsDevice,
            InitInfo initInfo)
        {
            Effect = new VisionEffect(initInfo.Fx, graphicsDevice.SamplerStates.LinearClamp)
            {
                SunlightDirection = VisionContent.SunlightDirection - new Vector3(0, VisionContent.SunlightDirection.Y/2, 0)
            };

            _waveBumpMapVelocity0 = initInfo.waveBumpMapVelocity0;
            _waveBumpMapVelocity1 = initInfo.waveBumpMapVelocity1;
            _waveDispMapVelocity0 = initInfo.waveDispMapVelocity0;
            _waveDispMapVelocity1 = initInfo.waveDispMapVelocity1;

            _hiPolyPlane = generatePlane(graphicsDevice, initInfo.SquareSize, initInfo.dx, initInfo.dz,
                                         initInfo.texScale);

            _lakePlane = generatePlane(graphicsDevice, 1, initInfo.SquareSize*512, initInfo.SquareSize*512, initInfo.texScale*512);

            buildFx(initInfo);

            var targetWidth = graphicsDevice.BackBuffer.Width;
            var targetHeight = graphicsDevice.BackBuffer.Height;
            _reflectionTarget = RenderTarget2D.New(
                graphicsDevice,
                targetWidth,
                targetHeight*11/10, //compensate for displaced waves
                graphicsDevice.BackBuffer.Format);

            _reflectionCamera = new Camera(
                new Vector2(targetWidth, targetHeight),
                null,
                null,
                null,
                Vector3.Zero,
                Vector3.Up);

            Update(10);
        }
示例#17
0
        public void RenderReflection(Camera camera)
        {
            const float waterMeshPositionY = 0.75f; //experimenting with this

            // Reflect the camera's properties across the water plane
            var reflectedCameraPosition = camera.Position;
            reflectedCameraPosition.Y = -reflectedCameraPosition.Y + 1 + waterMeshPositionY * 2;
            var reflectedCameraTarget = camera.Target;
            reflectedCameraTarget.Y = -reflectedCameraTarget.Y + 1 + waterMeshPositionY * 2;

            _reflectionCamera.Update(
                reflectedCameraPosition,
                reflectedCameraTarget);

            Effect.GraphicsDevice.SetRenderTargets(Effect.GraphicsDevice.DepthStencilBuffer, _reflectionTarget);
            Effect.GraphicsDevice.Clear(Color.CornflowerBlue);

            var clipPlane = new Vector4(0, 1, 0, -waterMeshPositionY);
            foreach (var cd in ReflectedObjects)
                cd.DrawReflection(clipPlane, _reflectionCamera);

            Effect.GraphicsDevice.SetRenderTargets(Effect.GraphicsDevice.DepthStencilBuffer, Effect.GraphicsDevice.BackBuffer);

            _reflectedView.SetValue(_reflectionCamera.View);
            _reflectedMap.SetResource(_reflectionTarget);
        }
示例#18
0
 protected MoveCameraBase(Camera camera)
 {
     Camera = camera;
     FromLookAt = camera.Target;
 }