python/src/rotation.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #include <array> | ||
| 3 | #include <tuple> | ||
| 4 | |||
| 5 | #include <nanobind/stl/array.h> | ||
| 6 | #include <nanobind/stl/tuple.h> | ||
| 7 | |||
| 8 | #include "bindings.h" | ||
| 9 | |||
| 10 | namespace nb = nanobind; | ||
| 11 | |||
| 12 | namespace chrono::batch_render::python { | ||
| 13 | |||
| 14 | namespace { | ||
| 15 | |||
| 16 | using Vector = std::array<double, 3>; | ||
| 17 | using Quaternion = std::tuple<double, double, double, double>; | ||
| 18 | |||
| 19 | 50 | Double3 ToDouble3(const Vector& v) { | |
| 20 | 50 | return {v[0], v[1], v[2]}; | |
| 21 | } | ||
| 22 | |||
| 23 | 18 | Quaternion ToTuple(const Quatd& q) { | |
| 24 | 18 | return {q.x, q.y, q.z, q.w}; | |
| 25 | } | ||
| 26 | |||
| 27 | } | ||
| 28 | |||
| 29 | 2 | void BindRotation(nb::module_& module) { | |
| 30 | 2 | module.def( | |
| 31 | "look_at", | ||
| 32 | 17 | [](const Vector& eye, const Vector& target, const Vector& up) { | |
| 33 | 15 | return ToTuple(LookAt(ToDouble3(eye), ToDouble3(target), ToDouble3(up))); | |
| 34 | }, | ||
| 35 | 4 | nb::arg("eye"), nb::arg("target"), nb::arg("up") = Vector{0, 0, 1}); | |
| 36 | 2 | module.def( | |
| 37 | "look_along", | ||
| 38 | 4 | [](const Vector& direction, const Vector& up) { | |
| 39 | 2 | return ToTuple(LookAlong(ToDouble3(direction), ToDouble3(up))); | |
| 40 | }, | ||
| 41 | 4 | nb::arg("direction"), nb::arg("up") = Vector{0, 0, 1}); | |
| 42 | 2 | module.def( | |
| 43 | "from_axis_angle", | ||
| 44 | 3 | [](const Vector& axis, double degrees) { | |
| 45 | 1 | return ToTuple(FromAxisAngle(ToDouble3(axis), degrees)); | |
| 46 | }, | ||
| 47 | 2 | nb::arg("axis"), nb::arg("degrees")); | |
| 48 | 2 | module.def( | |
| 49 | "from_azimuth_elevation", | ||
| 50 | 3 | [](double azimuth, double elevation) { | |
| 51 | 1 | return ToTuple(FromAzimuthElevation(azimuth, elevation)); | |
| 52 | }, | ||
| 53 | 2 | nb::arg("azimuth"), nb::arg("elevation")); | |
| 54 | 2 | } | |
| 55 | |||
| 56 | } | ||
| 57 |