예제 #1
0
        /// <summary>
        /// Method to draw bounding box's
        /// </summary>
        /// <param name="gameTime"></param>
        public virtual void DrawBoundsBoxs(GameTime gameTime)
        {
            VertexPositionColor[] points;
            short[] index;

            GameComponentHelper.BuildBoxCorners(new List <BoundingBox>()
            {
                BoundingBox
            }, new List <Matrix>()
            {
                Matrix.Identity
            }, BoundsBoxColor, out points, out index);

            if (basicEffect == null)
            {
                basicEffect = new BasicEffect(GraphicsDevice);
            }

            basicEffect.World = Matrix.CreateScale(Scale) *
                                Matrix.CreateTranslation(Position);
            basicEffect.View               = camera.View;
            basicEffect.Projection         = camera.Projection;
            basicEffect.VertexColorEnabled = true;

            basicEffect.CurrentTechnique.Passes[0].Apply();
            GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, points, 0, points.Length, index, 0, 12 * 1);
        }
예제 #2
0
        public void GetReflectionMap(GameTime gameTime, float waterHeight)
        {
            Quaternion orgRot  = Camera.Rotation;
            Matrix     orgView = Camera.View;

            Vector3 refCamPos = Camera.Position;

            refCamPos.Y = -refCamPos.Y + waterHeight * 2;

            GameComponentHelper.LockRotation(ref orgRot, Vector3.Forward);
            Matrix rot = Matrix.CreateFromQuaternion(orgRot);

            Vector3 refTargetPos = Camera.Position + Vector3.Transform(Vector3.Forward, rot);

            refTargetPos.Y = -refTargetPos.Y + waterHeight * 2;

            Vector3 camRight = Vector3.Transform(Vector3.Right, rot);
            Vector3 invUp    = Vector3.Cross(camRight, refCamPos - refTargetPos);

            Camera.View = Matrix.CreateLookAt(refCamPos, refTargetPos, invUp);

            GameComponentHelper.WaterReflectionPane = GameComponentHelper.CreatePlane(waterHeight, new Vector3(0, -1, 0), Camera.View, true, Camera.Projection);
            Game.GraphicsDevice.SetRenderTargets(GameComponentHelper.reflectionMap, GameComponentHelper.reflectionSGRMap);
            Game.GraphicsDevice.BlendState        = BlendState.Opaque;
            Game.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);

            // Draw here.
            if (!StopRender)
            {
                int cnt = Game.Components.Count;
                for (int c = 0; c < cnt; c++)
                {
                    // Do draw
                    if (Game.Components[c] is IDeferredRender)
                    {
                        ((IDeferredRender)Game.Components[c]).Draw(gameTime);
                    }
                }
            }
            else
            {
                if (CanDrawDeferred != null && CanDrawDeferred is IDeferredRender)
                {
                    CanDrawDeferred.Draw(gameTime);
                }
            }

            //GraphicsDevice.ClipPlanes[0].IsEnabled = false;
            Game.GraphicsDevice.SetRenderTargets(null);

            Camera.Rotation = orgRot;
            Camera.View     = orgView;
            //SaveJpg(GameComponentHelper.reflectionMap, "ReflectionMap.jpg");
            Game.GraphicsDevice.DepthStencilState = DepthStencilState.None;

            GameComponentHelper.WaterReflectionPane = new Plane();
        }
