Skip to content

Commit d1a1b46

Browse files
yet another partial change
1 parent 4f48cfa commit d1a1b46

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/level_gen.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ static Entity makeRoadEdge(Engine &ctx, const MapRoad &roadInit, CountT j) {
171171
return road_edge;
172172
}
173173

174-
float calculateDistance(float x1, float y1, float x2, float y2) {
175-
return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
174+
float calculateDistance(float x1, float y1, float z1, float x2, float y2, float z2) {
175+
return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) + pow(z2 - z1, 2));
176176
}
177177

178178
static Entity makeCube(Engine &ctx, const MapRoad &roadInit) {
179179

180-
MapVector2 points[] = {
180+
MapVector3 points[] = {
181181
roadInit.geometry[0],
182182
roadInit.geometry[1],
183183
roadInit.geometry[2],
@@ -188,9 +188,9 @@ static Entity makeCube(Engine &ctx, const MapRoad &roadInit) {
188188
float lengths[4];
189189
for (int i = 0; i < 4; ++i)
190190
{
191-
MapVector2 &p_start = points[i];
192-
MapVector2 &p_end = points[(i + 1) % 4]; // Wrap around to the first point
193-
lengths[i] = calculateDistance(p_start.x, p_start.y, p_end.x, p_end.y);
191+
MapVector3 &p_start = points[i];
192+
MapVector3 &p_end = points[(i + 1) % 4]; // Wrap around to the first point
193+
lengths[i] = calculateDistance(p_start.x, p_start.y, p_start.z, p_end.x, p_end.y, p_end.z);
194194
}
195195

196196
int maxLength_i = 0;
@@ -202,8 +202,8 @@ static Entity makeCube(Engine &ctx, const MapRoad &roadInit) {
202202
minLength_i = i;
203203
}
204204

205-
MapVector2 &start = points[maxLength_i];
206-
MapVector2 &end = points[(maxLength_i + 1) % 4];
205+
MapVector3 &start = points[maxLength_i];
206+
MapVector3 &end = points[(maxLength_i + 1) % 4];
207207

208208
// Calculate rotation angle (assuming longer side is used to calculate angle)
209209
float angle = atan2(end.y - start.y, end.x - start.x);
@@ -213,13 +213,15 @@ static Entity makeCube(Engine &ctx, const MapRoad &roadInit) {
213213

214214
float sum_x = 0.0f;
215215
float sum_y = 0.0f;
216+
float sum_z = 0.0f;
216217

217218
for (const auto& point : points) {
218219
sum_x += point.x;
219220
sum_y += point.y;
221+
sum_z += point.z;
220222
}
221223

222-
auto pos = Vector3{.x = sum_x/4 - ctx.singleton<WorldMeans>().mean.x, .y = sum_y/4 - ctx.singleton<WorldMeans>().mean.y, .z = 1 + consts::lidarRoadLineOffset};
224+
auto pos = Vector3{.x = sum_x/4 - ctx.singleton<WorldMeans>().mean.x, .y = sum_y/4 - ctx.singleton<WorldMeans>().mean.y, .z = sum_z/4 - ctx.singleton<WorldMeans>().mean.z};
223225
auto rot = Quat::angleAxis(angle, madrona::math::up);
224226
auto scale = Diag3x3{.d0 = lengths[maxLength_i]/2, .d1 = lengths[minLength_i]/2, .d2 = 0.1};
225227
setRoadEntitiesProps(ctx, speed_bump, pos, rot, scale, roadInit.type, ObjectID{(int32_t)SimObject::SpeedBump}, ResponseType::Static, roadInit.id, roadInit.mapType);
@@ -230,11 +232,12 @@ static Entity makeCube(Engine &ctx, const MapRoad &roadInit) {
230232
static Entity makeStopSign(Engine &ctx, const MapRoad &roadInit) {
231233
float x1 = roadInit.geometry[0].x;
232234
float y1 = roadInit.geometry[0].y;
235+
float z1 = roadInit.geometry[0].z;
233236

234237
auto stop_sign = ctx.makeRenderableEntity<PhysicsEntity>();
235238
ctx.get<RoadInterfaceEntity>(stop_sign).e = ctx.makeEntity<RoadInterface>();
236239

237-
auto pos = Vector3{.x = x1 - ctx.singleton<WorldMeans>().mean.x, .y = y1 - ctx.singleton<WorldMeans>().mean.y, .z = 1};
240+
auto pos = Vector3{.x = x1 - ctx.singleton<WorldMeans>().mean.x, .y = y1 - ctx.singleton<WorldMeans>().mean.y, .z = z1 - ctx.singleton<WorldMeans>().mean.z};
238241
auto rot = Quat::angleAxis(0, madrona::math::up);
239242
auto scale = Diag3x3{.d0 = 0.2, .d1 = 0.2, .d2 = 1};
240243
setRoadEntitiesProps(ctx, stop_sign, pos, rot, scale, EntityType::StopSign, ObjectID{(int32_t)SimObject::StopSign}, ResponseType::Static, roadInit.id, roadInit.mapType);

0 commit comments

Comments
 (0)