0

How do I get the vector indicating the direction to travel if I have a starting position vector3 and rotation vector3? I get a normalized vector to indicate how it's rotated but of course that only indicated how it's rotated not the direction of travel. i.e. if I rotate on the y that should affect the direction of travel on the x and the z rather than what normailzing a vector rotated on the y would do which would indicate just indicate it has been rotated on the y.

2 Answers 2

1

At some point you will probably take that 'rotation Vector3' and make a Matrix from it. That Matrix has a Vector3 property (Matrix.Forward) that is the direction in that corresponds to the 'rotation Vector3'. If you don't want to mess with a matrix you already have, this method should do the job.

Vector3 DirectionToTravel(bool rotationVecIsInRadians, Vector3 rotationVec)//rotation vec must not be normalized at this point
{
    Vector3 result;

    if (!rotationVecIsInRadians)
    {
        rotationVec *= MathHelper.Pi / 180f;
    }

    float angle = rotationVec.Length();
    rotationVec /= angle; //normalizes rotation vec

    result = Matrix.CreateFromAxisAngle(rotationVec, angle).Forward;

    return result;
}
Sign up to request clarification or add additional context in comments.

Comments

0

In addition to Steve H's answer, you may find you need to use Quarternions to do rotation in an 3D space more effectively. I've provided some links that might help you out if you decide to use Quarternions.

Quarternion Structure (MSDN)

Quarternion Tutorial (MSDN Social)

Quarternion Rotation in XNA (Stackoverflow Question)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.