tor-browser

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

Vec3C.h (2325B)


      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_Vec3C_h_GUID_BF4E98ED_74CF_4785_DB61_109A00BA74DE
     30 #define INCLUDED_Vec3C_h_GUID_BF4E98ED_74CF_4785_DB61_109A00BA74DE
     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 3D vector, often a position/translation.
     47 */
     48 typedef struct OSVR_Vec3 {
     49  /** @brief Internal array data. */
     50  double data[3];
     51 } OSVR_Vec3;
     52 
     53 #define OSVR_VEC_MEMBER(COMPONENT, INDEX)                             \
     54  /** @brief Accessor for Vec3 component COMPONENT */                 \
     55  OSVR_INLINE double osvrVec3Get##COMPONENT(OSVR_Vec3 const* v) {     \
     56    return v->data[INDEX];                                            \
     57  }                                                                   \
     58  /** @brief Setter for Vec3 component COMPONENT */                   \
     59  OSVR_INLINE void osvrVec3Set##COMPONENT(OSVR_Vec3* v, double val) { \
     60    v->data[INDEX] = val;                                             \
     61  }
     62 
     63 OSVR_VEC_MEMBER(X, 0)
     64 OSVR_VEC_MEMBER(Y, 1)
     65 OSVR_VEC_MEMBER(Z, 2)
     66 
     67 #undef OSVR_VEC_MEMBER
     68 
     69 /** @brief Set a Vec3 to the zero vector */
     70 OSVR_INLINE void osvrVec3Zero(OSVR_Vec3* v) {
     71  osvrVec3SetX(v, 0);
     72  osvrVec3SetY(v, 0);
     73  osvrVec3SetZ(v, 0);
     74 }
     75 
     76 /** @} */
     77 
     78 OSVR_EXTERN_C_END
     79 
     80 #ifdef __cplusplus
     81 template <typename StreamType>
     82 inline StreamType& operator<<(StreamType& os, OSVR_Vec3 const& vec) {
     83  os << "(" << vec.data[0] << ", " << vec.data[1] << ", " << vec.data[2] << ")";
     84  return os;
     85 }
     86 #endif
     87 
     88 #endif