/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Copyright 2011 Danny Robson */ #ifndef __UTIL_QUATERNION_HPP #define __UTIL_QUATERNION_HPP #include "coord.hpp" #include "vector.hpp" #include "matrix.hpp" #include namespace util { // quaternions must be 4 elements, but we include a size parameter so it // fits with the generic coord infrastructure more easily. // // specifically: // large regions of base code require a template template parameter with // size and type arguments, which is annoying to work around for this one // case. // // we protect against invalid instantiations through static_assert template struct quaternion : public coord::base<4,T,quaternion,coord::wxyz,coord::abcd> { static_assert (S == 4, "quaternions must be 4 elements"); using coord::base::base; static quaternion rotation (T radians, vector<3,T> axis); static quaternion rotation (vector<3,T> src, vector<3,T> dst); matrix4 as_matrix (void) const; static const quaternion IDENTITY; }; template quaternion operator* (const quaternion, const quaternion); template quaternion operator/ (const quaternion, const quaternion); typedef quaternion<4,float> quaternionf; template std::ostream& operator<< (std::ostream&, quaternion); } #endif