Skip to content

Commit a98b403

Browse files
rotation and other lvl_gen changes
1 parent 7dd7751 commit a98b403

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

src/knn.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void fillZeros(gpudrive::MapObservation *begin,
2020
gpudrive::MapObservation *beyond) {
2121
while (begin < beyond) {
2222
*begin++ =
23-
gpudrive::MapObservation{.position = {0, 0},
23+
gpudrive::MapObservation{.position = {0, 0, 0},
2424
.scale = madrona::math::Diag3x3{0, 0, 0},
2525
.heading = 0.f,
2626
.type = (float)gpudrive::EntityType::None};
@@ -30,16 +30,17 @@ void fillZeros(gpudrive::MapObservation *begin,
3030
gpudrive::MapObservation
3131
relativeObservation(const gpudrive::MapObservation &absoluteObservation,
3232
const madrona::base::Rotation &referenceRotation,
33-
const madrona::math::Vector2 &referencePosition) {
33+
const madrona::math::Vector3 &referencePosition) {
3434
auto relativePosition =
35-
madrona::math::Vector2{.x = absoluteObservation.position.x,
36-
.y = absoluteObservation.position.y} -
35+
madrona::math::Vector3{.x = absoluteObservation.position.x,
36+
.y = absoluteObservation.position.y,
37+
.z = absoluteObservation.position.z} -
3738
referencePosition;
3839

3940
return gpudrive::MapObservation{
4041
.position = referenceRotation.inv()
41-
.rotateVec({relativePosition.x, relativePosition.y, 0})
42-
.xy(),
42+
.rotateVec({relativePosition.x, relativePosition.y, relativePosition.z})
43+
.xyz(),
4344
.scale = absoluteObservation.scale,
4445
.heading = gpudrive::utils::quatToYaw(referenceRotation.inv() * madrona::math::Quat::angleAxis(absoluteObservation.heading,madrona::math::up)),
4546
.type = absoluteObservation.type};
@@ -50,7 +51,7 @@ bool isObservationsValid(gpudrive::Engine &ctx,
5051
gpudrive::MapObservation *observations,
5152
madrona::CountT K,
5253
const madrona::base::Rotation &referenceRotation,
53-
const madrona::math::Vector2 &referencePosition) {
54+
const madrona::math::Vector3 &referencePosition) {
5455
#ifdef MADRONA_GPU_MODE
5556
return true;
5657
#else
@@ -102,7 +103,7 @@ namespace gpudrive {
102103

103104
template <madrona::CountT K>
104105
void selectKNearestRoadEntities(Engine &ctx, const Rotation &referenceRotation,
105-
const madrona::math::Vector2 &referencePosition,
106+
const madrona::math::Vector3 &referencePosition,
106107
gpudrive::MapObservation *heap) {
107108
const Entity *roads = ctx.data().roads;
108109
const auto roadCount = ctx.data().numRoads;

src/level_gen.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,23 @@ static Entity makeRoadEdge(Engine &ctx, const MapRoad &roadInit, CountT j) {
163163
ctx.get<RoadInterfaceEntity>(road_edge).e = ctx.makeEntity<RoadInterface>();
164164

165165
auto pos = Vector3{.x = (start.x + end.x)/2, .y = (start.y + end.y)/2, .z = (start.z + end.z)/2};
166-
auto rot = Quat::angleAxis(atan2(end.y - start.y, end.x - start.x), madrona::math::up);
166+
167+
//Rotation calculation
168+
float dx = end.x - start.x;
169+
float dy = end.y - start.y;
170+
float dz = end.z - start.z;
171+
// XY rotation (yaw)
172+
auto yawRot = Quat::angleAxis(atan2(dy, dx), madrona::math::up);
173+
174+
// Z rotation (pitch)
175+
float horizontalDist = sqrt(dx*dx + dy*dy);
176+
float pitchAngle = atan2(dz, horizontalDist);
177+
Vector3 pitchAxis = Vector3::cross(Vector3{dx/horizontalDist, dy/horizontalDist, 0}, madrona::math::up);
178+
auto pitchRot = Quat::angleAxis(pitchAngle, pitchAxis);
179+
180+
// Combined rotation
181+
auto rot = yawRot * pitchRot;
182+
167183
auto scale = Diag3x3{.d0 = start.distance(end)/2, .d1 = 0.1, .d2 = 0.1};
168184
setRoadEntitiesProps(ctx, road_edge, pos, rot, scale, roadInit.type, ObjectID{(int32_t)SimObject::Cube}, ResponseType::Static, roadInit.id, roadInit.mapType);
169185
registerRigidBodyEntity(ctx, road_edge, SimObject::Cube);
@@ -367,7 +383,7 @@ void createPersistentEntities(Engine &ctx) {
367383
ctx.singleton<ResetMap>().reset = 0;
368384

369385
auto& means = ctx.singleton<WorldMeans>().mean;
370-
means = {map.mean.x, map.mean.y, 0}; // TODO: Add z to the map
386+
means = {map.mean.x, map.mean.y, map.mean.z};
371387

372388
CountT agentIdx = 0;
373389
for (CountT agentCtr = 0; agentCtr < map.numObjects && agentIdx < consts::kMaxAgentCount; ++agentCtr) {

src/level_gen.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void destroyWorld(Engine &ctx);
5656
ctx.get<ResponseType>(road) = responseType;
5757
ctx.get<RoadMapId>(road).id = roadIdx;
5858
ctx.get<MapType>(road) = mapType;
59-
ctx.get<MapObservation>(ctx.get<RoadInterfaceEntity>(road).e) = MapObservation{.position = pos.xy(),
59+
ctx.get<MapObservation>(ctx.get<RoadInterfaceEntity>(road).e) = MapObservation{.position = pos,
6060
.scale = scale,
6161
.heading = utils::quatToYaw(rot),
6262
.type = (float)type,

0 commit comments

Comments
 (0)