aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-08-19 06:35:08 +0000
committernathan <nathansmith@disroot.org>2025-08-19 06:35:08 +0000
commit3c47ac22527d509fdf4fd68fedb26c2a738758d8 (patch)
tree6d128dbf29795979e3fdea515211179028a5c859
parente9a3fdc1037b7643cf1da9e080f447b4d4daae4c (diff)
downloadFindThings-3c47ac22527d509fdf4fd68fedb26c2a738758d8.tar.gz
FindThings-3c47ac22527d509fdf4fd68fedb26c2a738758d8.tar.bz2
FindThings-3c47ac22527d509fdf4fd68fedb26c2a738758d8.zip
Utility pole lines working
-rw-r--r--design.org4
-rw-r--r--src/world.c75
-rw-r--r--src/world.h2
3 files changed, 41 insertions, 40 deletions
diff --git a/design.org b/design.org
index a28699e..bc1c888 100644
--- a/design.org
+++ b/design.org
@@ -94,13 +94,13 @@ creates is possible to beat. A little wack is fine as long as its
beatable. Since most of the world will just be a height map a image will be
generated first than rest of the world will be based around it.
-* TODO World generation check list [5/8]
+* TODO World generation check list [6/8]
+ [X] Basic terrain
+ [X] Ground texture
+ [X] Trees/plants
+ [X] Sky
+ [X] Pond
-+ [ ] Power lines
++ [X] Power lines
+ [ ] Buildings
+ [ ] Roads
diff --git a/src/world.c b/src/world.c
index 19c2354..0217fd7 100644
--- a/src/world.c
+++ b/src/world.c
@@ -489,19 +489,41 @@ Vector3 utilityPoleIndexToPosition(int index, const World* world)
return position;
}
-// TODO: make the thing work
-void getUtilityPoleLinePositions(Vector3 position,
- Vector3 output[UTILITY_LINE_COUNT])
+void generateWorldUtilityPoleLines(
+ World* world, Quaternion rotations[WORLD_UTILITY_POLE_COUNT],
+ int start, int end)
{
- 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}
+ Vector3 linePositions[UTILITY_LINE_COUNT] = {
+ (Vector3){40.4336, 98.288, -4.18579},
+ (Vector3){40.4336, 82.729, -4.18579},
+ (Vector3){-40.4336, 98.288, -4.18579},
+ (Vector3){-40.4336, 82.729, -4.18579}
};
+
+ for (int index = start; index < end - 1; ++index)
+ {
+ Vector3 position = world->entities[index].position;
+ Vector3 nextPosition = world->entities[index + 1].position;
+ UtilityPoleLines lines;
+
+ for (int lineIndex = 0; lineIndex < UTILITY_LINE_COUNT; ++lineIndex)
+ {
+ // Line start.
+ Vector3 linePosition = Vector3RotateByQuaternion(
+ linePositions[lineIndex], rotations[index - start]);
+ lines[lineIndex].start = Vector3Add(linePosition, position);
+
+ // Line end.
+ linePosition = Vector3RotateByQuaternion(
+ linePositions[lineIndex], rotations[index - start + 1]);
+ lines[lineIndex].end = Vector3Add(linePosition, nextPosition);
+ }
+
+ memcpy(&world->utilityPoleLines[index - start], &lines,
+ sizeof(UtilityPoleLines));
+ }
}
-// TODO: UGGGGG HEADACHES. THIS IS SIMPLE BUT HEADACHES MAKE THINGS HARD.
Seed generateWorldUtilityPoles(World* world, const Assets* assets, Seed seed,
int start, int end)
{
@@ -510,12 +532,7 @@ Seed generateWorldUtilityPoles(World* world, const Assets* assets, Seed seed,
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}
- };
+ Quaternion poleRotations[WORLD_UTILITY_POLE_COUNT];
for (int index = start; index < end; ++index)
{
@@ -534,7 +551,8 @@ Seed generateWorldUtilityPoles(World* world, const Assets* assets, Seed seed,
Matrix lookat = MatrixLookAt(position, nextPosition,
(Vector3){0.0, 1.0, 0.0});
Quaternion rotation = QuaternionFromMatrix(MatrixInvert(lookat));
- // Hack for it to not effect position. Luckily this isn't in a update look.
+ poleRotations[index - start] = rotation;
+ // Hack for it to not effect position. Luckily this isn't in a update loop.
lookat = QuaternionToMatrix(rotation);
// Add pole to instancing data.
@@ -542,34 +560,17 @@ Seed generateWorldUtilityPoles(World* world, const Assets* assets, Seed seed,
entity.position.y,
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));
+ world->utilityPoleTransforms[index - start] = matrix;
}
+ generateWorldUtilityPoleLines(world, poleRotations, start, end);
+
return seed;
}
void drawUtilityPoleLines(const World* world)
{
- for (int index = 0; index < WORLD_UTILITY_POLE_COUNT; ++index)
+ for (int index = 0; index < WORLD_UTILITY_POLE_COUNT - 1; ++index)
{
for (int innerIndex = 0; innerIndex < UTILITY_LINE_COUNT; ++innerIndex)
{
diff --git a/src/world.h b/src/world.h
index f232333..0cdaf30 100644
--- a/src/world.h
+++ b/src/world.h
@@ -66,7 +66,7 @@ struct World {
// Transforms for mesh instancing.
Matrix utilityPoleTransforms[WORLD_UTILITY_POLE_COUNT];
- UtilityPoleLines utilityPoleLines[WORLD_UTILITY_POLE_COUNT];
+ UtilityPoleLines utilityPoleLines[WORLD_UTILITY_POLE_COUNT - 1];
int bvhDebugSelect;
};