Rotation to Vector/Angle

De DigiWiki.

These functions will let you convert rotations into a vector (axis) and the angle the vector is rotated by (the rotation is perpendicular to the vector). The final function lets you convert back.

vector getVecFromRot(rotation r)
{//llRot2Axis
    vector v = <r.x, r.y, r.z>;
    if(v)//Is the vector a zero vector?
        return llVecNorm(v);//not a zero vector, so normalize it
    return v;//vector was zero.
}
 
float getAngleFromRot(rotation r)
{//llRot2Angle
    return 2 * llAcos(r.s / llSqrt(r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s));
}
 
rotation getRotFromVecAngle(vector v, float a)
{//llAxisAngle2Rot, not normalized
    return <v.x, v.y, v.z, 1 / llTan(a / 2)>;
}
Outils personnels
  • Cette page a été consultée 515 fois.
donate
Google Ads