public static SCNMatrix4 ToMatrix4(this SCNQuaternion quaternion) { quaternion.Normalize(); nfloat x = quaternion.X; nfloat y = quaternion.Y; nfloat z = quaternion.Z; nfloat w = quaternion.W; nfloat doubleX = x + x; nfloat doubleY = y + y; nfloat doubleZ = z + z; nfloat doubleW = w + w; return(new SCNMatrix4( 1.0f - doubleY * y - doubleZ * z, doubleX * y + doubleW * z, doubleX * z - doubleW * y, 0.0f, doubleX * y - doubleW * z, 1.0f - doubleX * x - doubleZ * z, doubleY * z + doubleW * x, 0.0f, doubleX * z + doubleW * y, doubleY * z - doubleW * x, 1.0f - doubleX * x - doubleY * y, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f )); }
public static SCNQuaternion CreateQuaternion(SCNVector3 v1, SCNVector3 v2) { var a = SCNVector3.Cross(v1, v2); var w = (float)Math.Sqrt(v1.LengthSquared * v2.LengthSquared) + SCNVector3.Dot(v1, v2); var result = new SCNQuaternion(a.X, a.Y, a.Z, w); result.Normalize(); return(result); }