Added world rotation normalize
This commit is contained in:
parent
c40e9780c3
commit
b8cc2426c3
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include "carla/MsgPack.h"
|
#include "carla/MsgPack.h"
|
||||||
#include "carla/geom/Math.h"
|
#include "carla/geom/Math.h"
|
||||||
#include "carla/geom/Vector3D.h"
|
#include "carla/geom/Vector3D.h"
|
||||||
|
@ -124,18 +126,89 @@ namespace geom {
|
||||||
in_point = out_point;
|
in_point = out_point;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// -- UE4 methods -------------------------------------------------
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
Rotation Normalize() {
|
||||||
|
Rotation V0 = Rotation(*this);
|
||||||
|
|
||||||
|
V0.pitch = V0.pitch - (360.0f * trunc(V0.pitch/360.0f));
|
||||||
|
V0.yaw = V0.yaw - (360.0f * trunc(V0.yaw/360.0f));
|
||||||
|
V0.roll = V0.roll - (360.0f * trunc(V0.roll/360.0f));
|
||||||
|
|
||||||
|
if( V0.pitch < 0.0f ){
|
||||||
|
V0.pitch += 360.0f;
|
||||||
|
}
|
||||||
|
if( V0.yaw < 0.0f ){
|
||||||
|
V0.yaw += 360.0f;
|
||||||
|
}
|
||||||
|
if( V0.roll < 0.0f ){
|
||||||
|
V0.roll += 360.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( V0.pitch >= 180.0f ){
|
||||||
|
V0.pitch -= 360.0f;
|
||||||
|
}
|
||||||
|
if( V0.yaw >= 180.0f ){
|
||||||
|
V0.yaw -= 360.0f;
|
||||||
|
}
|
||||||
|
if( V0.roll >= 180.0f ){
|
||||||
|
V0.roll -= 360.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return V0;
|
||||||
|
}
|
||||||
|
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
// -- Comparison operators -------------------------------------------------
|
// -- Comparison operators -------------------------------------------------
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
|
|
||||||
bool operator==(const Rotation &rhs) const {
|
bool operator==(const Rotation &rhs) const {
|
||||||
return (pitch == rhs.pitch) && (yaw == rhs.yaw) && (roll == rhs.roll);
|
return ((pitch == rhs.pitch) && (yaw == rhs.yaw) && (roll == rhs.roll)) ||
|
||||||
|
// When comparing two normalized rotators the sum of both comps can be 180 according to UE, we are following same structure for rotators
|
||||||
|
( ( abs(pitch) + abs(rhs.pitch) == 180.0f) && ( abs(yaw) + abs(rhs.yaw) == 180.0f) && ( abs(roll) + abs(rhs.roll) == 180.0f) );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const Rotation &rhs) const {
|
bool operator!=(const Rotation &rhs) const {
|
||||||
return !(*this == rhs);
|
return !(*this == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// -- Aritmetic operators -------------------------------------------------
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
Rotation operator+(const Rotation &rhs) const{
|
||||||
|
Rotation Result;
|
||||||
|
Result.pitch = pitch + rhs.pitch;
|
||||||
|
Result.yaw = yaw + rhs.yaw;
|
||||||
|
Result.roll = roll + rhs.roll;
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rotation operator-(const Rotation &rhs) const{
|
||||||
|
Rotation Result;
|
||||||
|
Result.pitch = pitch - rhs.pitch;
|
||||||
|
Result.yaw = yaw - rhs.yaw;
|
||||||
|
Result.roll = roll - rhs.roll;
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rotation& operator+=(const Rotation &rhs){
|
||||||
|
pitch += rhs.pitch;
|
||||||
|
yaw += rhs.yaw;
|
||||||
|
roll += rhs.roll;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rotation& operator-=(const Rotation &rhs){
|
||||||
|
pitch -= rhs.pitch;
|
||||||
|
yaw -= rhs.yaw;
|
||||||
|
roll -= rhs.roll;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
// -- Conversions to UE4 types ---------------------------------------------
|
// -- Conversions to UE4 types ---------------------------------------------
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
|
|
|
@ -151,6 +151,7 @@ void export_geom() {
|
||||||
.def("get_forward_vector", &cg::Rotation::GetForwardVector)
|
.def("get_forward_vector", &cg::Rotation::GetForwardVector)
|
||||||
.def("get_right_vector", &cg::Rotation::GetRightVector)
|
.def("get_right_vector", &cg::Rotation::GetRightVector)
|
||||||
.def("get_up_vector", &cg::Rotation::GetUpVector)
|
.def("get_up_vector", &cg::Rotation::GetUpVector)
|
||||||
|
.def("get_normalized", &cg::Rotation::Normalize)
|
||||||
.def("__eq__", &cg::Rotation::operator==)
|
.def("__eq__", &cg::Rotation::operator==)
|
||||||
.def("__ne__", &cg::Rotation::operator!=)
|
.def("__ne__", &cg::Rotation::operator!=)
|
||||||
.def(self_ns::str(self_ns::self))
|
.def(self_ns::str(self_ns::self))
|
||||||
|
|
|
@ -349,7 +349,7 @@ void FCarlaActor::SetActorGlobalTransform(
|
||||||
LocalTransform =
|
LocalTransform =
|
||||||
LargeMap->GlobalToLocalTransform(LocalTransform);
|
LargeMap->GlobalToLocalTransform(LocalTransform);
|
||||||
}
|
}
|
||||||
GetActor()->SetActorRelativeTransform(
|
GetActor()->SetActorTransform(
|
||||||
LocalTransform,
|
LocalTransform,
|
||||||
false,
|
false,
|
||||||
nullptr,
|
nullptr,
|
||||||
|
|
Loading…
Reference in New Issue