public static void Update(GameTime time, Camera camera)
        {
            List<Sound3D> toRemove = new List<Sound3D>();

            Matrix viewInverse = Matrix.Invert(camera.ViewMatrix);
            Listener.Position = camera.Position;
            Listener.Up = viewInverse.Up;
            Listener.Velocity = camera.Velocity;
            Listener.Forward = viewInverse.Forward;

            foreach (Sound3D instance in ActiveSounds)
            {
                if (instance.HasStarted && instance.EffectInstance.State == SoundState.Stopped)
                {
                    instance.EffectInstance.Dispose();
                    toRemove.Add(instance);
                }
                else if (!instance.HasStarted)
                {
                    Emitter.Position = instance.Position;
                    instance.EffectInstance.Apply3D(Listener, Emitter);
                    instance.EffectInstance.Play();
                    instance.HasStarted = true;
                }
            }

            foreach (Sound3D r in toRemove)
            {
                ActiveSounds.Remove(r);
            }
        }
        public override void Render(GameTime gameTime,  Camera camera, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice, Effect effect)
        {
            if (IsVisible)
            {
                effect.Parameters["xTint"].SetValue(new Vector4(Tint.R, Tint.G, Tint.B, Tint.A));

                base.Render(gameTime,  camera, spriteBatch, graphicsDevice, effect);

            }
        }
        public override void Update(GameTime gameTime, Camera camera)
        {
            LightingTimer.Update(gameTime);
            Vector4 lerpTint = new Vector4((float)TargetTint.R / 255.0f, (float)TargetTint.G / 255.0f, (float)TargetTint.B / 255.0f, (float)TargetTint.A / 255.0f);
            Vector4 currTint = new Vector4((float)Tint.R / 255.0f, (float)Tint.G / 255.0f, (float)Tint.B / 255.0f, (float)Tint.A / 255.0f);

            Vector4 delta = lerpTint - currTint;
            lerpTint = currTint + delta * Math.Max(Math.Min(LightingTimer.CurrentTimeSeconds * TintChangeRate, 1.0f), 0.0f);

            Tint = new Color(lerpTint.X, lerpTint.Y, lerpTint.Z, lerpTint.W);

            base.Update(gameTime,camera);
        }
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Camera camera)
        {
            if (IsTracking && Component.GlobalTransform.Translation.Y < 1.0f)
            {
                float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;
                Vector3 force = Controller.GetOutput(dt, targetVelocity, Component.Velocity);
                force.Y = 0;

                Component.ApplyForce(force, dt);
            }

            base.Update(gameTime, camera);
        }
        public void CalculateCurrentOrientation(Camera camera)
        {
            float xComponent = Vector3.Dot(camera.ViewMatrix.Forward, GlobalTransform.Left);
            float yComponent = Vector3.Dot(camera.ViewMatrix.Forward, GlobalTransform.Forward);

            float angle = (float)Math.Atan2(yComponent, xComponent);

            if (angle > -MathHelper.PiOver2 + 0.01f && angle < MathHelper.PiOver2 - 0.01f)
            {
                CurrentOrientedAnimation.SetLeft();
            }
            else if (angle < -MathHelper.PiOver2 - 0.01f || angle > MathHelper.PiOver2 + 0.01f)
            {
                CurrentOrientedAnimation.SetRight();
            }
        }
