Skip to content

Commit d0adedf

Browse files
partial changes
1 parent 047e83b commit d0adedf

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/level_gen.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ static inline void resetAgent(Engine &ctx, Entity agent) {
2525
auto agent_iface = ctx.get<AgentInterfaceEntity>(agent).e;
2626
auto xCoord = ctx.get<Trajectory>(agent_iface).positions[0].x;
2727
auto yCoord = ctx.get<Trajectory>(agent_iface).positions[0].y;
28+
auto zCoord = ctx.get<Trajectory>(agent_iface).positions[0].z;
2829
auto xVelocity = ctx.get<Trajectory>(agent_iface).velocities[0].x;
2930
auto yVelocity = ctx.get<Trajectory>(agent_iface).velocities[0].y;
3031
auto speed = ctx.get<Trajectory>(agent_iface).velocities[0].length();
3132
auto heading = ctx.get<Trajectory>(agent_iface).headings[0];
3233

33-
ctx.get<Position>(agent) = Vector3{.x = xCoord, .y = yCoord, .z = 1};
34+
ctx.get<Position>(agent) = Vector3{.x = xCoord, .y = yCoord, .z = zCoord};
3435
ctx.get<Rotation>(agent) = Quat::angleAxis(heading, madrona::math::up);
3536
ctx.get<Velocity>(agent) = {
3637
Vector3{.x = xVelocity, .y = yVelocity, .z = 0}, Vector3::zero()};
@@ -80,7 +81,11 @@ static inline void populateExpertTrajectory(Engine &ctx, const Entity &agent, co
8081
auto &trajectory = ctx.get<Trajectory>(agent_iface);
8182
for(CountT i = 0; i < agentInit.numPositions; i++)
8283
{
83-
trajectory.positions[i] = Vector2{.x = agentInit.position[i].x - ctx.data().mean.x, .y = agentInit.position[i].y - ctx.data().mean.y};
84+
trajectory.positions[i] = Vector3{
85+
.x = agentInit.position[i].x - ctx.data().mean.x,
86+
.y = agentInit.position[i].y - ctx.data().mean.y,
87+
.z = agentInit.position[i].z - ctx.data().mean.z
88+
};
8489
trajectory.velocities[i] = Vector2{.x = agentInit.velocity[i].x, .y = agentInit.velocity[i].y};
8590
trajectory.headings[i] = toRadians(agentInit.heading[i]);
8691
trajectory.valids[i] = (float)agentInit.valid[i];
@@ -106,7 +111,7 @@ static inline void populateExpertTrajectory(Engine &ctx, const Entity &agent, co
106111
}
107112

108113
Rotation rot = Quat::angleAxis(trajectory.headings[i], madrona::math::up);
109-
Position pos = Vector3{.x = trajectory.positions[i].x, .y = trajectory.positions[i].y, .z = 1};
114+
Position pos = Vector3{.x = trajectory.positions[i].x, .y = trajectory.positions[i].y, .z = trajectory.positions[i].z};
110115
Velocity vel = {Vector3{.x = trajectory.velocities[i].x, .y = trajectory.velocities[i].y, .z = 0}, Vector3::zero()};
111116
Rotation targetRot = Quat::angleAxis(trajectory.headings[i+1], madrona::math::up);
112117
switch (ctx.data().params.dynamicsModel) {
@@ -123,7 +128,7 @@ static inline void populateExpertTrajectory(Engine &ctx, const Entity &agent, co
123128

124129
case DynamicsModel::DeltaLocal: {
125130
// Introduce another block scope here
126-
Position targetPos = Vector3{.x = trajectory.positions[i+1].x, .y = trajectory.positions[i+1].y, .z = 1};
131+
Position targetPos = Vector3{.x = trajectory.positions[i+1].x, .y = trajectory.positions[i+1].y, .z = trajectory.positions[i+1].z};
127132
trajectory.inverseActions[i] = inverseDeltaModel(rot, pos, targetRot, targetPos);
128133
break;
129134
}
@@ -146,7 +151,10 @@ static inline Entity createAgent(Engine &ctx, const MapObject &agentInit) {
146151

147152
auto agent_iface = ctx.get<AgentInterfaceEntity>(agent).e = ctx.makeEntity<AgentInterface>();
148153

149-
ctx.get<Goal>(agent)= Goal{.position = Vector2{.x = agentInit.goalPosition.x - ctx.data().mean.x, .y = agentInit.goalPosition.y - ctx.data().mean.y}};
154+
ctx.get<Goal>(agent)= Goal{.position = Vector3{
155+
.x = agentInit.goalPosition.x - ctx.data().mean.x,
156+
.y = agentInit.goalPosition.y - ctx.data().mean.y,
157+
.z = agentInit.goalPosition.z - ctx.data().mean.z}};
150158
populateExpertTrajectory(ctx, agent, agentInit);
151159

152160
auto isStatic = (ctx.get<Goal>(agent).position - ctx.get<Trajectory>(agent_iface).positions[0]).length() < consts::staticThreshold or agentInit.markAsStatic;
@@ -178,22 +186,24 @@ static inline Entity createAgent(Engine &ctx, const MapObject &agentInit) {
178186
return agent;
179187
}
180188

181-
static Entity makeRoadEdge(Engine &ctx, const MapVector2 &p1,
182-
const MapVector2 &p2, const EntityType &type) {
189+
static Entity makeRoadEdge(Engine &ctx, const MapVector3 &p1,
190+
const MapVector3 &p2, const EntityType &type) {
183191

184192

185193
float x1 = p1.x;
186194
float y1 = p1.y;
195+
float z1 = p1.z;
187196
float x2 = p2.x;
188197
float y2 = p2.y;
198+
float z2 = p2.z;
189199

190-
float z = 1 + (type == EntityType::RoadEdge ? consts::lidarRoadEdgeOffset : consts::lidarRoadLineOffset);
200+
// float z = 1 + (type == EntityType::RoadEdge ? consts::lidarRoadEdgeOffset : consts::lidarRoadLineOffset);
191201

192-
Vector3 start{.x = x1 - ctx.data().mean.x, .y = y1 - ctx.data().mean.y, .z = z};
193-
Vector3 end{.x = x2 - ctx.data().mean.x, .y = y2 - ctx.data().mean.y, .z = z};
202+
Vector3 start{.x = x1 - ctx.data().mean.x, .y = y1 - ctx.data().mean.y, .z = z1};
203+
Vector3 end{.x = x2 - ctx.data().mean.x, .y = y2 - ctx.data().mean.y, .z = z2};
194204
float distance = end.distance(start);
195205
auto road_edge = ctx.makeRenderableEntity<PhysicsEntity>();
196-
ctx.get<Position>(road_edge) = Vector3{.x = (start.x + end.x)/2, .y = (start.y + end.y)/2, .z = z};
206+
ctx.get<Position>(road_edge) = Vector3{.x = (start.x + end.x)/2, .y = (start.y + end.y)/2, .z = (start.z + end.z)/2};
197207
ctx.get<Rotation>(road_edge) = Quat::angleAxis(atan2(end.y - start.y, end.x - start.x), madrona::math::up);
198208
ctx.get<Scale>(road_edge) = Diag3x3{.d0 = distance/2, .d1 = 0.1, .d2 = 0.1};
199209
ctx.get<EntityType>(road_edge) = type;

0 commit comments

Comments
 (0)