diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game.c | 2 | ||||
-rw-r--r-- | src/player.c | 39 |
2 files changed, 26 insertions, 15 deletions
@@ -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); } |