Example #6
0
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Camera camera)
        {
            float x = (float)Math.Sin((gameTime.TotalGameTime.TotalSeconds + Offset) * Rate) * Magnitude;
            Matrix trans = Component.LocalTransform;

            trans.Translation = new Vector3(trans.Translation.X, x, trans.Translation.Z);
            Component.LocalTransform = trans;

            Component.HasMoved = true;

            if (Component.Parent is LocatableComponent)
            {
                (Component.Parent as LocatableComponent).HasMoved = true;
            }

            base.Update(gameTime, camera);
        }
        public override void Render(GameTime gameTime,
            Camera camera,
            SpriteBatch spriteBatch,
            GraphicsDevice graphicsDevice,
            Effect effect)
        {
            Matrix origTransform = m_globalTransform;
            for(int i = 0; i < LocalTransforms.Count; i++)
            {

                m_globalTransform = origTransform;
                m_globalTransform = LocalTransforms[i] * m_globalTransform;

                if ((m_globalTransform.Translation - camera.Position).LengthSquared() < CullDistance)
                {
                    BillboardRotation = Rotations[i];
                    Tint = Tints[i];
                    base.Render(gameTime, camera, spriteBatch, graphicsDevice, effect);
                }
            }
            m_globalTransform = origTransform;
        }
        public override void Update(GameTime gameTime,Camera camera)
        {
            if (HasMoved && UpdateTimer.HasTriggered)
            {
                LocatableComponent p = (LocatableComponent)Parent;

                Vector3 pos = p.GlobalTransform.Translation;
                pos.Y = Height;

                Matrix newTrans = LocalTransform;
                newTrans.Translation = (pos - p.GlobalTransform.Translation); // new Vector3(0, -2.15f, 0);
                LocalTransform = newTrans;

                UpdateTimer.HasTriggered = false;
            }
            else
            {
                UpdateTimer.Update(gameTime);
            }

            base.Update(gameTime, camera);
        }
        public override void Render(GameTime gameTime,  Camera camera, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice, Effect effect)
        {
            if (!IsVisible)
            {
                return;
            }

            base.Render(gameTime, camera, spriteBatch, graphicsDevice, effect);
            Texture2D originalText = effect.Parameters["xTexture"].GetValueTexture2D();

            RasterizerState r = graphicsDevice.RasterizerState;
            graphicsDevice.RasterizerState = rasterState;
            effect.Parameters["xTexture"].SetValue(Texture);

               // DepthStencilState origDepthStencil = graphicsDevice.DepthStencilState;
               // DepthStencilState newDepthStencil = DepthStencilState.DepthRead;
               // graphicsDevice.DepthStencilState = newDepthStencil;

            Matrix oldWorld = effect.Parameters["xWorld"].GetValueMatrix();
            effect.Parameters["xView"].SetValue(camera.ViewMatrix);
            effect.Parameters["xProjection"].SetValue(camera.ProjectionMatrix);

            effect.Parameters["xWorld"].SetValue(GlobalTransform);

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                Primitive.Render(graphicsDevice);
            }

            effect.Parameters["xWorld"].SetValue(oldWorld);

            effect.Parameters["xTexture"].SetValue(originalText);

               // graphicsDevice.DepthStencilState = origDepthStencil;
            graphicsDevice.RasterizerState = r;
        }
Example #10
0
 public void RenderSunMoon(GameTime time, GraphicsDevice device, Camera camera)
 {
     SkyEffect.Parameters["SkyboxTexture"].SetValue(SunMoon);
     SkyEffect.Parameters["ViewMatrix"].SetValue(camera.ViewMatrix);
     SkyEffect.Parameters["ProjectionMatrix"].SetValue(camera.ProjectionMatrix);
     SkyEffect.Parameters["xTransparency"].SetValue(1.0f);
     SkyEffect.Parameters["xRot"].SetValue(Matrix.CreateRotationZ(-(CosTime + 0.5f *(float)Math.PI)));
     SkyEffect.CurrentTechnique = SkyEffect.Techniques[1];
     SkyEffect.Parameters["xTint"].SetValue(0.0f);
     foreach (ModelMesh mesh in SkyMesh.Meshes)
     {
         mesh.Draw();
     }
 }
        public override void Update(GameTime gameTime, Camera camera)
        {
            if (IsActive)
            {
                if (CurrentAnimation != null)
                {
                    CurrentAnimation.Update(gameTime);
                }

            }

            base.Update(gameTime, camera);
        }
