diff options
author | nathan <nathansmith@disroot.org> | 2025-08-17 20:13:07 +0000 |
---|---|---|
committer | nathan <nathansmith@disroot.org> | 2025-08-17 20:13:07 +0000 |
commit | a53fddc7cb1f095145344c8781c0bea82c46babb (patch) | |
tree | ec345c30233d1cc5d9948387ea0fc92655e25919 /src | |
parent | ca95e9feead55e38c1078a09c3525549681ca0eb (diff) | |
download | FindThings-a53fddc7cb1f095145344c8781c0bea82c46babb.tar.gz FindThings-a53fddc7cb1f095145344c8781c0bea82c46babb.tar.bz2 FindThings-a53fddc7cb1f095145344c8781c0bea82c46babb.zip |
Poles face which other now
Diffstat (limited to 'src')
-rw-r--r-- | src/world.c | 42 | ||||
-rw-r--r-- | src/world.h | 2 |
2 files changed, 36 insertions, 8 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; diff --git a/src/world.h b/src/world.h index 8cfa91f..97311a1 100644 --- a/src/world.h +++ b/src/world.h @@ -7,7 +7,7 @@ #define WORLD_ENTITY_MAX 5000 #define WORLD_PLANT_COUNT 2500 -#define WORLD_UTILITY_POLE_COUNT 50 +#define WORLD_UTILITY_POLE_COUNT 25 #define WORLD_PLACE_COUNT 1 #define WORLD_SIZE (Vector3){4096.0, 256.0, 4096.0} |