aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/world.c b/src/world.c
index 2130468..fa676c8 100644
--- a/src/world.c
+++ b/src/world.c
@@ -473,6 +473,22 @@ Seed generateWorldPlants(World* world, Seed seed, int start, int end)
return seed;
}
+// Use sin wave for computing pole positions.
+// Does not set y position.
+// Index as in World.utilityPoleTransforms index.
+Vector3 utilityPoleIndexToPosition(int index, const World* world)
+{
+ float centerZ = (float)world->size.z / 2.0;
+ float spacing = (float)world->size.x / WORLD_UTILITY_POLE_COUNT;
+
+ Vector3 position;
+ position.x = index * spacing;
+ position.y = 0.0;
+ position.z = sinf(position.x) * centerZ + centerZ;
+
+ return position;
+}
+
Seed generateWorldUtilityPoles(World* world, const Assets* assets, Seed seed,
int start, int end)
{
@@ -480,20 +496,32 @@ Seed generateWorldUtilityPoles(World* world, const Assets* assets, Seed seed,
assets->shaders[INSTANCING_SHADER];
assets->models[UTILITY_POLE_MODEL].materials[0]
.maps[MATERIAL_MAP_DIFFUSE].color = BROWN;
-
- float centerZ = world->size.z / 2.0;
- float spacing = (float)world->size.x / WORLD_UTILITY_POLE_COUNT;
for (int index = start; index < end; ++index)
{
FT_RANDOM16(seed);
- Entity entity = createEntity(UTILITY_POLE, Vector3Zero());
- seed = putEntityInRandomPlace(world, seed, &entity);
+ Vector3 position = utilityPoleIndexToPosition(index - start, world);
+
+ // Create pole.
+ Entity entity = createEntity(UTILITY_POLE, position);
+ placeEntityOnGround(&entity, world);
world->entities[index] = entity;
- world->utilityPoleTransforms[index - start] = MatrixTranslate(
- entity.position.x, entity.position.y, entity.position.z);
+ // Get direction to next pole.
+ Vector3 nextPosition = utilityPoleIndexToPosition(index - start + 1,
+ world);
+ Matrix lookat = MatrixLookAt(position, nextPosition,
+ (Vector3){0.0, 1.0, 0.0});
+ // Hack for it to not effect position. Likely this isn't in a update look.
+ lookat = QuaternionToMatrix(QuaternionFromMatrix(MatrixInvert(lookat)));
+
+ // Add pole to instancing data.
+ Matrix translation = MatrixTranslate(entity.position.x,
+ entity.position.y,
+ entity.position.z);
+ Matrix matrix = MatrixMultiply(lookat, translation);
+ world->utilityPoleTransforms[index - start] = matrix;
}
return seed;