Example #12
0
        public override void Update(GameTime gameTime, Camera camera)
        {
            monitor.SetCurrentAnimation("dead");
            if (GlobalTransform.Translation.Y >= 1)
            {
                State = "fly";
            }
            else if(State.Equals("fly"))
            {
                State = "walk";
            }
            if (State.Equals("dead"))
            {
                velocityController.targetVelocity = Vector3.Zero;
            }
            else if (State.Equals("dying"))
            {
                velocityController.targetVelocity = Vector3.Zero;
                DieTimer.Update(gameTime);
                if (DieTimer.HasTriggered)
                {
                    State = "dead";
                    string[] deathSounds = { "manDying1", "manDying2"};
                    SoundManager.PlaySound(deathSounds[RandomHelper.random.Next(0, 2)], GlobalTransform.Translation);
                }
            }
            else if (State.Equals("walk"))
            {
                monitor.SetCurrentAnimation("alive");
                WalkTimer.Update(gameTime);

                Vector3 normalized = (Target - GlobalTransform.Translation);
                normalized.Normalize();

                velocityController.targetVelocity = velocityController.MaxSpeed * normalized;
                velocityController.IsTracking = true;

                if (WalkTimer.HasTriggered)
                {
                    State = "dying";
                    DieTimer.Reset(MaxDieTime);
                    image.GetOrientedAnimation(AnimationState["dying"]).Reset();
                }
            }
            SetAnimation();
            base.Update(gameTime, camera);
        }
        public override void Update(GameTime gameTime, Camera camera)
        {
            if (Velocity.LengthSquared() < 0.1f)
            {
                IsSleeping = true;
            }
            else
            {
                IsSleeping = false;
            }

            float dt = (float)(gameTime.ElapsedGameTime.TotalSeconds);

            if (m_applyGravityThisFrame)
            {
                ApplyForce(Gravity, dt);
            }
            else
            {
                m_applyGravityThisFrame = true;
            }

            Matrix transform = LocalTransform;
            PreviousPosition = transform.Translation;
            transform.Translation = LocalTransform.Translation + Velocity * dt;

            if (!OrientWithVelocity)
            {
                Matrix dA = Matrix.Identity;
                dA *= Matrix.CreateRotationX(AngularVelocity.X * dt);
                dA *= Matrix.CreateRotationY(AngularVelocity.Y * dt);
                dA *= Matrix.CreateRotationZ(AngularVelocity.Z * dt);

                transform = dA * transform;
            }
            else
            {
                if (Velocity.Length() > 0.4f)
                {
                    Matrix newTransform = Matrix.CreateRotationY((float)Math.Atan2(Velocity.X, -Velocity.Z));
                    newTransform.Translation = transform.Translation;
                    transform = newTransform;
                }
            }

            LocalTransform = transform;

            if (Math.Abs(Velocity.Y) < 0.1f)
            {
                Velocity = new Vector3(Velocity.X * Friction, Velocity.Y, Velocity.Z * Friction);
            }

            Velocity *= LinearDamping;
            AngularVelocity *= AngularDamping;
            UpdateBoundingBox();

            base.Update(gameTime, camera);
        }
        public override void Render(GameTime gameTime,
            Camera camera,
            SpriteBatch spriteBatch,
            GraphicsDevice graphicsDevice,
            Effect effect)
        {
            base.Render(gameTime, camera, spriteBatch, graphicsDevice, effect);

            if (IsVisible)
            {

                RasterizerState r = graphicsDevice.RasterizerState;
                graphicsDevice.RasterizerState = rasterState;
                effect.Parameters["xTexture"].SetValue(SpriteSheet);

                DepthStencilState origDepthStencil = graphicsDevice.DepthStencilState;
                DepthStencilState newDepthStencil = DepthStencilState.DepthRead;
                graphicsDevice.DepthStencilState = newDepthStencil;

                if (CurrentAnimation != null)
                {
                    Matrix oldWorld = effect.Parameters["xWorld"].GetValueMatrix();

                    if (OrientsToCamera)
                    {
                        float xscale = GlobalTransform.Left.Length();
                        float yscale = GlobalTransform.Up.Length();
                        float zscale = GlobalTransform.Forward.Length();
                        Matrix rot = Matrix.CreateRotationZ(BillboardRotation);

                        Matrix bill = Matrix.CreateBillboard(GlobalTransform.Translation, camera.Position, camera.UpVector, null);
                        Matrix noTransBill = bill;
                        noTransBill.Translation = Vector3.Zero;

                        Matrix worldRot = Matrix.CreateScale(new Vector3(xscale, yscale, zscale)) * rot * noTransBill;
                        worldRot.Translation = bill.Translation + Offset;

                        effect.Parameters["xWorld"].SetValue(worldRot);
                    }
                    else
                    {
                        Matrix newMatrix = GlobalTransform * Matrix.CreateTranslation(Offset);
                        effect.Parameters["xWorld"].SetValue(newMatrix);
                    }

                    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                    {
                        pass.Apply();
                        CurrentAnimation.Primitives[CurrentAnimation.CurrentFrame].Render(graphicsDevice);
                    }
                    effect.Parameters["xWorld"].SetValue(oldWorld);
                }

                if (origDepthStencil != null)
                {
                    graphicsDevice.DepthStencilState = origDepthStencil;
                }

                if (r != null)
                {
                    graphicsDevice.RasterizerState = r;
                }
            }
        }
