/// <summary> /// Inverts quaternion /// </summary> /// <returns> /// inverted quaternion /// </returns> public JsValue QuatInv(CpuBlock c, JsValue thizArg, JsValue[] x) { var thiz = ((ObjectInstance)thizArg); var q1 = BlockUtils.ToQuat(thiz); return(BlockUtils.Quat2Obj(c, Quaternion.Inverse(q1))); }
/// <summary> /// Multiply quaternion with either another quaternion or a 3d vector. /// </summary> /// <returns> /// Vector if second argument is vector and quaternion if second argument is quaternion /// </returns> public JsValue QuatMult(CpuBlock c, JsValue thizArg, JsValue[] x) { if (x.Length < 1) { throw new Exception("Invalid value"); } var q1obj = ((ObjectInstance)thizArg); var q2obj = ((ObjectInstance)x[0]); var q1 = BlockUtils.ToQuat(q1obj); if (q2obj.HasProperty("w")) { var q2 = BlockUtils.ToQuat(q2obj); return(BlockUtils.Quat2Obj(c, q1 * q2)); } else { var v = BlockUtils.ToVector3(q2obj); return(BlockUtils.Vec2Obj(c, q1 * v)); } }