/// <summary> /// This function returns a vector that is rotated by the opposite of me /// </summary> public MyVector GetRotatedVectorReverse(MyVector vector, bool isQuatNormalized) { if (!isQuatNormalized) { // I'm not normalized, clone myself and normalize it MyQuaternion myUnitClone = new MyQuaternion(this.X, this.Y, this.Z, this.W); myUnitClone.BecomeUnitQuaternion(); return(myUnitClone.GetRotatedVectorReverse(vector, true)); } MyVector qvec = new MyVector(this.X, this.Y, this.Z); //Vector uv = qvec.Cross(vector); MyVector uv = MyVector.Cross(qvec, vector); //Vector uuv = qvec.Cross(uv); MyVector uuv = MyVector.Cross(qvec, uv); //uv *= (2.0f * quat.w); uv.Multiply(this.W * -2d); //uuv *= 2.0f; uuv.Multiply(2d); //return vector + uv + uuv; MyVector retVal = vector.Clone(); retVal.Add(uv); retVal.Add(uuv); return(retVal); }
public DoubleVector GetRotatedVectorReverse(DoubleVector doubleVector, bool isQuatNormalized) { if (!isQuatNormalized) { // I'm not normalized, clone myself and normalize it MyQuaternion myUnitClone = new MyQuaternion(this.X, this.Y, this.Z, this.W); myUnitClone.BecomeUnitQuaternion(); return(myUnitClone.GetRotatedVectorReverse(doubleVector, true)); } return(new DoubleVector(GetRotatedVectorReverse(doubleVector.Standard, true), GetRotatedVectorReverse(doubleVector.Orth, true))); }
/// <summary> /// WARNING: Don't rotate my direction facing outside of me, we will fall out of sync /// </summary> public virtual void RotateAroundAxis(MyVector rotateAround, double radians) { // Avoid mathmatical drift _numRotations++; if (_numRotations > 10000) { _numRotations = 0; _rotation.BecomeUnitQuaternion(); } // Make a quaternion that holds the axis and radians passed in MyQuaternion intermediate = new MyQuaternion(rotateAround, radians); // Apply that to my existing one _rotation = MyQuaternion.Multiply(intermediate, _rotation); // it seems counterintuitive to multiply them in this order, but testing shows it doesn't work the other way (and reading some articles confirms the order) if (_dirFacingRequested) { SyncDirFacing(); } }
/// <summary> /// This function creates a vector that is the vector passed in rotated by my definition /// </summary> /// <param name="vector">The vector to rotate (I don't touch this vector, I create a new one that is rotated)</param> /// <param name="isQuatNormalized">Whether this class is already normalized or not (if you don't know, pass false)</param> public MyVector GetRotatedVector(MyVector vector, bool isQuatNormalized) { if (!isQuatNormalized) { // I'm not normalized, clone myself and normalize it MyQuaternion myUnitClone = new MyQuaternion(this.X, this.Y, this.Z, this.W); myUnitClone.BecomeUnitQuaternion(); return myUnitClone.GetRotatedVector(vector, true); } MyVector qvec = new MyVector(this.X, this.Y, this.Z); //Vector uv = qvec.Cross(vector); MyVector uv = MyVector.Cross(qvec, vector); //Vector uuv = qvec.Cross(uv); MyVector uuv = MyVector.Cross(qvec, uv); //uv *= (2.0f * quat.w); uv.Multiply(this.W * 2d); //uuv *= 2.0f; uuv.Multiply(2d); //return vector + uv + uuv; MyVector retVal = vector.Clone(); retVal.Add(uv); retVal.Add(uuv); return retVal; }
public DoubleVector GetRotatedVectorReverse(DoubleVector doubleVector, bool isQuatNormalized) { if (!isQuatNormalized) { // I'm not normalized, clone myself and normalize it MyQuaternion myUnitClone = new MyQuaternion(this.X, this.Y, this.Z, this.W); myUnitClone.BecomeUnitQuaternion(); return myUnitClone.GetRotatedVectorReverse(doubleVector, true); } return new DoubleVector(GetRotatedVectorReverse(doubleVector.Standard, true), GetRotatedVectorReverse(doubleVector.Orth, true)); }