Example #15
0
        public override void Render(SpriteBatch batch, Camera camera, Viewport viewport)
        {
            Vector2 extents = Font.MeasureString(Text);
            Vector3 unprojected = viewport.Project(Position, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity);

            Rectangle rect = new Rectangle((int)(unprojected.X - extents.X / 2.0f  - StrokeWeight), (int)(unprojected.Y - extents.Y / 2.0f - StrokeWeight),
                                           (int)(extents.X + StrokeWeight + 5), (int)(extents.Y + StrokeWeight + 5));

            Drawer2D.FillRect(batch, rect, FillColor);
            Drawer2D.DrawRect(batch, rect, RectStrokeColor, StrokeWeight);
            batch.DrawString(Font, Text, new Vector2(unprojected.X + 1, unprojected.Y) - extents / 2.0f, StrokeColor);
            batch.DrawString(Font, Text, new Vector2(unprojected.X - 1, unprojected.Y) - extents / 2.0f, StrokeColor);

            batch.DrawString(Font, Text, new Vector2(unprojected.X, unprojected.Y + 1) - extents / 2.0f, StrokeColor);
            batch.DrawString(Font, Text, new Vector2(unprojected.X, unprojected.Y - 1) - extents / 2.0f, StrokeColor);

            batch.DrawString(Font, Text, new Vector2(unprojected.X, unprojected.Y) - extents / 2.0f, TextColor);

            base.Render(batch, camera, viewport);
        }
