Exposing the 4-matrix form of the transformation
to the client API
This commit is contained in:
parent
693d0112f7
commit
7e2b57338b
|
@ -77,6 +77,30 @@ namespace geom {
|
|||
in_point = out_point;
|
||||
}
|
||||
|
||||
std::array<float, 16> GetMatrix() const {
|
||||
const float yaw = rotation.yaw;
|
||||
const float cy = std::cos(Math::ToRadians(yaw));
|
||||
const float sy = std::sin(Math::ToRadians(yaw));
|
||||
|
||||
const float roll = rotation.roll;
|
||||
const float cr = std::cos(Math::ToRadians(roll));
|
||||
const float sr = std::sin(Math::ToRadians(roll));
|
||||
|
||||
const float pitch = rotation.pitch;
|
||||
const float cp = std::cos(Math::ToRadians(pitch));
|
||||
const float sp = std::sin(Math::ToRadians(pitch));
|
||||
|
||||
std::array<float, 16> transform = {
|
||||
cp * cy, cy * sp * sr - sy * cr, -cy * sp * cr - sy * sr, location.x,
|
||||
cp * sy, sy * sp * sr + cy * cr, -sy * sp * cr + cy * sr, location.y,
|
||||
sp, -cp * sr, cp * cr, location.z,
|
||||
0.0, 0.0, 0.0, 1.0};
|
||||
|
||||
return transform;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// =========================================================================
|
||||
// -- Comparison operators -------------------------------------------------
|
||||
// =========================================================================
|
||||
|
|
|
@ -86,6 +86,36 @@ static void TransformList(const carla::geom::Transform &self, boost::python::lis
|
|||
}
|
||||
}
|
||||
|
||||
static auto GetTransformMatrix(const carla::geom::Transform &self) {
|
||||
const std::array<float, 16> tr = self.GetMatrix();
|
||||
boost::python::list py_tranf;
|
||||
boost::python::list rows[4];
|
||||
|
||||
rows[0].append(tr[0]);
|
||||
rows[0].append(tr[1]);
|
||||
rows[0].append(tr[2]);
|
||||
rows[0].append(tr[3]);
|
||||
rows[1].append(tr[4]);
|
||||
rows[1].append(tr[5]);
|
||||
rows[1].append(tr[6]);
|
||||
rows[1].append(tr[7]);
|
||||
rows[2].append(tr[8]);
|
||||
rows[2].append(tr[9]);
|
||||
rows[2].append(tr[10]);
|
||||
rows[2].append(tr[11]);
|
||||
rows[3].append(tr[12]);
|
||||
rows[3].append(tr[13]);
|
||||
rows[3].append(tr[14]);
|
||||
rows[3].append(tr[15]);
|
||||
|
||||
py_tranf.append(rows[0]);
|
||||
py_tranf.append(rows[1]);
|
||||
py_tranf.append(rows[2]);
|
||||
py_tranf.append(rows[3]);
|
||||
|
||||
return py_tranf;
|
||||
}
|
||||
|
||||
void export_geom() {
|
||||
using namespace boost::python;
|
||||
namespace cg = carla::geom;
|
||||
|
@ -175,6 +205,7 @@ void export_geom() {
|
|||
.def("get_forward_vector", &cg::Transform::GetForwardVector)
|
||||
.def("get_right_vector", &cg::Transform::GetRightVector)
|
||||
.def("get_up_vector", &cg::Transform::GetUpVector)
|
||||
.def("get_matrix", &GetTransformMatrix)
|
||||
.def("__eq__", &cg::Transform::operator==)
|
||||
.def("__ne__", &cg::Transform::operator!=)
|
||||
.def(self_ns::str(self_ns::self))
|
||||
|
|
Loading…
Reference in New Issue