Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
coordinate_utils.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
11
12namespace momentum {
13
19
20// --- Vector conversions (coordinate system change: meters <-> centimeters) ---
21
22[[nodiscard]] inline Vector3f toMomentumVec3f(const std::array<float, 3>& vec) noexcept {
23 return toMomentumVector(Vector3f(vec[0], vec[1], vec[2]), kGltfCoordinateSystem);
24}
25
26[[nodiscard]] inline Vector3f fromMomentumVec3f(const Vector3f& vec) noexcept {
28}
29
30inline void toMomentumVec3f(std::vector<Vector3f>& vec) {
31 if (vec.empty()) {
32 return;
33 }
35 Map<VectorXf>(&vec[0][0], vec.size() * 3) *= s;
36}
37
38inline void fromMomentumVec3f(std::vector<Vector3f>& vec) {
39 if (vec.empty()) {
40 return;
41 }
43 Map<VectorXf>(&vec[0][0], vec.size() * 3) *= s;
44}
45
46inline void fromMomentumVec3f(VectorXf& vec) {
47 if (vec.size() == 0) {
48 return;
49 }
51 vec *= s;
52}
53
54// --- Quaternion component reordering (NOT a coordinate system operation) ---
55// glTF stores quaternions as [x, y, z, w], Eigen stores as [w, x, y, z].
56
58 const std::array<float, 4>& gltfQuat) noexcept {
59 return {gltfQuat[3], gltfQuat[0], gltfQuat[1], gltfQuat[2]};
60}
61
62[[nodiscard]] inline std::array<float, 4> fromMomentumQuaternionf(
63 const Quaternionf& quat) noexcept {
64 return {quat.x(), quat.y(), quat.z(), quat.w()};
65}
66
67} // namespace momentum
Quaternionf toMomentumQuaternionf(const std::array< float, 4 > &gltfQuat) noexcept
Quaternion< float > Quaternionf
Definition types.h:386
template float scaleFactor< float >(const CoordinateSystem &, const CoordinateSystem &)
constexpr CoordinateSystem kGltfCoordinateSystem
The glTF coordinate system: Y-up, right-handed, meters.
Vector3< T > toMomentumVector(const Vector3< T > &v, const CoordinateSystem &from)
Converts a position vector from from into Momentum's canonical coordinate system.
Vector3< T > fromMomentumVector(const Vector3< T > &v, const CoordinateSystem &to)
Converts a position vector from Momentum's canonical coordinate system into to.
Vector3f toMomentumVec3f(const std::array< float, 3 > &vec) noexcept
Vector3f fromMomentumVec3f(const Vector3f &vec) noexcept
std::array< float, 4 > fromMomentumQuaternionf(const Quaternionf &quat) noexcept
constexpr CoordinateSystem kMomentumCoordinateSystem
Momentum's canonical coordinate system: Y-up, right-handed, centimeters.
Vector3< float > Vector3f
Definition types.h:251
VectorX< float > VectorXf
Definition types.h:209
Eigen::Map< T > Map
Definition types.h:40
A 3D coordinate system defined by its up axis, handedness, and length unit.