Changeset 2860


Ignore:
Timestamp:
Sep 3, 2013, 8:17:08 PM (6 years ago)
Author:
sam
Message:

math: create a quaternion from two vectors.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/math/vector.h

    r2852 r2860  
    940940    static Quat<T> rotate(T degrees, Vec3<T> const &v);
    941941
     942    /* Create a unit quaternion representing a rotation between two vectors.
     943     * Input vectors need not be normalised. */
     944    static Quat<T> rotate(Vec3<T> const &src, Vec3<T> const &dst);
     945
    942946    /* Convert from Euler angles. The axes in fromeuler_xyx are
    943947     * x, then y', then x", ie. the axes are attached to the model.
  • trunk/src/math/vector.cpp

    r2816 r2860  
    500500{
    501501    return quat::rotate(degrees, vec3(x, y, z));
     502}
     503
     504template<> quat quat::rotate(vec3 const &src, vec3 const &dst)
     505{
     506    vec3 v = cross(src, dst);
     507    float d = dot(src, dst) + lol::sqrt(sqlength(src) * sqlength(dst));
     508
     509    return normalize(quat(d, v.x, v.y, v.z));
    502510}
    503511
Note: See TracChangeset for help on using the changeset viewer.