Rotate a vector

Posted by marc wellman on Game Development See other posts from Game Development or by marc wellman
Published on 2012-10-09T09:52:52Z Indexed on 2012/10/09 15:59 UTC
Read the original article Hit count: 231

Filed under:
|
|
|
|

I want my first-person camera to smoothly change its viewing direction from direction d1 to direction d2. The latter direction is indicated by a target position t2.

So far I have implemented a rotation that works fine but the speed of the rotation slows down the closer the current direction gets to the desired one. This is what I want to avoid.

Here are the two very simple methods I have written so far:

// this method initiates the direction change and sets the parameter
public void LookAt(Vector3 target) {

        _desiredDirection = target - _cameraPosition;
        _desiredDirection.Normalize();

        _rotation = new Matrix();

        _rotationAxis = Vector3.Cross(Direction, _desiredDirection);

        _isLooking = true;
    }


// this method gets execute by the Update()-method if _isLooking flag is up.
private void _lookingAt() {

        dist = Vector3.Distance(Direction, _desiredDirection);

        // check whether the current direction has reached the desired one.
        if (dist >= 0.00001f) {

            _rotationAxis = Vector3.Cross(Direction, _desiredDirection);
            _rotation = Matrix.CreateFromAxisAngle(_rotationAxis, MathHelper.ToRadians(1));


            Direction = Vector3.TransformNormal(Direction, _rotation);
        } else {

            _onDirectionReached();
            _isLooking = false;
        }
    }

Again, rotation works fine; camera reaches its desired direction. But the speed is not equal over the course of movement -> it slows down.

How to achieve a rotation with constant speed ?

© Game Development or respective owner

Related posts about XNA

Related posts about c#