Skip to content

Commit a426211

Browse files
committed
Fix relative obs
1 parent d7ab7cb commit a426211

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/sim.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ inline void collectPartnerObsSystem(Engine &ctx,
192192
const Rotation &other_rot = ctx.get<Rotation>(other);
193193
const VehicleSize &other_size = ctx.get<VehicleSize>(other);
194194

195-
Vector2 relative_pos = (other_position - pos).xy();
196-
relative_pos = rot.inv().rotateVec({relative_pos.x, relative_pos.y, 0}).xy();
195+
Vector3 relative_pos = (other_position - pos);
196+
relative_pos = rot.inv().rotateVec(relative_pos);
197197
float relative_speed = other_velocity.linear.length(); // Design decision: return the speed of the other agent directly
198198

199199
Rotation relative_orientation = rot.inv() * other_rot;

tests/EgocentricRoadObservationTests.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ using namespace madrona::math;
77
using gpudrive::utils::ReferenceFrame;
88

99
TEST(EgocentricRoadObservationTests, Relative) {
10-
ReferenceFrame rf{Vector2{.x = 3, .y = 0},
10+
ReferenceFrame rf{Vector3{.x = 3, .y = 0, .z=0},
1111
Quat::angleAxis(toRadians(90), madrona::math::up)};
1212

1313
auto mapObs =
14-
rf.observationOf(Vector3{.x = 3, .y = 3, .z = 0},
14+
rf.observationOf(Vector3{.x = 3, .y = 3, .z = 3},
1515
Quat::angleAxis(toRadians(270), madrona::math::up),
1616
Scale{{.d0 = 10, .d1 = 0.1, .d2 = 0.1}},
1717
static_cast<gpudrive::EntityType>(0), 0);
1818

1919
EXPECT_LT(mapObs.position.x - 3, 0.000001);
2020
EXPECT_LT(mapObs.position.y - 0, 0.000001);
21+
EXPECT_LT(mapObs.position.z - 3, 0.000001);
2122
EXPECT_EQ(mapObs.heading, toRadians(180));
2223
}

0 commit comments

Comments
 (0)