tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

QuaternionC.h (2589B)


      1 /** @file
      2    @brief Header
      3 
      4    Must be c-safe!
      5 
      6    @date 2014
      7 
      8    @author
      9    Sensics, Inc.
     10    <http://sensics.com/osvr>
     11 */
     12 
     13 /*
     14 // Copyright 2014 Sensics, Inc.
     15 //
     16 // Licensed under the Apache License, Version 2.0 (the "License");
     17 // you may not use this file except in compliance with the License.
     18 // You may obtain a copy of the License at
     19 //
     20 //     http://www.apache.org/licenses/LICENSE-2.0
     21 //
     22 // Unless required by applicable law or agreed to in writing, software
     23 // distributed under the License is distributed on an "AS IS" BASIS,
     24 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     25 // See the License for the specific language governing permissions and
     26 // limitations under the License.
     27 */
     28 
     29 #ifndef INCLUDED_QuaternionC_h_GUID_1470A5FE_8209_41A6_C19E_46077FDF9C66
     30 #define INCLUDED_QuaternionC_h_GUID_1470A5FE_8209_41A6_C19E_46077FDF9C66
     31 
     32 /* Internal Includes */
     33 #include <osvr/Util/APIBaseC.h>
     34 
     35 /* Library/third-party includes */
     36 /* none */
     37 
     38 /* Standard includes */
     39 /* none */
     40 
     41 OSVR_EXTERN_C_BEGIN
     42 
     43 /** @addtogroup UtilMath
     44    @{
     45 */
     46 /** @brief A structure defining a quaternion, often a unit quaternion
     47 * representing 3D rotation.
     48 */
     49 typedef struct OSVR_Quaternion {
     50  /** @brief Internal data - direct access not recommended */
     51  double data[4];
     52 } OSVR_Quaternion;
     53 
     54 #define OSVR_QUAT_MEMBER(COMPONENT, INDEX)                                  \
     55  /** @brief Accessor for quaternion component COMPONENT */                 \
     56  OSVR_INLINE double osvrQuatGet##COMPONENT(OSVR_Quaternion const* q) {     \
     57    return q->data[INDEX];                                                  \
     58  }                                                                         \
     59  /** @brief Setter for quaternion component COMPONENT */                   \
     60  OSVR_INLINE void osvrQuatSet##COMPONENT(OSVR_Quaternion* q, double val) { \
     61    q->data[INDEX] = val;                                                   \
     62  }
     63 
     64 OSVR_QUAT_MEMBER(W, 0)
     65 OSVR_QUAT_MEMBER(X, 1)
     66 OSVR_QUAT_MEMBER(Y, 2)
     67 OSVR_QUAT_MEMBER(Z, 3)
     68 
     69 #undef OSVR_QUAT_MEMBER
     70 
     71 /** @brief Set a quaternion to the identity rotation */
     72 OSVR_INLINE void osvrQuatSetIdentity(OSVR_Quaternion* q) {
     73  osvrQuatSetW(q, 1);
     74  osvrQuatSetX(q, 0);
     75  osvrQuatSetY(q, 0);
     76  osvrQuatSetZ(q, 0);
     77 }
     78 
     79 /** @} */
     80 
     81 OSVR_EXTERN_C_END
     82 
     83 #ifdef __cplusplus
     84 template <typename StreamType>
     85 inline StreamType& operator<<(StreamType& os, OSVR_Quaternion const& quat) {
     86  os << "(" << osvrQuatGetW(&quat) << ", (" << osvrQuatGetX(&quat) << ", "
     87     << osvrQuatGetY(&quat) << ", " << osvrQuatGetZ(&quat) << "))";
     88  return os;
     89 }
     90 #endif
     91 
     92 #endif