From 025655dcf21ec40f1730097d3614114c704f5a17 Mon Sep 17 00:00:00 2001 From: nathan Date: Sat, 5 Jul 2025 08:06:37 -0600 Subject: Playing around with concepts --- src/player.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'src/player.c') 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); } -- cgit v1.2.3