예제 #3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (inputHandler.KeyboardManager.KeyPress(Keys.Escape))
            {
                this.Exit();
            }

            float x = (float)Math.Cos(gameTime.TotalGameTime.TotalSeconds) * 10;
            float y = 1;// MathHelper.Clamp((float)Math.Cos(gameTime.TotalGameTime.TotalSeconds), 0, 1);
            float z = (float)Math.Sin(gameTime.TotalGameTime.TotalSeconds) * 10;

            Vector3 lp = tailInstancer.Position;

            tailInstancer.Position = new Vector3(x, y, z - 10);
            GameComponentHelper.LookAt(lp, 1, tailInstancer.Position, ref tailInstancer.Rotation, Vector3.Down);

            float speedTran = .1f;
            float speedRot  = .01f;

            if (inputHandler.KeyboardManager.KeyPress(Keys.F1))
            {
                renderer.DebugDeferred = !renderer.DebugDeferred;
            }

            if (inputHandler.KeyboardManager.KeyPress(Keys.Space))
            {
                renderer.DirectionalLights[0].CastShadow = !renderer.DirectionalLights[0].CastShadow;
            }

            if (inputHandler.KeyboardManager.KeyDown(Keys.W) || inputHandler.GamePadManager.ButtonDown(PlayerIndex.One, Buttons.DPadUp))
            {
                camera.Translate(Vector3.Forward * speedTran);
            }
            if (inputHandler.KeyboardManager.KeyDown(Keys.S) || inputHandler.GamePadManager.ButtonDown(PlayerIndex.One, Buttons.DPadDown))
            {
                camera.Translate(Vector3.Backward * speedTran);
            }
            if (inputHandler.KeyboardManager.KeyDown(Keys.A) || inputHandler.GamePadManager.ButtonDown(PlayerIndex.One, Buttons.DPadLeft))
            {
                camera.Translate(Vector3.Left * speedTran);
            }
            if (inputHandler.KeyboardManager.KeyDown(Keys.D) || inputHandler.GamePadManager.ButtonDown(PlayerIndex.One, Buttons.DPadRight))
            {
                camera.Translate(Vector3.Right * speedTran);
            }

            if (inputHandler.KeyboardManager.KeyDown(Keys.Left) || inputHandler.GamePadManager.State[PlayerIndex.One].ThumbSticks.Right.X < 0)
            {
                camera.Rotate(Vector3.Up, speedRot);
            }
            if (inputHandler.KeyboardManager.KeyDown(Keys.Right) || inputHandler.GamePadManager.State[PlayerIndex.One].ThumbSticks.Right.X > 0)
            {
                camera.Rotate(Vector3.Up, -speedRot);
            }
            if (inputHandler.KeyboardManager.KeyDown(Keys.Up) || inputHandler.GamePadManager.State[PlayerIndex.One].ThumbSticks.Right.Y > 0)
            {
                camera.Rotate(Vector3.Right, speedRot);
            }
            if (inputHandler.KeyboardManager.KeyDown(Keys.Down) || inputHandler.GamePadManager.State[PlayerIndex.One].ThumbSticks.Right.Y < 0)
            {
                camera.Rotate(Vector3.Right, -speedRot);
            }

            if (inputHandler.KeyboardManager.KeyPress(Keys.F2))
            {
                snowInstancer.Enabled = !snowInstancer.Enabled;
            }

            if (inputHandler.KeyboardManager.KeyPress(Keys.F3))
            {
                tailInstancer.Enabled = !tailInstancer.Enabled;
            }

            if (inputHandler.KeyboardManager.KeyPress(Keys.F4))
            {
                smokeInstancer.Enabled = !smokeInstancer.Enabled;
            }


            box.Rotate(Vector3.Up, .01f);
            box1.Rotate(Vector3.Up + Vector3.Left, .01f);
            box2.Rotate(Vector3.Left, .01f);

            base.Update(gameTime);
        }
예제 #4
0
 public override void TranslateOO(Vector3 distance)
 {
     HasMoved            = Moved(distance);
     RigidBody.Position += ToJitterVector(GameComponentHelper.Translate3D(distance, rotation));
 }
예제 #5
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            msm.PreUpdate(gameTime);
            kbm.PreUpdate(gameTime);
            base.Update(gameTime);

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || kbm.KeyDown(Keys.Escape))
            {
                Exit();
            }

            // Camera controls..
            float speedTran = .1f;
            float speedRot  = .01f;

            if (kbm.KeyDown(Keys.W) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y > 0)
            {
                camera.Translate(Vector3.Forward * speedTran);
            }
            if (kbm.KeyDown(Keys.S) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y < 0)
            {
                camera.Translate(Vector3.Backward * speedTran);
            }
            if (kbm.KeyDown(Keys.A) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X < 0)
            {
                camera.Translate(Vector3.Left * speedTran);
            }
            if (kbm.KeyDown(Keys.D) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X > 0)
            {
                camera.Translate(Vector3.Right * speedTran);
            }

            if (kbm.KeyDown(Keys.Left) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X < 0)
            {
                camera.Rotate(Vector3.Up, speedRot);
            }
            if (kbm.KeyDown(Keys.Right) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X > 0)
            {
                camera.Rotate(Vector3.Up, -speedRot);
            }
            if (kbm.KeyDown(Keys.Up) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y > 0)
            {
                camera.Rotate(Vector3.Right, speedRot);
            }
            if (kbm.KeyDown(Keys.Down) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y < 0)
            {
                camera.Rotate(Vector3.Right, -speedRot);
            }

            // Do picking
            if (msm.LeftClicked)
            {
                float minD = float.MaxValue;

                foreach (Base3DObject obj in sceneObjects)
                {
                    BoundingBox tbb = GameComponentHelper.TransformedBoundingBoxAA(obj.BoundingBox, obj.Position, obj.Scale);
                    float       d   = GameComponentHelper.RayPicking(msm.ScreenPoint, tbb, camera);

                    if (d < minD)
                    {
                        minD = d;
                        if (selected != null)
                        {
                            selected.DrawBoxBounds = false;
                        }
                        selected = obj;
                        selected.DrawBoxBounds = true;
                    }
                }

                if (minD == float.MaxValue)
                {
                    if (selected != null)
                    {
                        selected.DrawBoxBounds = false;
                    }

                    selected = null;
                }
            }
        }