diff options
author | nathan <nathansmith@disroot.org> | 2025-07-05 14:06:37 +0000 |
---|---|---|
committer | nathan <nathansmith@disroot.org> | 2025-07-05 14:06:37 +0000 |
commit | 025655dcf21ec40f1730097d3614114c704f5a17 (patch) | |
tree | 54868a60c38fd29fcc4e9c0c51b26c817e5ab3fe | |
parent | a5b8ea449bbb6fe30a6bf27843eab1df6a21ccef (diff) | |
download | FindThings-025655dcf21ec40f1730097d3614114c704f5a17.tar.gz FindThings-025655dcf21ec40f1730097d3614114c704f5a17.tar.bz2 FindThings-025655dcf21ec40f1730097d3614114c704f5a17.zip |
Playing around with concepts
-rw-r--r-- | assets/heightmap.png | bin | 111957 -> 107055 bytes | |||
-rw-r--r-- | src/game.c | 2 | ||||
-rw-r--r-- | src/player.c | 39 |
3 files changed, 26 insertions, 15 deletions
diff --git a/assets/heightmap.png b/assets/heightmap.png Binary files differindex 76a2ea0..b9a1b69 100644 --- a/assets/heightmap.png +++ b/assets/heightmap.png @@ -22,7 +22,7 @@ void initGame(Game* game) // Heightmap. Mesh heightmapMesh = GenMeshHeightmap(game->assets.images[HEIGHT_MAP_IMAGE], - (Vector3){100.0, 30.0, 100.0}); + (Vector3){1000.0, 30.0, 1000.0}); game->heightmap = LoadModelFromMesh(heightmapMesh); game->heightmap.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = game->assets.textures[HEIGHT_MAP_TEXTURE]; diff --git a/src/player.c b/src/player.c index 880aa34..18d18bc 100644 --- a/src/player.c +++ b/src/player.c @@ -18,24 +18,35 @@ Player createPlayer() }; } +// TODO: clean this all up +float getHeightOnMap(int x, int y, Model* map) +{ + int v = (y * 1023 + x) * 18; + float height = 0.0; + float c = 0.0; + + for (int n = 1; n < 18; n += 3) + { + height += map->meshes[0].vertices[v + n]; + ++c; + } + + return height / c; +} + // TODO: subpixel hackery -void readoutMapHeight(Player* player, Game* game) +// This is only for testing ideas. +void idkkk(Player* player, Game* game) { Vector3 position = player->position; Image* map = &game->assets.images[HEIGHT_MAP_IMAGE]; - // Map player position to height map pixel. - int pixelX = (int)roundf(position.x) * (map->width / 100); - int pixelY = (int)roundf(position.z) * (map->height / 100); - pixelX = Clamp(pixelX, 0, map->width); - pixelY = Clamp(pixelY, 0, map->height); - - Color color = game->heightmapColors[pixelY * map->width + pixelX]; - float height = Vector3Length((Vector3){color.r, color.g, color.b}) - * (30.0 / 255.0) - 15.0; + float toMapX = map->width / 1000.0; + float toMapY = map->height / 1000.0; + int pixelX = roundf(position.x * toMapX); + int pixelY = roundf(position.z * toMapY); - printf("%f\n", height); - player->position.y = height + 1.0; + player->position.y = getHeightOnMap(pixelX, pixelY, &game->heightmap) + 2.0; } // TODO: move magic numbers to settings @@ -83,7 +94,7 @@ void updatePlayer(Player* player, Game* game) player->velocity.x += -sinf(cameraAngle->x + (PI / 2.0)); } - player->velocity = Vector3Scale(player->velocity, 5.0); + player->velocity = Vector3Scale(player->velocity, 10.0); // Apply velocity player->position = Vector3Add( @@ -93,5 +104,5 @@ void updatePlayer(Player* player, Game* game) camera->position = player->position; camera->target = Vector3Add(player->position, player->direction); - readoutMapHeight(player, game); + idkkk(player, game); } |