| 1 | /* |
| 2 | Copyright 2018 Google Inc. All Rights Reserved. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS-IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef RESONANCE_AUDIO_PLATFORM_COMMON_UTILS_H_ |
| 18 | #define RESONANCE_AUDIO_PLATFORM_COMMON_UTILS_H_ |
| 19 | |
| 20 | #include "Eigen/Dense" |
| 21 | |
| 22 | namespace vraudio { |
| 23 | |
| 24 | // Flips the z-axis of a transformation matrix, which effectively allows |
| 25 | // switching between the left-handed and right-handed coordinate systems. |
| 26 | // |
| 27 | // @param matrix 4x4 transformation matrix. |
| 28 | // @return 4x4 transformation matrix with the z-axis flipped. |
| 29 | void FlipZAxis(Eigen::Matrix4f* matrix); |
| 30 | |
| 31 | // Returns the position vector of a transformation matrix. |
| 32 | // |
| 33 | // @param matrix 4x4 transformation matrix. |
| 34 | // @return 3D position vector. |
| 35 | Eigen::Vector3f GetPosition(const Eigen::Matrix4f& matrix); |
| 36 | |
| 37 | // Returns the rotation quaternion of a transformation matrix. |
| 38 | // |
| 39 | // @param matrix 4x4 transformation matrix. |
| 40 | // @return Quaternion representation of the rotation. |
| 41 | Eigen::Quaternionf GetQuaternion(const Eigen::Matrix4f& matrix); |
| 42 | |
| 43 | // Returns a transformation matrix from position, forward & up vectors. |
| 44 | // |
| 45 | // @param position Position vector. |
| 46 | // @param forward Forward direction vector describing rotation. |
| 47 | // @param up Up direction vector describing rotation. |
| 48 | // @return 4x4 transformation matrix. |
| 49 | Eigen::Matrix4f GetTransformMatrix(const Eigen::Vector3f& position, |
| 50 | const Eigen::Vector3f& forward, |
| 51 | const Eigen::Vector3f& up); |
| 52 | |
| 53 | } // namespace vraudio |
| 54 | |
| 55 | #endif // RESONANCE_AUDIO_PLATFORM_COMMON_UTILS_H_ |
| 56 | |