public void FVector3AndTheta(FVector3 v, Fix64 theta) { // initializes a quaternion based on a 3d direction vector and angle // note the direction vector must be a unit vector // and the angle is in rads Fix64 theta_div_2 = theta * Fix64.Half; // compute theta/2 // compute the quaterion, note this is from chapter 4 // pre-compute to save time Fix64 sinf_theta = Fix64.Sin(theta_div_2); x = sinf_theta * v.x; y = sinf_theta * v.y; z = sinf_theta * v.z; w = Fix64.Cos(theta_div_2); }
// // // // 摘要: // // Creates a rotation which rotates from fromDirection to toDirection. // // // // 参数: // // fromDirection: // // // // toDirection: // public void SetFromToRotation(Vector3 fromDirection, Vector3 toDirection); // // // // 摘要: // // Creates a rotation with the specified forward and upwards directions. // // // // 参数: // // view: // // The direction to look in. // // // // up: // // The vector that defines in which direction up is. // public void SetLookRotation(Vector3 view, [DefaultValue("Vector3.up")] Vector3 up); // // // // 摘要: // // Creates a rotation with the specified forward and upwards directions. // // // // 参数: // // view: // // The direction to look in. // // // // up: // // The vector that defines in which direction up is. // [ExcludeFromDocs] // public void SetLookRotation(Vector3 view); public void ToAngleAxis(out Fix64 angle, out FVector3 axis) { // this function converts a unit quaternion into a unit direction // vector and rotation angle about that vector // extract theta angle = Fix64.Acos(w); // pre-compute to save time Fix64 sinf_theta_inv = Fix64.One / Fix64.Sin(angle); // now the vector axis.x = x * sinf_theta_inv; axis.y = y * sinf_theta_inv; axis.z = z * sinf_theta_inv; // multiply by 2 angle *= Fix64.Two; }