Example #1
0
        /**
         *   @brief This function updates the location of the camera.
         *	@param direction the direction the camera is travelling
         *	@param cameraSpeed the velocity of the camera
         *	@param deltaTime the slice of time the game has elapsed
         *	@param fps the framerate
         *	@return subjectPosition the new camera position
         *	@pre
         *	@post subjectPosition will be updated
         */
        public void SubjectMove(InputHandler.keyStates direction, float cameraSpeed, float deltaTime, float fps)
        {
            subjectRotation.Normalize();

            if (direction == InputHandler.keyStates.Forwards)
            {
                //futurePosition += cameraSpeed * actorRotation * deltaTime * fps;
                subjectPosition += cameraSpeed * subjectRotation * deltaTime * fps;

                Debug.WriteLine("position Vector: " + subjectPosition.X + " " + subjectPosition.Y + " " + subjectPosition.Z);
            }

            if (direction == InputHandler.keyStates.Backwards)
            {
                //futurePosition -= cameraSpeed * actorRotation * deltaTime * fps;
                subjectPosition -= cameraSpeed * subjectRotation * deltaTime * fps;

                Debug.WriteLine("position Vector: " + subjectPosition.X + " " + subjectPosition.Y + " " + subjectPosition.Z);
            }

            if (direction == InputHandler.keyStates.Left)
            {
                Vector3 tempDeltaVector = Vector3.Cross(Vector3.Up, subjectRotation);
                tempDeltaVector.Normalize();
                //futurePosition += cameraSpeed * tempDeltaVector * deltaTime * fps;
                subjectPosition += cameraSpeed * tempDeltaVector * deltaTime * fps;

                Debug.WriteLine("position Vector: " + subjectPosition.X + " " + subjectPosition.Y + " " + subjectPosition.Z);
            }

            if (direction == InputHandler.keyStates.Right)
            {
                Vector3 tempDeltaVector = Vector3.Cross(Vector3.Up, subjectRotation);
                tempDeltaVector.Normalize();
                //futurePosition -= cameraSpeed * tempDeltaVector * deltaTime * fps;
                subjectPosition -= cameraSpeed * tempDeltaVector * deltaTime * fps;

                Debug.WriteLine("position Vector: " + subjectPosition.X + " " + subjectPosition.Y + " " + subjectPosition.Z);
            }

            if (direction == InputHandler.keyStates.ZoomIn)
            {
                float zoomFactor = 0.005f;
                subjectPosition /= zoomFactor * subjectRotation * deltaTime * fps;
            }

            if (direction == InputHandler.keyStates.ZoomOut)
            {
                float zoomFactor = 0.005f;
                subjectPosition *= zoomFactor * subjectRotation * deltaTime * fps;
            }

            // calculates the new camera bounding box
            this.maxPoint = this.subjectPosition + this.AABBOffset;
            this.minPoint = this.subjectPosition - this.AABBOffset;
        }
Example #2
0
        /**
         *   @brief This function updates the location of the pigeon.
         *	@param direction the direction the pigeon is travelling
         *	@param cameraSpeed the velocity of the pigeon
         *	@param deltaTime the slice of time the game has elapsed
         *	@param fps the framerate
         *	@return subjectPosition the new pigeon position
         *	@pre
         *	@post subjectPosition will be updated
         */
        public void SubjectMove(InputHandler.keyStates direction, float cameraSpeed, float deltaTime, float fps)
        {
            //Debug.WriteLine("Input Down: " + direction);


            if (direction == InputHandler.keyStates.Right)
            {
                rotationDelta = subjectRotation;
                rotationDelta.Normalize();

                //futurePosition += cameraSpeed * rotationDelta * deltaTime * fps;
                subjectPosition += cameraSpeed * rotationDelta * deltaTime * fps;

                cameraPosition = Vector3.Add(subjectPosition, cameraDelta);
            }

            if (direction == InputHandler.keyStates.Left)
            {
                rotationDelta = subjectRotation;
                rotationDelta.Normalize();
                //futurePosition -= cameraSpeed * rotationDelta * deltaTime * fps;
                subjectPosition -= cameraSpeed * rotationDelta * deltaTime * fps;
                cameraPosition   = Vector3.Add(subjectPosition, cameraDelta);
            }

            if (direction == InputHandler.keyStates.Forwards)
            {
                Vector3 tempDeltaVector = Vector3.Cross(Vector3.Up, subjectRotation);
                tempDeltaVector.Normalize();
                // futurePosition += cameraSpeed * tempDeltaVector * deltaTime * fps;
                subjectPosition += cameraSpeed * tempDeltaVector * deltaTime * fps;
                cameraPosition   = Vector3.Add(subjectPosition, cameraDelta);
            }

            if (direction == InputHandler.keyStates.Backwards)
            {
                Vector3 tempDeltaVector = Vector3.Cross(Vector3.Up, subjectRotation);
                tempDeltaVector.Normalize();
                // futurePosition -= cameraSpeed * tempDeltaVector * deltaTime * fps;
                subjectPosition -= cameraSpeed * tempDeltaVector * deltaTime * fps;
                cameraPosition   = Vector3.Add(subjectPosition, cameraDelta);
            }


            if (direction == InputHandler.keyStates.CW)
            {
                cameraDelta    = cameraSpeed * OrbitCW() * deltaTime * fps;
                cameraPosition = Vector3.Add(subjectPosition, cameraDelta);

                // rotating the model to the direction you are facing
                // calculate pitch axis for rotating, therefore the orthogonal between the forward and up
                // assuming righthandedness
                Vector3 pitchAxis = Vector3.Cross(subjectRotation, Vector3.Up);
                //pitchAxis.Normalize();

                float radian = SubjectRadians(1);

                subjectRotation = Vector3.Transform(pitchAxis, Matrix.CreateRotationY(radian));
            }

            if (direction == InputHandler.keyStates.CCW)
            {
                cameraDelta    = cameraSpeed * OrbitCCW() * deltaTime * fps;
                cameraPosition = Vector3.Add(subjectPosition, cameraDelta);

                // rotating the model to the direction you are facing
                // calculate pitch axis for rotating, therefore the orthogonal between the forward and up
                // assuming righthandedness
                Vector3 pitchAxis = Vector3.Cross(subjectRotation, Vector3.Up);
                //pitchAxis.Normalize();

                float radian = SubjectRadians(-1);

                subjectRotation = Vector3.Transform(pitchAxis, Matrix.CreateRotationY(radian));
            }


            // calculates the new camera bounding box
            this.maxPoint = this.subjectPosition + this.AABBOffset;
            this.minPoint = this.subjectPosition - this.AABBOffset;
        }
