/// <summary> /// Translates the shape over a specified vector. /// </summary> /// <param name="Translation">A quaternion or a Vector3 object that represents the translation.</param> public void Translate(My.Quaternion Translation) { for (int i = 0; i < currentVertices.Length; i++) { currentVertices[i] = new VertexPositionNormalTexture( (Vector3)(currentVertices[i].Position + Translation), Vector3.Up, currentVertices[i].TextureCoordinate); } Center = (Vector3)(Center + Translation); }
/// <summary> /// Sets the default rotation for the RotateDefault() method. /// </summary> /// <param name="Axis1">A quaternion or a Vector3 object that represents the first axis. It is assumed that the axis starts at the origin.</param> /// <param name="RotationAngle1">The angle of rotation around the first axis.</param> /// <param name="Axis2">A quaternion or a Vector3 object that represents the second axis. It is assumed that the axis starts at the origin.</param> /// <param name="RotationAngle2">The angle of rotation around the second axis.</param> /// <param name="Axis3">A quaternion or a Vector3 object that represents the third axis. It is assumed that the axis starts at the origin.</param> /// <param name="RotationAngle3">The angle of rotation around the third axis.</param> public void SetDefaultRotation(My.Quaternion Axis1, float RotationAngle1, My.Quaternion Axis2, float RotationAngle2, My.Quaternion Axis3, float RotationAngle3) { My.Quaternion qRot1 = My.Quaternion.RotationQuaternion(Axis1, RotationAngle1); My.Quaternion qRot2 = My.Quaternion.RotationQuaternion(Axis2, RotationAngle2); My.Quaternion qRot3 = My.Quaternion.RotationQuaternion(Axis3, RotationAngle3); DefaultRotation = qRot3 * qRot2 * qRot1; }
/// <summary> /// Rotates the shape around two axises over two specified angles. The rotation is based on quaternions. /// </summary> /// <param name="Axis1">A quaternion or a Vector3 object that represents the first axis. It is assumed that the axis starts at the origin.</param> /// <param name="RotationAngle1">The angle of rotation around the first axis.</param> /// <param name="Axis2">A quaternion or a Vector3 object that represents the second axis. It is assumed that the axis starts at the origin.</param> /// <param name="RotationAngle2">The angle of rotation around the second axis.</param> /// <param name="Axis3">A quaternion or a Vector3 object that represents the third axis. It is assumed that the axis starts at the origin.</param> /// <param name="RotationAngle3">The angle of rotation around the third axis.</param> public void RotateComposition(My.Quaternion Axis1, float RotationAngle1, My.Quaternion Axis2, float RotationAngle2, My.Quaternion Axis3, float RotationAngle3) { My.Quaternion qRot1 = My.Quaternion.RotationQuaternion(Axis1, RotationAngle1); My.Quaternion qRot2 = My.Quaternion.RotationQuaternion(Axis2, RotationAngle2); My.Quaternion qRot3 = My.Quaternion.RotationQuaternion(Axis3, RotationAngle3); My.Quaternion qComb = qRot3 * qRot2 * qRot1; //Quaternion's multiplication is accotiative My.Quaternion qCombConj = qComb.Conjugate(); for (int i = 0; i < currentVertices.Length; i++) { currentVertices[i] = new VertexPositionNormalTexture( (Vector3)(qComb * currentVertices[i].Position * qCombConj), Vector3.Up, currentVertices[i].TextureCoordinate); } Center = (Vector3)(qComb * Center * qCombConj); }
/// <summary> /// Sets the default rotation for the RotateDefault() method. /// </summary> /// <param name="Axis">A quaternion or a Vector3 object that represents the axis.</param> /// <param name="RotationAngle">The angle of rotation around the axis.</param> public void SetDefaultRotation(My.Quaternion Axis, float RotationAngle) { DefaultRotation = My.Quaternion.RotationQuaternion(Axis, RotationAngle); }
/// <summary> /// Rotates the shape around an axis over a specified angle. The rotation is based on quaternions. /// </summary> /// <param name="Axis">A quaternion or a Vector3 object that represents the axis.</param> /// <param name="Translation">A quaternion or a Vector3 object that represents the point at which the axis starts.</param> /// <param name="RotationAngle">The angle of rotation.</param> public void Rotate(My.Quaternion Axis, My.Quaternion Translation, float RotationAngle) { if (RotationAngle == 0) return; My.Quaternion qRot = My.Quaternion.RotationQuaternion(Axis, RotationAngle); My.Quaternion qRotConj = qRot.Conjugate(); for (int i = 0; i < currentVertices.Length; i++) { currentVertices[i] = new VertexPositionNormalTexture( (Vector3)(qRot * (currentVertices[i].Position - Translation) * qRotConj + Translation), Vector3.Up, currentVertices[i].TextureCoordinate); } Center = (Vector3)(qRot*(Center - Translation)*qRotConj + Translation); }