void Vector3f::Rotate(float Angle, const Vector3f& Axis) { /*printf("\n"); printf("Angle %f\n", Angle); printf("Before %f %f %f\n", x, y, z);*/ const float SinHalfAngle = sinf(ToRadian(Angle/2)); const float CosHalfAngle = cosf(ToRadian(Angle/2)); //printf("sin %f cos %f\n", SinHalfAngle, CosHalfAngle); const float Rx = Axis.x * SinHalfAngle; const float Ry = Axis.y * SinHalfAngle; const float Rz = Axis.z * SinHalfAngle; const float Rw = CosHalfAngle; //printf("Rotation quaternion %f %f %f %f\n", Rx, Ry, Rz, Rw); Quaternion RotationQ(Rx, Ry, Rz, Rw); Quaternion ConjugateQ = RotationQ.Conjugate(); ConjugateQ.Normalize(); //printf("Conjugate %f %f %f %f\n", ConjugateQ.x, ConjugateQ.y, ConjugateQ.z, ConjugateQ.w); Quaternion W = RotationQ * (*this); // printf("Q * View: %f %f %f %f\n", W.x, W.y, W.z, W.w); W *= ConjugateQ; // printf("Q * View * Conjugate: %f %f %f %f\n", W.x, W.y, W.z, W.w); x = W.x; y = W.y; z = W.z; //printf("After %f %f %f\n", x, y, z); }
void vec3D::Rotate(float Angle, const vec3D& Axe) { const float SinHalfAngle = sinf(ToRadian(Angle/2)); const float CosHalfAngle = cosf(ToRadian(Angle/2)); const float Rx = Axe.x * SinHalfAngle; const float Ry = Axe.y * SinHalfAngle; const float Rz = Axe.z * SinHalfAngle; const float Rw = CosHalfAngle; Quaternion RotationQ(Rx, Ry, Rz, Rw); Quaternion ConjugateQ = RotationQ.Conjugate(); Quaternion W = RotationQ * (*this) * ConjugateQ; x = W.x; y = W.y; z = W.z; }
void Vector3f::rotate(float Angle, const Vector3f& Axis) { const float SinHalfAngle = sinf(ToRadian(Angle/2)); const float CosHalfAngle = cosf(ToRadian(Angle/2)); const float Rx = Axis.x * SinHalfAngle; const float Ry = Axis.y * SinHalfAngle; const float Rz = Axis.z * SinHalfAngle; const float Rw = CosHalfAngle; Quaternion RotationQ(Rx, Ry, Rz, Rw); Quaternion ConjugateQ = RotationQ.conjugate(); //ConjugateQ.Normalize(); Quaternion W = RotationQ * (*this) * ConjugateQ; x = W.x; y = W.y; z = W.z; }