Example #3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            int screenX = GraphicsDevice.Viewport.Width;
            int screenY = GraphicsDevice.Viewport.Height;

            //int screenX = Window.ClientBounds.Width;
            //int screenY = Window.ClientBounds.Height;
            projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), screenX / screenY, 0.1f, 8000f);

            int centerX = (int)(screenX / 2);
            int centerY = (int)(screenY / 2);

            this.IsMouseVisible = true;
            Mouse.SetPosition((int)centerX, (int)centerY);

            mapClient = new PlotClient(Content, 23, 23, 1.0f);
            mapClient.SetPlotDictionary();
            mapClient.SetPlotList();
            mapClient.PrintPlotList();

            Vector3 camEyeVector      = new Vector3(0, 0, 0);
            Vector3 camPositionVector = Vector3.Add(new Vector3(0, 0, 0), new Vector3(0, 1.6f, 0));
            Vector3 deltaVector       = new Vector3(0, 0, 0.001f);
            Vector3 AABBOffsetCamera  = new Vector3(0.5f, 0.25f, 0.5f);

            camera      = new Camera(theCamera, camPositionVector, camEyeVector, deltaVector, AABBOffsetCamera);
            cameraSpeed = 2f;
            fps         = 60f;

            // need to singleton this
            gameState = InputHandler.keyStates.Pigeon;
            string  modelPigeon      = "Models/SK_Pigeon";
            string  texturePigeon    = "Maya/sourceimages/pigeon_normal2";
            Vector3 predictedPigeon  = camPositionVector;
            Vector3 positionPigeon   = camPositionVector;
            Vector3 rotationPigeon   = new Vector3(-90, 0, 0) + deltaVector;
            Vector3 AABBOffsetPigeon = new Vector3(0.5f, 0.25f, 0.5f);
            float   scalePigeon      = 0.05f;

            pigeon = new Pigeon(Content, modelPigeon, texturePigeon, predictedPigeon, positionPigeon, rotationPigeon,
                                scalePigeon, AABBOffsetPigeon, camera);

            gamePadInput = GamePad.GetState(PlayerIndex.One);

            for (int ii = 0; ii < mapClient.GetPlotList().Count; ii += 1)
            {
                pigeon.SetObservers(mapClient.GetPlotList()[ii]);
            }

            for (int ii = 0; ii < mapClient.GetPlotList().Count; ii += 1)
            {
                camera.SetObservers(mapClient.GetPlotList()[ii]);
            }

            Song birdSong = Content.Load <Song>("Audio/Pigeon-Song");

            MediaPlayer.Play(birdSong);
            MediaPlayer.IsRepeating = false;


            base.Initialize();
        }
Example #4
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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            //int screenX = GraphicsDevice.Viewport.Width;
            //int screenY = GraphicsDevice.Viewport.Height;
            int screenX = Window.ClientBounds.Width;
            int screenY = Window.ClientBounds.Height;

            int centerX = (int)(screenX / 2);
            int centerY = (int)(screenY / 2);

            inputHandlers   = new InputHandler(screenX, screenY);
            mouseInputDelta = inputHandlers.MouseHandler(screenX, screenY, 1.00f);
            mouseInputDelta = inputHandlers.RightGamePadHandler(screenX, screenY, 1.00f);

            if (!gamePadInput.IsConnected)
            {
                Debug.WriteLine("gamePadInput: " + gamePadInput.IsConnected);
                keyboardInput = inputHandlers.KeyboardHandler();
            }
            else
            {
                keyboardInput = inputHandlers.LeftGamePadHandler();
            }


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

            // selects between first person and third person states
            // copies the last known position and rotation to the game state
            if (keyboardInput == InputHandler.keyStates.Pigeon)
            {
                gameState = InputHandler.keyStates.Pigeon;
                pigeon.subjectPosition = camera.subjectPosition;
                pigeon.subjectRotation = camera.subjectRotation;
            }

            if (keyboardInput == InputHandler.keyStates.FPS)
            {
                gameState = InputHandler.keyStates.FPS;
                camera.subjectPosition = pigeon.subjectPosition;
                camera.subjectRotation = pigeon.subjectRotation;
            }

            if (gameState == InputHandler.keyStates.Pigeon)
            {
                pigeon.SubjectMove(keyboardInput, cameraSpeed, deltaTime, fps);

                theCamera = pigeon.SubjectUpdate(mouseInputDelta, deltaTime, fps);
            }
            else
            {
                camera.SubjectMove(keyboardInput, cameraSpeed, deltaTime, fps);
                //setting up collisions

                theCamera = camera.SubjectUpdate(mouseInputDelta, deltaTime, fps);
            }


            base.Update(gameTime);
        }