diff options
Diffstat (limited to 'gfx/vr/service/osvr/Util')
21 files changed, 2444 insertions, 0 deletions
diff --git a/gfx/vr/service/osvr/Util/APIBaseC.h b/gfx/vr/service/osvr/Util/APIBaseC.h new file mode 100644 index 0000000000..5d133f5c52 --- /dev/null +++ b/gfx/vr/service/osvr/Util/APIBaseC.h @@ -0,0 +1,50 @@ +/** @file + @brief Header providing basic C macros for defining API headers. + + Must be c-safe! + + @date 2014 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2014 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_APIBaseC_h_GUID_C5A2E769_2ADC_429E_D250_DF0883E6E5DB +#define INCLUDED_APIBaseC_h_GUID_C5A2E769_2ADC_429E_D250_DF0883E6E5DB + +#ifdef __cplusplus +# define OSVR_C_ONLY(X) +# define OSVR_CPP_ONLY(X) X +# define OSVR_EXTERN_C_BEGIN extern "C" { +# define OSVR_EXTERN_C_END } +# define OSVR_INLINE inline +#else +# define OSVR_C_ONLY(X) X +# define OSVR_CPP_ONLY(X) +# define OSVR_EXTERN_C_BEGIN +# define OSVR_EXTERN_C_END +# ifdef _MSC_VER +# define OSVR_INLINE static __inline +# else +# define OSVR_INLINE static inline +# endif +#endif + +#endif diff --git a/gfx/vr/service/osvr/Util/AnnotationMacrosC.h b/gfx/vr/service/osvr/Util/AnnotationMacrosC.h new file mode 100644 index 0000000000..6ce645840c --- /dev/null +++ b/gfx/vr/service/osvr/Util/AnnotationMacrosC.h @@ -0,0 +1,232 @@ +/** @file + @brief Header containing macros for source-level annotation. + + In theory, supporting MSVC SAL, as well as compatible GCC and + Clang attributes. In practice, expanded as time allows and requires. + + Must be c-safe! + + @date 2014 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2014 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_AnnotationMacrosC_h_GUID_48538D9B_35E3_4E9A_D2B0_D83D51DD5900 +#define INCLUDED_AnnotationMacrosC_h_GUID_48538D9B_35E3_4E9A_D2B0_D83D51DD5900 + +#ifndef OSVR_DISABLE_ANALYSIS + +# if defined(_MSC_VER) && (_MSC_VER >= 1700) +/* Visual C++ (2012 and newer) */ +/* Using SAL attribute format: + * http://msdn.microsoft.com/en-us/library/ms182032(v=vs.120).aspx */ + +# include <sal.h> + +# define OSVR_IN _In_ +# define OSVR_IN_PTR _In_ +# define OSVR_IN_OPT _In_opt_ +# define OSVR_IN_STRZ _In_z_ +# define OSVR_IN_READS(NUM_ELEMENTS) _In_reads_(NUM_ELEMENTS) + +# define OSVR_OUT _Out_ +# define OSVR_OUT_PTR _Outptr_ +# define OSVR_OUT_OPT _Out_opt_ + +# define OSVR_INOUT _Inout_ +# define OSVR_INOUT_PTR _Inout_ + +# define OSVR_RETURN_WARN_UNUSED _Must_inspect_result_ +# define OSVR_RETURN_SUCCESS_CONDITION(X) _Return_type_success_(X) + +/* end of msvc section */ +# elif defined(__GNUC__) && (__GNUC__ >= 4) +/* section for GCC and GCC-alikes */ + +# if defined(__clang__) +/* clang-specific section */ +# endif + +# define OSVR_FUNC_NONNULL(X) __attribute__((__nonnull__ X)) +# define OSVR_RETURN_WARN_UNUSED __attribute__((warn_unused_result)) + +/* end of gcc section and compiler detection */ +# endif + +/* end of ndef disable analysis */ +#endif + +/* Fallback declarations */ +/** +@defgroup annotation_macros Static analysis annotation macros +@brief Wrappers for Microsoft's SAL annotations and others +@ingroup Util + +Use of these is optional, but recommended particularly for C APIs, +as well as any methods handling a buffer with a length. +@{ +*/ +/** @name Parameter annotations + + These indicate the role and valid values for parameters to functions. + + At most one of these should be placed before a parameter's type name in the + function parameter list, in both the declaration and definition. (They must + match!) + @{ +*/ +/** @def OSVR_IN + @brief Indicates a required function parameter that serves only as input. +*/ +#ifndef OSVR_IN +# define OSVR_IN +#endif + +/** @def OSVR_IN_PTR + @brief Indicates a required pointer (non-null) function parameter that + serves only as input. +*/ +#ifndef OSVR_IN_PTR +# define OSVR_IN_PTR +#endif + +/** @def OSVR_IN_OPT + @brief Indicates a function parameter (pointer) that serves only as input, + but is optional and might be NULL. +*/ +#ifndef OSVR_IN_OPT +# define OSVR_IN_OPT +#endif + +/** @def OSVR_IN_STRZ + @brief Indicates a null-terminated string function parameter that serves + only as input. +*/ +#ifndef OSVR_IN_STRZ +# define OSVR_IN_STRZ +#endif + +/** @def OSVR_IN_READS(NUM_ELEMENTS) + @brief Indicates a buffer containing input with the specified number of + elements. + + The specified number of elements is typically the name of another parameter. +*/ +#ifndef OSVR_IN_READS +# define OSVR_IN_READS(NUM_ELEMENTS) +#endif + +/** @def OSVR_OUT + @brief Indicates a required function parameter that serves only as output. + In C code, since this usually means "pointer", you probably want + OSVR_OUT_PTR instead. +*/ +#ifndef OSVR_OUT +# define OSVR_OUT +#endif + +/** @def OSVR_OUT_PTR + @brief Indicates a required pointer (non-null) function parameter that + serves only as output. +*/ +#ifndef OSVR_OUT_PTR +# define OSVR_OUT_PTR +#endif + +/** @def OSVR_OUT_OPT + @brief Indicates a function parameter (pointer) that serves only as output, + but is optional and might be NULL +*/ +#ifndef OSVR_OUT_OPT +# define OSVR_OUT_OPT +#endif + +/** @def OSVR_INOUT + @brief Indicates a required function parameter that is both read and written + to. + + In C code, since this usually means "pointer", you probably want + OSVR_INOUT_PTR instead. +*/ +#ifndef OSVR_INOUT +# define OSVR_INOUT +#endif + +/** @def OSVR_INOUT_PTR + @brief Indicates a required pointer (non-null) function parameter that is + both read and written to. +*/ +#ifndef OSVR_INOUT_PTR +# define OSVR_INOUT_PTR +#endif + +/* End of parameter annotations. */ +/** @} */ + +/** @name Function annotations + + These indicate particular relevant aspects about a function. Some + duplicate the effective meaning of parameter annotations: applying both + allows the fullest extent of static analysis tools to analyze the code, + and in some compilers, generate warnings. + + @{ +*/ +/** @def OSVR_FUNC_NONNULL(X) + @brief Indicates the parameter(s) that must be non-null. + + @param X A parenthesized list of parameters by number (1-based index) + + Should be placed after a function declaration (but before the + semicolon). Repeating in the definition is not needed. +*/ +#ifndef OSVR_FUNC_NONNULL +# define OSVR_FUNC_NONNULL(X) +#endif + +/** @def OSVR_RETURN_WARN_UNUSED + @brief Indicates the function has a return value that must be used (either a + security problem or an obvious bug if not). + + Should be placed before the return value (and virtual keyword, if + applicable) in both declaration and definition. +*/ +#ifndef OSVR_RETURN_WARN_UNUSED +# define OSVR_RETURN_WARN_UNUSED +#endif +/* End of function annotations. */ +/** @} */ + +/** @def OSVR_RETURN_SUCCESS_CONDITION + @brief Applied to a typedef, indicates the condition for `return` under + which a function returning it should be considered to have succeeded (thus + holding certain specifications). + + Should be placed before the typename in a typedef, with the parameter + including the keyword `return` to substitute for the return value. +*/ +#ifndef OSVR_RETURN_SUCCESS_CONDITION +# define OSVR_RETURN_SUCCESS_CONDITION(X) +#endif + +/* End of annotation group. */ +/** @} */ +#endif diff --git a/gfx/vr/service/osvr/Util/BoolC.h b/gfx/vr/service/osvr/Util/BoolC.h new file mode 100644 index 0000000000..b50ec7cfd7 --- /dev/null +++ b/gfx/vr/service/osvr/Util/BoolC.h @@ -0,0 +1,59 @@ +/** @file + @brief Header providing a C-safe "bool" type, because we can't depend on + Visual Studio providing proper C99 support in external-facing APIs. + + Must be c-safe! + + @date 2015 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2015 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_BoolC_h_GUID_4F97BE90_2758_4BA5_B0FC_0CA92DEBA210 +#define INCLUDED_BoolC_h_GUID_4F97BE90_2758_4BA5_B0FC_0CA92DEBA210 + +/* Internal Includes */ +#include <osvr/Util/APIBaseC.h> +#include <osvr/Util/StdInt.h> + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN +/** @addtogroup Util +@{ +*/ + +/** @brief A pre-C99-safe bool type. Canonical values for true and false are + * provided. Interpretation of other values is not defined. */ +typedef uint8_t OSVR_CBool; +/** @brief Canonical "true" value for OSVR_CBool */ +#define OSVR_TRUE (1) +/** @brief Canonical "false" value for OSVR_CBool */ +#define OSVR_FALSE (0) + +/** @} */ +OSVR_EXTERN_C_END + +#endif diff --git a/gfx/vr/service/osvr/Util/ChannelCountC.h b/gfx/vr/service/osvr/Util/ChannelCountC.h new file mode 100644 index 0000000000..dc49b3b171 --- /dev/null +++ b/gfx/vr/service/osvr/Util/ChannelCountC.h @@ -0,0 +1,57 @@ +/** @file + @brief Header + + Must be c-safe! + + @date 2015 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2015 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_ChannelCountC_h_GUID_CF7E5EE7_28B0_4B99_E823_DD701904B5D1 +#define INCLUDED_ChannelCountC_h_GUID_CF7E5EE7_28B0_4B99_E823_DD701904B5D1 + +/* Internal Includes */ +#include <osvr/Util/StdInt.h> +#include <osvr/Util/APIBaseC.h> + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN + +/** @addtogroup PluginKit +@{ +*/ + +/** @brief The integer type specifying a number of channels/sensors or a +channel/sensor index. +*/ +typedef uint32_t OSVR_ChannelCount; + +/** @} */ + +OSVR_EXTERN_C_END + +#endif diff --git a/gfx/vr/service/osvr/Util/ClientCallbackTypesC.h b/gfx/vr/service/osvr/Util/ClientCallbackTypesC.h new file mode 100644 index 0000000000..4a3c53e822 --- /dev/null +++ b/gfx/vr/service/osvr/Util/ClientCallbackTypesC.h @@ -0,0 +1,140 @@ +/** @file + @brief Header + + Must be c-safe! + + GENERATED - do not edit by hand! + + @date 2014 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2014 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_ClientCallbackTypesC_h_GUID_4D43A675_C8A4_4BBF_516F_59E6C785E4EF +#define INCLUDED_ClientCallbackTypesC_h_GUID_4D43A675_C8A4_4BBF_516F_59E6C785E4EF + +/* Internal Includes */ +#include <osvr/Util/ClientReportTypesC.h> +#include <osvr/Util/ImagingReportTypesC.h> +#include <osvr/Util/ReturnCodesC.h> +#include <osvr/Util/TimeValueC.h> + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN + +/** @addtogroup ClientKit + @{ +*/ + +/** @name Report callback types + @{ +*/ + +/* generated file - do not edit! */ +/** @brief C function type for a Pose callback */ +typedef void (*OSVR_PoseCallback)(void* userdata, + const struct OSVR_TimeValue* timestamp, + const struct OSVR_PoseReport* report); +/** @brief C function type for a Position callback */ +typedef void (*OSVR_PositionCallback)(void* userdata, + const struct OSVR_TimeValue* timestamp, + const struct OSVR_PositionReport* report); +/** @brief C function type for a Orientation callback */ +typedef void (*OSVR_OrientationCallback)( + void* userdata, const struct OSVR_TimeValue* timestamp, + const struct OSVR_OrientationReport* report); +/** @brief C function type for a Velocity callback */ +typedef void (*OSVR_VelocityCallback)(void* userdata, + const struct OSVR_TimeValue* timestamp, + const struct OSVR_VelocityReport* report); +/** @brief C function type for a LinearVelocity callback */ +typedef void (*OSVR_LinearVelocityCallback)( + void* userdata, const struct OSVR_TimeValue* timestamp, + const struct OSVR_LinearVelocityReport* report); +/** @brief C function type for a AngularVelocity callback */ +typedef void (*OSVR_AngularVelocityCallback)( + void* userdata, const struct OSVR_TimeValue* timestamp, + const struct OSVR_AngularVelocityReport* report); +/** @brief C function type for a Acceleration callback */ +typedef void (*OSVR_AccelerationCallback)( + void* userdata, const struct OSVR_TimeValue* timestamp, + const struct OSVR_AccelerationReport* report); +/** @brief C function type for a LinearAcceleration callback */ +typedef void (*OSVR_LinearAccelerationCallback)( + void* userdata, const struct OSVR_TimeValue* timestamp, + const struct OSVR_LinearAccelerationReport* report); +/** @brief C function type for a AngularAcceleration callback */ +typedef void (*OSVR_AngularAccelerationCallback)( + void* userdata, const struct OSVR_TimeValue* timestamp, + const struct OSVR_AngularAccelerationReport* report); +/** @brief C function type for a Button callback */ +typedef void (*OSVR_ButtonCallback)(void* userdata, + const struct OSVR_TimeValue* timestamp, + const struct OSVR_ButtonReport* report); +/** @brief C function type for a Analog callback */ +typedef void (*OSVR_AnalogCallback)(void* userdata, + const struct OSVR_TimeValue* timestamp, + const struct OSVR_AnalogReport* report); +/** @brief C function type for a Imaging callback */ +typedef void (*OSVR_ImagingCallback)(void* userdata, + const struct OSVR_TimeValue* timestamp, + const struct OSVR_ImagingReport* report); +/** @brief C function type for a Location2D callback */ +typedef void (*OSVR_Location2DCallback)( + void* userdata, const struct OSVR_TimeValue* timestamp, + const struct OSVR_Location2DReport* report); +/** @brief C function type for a Direction callback */ +typedef void (*OSVR_DirectionCallback)( + void* userdata, const struct OSVR_TimeValue* timestamp, + const struct OSVR_DirectionReport* report); +/** @brief C function type for a EyeTracker2D callback */ +typedef void (*OSVR_EyeTracker2DCallback)( + void* userdata, const struct OSVR_TimeValue* timestamp, + const struct OSVR_EyeTracker2DReport* report); +/** @brief C function type for a EyeTracker3D callback */ +typedef void (*OSVR_EyeTracker3DCallback)( + void* userdata, const struct OSVR_TimeValue* timestamp, + const struct OSVR_EyeTracker3DReport* report); +/** @brief C function type for a EyeTrackerBlink callback */ +typedef void (*OSVR_EyeTrackerBlinkCallback)( + void* userdata, const struct OSVR_TimeValue* timestamp, + const struct OSVR_EyeTrackerBlinkReport* report); +/** @brief C function type for a NaviVelocity callback */ +typedef void (*OSVR_NaviVelocityCallback)( + void* userdata, const struct OSVR_TimeValue* timestamp, + const struct OSVR_NaviVelocityReport* report); +/** @brief C function type for a NaviPosition callback */ +typedef void (*OSVR_NaviPositionCallback)( + void* userdata, const struct OSVR_TimeValue* timestamp, + const struct OSVR_NaviPositionReport* report); + +/** @} */ + +/** @} */ + +OSVR_EXTERN_C_END + +#endif diff --git a/gfx/vr/service/osvr/Util/ClientOpaqueTypesC.h b/gfx/vr/service/osvr/Util/ClientOpaqueTypesC.h new file mode 100644 index 0000000000..84203bb0d4 --- /dev/null +++ b/gfx/vr/service/osvr/Util/ClientOpaqueTypesC.h @@ -0,0 +1,69 @@ +/** @file + @brief Header declaring opaque types used by @ref Client and @ref ClientKit + + Must be c-safe! + + @date 2014 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2014 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_ClientOpaqueTypesC_h_GUID_24B79ED2_5751_4BA2_1690_BBD250EBC0C1 +#define INCLUDED_ClientOpaqueTypesC_h_GUID_24B79ED2_5751_4BA2_1690_BBD250EBC0C1 + +/* Internal Includes */ +#include <osvr/Util/APIBaseC.h> + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN + +/** @addtogroup ClientKit + @{ +*/ +/** @brief Opaque handle that should be retained by your application. You need + only and exactly one. + + Created by osvrClientInit() at application start. + + You are required to clean up this handle with osvrClientShutdown(). +*/ +typedef struct OSVR_ClientContextObject* OSVR_ClientContext; + +/** @brief Opaque handle to an interface used for registering callbacks and + getting status. + + You are not required to clean up this handle (it will be automatically + cleaned up when the context is), but you can if you are no longer using it, + using osvrClientFreeInterface() to inform the context that you no longer need + this interface. +*/ +typedef struct OSVR_ClientInterfaceObject* OSVR_ClientInterface; + +/** @} */ + +OSVR_EXTERN_C_END + +#endif diff --git a/gfx/vr/service/osvr/Util/ClientReportTypesC.h b/gfx/vr/service/osvr/Util/ClientReportTypesC.h new file mode 100644 index 0000000000..09769d2462 --- /dev/null +++ b/gfx/vr/service/osvr/Util/ClientReportTypesC.h @@ -0,0 +1,348 @@ +/** @file + @brief Header + + Must be c-safe! + + @date 2014 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2014 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_ClientReportTypesC_h_GUID_E79DAB07_78B7_4795_1EB9_CA6EEB274AEE +#define INCLUDED_ClientReportTypesC_h_GUID_E79DAB07_78B7_4795_1EB9_CA6EEB274AEE + +/* Internal Includes */ +#include <osvr/Util/APIBaseC.h> +#include <osvr/Util/Pose3C.h> +#include <osvr/Util/StdInt.h> + +#include <osvr/Util/Vec2C.h> +#include <osvr/Util/Vec3C.h> +#include <osvr/Util/ChannelCountC.h> +#include <osvr/Util/BoolC.h> + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN + +/** @addtogroup ClientKit + @{ +*/ + +/** @name State types +@{ +*/ +/** @brief Type of position state */ +typedef OSVR_Vec3 OSVR_PositionState; + +/** @brief Type of orientation state */ +typedef OSVR_Quaternion OSVR_OrientationState; + +/** @brief Type of pose state */ +typedef OSVR_Pose3 OSVR_PoseState; + +/** @brief Type of linear velocity state */ +typedef OSVR_Vec3 OSVR_LinearVelocityState; + +/** @brief The quaternion represents the incremental rotation taking place over + a period of dt seconds. Use of dt (which does not necessarily + have to be 1, as other velocity/acceleration representations imply) and an + incremental quaternion allows device reports to be scaled to avoid aliasing +*/ +typedef struct OSVR_IncrementalQuaternion { + OSVR_Quaternion incrementalRotation; + double dt; +} OSVR_IncrementalQuaternion; + +/** @brief Type of angular velocity state: an incremental quaternion, providing + the incremental rotation taking place due to velocity over a period of dt + seconds. +*/ +typedef OSVR_IncrementalQuaternion OSVR_AngularVelocityState; + +/** @brief Struct for combined velocity state */ +typedef struct OSVR_VelocityState { + OSVR_LinearVelocityState linearVelocity; + /** @brief Whether the data source reports valid data for + #OSVR_VelocityState::linearVelocity */ + OSVR_CBool linearVelocityValid; + + OSVR_AngularVelocityState angularVelocity; + /** @brief Whether the data source reports valid data for + #OSVR_VelocityState::angularVelocity */ + OSVR_CBool angularVelocityValid; +} OSVR_VelocityState; + +/** @brief Type of linear acceleration state */ +typedef OSVR_Vec3 OSVR_LinearAccelerationState; + +/** @brief Type of angular acceleration state + */ +typedef OSVR_IncrementalQuaternion OSVR_AngularAccelerationState; + +/** @brief Struct for combined acceleration state */ +typedef struct OSVR_AccelerationState { + OSVR_LinearAccelerationState linearAcceleration; + /** @brief Whether the data source reports valid data for + #OSVR_AccelerationState::linearAcceleration */ + OSVR_CBool linearAccelerationValid; + + OSVR_AngularAccelerationState angularAcceleration; + /** @brief Whether the data source reports valid data for + #OSVR_AccelerationState::angularAcceleration */ + OSVR_CBool angularAccelerationValid; +} OSVR_AccelerationState; + +/** @brief Type of button state */ +typedef uint8_t OSVR_ButtonState; + +/** @brief OSVR_ButtonState value indicating "button down" */ +#define OSVR_BUTTON_PRESSED (1) + +/** @brief OSVR_ButtonState value indicating "button up" */ +#define OSVR_BUTTON_NOT_PRESSED (0) + +/** @brief Type of analog channel state */ +typedef double OSVR_AnalogState; + +/** @} */ + +/** @name Report types + @{ +*/ +/** @brief Report type for a position callback on a tracker interface */ +typedef struct OSVR_PositionReport { + /** @brief Identifies the sensor that the report comes from */ + int32_t sensor; + /** @brief The position vector */ + OSVR_PositionState xyz; +} OSVR_PositionReport; + +/** @brief Report type for an orientation callback on a tracker interface */ +typedef struct OSVR_OrientationReport { + /** @brief Identifies the sensor that the report comes from */ + int32_t sensor; + /** @brief The rotation unit quaternion */ + OSVR_OrientationState rotation; +} OSVR_OrientationReport; + +/** @brief Report type for a pose (position and orientation) callback on a + tracker interface +*/ +typedef struct OSVR_PoseReport { + /** @brief Identifies the sensor that the report comes from */ + int32_t sensor; + /** @brief The pose structure, containing a position vector and a rotation + quaternion + */ + OSVR_PoseState pose; +} OSVR_PoseReport; + +/** @brief Report type for a velocity (linear and angular) callback on a + tracker interface +*/ +typedef struct OSVR_VelocityReport { + /** @brief Identifies the sensor that the report comes from */ + int32_t sensor; + /** @brief The data state - note that not all fields are neccesarily valid, + use the `Valid` members to check the status of the other fields. + */ + OSVR_VelocityState state; +} OSVR_VelocityReport; + +/** @brief Report type for a linear velocity callback on a tracker interface + */ +typedef struct OSVR_LinearVelocityReport { + /** @brief Identifies the sensor that the report comes from */ + int32_t sensor; + /** @brief The state itself */ + OSVR_LinearVelocityState state; +} OSVR_LinearVelocityReport; + +/** @brief Report type for an angular velocity callback on a tracker interface + */ +typedef struct OSVR_AngularVelocityReport { + /** @brief Identifies the sensor that the report comes from */ + int32_t sensor; + /** @brief The state itself */ + OSVR_AngularVelocityState state; +} OSVR_AngularVelocityReport; + +/** @brief Report type for an acceleration (linear and angular) callback on a + tracker interface +*/ +typedef struct OSVR_AccelerationReport { + /** @brief Identifies the sensor that the report comes from */ + int32_t sensor; + /** @brief The data state - note that not all fields are neccesarily valid, + use the `Valid` members to check the status of the other fields. + */ + OSVR_AccelerationState state; +} OSVR_AccelerationReport; + +/** @brief Report type for a linear acceleration callback on a tracker interface + */ +typedef struct OSVR_LinearAccelerationReport { + /** @brief Identifies the sensor that the report comes from */ + int32_t sensor; + /** @brief The state itself */ + OSVR_LinearAccelerationState state; +} OSVR_LinearAccelerationReport; + +/** @brief Report type for an angular acceleration callback on a tracker + interface +*/ +typedef struct OSVR_AngularAccelerationReport { + /** @brief Identifies the sensor that the report comes from */ + int32_t sensor; + /** @brief The state itself */ + OSVR_AngularAccelerationState state; +} OSVR_AngularAccelerationReport; + +/** @brief Report type for a callback on a button interface */ +typedef struct OSVR_ButtonReport { + /** @brief Identifies the sensor that the report comes from */ + int32_t sensor; + /** @brief The button state: 1 is pressed, 0 is not pressed. */ + OSVR_ButtonState state; +} OSVR_ButtonReport; + +/** @brief Report type for a callback on an analog interface */ +typedef struct OSVR_AnalogReport { + /** @brief Identifies the sensor/channel that the report comes from */ + int32_t sensor; + /** @brief The analog state. */ + OSVR_AnalogState state; +} OSVR_AnalogReport; + +/** @brief Type of location within a 2D region/surface, in normalized + coordinates (in range [0, 1] in standard OSVR coordinate system) +*/ +typedef OSVR_Vec2 OSVR_Location2DState; + +/** @brief Report type for 2D location */ +typedef struct OSVR_Location2DReport { + OSVR_ChannelCount sensor; + OSVR_Location2DState location; +} OSVR_Location2DReport; + +/** @brief Type of unit directional vector in 3D with no particular origin */ +typedef OSVR_Vec3 OSVR_DirectionState; + +/** @brief Report type for 3D Direction vector */ +typedef struct OSVR_DirectionReport { + OSVR_ChannelCount sensor; + OSVR_DirectionState direction; +} OSVR_DirectionReport; + +/** @brief Type of eye gaze direction in 3D which contains 3D vector (position) + containing gaze base point of the user's respective eye in 3D device + coordinates. +*/ +typedef OSVR_PositionState OSVR_EyeGazeBasePoint3DState; + +/** @brief Type of eye gaze position in 2D which contains users's gaze/point of + regard in normalized display coordinates (in range [0, 1] in standard OSVR + coordinate system) +*/ +typedef OSVR_Location2DState OSVR_EyeGazePosition2DState; + +// typedef OSVR_DirectionState OSVR_EyeGazeBasePoint3DState; + +/** @brief Type of 3D vector (direction vector) containing the normalized gaze + direction of user's respective eye */ +typedef OSVR_DirectionState OSVR_EyeGazeDirectionState; + +/** @brief State for 3D gaze report */ +typedef struct OSVR_EyeTracker3DState { + OSVR_CBool directionValid; + OSVR_DirectionState direction; + OSVR_CBool basePointValid; + OSVR_PositionState basePoint; +} OSVR_EyeTracker3DState; + +/** @brief Report type for 3D gaze report */ +typedef struct OSVR_EyeTracker3DReport { + OSVR_ChannelCount sensor; + OSVR_EyeTracker3DState state; +} OSVR_EyeTracker3DReport; + +/** @brief State for 2D location report */ +typedef OSVR_Location2DState OSVR_EyeTracker2DState; + +/** @brief Report type for 2D location report */ +typedef struct OSVR_EyeTracker2DReport { + OSVR_ChannelCount sensor; + OSVR_EyeTracker2DState state; +} OSVR_EyeTracker2DReport; + +/** @brief State for a blink event */ +typedef OSVR_ButtonState OSVR_EyeTrackerBlinkState; + +/** @brief OSVR_EyeTrackerBlinkState value indicating an eyes blink had occurred + */ +#define OSVR_EYE_BLINK (1) + +/** @brief OSVR_EyeTrackerBlinkState value indicating eyes are not blinking */ +#define OSVR_EYE_NO_BLINK (0) + +/** @brief Report type for a blink event */ +typedef struct OSVR_EyeTrackerBlinkReport { + OSVR_ChannelCount sensor; + OSVR_EyeTrackerBlinkState state; +} OSVR_EyeTrackerBlinkReport; + +/** @brief Report type for an Imaging callback (forward declaration) */ +struct OSVR_ImagingReport; + +/** @brief Type of Navigation Velocity state */ +typedef OSVR_Vec2 OSVR_NaviVelocityState; + +/** @brief Type of Navigation Position state */ +typedef OSVR_Vec2 OSVR_NaviPositionState; + +/** @brief Report type for an navigation velocity callback on a tracker + * interface */ +typedef struct OSVR_NaviVelocityReport { + OSVR_ChannelCount sensor; + /** @brief The 2D vector in world coordinate system, in meters/second */ + OSVR_NaviVelocityState state; +} OSVR_NaviVelocityReport; + +/** @brief Report type for an navigation position callback on a tracker + * interface */ +typedef struct OSVR_NaviPositionReport { + OSVR_ChannelCount sensor; + /** @brief The 2D vector in world coordinate system, in meters, relative to + * starting position */ + OSVR_NaviPositionState state; +} OSVR_NaviPositionReport; + +/** @} */ + +/** @} */ +OSVR_EXTERN_C_END + +#endif diff --git a/gfx/vr/service/osvr/Util/Export.h b/gfx/vr/service/osvr/Util/Export.h new file mode 100644 index 0000000000..24e8d388df --- /dev/null +++ b/gfx/vr/service/osvr/Util/Export.h @@ -0,0 +1,139 @@ +/** @file + @brief Automatically-generated export header - do not edit! + + @date 2016 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +// Copyright 2016 Sensics, Inc. +// +// 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. + +#ifndef OSVR_UTIL_EXPORT_H +#define OSVR_UTIL_EXPORT_H + +#ifdef OSVR_UTIL_STATIC_DEFINE +# define OSVR_UTIL_EXPORT +# define OSVR_UTIL_NO_EXPORT +#endif + +/* Per-compiler advance preventative definition */ +#if defined(__BORLANDC__) || defined(__CODEGEARC__) || defined(__HP_aCC) || \ + defined(__PGI) || defined(__WATCOMC__) +/* Compilers that don't support deprecated, according to CMake. */ +# ifndef OSVR_UTIL_DEPRECATED +# define OSVR_UTIL_DEPRECATED +# endif +#endif + +/* Check for attribute support */ +#if defined(__INTEL_COMPILER) +/* Checking before GNUC because Intel implements GNU extensions, + * so it chooses to define __GNUC__ as well. */ +# if __INTEL_COMPILER >= 1200 +/* Intel compiler 12.0 or newer can handle these attributes per CMake */ +# define OSVR_UTIL_EXPORT_HEADER_SUPPORTS_ATTRIBUTES +# endif + +#elif defined(__GNUC__) +# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) +/* GCC 4.2+ */ +# define OSVR_UTIL_EXPORT_HEADER_SUPPORTS_ATTRIBUTES +# endif +#endif + +/* Per-platform defines */ +#if defined(_MSC_VER) +/* MSVC on Windows */ + +# ifndef OSVR_UTIL_EXPORT +# ifdef osvrUtil_EXPORTS +/* We are building this library */ +# define OSVR_UTIL_EXPORT __declspec(dllexport) +# else +/* We are using this library */ +# define OSVR_UTIL_EXPORT __declspec(dllimport) +# endif +# endif + +# ifndef OSVR_UTIL_DEPRECATED +# define OSVR_UTIL_DEPRECATED __declspec(deprecated) +# endif + +#elif defined(_WIN32) && defined(__GNUC__) +/* GCC-compatible on Windows */ + +# ifndef OSVR_UTIL_EXPORT +# ifdef osvrUtil_EXPORTS +/* We are building this library */ +# define OSVR_UTIL_EXPORT __attribute__((dllexport)) +# else +/* We are using this library */ +# define OSVR_UTIL_EXPORT __attribute__((dllimport)) +# endif +# endif + +# ifndef OSVR_UTIL_DEPRECATED +# define OSVR_UTIL_DEPRECATED __attribute__((__deprecated__)) +# endif + +#elif defined(OSVR_UTIL_EXPORT_HEADER_SUPPORTS_ATTRIBUTES) || \ + (defined(__APPLE__) && defined(__MACH__)) +/* GCC4.2+ compatible (assuming something *nix-like) and Mac OS X */ +/* (The first macro is defined at the top of the file, if applicable) */ +/* see https://gcc.gnu.org/wiki/Visibility */ + +# ifndef OSVR_UTIL_EXPORT +/* We are building/using this library */ +# define OSVR_UTIL_EXPORT __attribute__((visibility("default"))) +# endif + +# ifndef OSVR_UTIL_NO_EXPORT +# define OSVR_UTIL_NO_EXPORT __attribute__((visibility("hidden"))) +# endif + +# ifndef OSVR_UTIL_DEPRECATED +# define OSVR_UTIL_DEPRECATED __attribute__((__deprecated__)) +# endif + +#endif +/* End of platform ifdefs */ + +/* fallback def */ +#ifndef OSVR_UTIL_EXPORT +# define OSVR_UTIL_EXPORT +#endif + +/* fallback def */ +#ifndef OSVR_UTIL_NO_EXPORT +# define OSVR_UTIL_NO_EXPORT +#endif + +/* fallback def */ +#ifndef OSVR_UTIL_DEPRECATED_EXPORT +# define OSVR_UTIL_DEPRECATED_EXPORT OSVR_UTIL_EXPORT OSVR_UTIL_DEPRECATED +#endif + +/* fallback def */ +#ifndef OSVR_UTIL_DEPRECATED_NO_EXPORT +# define OSVR_UTIL_DEPRECATED_NO_EXPORT \ + OSVR_UTIL_NO_EXPORT OSVR_UTIL_DEPRECATED +#endif + +/* Clean up after ourselves */ +#undef OSVR_UTIL_EXPORT_HEADER_SUPPORTS_ATTRIBUTES + +#endif diff --git a/gfx/vr/service/osvr/Util/ImagingReportTypesC.h b/gfx/vr/service/osvr/Util/ImagingReportTypesC.h new file mode 100644 index 0000000000..c3d1a1dee8 --- /dev/null +++ b/gfx/vr/service/osvr/Util/ImagingReportTypesC.h @@ -0,0 +1,91 @@ +/** @file + @brief Header + + Must be c-safe! + + @date 2015 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2015 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_ImagingReportTypesC_h_GUID_746A7BF8_B92D_4585_CA72_DC5391DEDF24 +#define INCLUDED_ImagingReportTypesC_h_GUID_746A7BF8_B92D_4585_CA72_DC5391DEDF24 + +/* Internal Includes */ +#include <osvr/Util/APIBaseC.h> +#include <osvr/Util/StdInt.h> +#include <osvr/Util/ChannelCountC.h> + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN + +/** @addtogroup ClientKit + @{ +*/ +typedef uint32_t OSVR_ImageDimension; +typedef uint8_t OSVR_ImageChannels; +typedef uint8_t OSVR_ImageDepth; + +/** @brief Type for raw buffer access to image data */ +typedef unsigned char OSVR_ImageBufferElement; + +typedef enum OSVR_ImagingValueType { + OSVR_IVT_UNSIGNED_INT = 0, + OSVR_IVT_SIGNED_INT = 1, + OSVR_IVT_FLOATING_POINT = 2 +} OSVR_ImagingValueType; + +typedef struct OSVR_ImagingMetadata { + /** @brief height in pixels */ + OSVR_ImageDimension height; + /** @brief width in pixels */ + OSVR_ImageDimension width; + /** @brief number of channels of data for each pixel */ + OSVR_ImageChannels channels; + /** @brief the depth (size) in bytes of each channel - valid values are 1, + * 2, 4, and 8 */ + OSVR_ImageDepth depth; + /** @brief Whether values are unsigned ints, signed ints, or floating point + */ + OSVR_ImagingValueType type; + +} OSVR_ImagingMetadata; + +typedef struct OSVR_ImagingState { + OSVR_ImagingMetadata metadata; + OSVR_ImageBufferElement* data; +} OSVR_ImagingState; + +typedef struct OSVR_ImagingReport { + OSVR_ChannelCount sensor; + OSVR_ImagingState state; +} OSVR_ImagingReport; + +/** @} */ + +OSVR_EXTERN_C_END + +#endif diff --git a/gfx/vr/service/osvr/Util/MatrixConventionsC.h b/gfx/vr/service/osvr/Util/MatrixConventionsC.h new file mode 100644 index 0000000000..d9d31ef857 --- /dev/null +++ b/gfx/vr/service/osvr/Util/MatrixConventionsC.h @@ -0,0 +1,190 @@ +/** @file + @brief Header + + Must be c-safe! + + @date 2015 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2015 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_MatrixConventionsC_h_GUID_6FC7A4C6_E6C5_4A96_1C28_C3D21B909681 +#define INCLUDED_MatrixConventionsC_h_GUID_6FC7A4C6_E6C5_4A96_1C28_C3D21B909681 + +/* Internal Includes */ +#include <osvr/Util/Export.h> +#include <osvr/Util/APIBaseC.h> +#include <osvr/Util/StdInt.h> +#include <osvr/Util/Pose3C.h> +#include <osvr/Util/ReturnCodesC.h> + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN + +/** @defgroup MatrixConvention Matrix conventions and bit flags + @ingroup UtilMath +*/ + +/** @brief Type for passing matrix convention flags. + @ingroup MatrixConvention +*/ +typedef uint16_t OSVR_MatrixConventions; + +#ifndef OSVR_DOXYGEN_EXTERNAL +/** @brief Bitmasks for testing matrix conventions. + @ingroup MatrixConvention +*/ +typedef enum OSVR_MatrixMasks { + OSVR_MATRIX_MASK_ROWMAJOR = 0x1, + OSVR_MATRIX_MASK_ROWVECTORS = 0x2, + OSVR_MATRIX_MASK_LHINPUT = 0x4, + OSVR_MATRIX_MASK_UNSIGNEDZ = 0x8 +} OSVR_MatrixMasks; +#endif + +/** @defgroup MatrixFlags Matrix flags + @ingroup MatrixConvention + + Bit flags for specifying matrix options. Only one option may be specified + per enum, with all the specified options combined with bitwise-or `|`. + + Most methods that take matrix flags only obey ::OSVR_MatrixOrderingFlags and + ::OSVR_MatrixVectorFlags - the flags that affect memory order. The remaining + flags are for use with projection matrix generation API methods. + + @{ +*/ +/** @brief Flag bit controlling output memory order */ +typedef enum OSVR_MatrixOrderingFlags { + /** @brief Column-major memory order (default) */ + OSVR_MATRIX_COLMAJOR = 0x0, + /** @brief Row-major memory order */ + OSVR_MATRIX_ROWMAJOR = OSVR_MATRIX_MASK_ROWMAJOR +} OSVR_MatrixOrderingFlags; + +/** @brief Flag bit controlling expected input to matrices. + (Related to ::OSVR_MatrixOrderingFlags - setting one to non-default results + in an output change, but setting both to non-default results in effectively + no change in the output. If this blows your mind, just ignore this aside and + carry on.) +*/ +typedef enum OSVR_MatrixVectorFlags { + /** @brief Matrix transforms column vectors (default) */ + OSVR_MATRIX_COLVECTORS = 0x0, + /** @brief Matrix transforms row vectors */ + OSVR_MATRIX_ROWVECTORS = OSVR_MATRIX_MASK_ROWVECTORS +} OSVR_MatrixVectorFlags; + +/** @brief Flag bit to indicate coordinate system input to projection matrix */ +typedef enum OSVR_ProjectionMatrixInputFlags { + /** @brief Matrix takes vectors from a right-handed coordinate system + (default) */ + OSVR_MATRIX_RHINPUT = 0x0, + /** @brief Matrix takes vectors from a left-handed coordinate system */ + OSVR_MATRIX_LHINPUT = OSVR_MATRIX_MASK_LHINPUT + +} OSVR_ProjectionMatrixInputFlags; + +/** @brief Flag bit to indicate the desired post-projection Z value convention + */ +typedef enum OSVR_ProjectionMatrixZFlags { + /** @brief Matrix maps the near and far planes to signed Z values (in the + range [-1, 1]) (default)*/ + OSVR_MATRIX_SIGNEDZ = 0x0, + /** @brief Matrix maps the near and far planes to unsigned Z values (in the + range [0, 1]) */ + OSVR_MATRIX_UNSIGNEDZ = OSVR_MATRIX_MASK_UNSIGNEDZ +} OSVR_ProjectionMatrixZFlags; +/** @} */ /* end of matrix flags group */ + +enum { + /** @brief Constant for the number of elements in the matrices we use - 4x4. + @ingroup MatrixConvention + */ + OSVR_MATRIX_SIZE = 16 +}; + +/** @addtogroup UtilMath + @{ +*/ +/** @brief Set a matrix of doubles based on a Pose3. + @param pose The Pose3 to convert + @param flags Memory ordering flag - see @ref MatrixFlags + @param[out] mat an array of 16 doubles +*/ +OSVR_UTIL_EXPORT OSVR_ReturnCode osvrPose3ToMatrixd( + OSVR_Pose3 const* pose, OSVR_MatrixConventions flags, double* mat); + +/** @brief Set a matrix of floats based on a Pose3. + @param pose The Pose3 to convert + @param flags Memory ordering flag - see @ref MatrixFlags + @param[out] mat an array of 16 floats +*/ +OSVR_UTIL_EXPORT OSVR_ReturnCode osvrPose3ToMatrixf( + OSVR_Pose3 const* pose, OSVR_MatrixConventions flags, float* mat); +/** @} */ + +OSVR_EXTERN_C_END + +#ifdef __cplusplus +/** @brief Set a matrix based on a Pose3. (C++-only overload - detecting scalar + * type) */ +inline OSVR_ReturnCode osvrPose3ToMatrix(OSVR_Pose3 const* pose, + OSVR_MatrixConventions flags, + double* mat) { + return osvrPose3ToMatrixd(pose, flags, mat); +} + +/** @brief Set a matrix based on a Pose3. (C++-only overload - detecting scalar + * type) */ +inline OSVR_ReturnCode osvrPose3ToMatrix(OSVR_Pose3 const* pose, + OSVR_MatrixConventions flags, + float* mat) { + return osvrPose3ToMatrixf(pose, flags, mat); +} + +/** @brief Set a matrix based on a Pose3. (C++-only overload - detects scalar + * and takes array rather than pointer) */ +template <typename Scalar> +inline OSVR_ReturnCode osvrPose3ToMatrix(OSVR_Pose3 const* pose, + OSVR_MatrixConventions flags, + Scalar mat[OSVR_MATRIX_SIZE]) { + return osvrPose3ToMatrix(pose, flags, &(mat[0])); +} +/** @brief Set a matrix based on a Pose3. (C++-only overload - detects scalar, + * takes array, takes pose by reference) */ +template <typename Scalar> +inline OSVR_ReturnCode osvrPose3ToMatrix(OSVR_Pose3 const& pose, + OSVR_MatrixConventions flags, + Scalar mat[OSVR_MATRIX_SIZE]) { + return osvrPose3ToMatrix(&pose, flags, &(mat[0])); +} + +#endif + +/** @} */ + +#endif diff --git a/gfx/vr/service/osvr/Util/PlatformConfig.h b/gfx/vr/service/osvr/Util/PlatformConfig.h new file mode 100644 index 0000000000..081712d3a3 --- /dev/null +++ b/gfx/vr/service/osvr/Util/PlatformConfig.h @@ -0,0 +1,87 @@ +/** @file + @brief Auto-configured header + + If this filename ends in `.h`, don't edit it: your edits will + be lost next time this file is regenerated! + + Must be c-safe! + + @date 2014 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2014 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_PlatformConfig_h_GUID_0D10E644_8114_4294_A839_699F39E1F0E0 +#define INCLUDED_PlatformConfig_h_GUID_0D10E644_8114_4294_A839_699F39E1F0E0 + +/** @def OSVR_HAVE_STRUCT_TIMEVAL_IN_WINSOCK2_H + @brief Does the system have struct timeval in <winsock2.h>? +*/ +#define OSVR_HAVE_STRUCT_TIMEVAL_IN_WINSOCK2_H + +/** @def OSVR_HAVE_STRUCT_TIMEVAL_IN_SYS_TIME_H + @brief Does the system have struct timeval in <sys/time.h>? +*/ + +/* + MinGW and similar environments have both winsock and sys/time.h, so + we hide this define for disambiguation at the top level. +*/ +#ifndef OSVR_HAVE_STRUCT_TIMEVAL_IN_WINSOCK2_H +/* #undef OSVR_HAVE_STRUCT_TIMEVAL_IN_SYS_TIME_H */ +#endif + +#if defined(OSVR_HAVE_STRUCT_TIMEVAL_IN_SYS_TIME_H) || \ + defined(OSVR_HAVE_STRUCT_TIMEVAL_IN_WINSOCK2_H) +# define OSVR_HAVE_STRUCT_TIMEVAL +#endif + +/** + * Platform-specific variables. + * + * Prefer testing for specific compiler or platform features instead of relying + * on these variables. + * + */ +//@{ +/* #undef OSVR_AIX */ +/* #undef OSVR_ANDROID */ +/* #undef OSVR_BSDOS */ +/* #undef OSVR_FREEBSD */ +/* #undef OSVR_HPUX */ +/* #undef OSVR_IRIX */ +/* #undef OSVR_LINUX */ +/* #undef OSVR_KFREEBSD */ +/* #undef OSVR_NETBSD */ +/* #undef OSVR_OPENBSD */ +/* #undef OSVR_OFS1 */ +/* #undef OSVR_SCO_SV */ +/* #undef OSVR_UNIXWARE */ +/* #undef OSVR_XENIX */ +/* #undef OSVR_SUNOS */ +/* #undef OSVR_TRU64 */ +/* #undef OSVR_ULTRIX */ +/* #undef OSVR_CYGWIN */ +/* #undef OSVR_MACOSX */ +#define OSVR_WINDOWS +//@} + +#endif diff --git a/gfx/vr/service/osvr/Util/Pose3C.h b/gfx/vr/service/osvr/Util/Pose3C.h new file mode 100644 index 0000000000..cf56e7cc53 --- /dev/null +++ b/gfx/vr/service/osvr/Util/Pose3C.h @@ -0,0 +1,70 @@ +/** @file + @brief Header + + Must be c-safe! + + @date 2014 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2014 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_Pose3C_h_GUID_066CFCE2_229C_4194_5D2B_2602CCD5C439 +#define INCLUDED_Pose3C_h_GUID_066CFCE2_229C_4194_5D2B_2602CCD5C439 + +/* Internal Includes */ + +/* Internal Includes */ +#include <osvr/Util/APIBaseC.h> +#include <osvr/Util/Vec3C.h> +#include <osvr/Util/QuaternionC.h> + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN + +/** @addtogroup UtilMath + @{ +*/ + +/** @brief A structure defining a 3D (6DOF) rigid body pose: translation and + rotation. +*/ +typedef struct OSVR_Pose3 { + /** @brief Position vector */ + OSVR_Vec3 translation; + /** @brief Orientation as a unit quaternion */ + OSVR_Quaternion rotation; +} OSVR_Pose3; + +/** @brief Set a pose to identity */ +OSVR_INLINE void osvrPose3SetIdentity(OSVR_Pose3* pose) { + osvrQuatSetIdentity(&(pose->rotation)); + osvrVec3Zero(&(pose->translation)); +} +/** @} */ + +OSVR_EXTERN_C_END + +#endif diff --git a/gfx/vr/service/osvr/Util/QuaternionC.h b/gfx/vr/service/osvr/Util/QuaternionC.h new file mode 100644 index 0000000000..065c68bd4e --- /dev/null +++ b/gfx/vr/service/osvr/Util/QuaternionC.h @@ -0,0 +1,92 @@ +/** @file + @brief Header + + Must be c-safe! + + @date 2014 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2014 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_QuaternionC_h_GUID_1470A5FE_8209_41A6_C19E_46077FDF9C66 +#define INCLUDED_QuaternionC_h_GUID_1470A5FE_8209_41A6_C19E_46077FDF9C66 + +/* Internal Includes */ +#include <osvr/Util/APIBaseC.h> + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN + +/** @addtogroup UtilMath + @{ +*/ +/** @brief A structure defining a quaternion, often a unit quaternion + * representing 3D rotation. + */ +typedef struct OSVR_Quaternion { + /** @brief Internal data - direct access not recommended */ + double data[4]; +} OSVR_Quaternion; + +#define OSVR_QUAT_MEMBER(COMPONENT, INDEX) \ + /** @brief Accessor for quaternion component COMPONENT */ \ + OSVR_INLINE double osvrQuatGet##COMPONENT(OSVR_Quaternion const* q) { \ + return q->data[INDEX]; \ + } \ + /** @brief Setter for quaternion component COMPONENT */ \ + OSVR_INLINE void osvrQuatSet##COMPONENT(OSVR_Quaternion* q, double val) { \ + q->data[INDEX] = val; \ + } + +OSVR_QUAT_MEMBER(W, 0) +OSVR_QUAT_MEMBER(X, 1) +OSVR_QUAT_MEMBER(Y, 2) +OSVR_QUAT_MEMBER(Z, 3) + +#undef OSVR_QUAT_MEMBER + +/** @brief Set a quaternion to the identity rotation */ +OSVR_INLINE void osvrQuatSetIdentity(OSVR_Quaternion* q) { + osvrQuatSetW(q, 1); + osvrQuatSetX(q, 0); + osvrQuatSetY(q, 0); + osvrQuatSetZ(q, 0); +} + +/** @} */ + +OSVR_EXTERN_C_END + +#ifdef __cplusplus +template <typename StreamType> +inline StreamType& operator<<(StreamType& os, OSVR_Quaternion const& quat) { + os << "(" << osvrQuatGetW(&quat) << ", (" << osvrQuatGetX(&quat) << ", " + << osvrQuatGetY(&quat) << ", " << osvrQuatGetZ(&quat) << "))"; + return os; +} +#endif + +#endif diff --git a/gfx/vr/service/osvr/Util/QuatlibInteropC.h b/gfx/vr/service/osvr/Util/QuatlibInteropC.h new file mode 100644 index 0000000000..1519f02c10 --- /dev/null +++ b/gfx/vr/service/osvr/Util/QuatlibInteropC.h @@ -0,0 +1,84 @@ +/** @file + @brief Header + + Must be c-safe! + + @date 2014 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2014 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_QuatlibInteropC_h_GUID_85D92019_F0CC_419C_5F6D_F5A3134AA5D4 +#define INCLUDED_QuatlibInteropC_h_GUID_85D92019_F0CC_419C_5F6D_F5A3134AA5D4 + +/* Internal Includes */ +#include <osvr/Util/APIBaseC.h> +#include <osvr/Util/Pose3C.h> + +/* Library/third-party includes */ +#include <quat.h> + +/* Standard includes */ +#include <string.h> + +OSVR_EXTERN_C_BEGIN + +/** @addtogroup UtilMath + @{ +*/ +OSVR_INLINE void osvrQuatToQuatlib(q_type dest, OSVR_Quaternion const* src) { + dest[Q_W] = osvrQuatGetW(src); + dest[Q_X] = osvrQuatGetX(src); + dest[Q_Y] = osvrQuatGetY(src); + dest[Q_Z] = osvrQuatGetZ(src); +} + +OSVR_INLINE void osvrQuatFromQuatlib(OSVR_Quaternion* dest, q_type const src) { + osvrQuatSetW(dest, src[Q_W]); + osvrQuatSetX(dest, src[Q_X]); + osvrQuatSetY(dest, src[Q_Y]); + osvrQuatSetZ(dest, src[Q_Z]); +} + +OSVR_INLINE void osvrVec3ToQuatlib(q_vec_type dest, OSVR_Vec3 const* src) { + memcpy((void*)(dest), (void const*)(src->data), sizeof(double) * 3); +} + +OSVR_INLINE void osvrVec3FromQuatlib(OSVR_Vec3* dest, q_vec_type const src) { + memcpy((void*)(dest->data), (void const*)(src), sizeof(double) * 3); +} + +OSVR_INLINE void osvrPose3ToQuatlib(q_xyz_quat_type* dest, + OSVR_Pose3 const* src) { + osvrVec3ToQuatlib(dest->xyz, &(src->translation)); + osvrQuatToQuatlib(dest->quat, &(src->rotation)); +} + +OSVR_INLINE void osvrPose3FromQuatlib(OSVR_Pose3* dest, + q_xyz_quat_type const* src) { + osvrVec3FromQuatlib(&(dest->translation), src->xyz); + osvrQuatFromQuatlib(&(dest->rotation), src->quat); +} + +/** @} */ + +OSVR_EXTERN_C_END +#endif diff --git a/gfx/vr/service/osvr/Util/RadialDistortionParametersC.h b/gfx/vr/service/osvr/Util/RadialDistortionParametersC.h new file mode 100644 index 0000000000..b3fea12625 --- /dev/null +++ b/gfx/vr/service/osvr/Util/RadialDistortionParametersC.h @@ -0,0 +1,62 @@ +/** @file + @brief Header + + Must be c-safe! + + @date 2015 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2015 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_RadialDistortionParametersC_h_GUID_925BCEB1_BACA_4DA7_5133_FFF560C72EBD +#define INCLUDED_RadialDistortionParametersC_h_GUID_925BCEB1_BACA_4DA7_5133_FFF560C72EBD + +/* Internal Includes */ +#include <osvr/Util/APIBaseC.h> +#include <osvr/Util/Vec2C.h> +#include <osvr/Util/Vec3C.h> + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN + +/** @addtogroup UtilMath +@{ +*/ + +/** @brief Parameters for a per-color-component radial distortion shader + */ +typedef struct OSVR_RadialDistortionParameters { + /** @brief Vector of K1 coefficients for the R, G, B channels*/ + OSVR_Vec3 k1; + /** @brief Center of projection for the radial distortion, relative to the + bounds of this surface. + */ + OSVR_Vec2 centerOfProjection; +} OSVR_RadialDistortionParameters; + +OSVR_EXTERN_C_END + +#endif diff --git a/gfx/vr/service/osvr/Util/RenderingTypesC.h b/gfx/vr/service/osvr/Util/RenderingTypesC.h new file mode 100644 index 0000000000..103d0396d9 --- /dev/null +++ b/gfx/vr/service/osvr/Util/RenderingTypesC.h @@ -0,0 +1,134 @@ +/** @file + @brief Header with integer types for Viewer, Eye, and Surface + counts/indices, as well as viewport information. + + Must be c-safe! + + @date 2015 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2015 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_RenderingTypesC_h_GUID_6689A6CA_76AC_48AC_A0D0_2902BC95AC35 +#define INCLUDED_RenderingTypesC_h_GUID_6689A6CA_76AC_48AC_A0D0_2902BC95AC35 + +/* Internal Includes */ +#include <osvr/Util/StdInt.h> +#include <osvr/Util/APIBaseC.h> + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN + +/** @addtogroup PluginKit +@{ +*/ + +/** @brief A count or index for a display input in a display config. + */ +typedef uint8_t OSVR_DisplayInputCount; + +/** @brief The integer type used in specification of size or location of a + display input, in pixels. +*/ +typedef int32_t OSVR_DisplayDimension; + +/** @brief The integer type specifying a number of viewers in a system. + + A "head" is a viewer (though not all viewers are necessarily heads). + + The count is output from osvrClientGetNumViewers(). + + When used as an ID/index, it is zero-based, so values range from 0 to (count + - 1) inclusive. + + The most frequent count is 1, though higher values are theoretically + possible. If you do not handle higher values, do still check and alert the + user if their system reports a higher number, as your application may not + behave as the user expects. +*/ +typedef uint32_t OSVR_ViewerCount; + +/** @brief The integer type specifying the number of eyes (viewpoints) of a + viewer. + + The count for a given viewer is output from osvrClientGetNumEyesForViewer(). + + When used as an ID/index, it is zero-based,so values range from 0 to (count + - 1) inclusive, for a given viewer. + + Use as an ID/index is not meaningful except in conjunction with the ID of + the corresponding viewer. (that is, there is no overall "eye 0", but "viewer + 0, eye 0" is meaningful.) + + In practice, the most frequent counts are 1 (e.g. mono) and 2 (e.g. stereo), + and for example the latter results in eyes with ID 0 and 1 for the viewer. + There is no innate or consistent semantics/meaning ("left" or "right") to + indices guaranteed at this time, and applications should not try to infer + any. +*/ +typedef uint8_t OSVR_EyeCount; + +/** @brief The integer type specifying the number of surfaces seen by a viewer's + eye. + + The count for a given viewer and eye is output from + osvrClientGetNumSurfacesForViewerEye(). Note that the count is not + necessarily equal between eyes of a viewer. + + When used as an ID/index, it is zero-based, so values range from 0 to (count + - 1) inclusive, for a given viewer and eye. + + Use as an ID/index is not meaningful except in conjunction with the IDs of + the corresponding viewer and eye. (that is, there is no overall "surface 0", + but "viewer 0, eye 0, surface 0" is meaningful.) +*/ +typedef uint32_t OSVR_SurfaceCount; + +/** @brief The integer type used in specification of size or location of a + viewport. +*/ +typedef int32_t OSVR_ViewportDimension; + +/** @brief The integer type used to indicate relative priorities of a display + distortion strategy. Negative values are defined to mean that strategy is + unavailable. + + @sa OSVR_DISTORTION_PRIORITY_UNAVAILABLE +*/ +typedef int32_t OSVR_DistortionPriority; + +/** @brief The constant to return as an OSVR_DistortionPriority if a given + strategy is not available for a surface. + + @sa OSVR_DistortionPriority +*/ +#define OSVR_DISTORTION_PRIORITY_UNAVAILABLE (-1) + +/** @} */ + +OSVR_EXTERN_C_END + +#endif diff --git a/gfx/vr/service/osvr/Util/ReturnCodesC.h b/gfx/vr/service/osvr/Util/ReturnCodesC.h new file mode 100644 index 0000000000..971798ea41 --- /dev/null +++ b/gfx/vr/service/osvr/Util/ReturnCodesC.h @@ -0,0 +1,57 @@ +/** @file + @brief Header declaring a type and values for simple C return codes. + + Must be c-safe! + + @date 2014 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2014 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_ReturnCodesC_h_GUID_C81A2FDE_E5BB_4AAA_70A4_C616DD7C141A +#define INCLUDED_ReturnCodesC_h_GUID_C81A2FDE_E5BB_4AAA_70A4_C616DD7C141A + +/* Internal Includes */ +#include <osvr/Util/APIBaseC.h> +#include <osvr/Util/AnnotationMacrosC.h> + +OSVR_EXTERN_C_BEGIN + +/** @addtogroup PluginKit + @{ +*/ +/** @name Return Codes + @{ +*/ +/** @brief The "success" value for an OSVR_ReturnCode */ +#define OSVR_RETURN_SUCCESS (0) +/** @brief The "failure" value for an OSVR_ReturnCode */ +#define OSVR_RETURN_FAILURE (1) +/** @brief Return type from C API OSVR functions. */ +typedef OSVR_RETURN_SUCCESS_CONDITION( + return == OSVR_RETURN_SUCCESS) char OSVR_ReturnCode; +/** @} */ + +/** @} */ /* end of group */ + +OSVR_EXTERN_C_END + +#endif diff --git a/gfx/vr/service/osvr/Util/StdInt.h b/gfx/vr/service/osvr/Util/StdInt.h new file mode 100644 index 0000000000..4fe7117cb5 --- /dev/null +++ b/gfx/vr/service/osvr/Util/StdInt.h @@ -0,0 +1,42 @@ +/** @file + @brief Header wrapping the C99 standard `stdint` header. + + Must be c-safe! + + @date 2014 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2014 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_StdInt_h_GUID_C1AAF35C_C704_4DB7_14AC_615730C4619B +#define INCLUDED_StdInt_h_GUID_C1AAF35C_C704_4DB7_14AC_615730C4619B + +/* IWYU pragma: begin_exports */ + +#if !defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER >= 1600) +# include <stdint.h> +#else +# include "MSStdIntC.h" +#endif + +/* IWYU pragma: end_exports */ + +#endif diff --git a/gfx/vr/service/osvr/Util/TimeValueC.h b/gfx/vr/service/osvr/Util/TimeValueC.h new file mode 100644 index 0000000000..eb6a4f7cec --- /dev/null +++ b/gfx/vr/service/osvr/Util/TimeValueC.h @@ -0,0 +1,267 @@ +/** @file + @brief Header defining a dependency-free, cross-platform substitute for + struct timeval + + Must be c-safe! + + @date 2014 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2014 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_TimeValueC_h_GUID_A02C6917_124D_4CB3_E63E_07F2DA7144E9 +#define INCLUDED_TimeValueC_h_GUID_A02C6917_124D_4CB3_E63E_07F2DA7144E9 + +/* Internal Includes */ +#include <osvr/Util/Export.h> +#include <osvr/Util/APIBaseC.h> +#include <osvr/Util/AnnotationMacrosC.h> +#include <osvr/Util/PlatformConfig.h> +#include <osvr/Util/StdInt.h> +#include <osvr/Util/BoolC.h> + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN + +/** @defgroup UtilTime Timestamp interaction + @ingroup Util + + This provides a level of interoperability with struct timeval on systems + with that facility. It provides a neutral representation with sufficiently + large types. + + For C++ code, use of std::chrono or boost::chrono instead is recommended. + + Note that these time values may not necessarily correlate between processes + so should not be used to estimate or measure latency, etc. + + @{ +*/ + +/** @brief The signed integer type storing the seconds in a struct + OSVR_TimeValue */ +typedef int64_t OSVR_TimeValue_Seconds; +/** @brief The signed integer type storing the microseconds in a struct + OSVR_TimeValue */ +typedef int32_t OSVR_TimeValue_Microseconds; + +/** @brief Standardized, portable parallel to struct timeval for representing + both absolute times and time intervals. + + Where interpreted as an absolute time, its meaning is to be considered the + same as that of the POSIX struct timeval: + time since 00:00 Coordinated Universal Time (UTC), January 1, 1970. + + For best results, please keep normalized. Output of all functions here + is normalized. + */ +typedef struct OSVR_TimeValue { + /** @brief Seconds portion of the time value. */ + OSVR_TimeValue_Seconds seconds; + /** @brief Microseconds portion of the time value. */ + OSVR_TimeValue_Microseconds microseconds; +} OSVR_TimeValue; + +#ifdef OSVR_HAVE_STRUCT_TIMEVAL +/** @brief Gets the current time in the TimeValue. Parallel to gettimeofday. */ +OSVR_UTIL_EXPORT void osvrTimeValueGetNow(OSVR_OUT OSVR_TimeValue* dest) + OSVR_FUNC_NONNULL((1)); + +struct timeval; /* forward declaration */ + +/** @brief Converts from a TimeValue struct to your system's struct timeval. + + @param dest Pointer to an empty struct timeval for your platform. + @param src A pointer to an OSVR_TimeValue you'd like to convert from. + + If either parameter is NULL, the function will return without doing + anything. +*/ +OSVR_UTIL_EXPORT void osvrTimeValueToStructTimeval( + OSVR_OUT struct timeval* dest, OSVR_IN_PTR const OSVR_TimeValue* src) + OSVR_FUNC_NONNULL((1, 2)); + +/** @brief Converts from a TimeValue struct to your system's struct timeval. + @param dest An OSVR_TimeValue destination pointer. + @param src Pointer to a struct timeval you'd like to convert from. + + The result is normalized. + + If either parameter is NULL, the function will return without doing + anything. +*/ +OSVR_UTIL_EXPORT void osvrStructTimevalToTimeValue( + OSVR_OUT OSVR_TimeValue* dest, OSVR_IN_PTR const struct timeval* src) + OSVR_FUNC_NONNULL((1, 2)); +#endif + +/** @brief "Normalizes" a time value so that the absolute number of microseconds + is less than 1,000,000, and that the sign of both components is the same. + + @param tv Address of a struct TimeValue to normalize in place. + + If the given pointer is NULL, this function returns without doing anything. +*/ +OSVR_UTIL_EXPORT void osvrTimeValueNormalize(OSVR_INOUT_PTR OSVR_TimeValue* tv) + OSVR_FUNC_NONNULL((1)); + +/** @brief Sums two time values, replacing the first with the result. + + @param tvA Destination and first source. + @param tvB second source + + If a given pointer is NULL, this function returns without doing anything. + + Both parameters are expected to be in normalized form. +*/ +OSVR_UTIL_EXPORT void osvrTimeValueSum(OSVR_INOUT_PTR OSVR_TimeValue* tvA, + OSVR_IN_PTR const OSVR_TimeValue* tvB) + OSVR_FUNC_NONNULL((1, 2)); + +/** @brief Computes the difference between two time values, replacing the first + with the result. + + Effectively, `*tvA = *tvA - *tvB` + + @param tvA Destination and first source. + @param tvB second source + + If a given pointer is NULL, this function returns without doing anything. + + Both parameters are expected to be in normalized form. +*/ +OSVR_UTIL_EXPORT void osvrTimeValueDifference( + OSVR_INOUT_PTR OSVR_TimeValue* tvA, OSVR_IN_PTR const OSVR_TimeValue* tvB) + OSVR_FUNC_NONNULL((1, 2)); + +/** @brief Compares two time values (assumed to be normalized), returning + the same values as strcmp + + @return <0 if A is earlier than B, 0 if they are the same, and >0 if A + is later than B. +*/ +OSVR_UTIL_EXPORT int osvrTimeValueCmp(OSVR_IN_PTR const OSVR_TimeValue* tvA, + OSVR_IN_PTR const OSVR_TimeValue* tvB) + OSVR_FUNC_NONNULL((1, 2)); + +OSVR_EXTERN_C_END + +/** @brief Compute the difference between the two time values, returning the + duration as a double-precision floating-point number of seconds. + + Effectively, `ret = *tvA - *tvB` + + @param tvA first source. + @param tvB second source + @return Duration of timespan in seconds (floating-point) +*/ +OSVR_INLINE double osvrTimeValueDurationSeconds( + OSVR_IN_PTR const OSVR_TimeValue* tvA, + OSVR_IN_PTR const OSVR_TimeValue* tvB) { + OSVR_TimeValue A = *tvA; + osvrTimeValueDifference(&A, tvB); + double dt = A.seconds + A.microseconds / 1000000.0; + return dt; +} + +/** @brief True if A is later than B */ +OSVR_INLINE OSVR_CBool +osvrTimeValueGreater(OSVR_IN_PTR const OSVR_TimeValue* tvA, + OSVR_IN_PTR const OSVR_TimeValue* tvB) { + if (!tvA || !tvB) { + return OSVR_FALSE; + } + return ((tvA->seconds > tvB->seconds) || + (tvA->seconds == tvB->seconds && + tvA->microseconds > tvB->microseconds)) + ? OSVR_TRUE + : OSVR_FALSE; +} + +#ifdef __cplusplus + +# include <cmath> +# include <cassert> + +/// Returns true if the time value is normalized. Typically used in assertions. +inline bool osvrTimeValueIsNormalized(const OSVR_TimeValue& tv) { +# ifdef __APPLE__ + // apparently standard library used on mac only has floating-point abs? + return std::abs(double(tv.microseconds)) < 1000000 && +# else + return std::abs(tv.microseconds) < 1000000 && +# endif + ((tv.seconds > 0) == (tv.microseconds > 0)); +} + +/// True if A is later than B +inline bool osvrTimeValueGreater(const OSVR_TimeValue& tvA, + const OSVR_TimeValue& tvB) { + assert(osvrTimeValueIsNormalized(tvA) && + "First timevalue argument to comparison was not normalized!"); + assert(osvrTimeValueIsNormalized(tvB) && + "Second timevalue argument to comparison was not normalized!"); + return (tvA.seconds > tvB.seconds) || + (tvA.seconds == tvB.seconds && tvA.microseconds > tvB.microseconds); +} + +/// Operator > overload for time values +inline bool operator>(const OSVR_TimeValue& tvA, const OSVR_TimeValue& tvB) { + return osvrTimeValueGreater(tvA, tvB); +} + +/// Operator < overload for time values +inline bool operator<(const OSVR_TimeValue& tvA, const OSVR_TimeValue& tvB) { + // Change the order of arguments before forwarding. + return osvrTimeValueGreater(tvB, tvA); +} + +/// Operator == overload for time values +inline bool operator==(const OSVR_TimeValue& tvA, const OSVR_TimeValue& tvB) { + assert(osvrTimeValueIsNormalized(tvA) && + "First timevalue argument to equality comparison was not normalized!"); + assert( + osvrTimeValueIsNormalized(tvB) && + "Second timevalue argument to equality comparison was not normalized!"); + return (tvA.seconds == tvB.seconds) && (tvA.microseconds == tvB.microseconds); +} +/// Operator == overload for time values +inline bool operator!=(const OSVR_TimeValue& tvA, const OSVR_TimeValue& tvB) { + assert(osvrTimeValueIsNormalized(tvA) && + "First timevalue argument to " + "inequality comparison was not " + "normalized!"); + assert(osvrTimeValueIsNormalized(tvB) && + "Second timevalue argument to " + "inequality comparison was not " + "normalized!"); + return (tvA.seconds != tvB.seconds) || (tvA.microseconds != tvB.microseconds); +} +#endif + +/** @} */ + +#endif diff --git a/gfx/vr/service/osvr/Util/Vec2C.h b/gfx/vr/service/osvr/Util/Vec2C.h new file mode 100644 index 0000000000..0641270c1f --- /dev/null +++ b/gfx/vr/service/osvr/Util/Vec2C.h @@ -0,0 +1,86 @@ +/** @file + @brief Header + + Must be c-safe! + + @date 2014 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2014 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_Vec2C_h_GUID_F9715DE4_2649_4182_0F4C_D62121235D5F +#define INCLUDED_Vec2C_h_GUID_F9715DE4_2649_4182_0F4C_D62121235D5F + +/* Internal Includes */ +#include <osvr/Util/APIBaseC.h> + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN + +/** @addtogroup UtilMath + @{ +*/ +/** @brief A structure defining a 2D vector, which represents position + */ +typedef struct OSVR_Vec2 { + /** @brief Internal array data. */ + double data[2]; +} OSVR_Vec2; + +#define OSVR_VEC_MEMBER(COMPONENT, INDEX) \ + /** @brief Accessor for Vec2 component COMPONENT */ \ + OSVR_INLINE double osvrVec2Get##COMPONENT(OSVR_Vec2 const* v) { \ + return v->data[INDEX]; \ + } \ + /** @brief Setter for Vec2 component COMPONENT */ \ + OSVR_INLINE void osvrVec2Set##COMPONENT(OSVR_Vec2* v, double val) { \ + v->data[INDEX] = val; \ + } + +OSVR_VEC_MEMBER(X, 0) +OSVR_VEC_MEMBER(Y, 1) + +#undef OSVR_VEC_MEMBER + +/** @brief Set a Vec2 to the zero vector */ +OSVR_INLINE void osvrVec2Zero(OSVR_Vec2* v) { + osvrVec2SetX(v, 0); + osvrVec2SetY(v, 0); +} + +/** @} */ + +OSVR_EXTERN_C_END + +#ifdef __cplusplus +template <typename StreamType> +inline StreamType& operator<<(StreamType& os, OSVR_Vec2 const& vec) { + os << "(" << vec.data[0] << ", " << vec.data[1] << ")"; + return os; +} +#endif + +#endif // INCLUDED_Vec2C_h_GUID_F9715DE4_2649_4182_0F4C_D62121235D5F diff --git a/gfx/vr/service/osvr/Util/Vec3C.h b/gfx/vr/service/osvr/Util/Vec3C.h new file mode 100644 index 0000000000..f72327c05b --- /dev/null +++ b/gfx/vr/service/osvr/Util/Vec3C.h @@ -0,0 +1,88 @@ +/** @file + @brief Header + + Must be c-safe! + + @date 2014 + + @author + Sensics, Inc. + <http://sensics.com/osvr> +*/ + +/* +// Copyright 2014 Sensics, Inc. +// +// 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. +*/ + +#ifndef INCLUDED_Vec3C_h_GUID_BF4E98ED_74CF_4785_DB61_109A00BA74DE +#define INCLUDED_Vec3C_h_GUID_BF4E98ED_74CF_4785_DB61_109A00BA74DE + +/* Internal Includes */ +#include <osvr/Util/APIBaseC.h> + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN + +/** @addtogroup UtilMath + @{ +*/ +/** @brief A structure defining a 3D vector, often a position/translation. + */ +typedef struct OSVR_Vec3 { + /** @brief Internal array data. */ + double data[3]; +} OSVR_Vec3; + +#define OSVR_VEC_MEMBER(COMPONENT, INDEX) \ + /** @brief Accessor for Vec3 component COMPONENT */ \ + OSVR_INLINE double osvrVec3Get##COMPONENT(OSVR_Vec3 const* v) { \ + return v->data[INDEX]; \ + } \ + /** @brief Setter for Vec3 component COMPONENT */ \ + OSVR_INLINE void osvrVec3Set##COMPONENT(OSVR_Vec3* v, double val) { \ + v->data[INDEX] = val; \ + } + +OSVR_VEC_MEMBER(X, 0) +OSVR_VEC_MEMBER(Y, 1) +OSVR_VEC_MEMBER(Z, 2) + +#undef OSVR_VEC_MEMBER + +/** @brief Set a Vec3 to the zero vector */ +OSVR_INLINE void osvrVec3Zero(OSVR_Vec3* v) { + osvrVec3SetX(v, 0); + osvrVec3SetY(v, 0); + osvrVec3SetZ(v, 0); +} + +/** @} */ + +OSVR_EXTERN_C_END + +#ifdef __cplusplus +template <typename StreamType> +inline StreamType& operator<<(StreamType& os, OSVR_Vec3 const& vec) { + os << "(" << vec.data[0] << ", " << vec.data[1] << ", " << vec.data[2] << ")"; + return os; +} +#endif + +#endif |