Example #16
0
        public override void Update(GameTime gameTime, Camera camera)
        {
            base.Update(gameTime, camera);

            if (pastPos.Count > 3)
            {
                pastPos.Dequeue();
                pastPos.Enqueue(LocalTransform.Translation);

                Vector3 newPos = new Vector3(0, 0, 0);

                Vector3 tempPos = pastPos.Dequeue();
                newPos += tempPos * 0.1f;
                pastPos.Enqueue(tempPos);
                tempPos = pastPos.Dequeue();
                newPos += tempPos * 0.3f;
                pastPos.Enqueue(tempPos);
                tempPos = pastPos.Dequeue();
                newPos += tempPos * 0.3f;
                pastPos.Enqueue(tempPos);
                tempPos = pastPos.Dequeue();
                newPos += tempPos * 0.3f;
                pastPos.Enqueue(tempPos);

                Vector3 offset = newPos - LocalTransform.Translation;

                image.Offset = offset;
                shadow.Offset = offset;
                teamCircle.Offset = offset;
            }

            if (team != null)
            { Score = team.Score; }

            if (Charging)
            {
                DefibCharge += (float)gameTime.ElapsedGameTime.TotalSeconds * DefibChargeRate;
            }
            if (DefibCharge == 0)
            {
                currentCharge = ChargeState.NO_CHARGE;
            }
            else if (DefibCharge < HIGH_DEFIB_CHARGE)
            {
                currentCharge = ChargeState.LOW_CHARGE;
            }
            else if (DefibCharge < MAX_DEFIB_CHARGE)
            {
                currentCharge = ChargeState.HIGH_CHARGE;
            }
            else
            {
                DefibCharge = MAX_DEFIB_CHARGE;
                currentCharge = ChargeState.MAX_CHARGE;
            }
            String prefix;
            if (Velocity.Length() < 1.0f)
            {
                prefix = "idle";
            }
            else
            {
                prefix = "walk";
            }
            switch (currentCharge)
            {
                case ChargeState.NO_CHARGE:
                    State = prefix;
                    break;
                case ChargeState.LOW_CHARGE:
                    State = prefix + "_low";
                    break;
                case ChargeState.HIGH_CHARGE:
                case ChargeState.MAX_CHARGE:
                    State = prefix + "_high";
                    break;
            }
            SetAnimation();
        }
 public override void Update(GameTime gameTime, Camera camera)
 {
     //base.Update(gameTime, chunks, camera);
 }
Example #18
0
 public void RenderDaySky(GameTime time, GraphicsDevice device, Camera camera)
 {
     SkyEffect.Parameters["SkyboxTexture"].SetValue(SkyTexture);
     SkyEffect.Parameters["ViewMatrix"].SetValue(camera.ViewMatrix);
     SkyEffect.Parameters["ProjectionMatrix"].SetValue(camera.ProjectionMatrix);
     SkyEffect.Parameters["xTransparency"].SetValue(1.0f - (float)Math.Pow(TimeOfDay, 2));
     SkyEffect.Parameters["xRot"].SetValue(Matrix.CreateRotationY((float)time.TotalGameTime.TotalSeconds * 0.005f));
     SkyEffect.CurrentTechnique = SkyEffect.Techniques[0];
     SkyEffect.Parameters["xTint"].SetValue(TimeOfDay);
     foreach (ModelMesh mesh in SkyMesh.Meshes)
     {
         mesh.Draw();
     }
 }
Example #19
0
 public virtual void Render(SpriteBatch batch, Camera camera, Viewport viewport)
 {
 }
        public override void Render(GameTime gameTime,
            Camera camera,
            SpriteBatch spriteBatch,
            GraphicsDevice graphicsDevice,
            Effect effect)
        {
            if (Primitive == null)
            {
                Primitive = new BatchBillboardPrimitive(graphicsDevice, SpriteSheet, Width, Height, Frame, 1.0f, 1.0f, false, LocalTransforms, Tints);
            }

            effect.Parameters["xTint"].SetValue(new Vector4(1, 1, 1, 1));
            if (IsVisible && (camera.Position - GlobalTransform.Translation).LengthSquared() < CullDistance)
            {
                Texture2D originalText = effect.Parameters["xTexture"].GetValueTexture2D();
                RasterizerState r = graphicsDevice.RasterizerState;
                graphicsDevice.RasterizerState = rasterState;
                effect.Parameters["xTexture"].SetValue(SpriteSheet);

                DepthStencilState origDepthStencil = graphicsDevice.DepthStencilState;
                DepthStencilState newDepthStencil = DepthStencilState.DepthRead;
                graphicsDevice.DepthStencilState = newDepthStencil;

                Matrix oldWorld = effect.Parameters["xWorld"].GetValueMatrix();
                effect.Parameters["xWorld"].SetValue(GlobalTransform);

                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    Primitive.Render(graphicsDevice);
                }
                effect.Parameters["xWorld"].SetValue(oldWorld);

                effect.Parameters["xTexture"].SetValue(originalText);

                if (origDepthStencil != null)
                {
                    graphicsDevice.DepthStencilState = origDepthStencil;
                }

                if (r != null)
                {
                    graphicsDevice.RasterizerState = r;
                }
            }
        }
