0 Replies - 1611 Views - Last Post: 29 November 2012 - 12:24 PM

#1 hao90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 16-November 12

Image translation.

Posted 29 November 2012 - 12:24 PM

Hi, I have some doubt on my code. I am doing some translation to up and down of an video following the camera. The camera managed to move up slowly following the amount * time set at first.
However, after the first translation for example move camera up, the camera target must be reset to vector.zero in order to move slowly, or else when the next key input is down, the camera will instantly move to the desired place without moving slowly. The main point is that I want the camera's action to move slowly following the amount given.

The following is part of my code.

 //Move the camera
    public void MoveCameraUp(float amount)
        {
            this.totalAmount += amount;

            moveUp = new Vector3(0, 1, 0);
            moveUp.Normalize();

            this.totalAmount = MathHelper.Clamp(this.totalAmount, 0.0f, 0.3f);

           this.target = moveUp * this.totalAmount;

        }


 public void MoveCameraDown(float amount)
        {
            this.totalAmount += amount;

            moveDown = new Vector3(0,-1,0);
            moveDown.Normalize();

            this.totalAmount = MathHelper.Clamp(this.totalAmount, 0.0f, 0.3f);

            this.target = moveDown * this.totalAmount;
        }


 public void Update()
        {

            this.viewMatrix = Matrix.CreateLookAt(cameraPosition, target, Vector3.Up);

            this.CreateProjectionMatrix();

        }
[/code]


// Update the camera based on the key input
 public void UpdateCamera(GameTime gameTime)
        {
            KeyboardState keyState = Keyboard.GetState();

            float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            movement = time * 0.003f;

            if (keyState.IsKeyDown(Keys.W))
            {
                camera.MoveCameraUp(time * 0.0003f);
            }
            else if (lastKeyState.IsKeyDown(Keys.W))
            {
                do
                {
                    camera.MoveCameraUp(-(time * 0.0003f));

                } while (camera.totalAmount != 0.0f);
            }
           
            if (keyState.IsKeyDown(Keys.S))
            {
                camera.MoveCameraDown(time * 0.0003f);

            }

            if (keyState.IsKeyDown(Keys.D))
            {
                camera.MoveCameraRight(time * 0.0003f);
            }

            if (keyState.IsKeyDown(Keys.A))
            {
                camera.MoveCameraLeft(time * 0.0003f);
            }


            camera.Update();

            lastKeyState = keyState;
        }


Did I miss out anything? Please correct me if I was wrong. Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1