Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
SupportUSD_Spat.h
1
2
3#pragma once
4
5#include "dim/DimensionedValues.h"
6#include "spat/Position.h"
7#include "spat/Vector.h"
8#include "spat/Matrix.h"
9
10#if defined(_MSC_VER)
11# pragma warning( push )
12# pragma warning( disable: 4244 ) // conversion from 'double' to 'float', possible loss of data
13# pragma warning( disable: 4305 ) //'argument': truncation from 'double' to 'float'
14#endif
15#include <pxr/base/gf/vec3f.h>
16#include <pxr/base/gf/vec3d.h>
17#include <pxr/base/gf/quatf.h>
18#include <pxr/base/tf/token.h>
19#if defined(_MSC_VER)
20# pragma warning( pop )
21#endif
22
23namespace trax{
24
25 template< class GfVect3Type >
26 inline GfVect3Type From( const spat::Position<Length>& p, Real usdStageMetersPerUnit ){
27 return GfVect3Type{ _m(p.x)/usdStageMetersPerUnit, _m(p.y)/usdStageMetersPerUnit, _m(p.z)/usdStageMetersPerUnit };
28 }
29
30 inline pxr::GfVec3f From( const spat::Position<One>& rotAngles ){
31 return pxr::GfVec3f{ _deg(rotAngles.x), _deg(rotAngles.y), _deg(rotAngles.z) };
32 }
33
34 inline pxr::GfVec3f From( const spat::Vector<One>& rot ){
35 return pxr::GfVec3f{ rot.dx, rot.dy, rot.dz };
36 }
37
38 // Function to calculate a quaternion from a rotation axis
39 inline pxr::GfQuatf CalculateQuaternionFromAxis( const pxr::GfVec3f& axis, float angle )
40 {
41 // Normalize the rotation axis vector
42 pxr::GfVec3f normalizedAxis = axis.GetNormalized();
43
44 // Calculate the sine and cosine of half the rotation angle
45 float halfAngle = angle / 2.0f;
46 float sinHalfAngle = std::sin(halfAngle);
47 float cosHalfAngle = std::cos(halfAngle);
48
49 // Construct the quaternion
50 pxr::GfQuatf quaternion{
51 cosHalfAngle,
52 sinHalfAngle * normalizedAxis[0],
53 sinHalfAngle * normalizedAxis[1],
54 sinHalfAngle * normalizedAxis[2] };
55
56 return quaternion;
57 }
58
59 inline pxr::GfQuatf From( const spat::Rotation<One>& rot )
60 {
61 return CalculateQuaternionFromAxis( From(-rot.RotationAxis()), _rad(rot.RotationAngle()) );
62 }
63
64
65
66}
Rotation matrix.
Definition Matrix.h:607
Valtype RotationAngle() const noexcept
Angle of the rotation described by this matrix.
Definition Matrix.h:2059
Vector< Valtype > RotationAxis() const noexcept
Axis of the rotation described by this matrix.
Definition Matrix.h:2028
constexpr Real _rad(Angle a) noexcept
Dimensionated Values conversion functions.
Definition DimensionedValues.h:1202
constexpr Real _m(Length l) noexcept
Dimensionated Values conversion functions.
Definition DimensionedValues.h:1210
float Real
Underlying floating point type to be used with the dim library.
Definition DimensionedValues.h:190
constexpr Real _deg(Angle a) noexcept
Dimensionated Values conversion functions.
Definition DimensionedValues.h:1194
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
Implements a 3D - position in cartesian coordinates.
Definition Position.h:46
Valtype y
cartesian y coordinate.
Definition Position.h:50
Valtype z
cartesian z coordinate.
Definition Position.h:51
Valtype x
cartesian x coordinate.
Definition Position.h:49
Implements a 3D - vector in cartesian coordinates.
Definition Vector.h:48
Valtype dy
cartesian y component.
Definition Vector.h:52
Valtype dx
cartesian x component.
Definition Vector.h:51
Valtype dz
cartesian z component.
Definition Vector.h:53