From e9a3fdc1037b7643cf1da9e080f447b4d4daae4c Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 18 Aug 2025 03:09:14 -0600 Subject: headaches --- src/world.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/world.h | 8 ++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/world.c b/src/world.c index fa676c8..19c2354 100644 --- a/src/world.c +++ b/src/world.c @@ -489,6 +489,19 @@ Vector3 utilityPoleIndexToPosition(int index, const World* world) return position; } +// TODO: make the thing work +void getUtilityPoleLinePositions(Vector3 position, + Vector3 output[UTILITY_LINE_COUNT]) +{ + Vector3 positions[UTILITY_LINE_COUNT] = { + (Vector3){40.4336, -4.18579, 98.288}, + (Vector3){40.4336, -4.18579, 82.729}, + (Vector3){-40.4335, -4.18579, 98.288}, + (Vector3){-40.4336, -4.18579, 82.729} + }; +} + +// TODO: UGGGGG HEADACHES. THIS IS SIMPLE BUT HEADACHES MAKE THINGS HARD. Seed generateWorldUtilityPoles(World* world, const Assets* assets, Seed seed, int start, int end) { @@ -496,6 +509,13 @@ 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; + + Vector3 linePositions[UTILITY_LINE_COUNT] = { + (Vector3){40.4336, -4.18579, 98.288}, + (Vector3){40.4336, -4.18579, 82.729}, + (Vector3){-40.4335, -4.18579, 98.288}, + (Vector3){-40.4336, -4.18579, 82.729} + }; for (int index = start; index < end; ++index) { @@ -513,8 +533,9 @@ Seed generateWorldUtilityPoles(World* world, const Assets* assets, Seed seed, 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))); + Quaternion rotation = QuaternionFromMatrix(MatrixInvert(lookat)); + // Hack for it to not effect position. Luckily this isn't in a update look. + lookat = QuaternionToMatrix(rotation); // Add pole to instancing data. Matrix translation = MatrixTranslate(entity.position.x, @@ -522,11 +543,43 @@ Seed generateWorldUtilityPoles(World* world, const Assets* assets, Seed seed, entity.position.z); Matrix matrix = MatrixMultiply(lookat, translation); world->utilityPoleTransforms[index - start] = matrix; + + // Get next position height for use of line creation. + nextPosition.y = getWorldHeightAtLocation(world, nextPosition.x, + nextPosition.z); + + // Create lines. + UtilityPoleLines lines; + + for (int lineIndex = 0; lineIndex < UTILITY_LINE_COUNT; ++lineIndex) + { + Vector3 linePosition = Vector3RotateByQuaternion( + linePositions[lineIndex], rotation); + + lines[lineIndex].start = Vector3Add(entity.position, linePosition); + lines[lineIndex].end = Vector3Add(nextPosition, linePosition); + } + + memcpy(&world->utilityPoleLines[index - start], &lines, + sizeof(UtilityPoleLines)); } return seed; } +void drawUtilityPoleLines(const World* world) +{ + for (int index = 0; index < WORLD_UTILITY_POLE_COUNT; ++index) + { + for (int innerIndex = 0; innerIndex < UTILITY_LINE_COUNT; ++innerIndex) + { + DrawLine3D(world->utilityPoleLines[index][innerIndex].start, + world->utilityPoleLines[index][innerIndex].end, + BLACK); + } + } +} + Seed generateWorldItems(World* world, Seed seed, int start, int end) { for (int index = start; index < end; ++index) @@ -658,6 +711,7 @@ void updateWorld(World* world, Game* game) game->assets.models[UTILITY_POLE_MODEL].materials[0], world->utilityPoleTransforms, WORLD_UTILITY_POLE_COUNT); + drawUtilityPoleLines(world); // Draw BVH leafs. #ifdef FT_DEBUG_MODE diff --git a/src/world.h b/src/world.h index 97311a1..f232333 100644 --- a/src/world.h +++ b/src/world.h @@ -48,6 +48,13 @@ typedef struct BVHNode { int8_t branchCount; } BVHNode; +#define UTILITY_LINE_COUNT 4 + +typedef struct { + Vector3 start; + Vector3 end; +} UtilityPoleLines[UTILITY_LINE_COUNT]; + struct World { Vector3 size; Texture heightmapTexture; @@ -59,6 +66,7 @@ struct World { // Transforms for mesh instancing. Matrix utilityPoleTransforms[WORLD_UTILITY_POLE_COUNT]; + UtilityPoleLines utilityPoleLines[WORLD_UTILITY_POLE_COUNT]; int bvhDebugSelect; }; -- cgit v1.2.3