Example #21
0
        public void Render(SpriteBatch batch, Camera camera, Viewport viewport)
        {
            foreach (DrawCommand2D draw in DrawCommands)
            {
                draw.Render(batch, camera, viewport);
            }

            while (DrawCommands.Count > 0)
            {
                DrawCommand2D draw = null;
                DrawCommands.TryDequeue(out draw);
            }
        }
        public override void Render(GameTime gameTime,  Camera camera, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice, Effect effect)
        {
            if (DrawBoundingBox)
            {
                SimpleDrawing.DrawBox(BoundingBox, Color.White, 0.02f);
            }

            base.Render(gameTime, camera, spriteBatch, graphicsDevice, effect);
        }
Example #23
0
        public override void Render(SpriteBatch batch, Camera camera, Viewport viewport)
        {
            Vector2 extents = Font.MeasureString(Text);
            Vector3 unprojected = viewport.Project(Position, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity);

            unprojected.X = Math.Min(Math.Max(extents.X * 0.5f, unprojected.X), viewport.Width - extents.X * 0.5f) ;
            unprojected.Y = Math.Min(Math.Max(extents.Y * 0.5f, unprojected.Y), viewport.Height - extents.Y * 0.5f);

            batch.DrawString(Font, Text, new Vector2(unprojected.X + 1, unprojected.Y) - extents / 2.0f, StrokeColor);
            batch.DrawString(Font, Text, new Vector2(unprojected.X - 1, unprojected.Y) - extents / 2.0f, StrokeColor);

            batch.DrawString(Font, Text, new Vector2(unprojected.X, unprojected.Y + 1) - extents / 2.0f, StrokeColor);
            batch.DrawString(Font, Text, new Vector2(unprojected.X, unprojected.Y - 1) - extents / 2.0f, StrokeColor);

            batch.DrawString(Font, Text, new Vector2(unprojected.X, unprojected.Y) - extents / 2.0f, TextColor);

            base.Render(batch, camera, viewport);
        }
Example #24
0
 public void RenderNightSky(GameTime time, GraphicsDevice device, Camera camera)
 {
     SkyEffect.Parameters["SkyboxTexture"].SetValue(NightTexture);
     SkyEffect.Parameters["ViewMatrix"].SetValue(camera.ViewMatrix);
     SkyEffect.Parameters["ProjectionMatrix"].SetValue(camera.ProjectionMatrix);
     SkyEffect.Parameters["xTransparency"].SetValue(TimeOfDay);
     SkyEffect.Parameters["xRot"].SetValue(Matrix.CreateRotationZ(-(CosTime + 0.5f)));
     SkyEffect.Parameters["xTint"].SetValue(0.0f);
     SkyEffect.CurrentTechnique = SkyEffect.Techniques[0];
     foreach (ModelMesh mesh in SkyMesh.Meshes)
     {
         mesh.Draw();
     }
 }
Example #25
0
 public void Render(GameTime time, GraphicsDevice device, Camera camera)
 {
     RenderNightSky(time, device, camera);
     RenderDaySky(time, device, camera);
     RenderSunMoon(time, device, camera);
 }
        public override void Update(GameTime gameTime,  Camera camera)
        {
            if (CurrentOrientedAnimation.Oriented())
            {
                CalculateCurrentOrientation(camera);
                CurrentAnimation = CurrentOrientedAnimation.GetAnimation();
            }

            base.Update(gameTime, camera);
        }
Example #27
0
 public override void Render(SpriteBatch batch, Camera camera, Viewport viewport)
 {
     Drawer2D.FillRect(batch, Bounds, FillColor);
     Drawer2D.DrawRect(batch, Bounds, StrokeColor, StrokeWeight);
     base.Render(batch, camera, viewport);
 }