Quaternion::Quaternion(const Vector& axis, float angle) { if (abs(angle) < 1e-6) { w = 1.0; x = y = z = 0.0; return; } angle *= 0.5; float sinAngle = sin(angle); w = cos(angle); x = axis.x * sinAngle; y = axis.y * sinAngle; z = axis.z * sinAngle; } float Vector::dot(const Vector& vector) const { return x * vector.x + y * vector.y + z * vector.z; } Vector Vector::cross(const Vector& vector) const { return Vector(y * vector.z - z * vector.y, z * vector.x - x * vector.z, x * vector.y - y * vector.x); } Quaternion Vector::rotationTo(const Vector& vector) const { if (*this == vector) return Quaternion::IDENTITY; else { Vector a = this->normalize(); Vector b = vector.normalize(); return Quaternion(a.cross(b), acos(a.dot(b))); } }