From 648548693dc06793cbd7bf8f74886dde2de07806 Mon Sep 17 00:00:00 2001 From: trotFunky Date: Mon, 4 Nov 2019 03:28:35 +0100 Subject: [PATCH] Cleaned static variables now part of the maze --- src/MovementManager.cpp | 4 ++-- src/MovementManager.h | 4 ++-- src/main.cpp | 14 ++++++-------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/MovementManager.cpp b/src/MovementManager.cpp index 1a36394..f727397 100644 --- a/src/MovementManager.cpp +++ b/src/MovementManager.cpp @@ -4,7 +4,7 @@ #include "MovementManager.h" -Vec3i current_map_colour(const Vec3d& world_pos, const Texture& texture, const int& pixel_scale) +Vec3i current_map_colour(const Vec3d& world_pos, const Texture& texture, const unsigned int& pixel_scale) { Vec2i map_pos{static_cast(world_pos.x/pixel_scale), static_cast(world_pos.z/pixel_scale)}; @@ -16,7 +16,7 @@ Vec3i current_map_colour(const Vec3d& world_pos, const Texture& texture, const i texture.image_data[data_index+2]}; } -void constrained_translation(const Vec3d& translation, Camera& camera, const Texture& map, const int& pixel_scale) +void constrained_translation(const Vec3d& translation, Camera& camera, const Texture& map, const unsigned int& pixel_scale) { Vec3d original_position = camera.get_eyepos(); diff --git a/src/MovementManager.h b/src/MovementManager.h index f4c5b77..23893a2 100644 --- a/src/MovementManager.h +++ b/src/MovementManager.h @@ -12,10 +12,10 @@ #include "TileTypes.h" /// Returns the colour of the pixel corresponding to the current world position, assuming the map starts at (0,0). -Vec3i current_map_colour(const Vec3d& world_pos, const Texture& texture, const int& pixel_scale); +Vec3i current_map_colour(const Vec3d& world_pos, const Texture& texture, const unsigned int& pixel_scale); /// Translates the camera inside the maze and check for collisions /// \param translation Translation that will be executed in the horizontal plane, x forward, z strafe. -void constrained_translation(const Vec3d& translation, Camera& camera, const Texture& map, const int& pixel_scale); +void constrained_translation(const Vec3d& translation, Camera& camera, const Texture& map, const unsigned int& pixel_scale); #endif //LABYRINTHE_MOVEMENTMANAGER_H diff --git a/src/main.cpp b/src/main.cpp index 7249555..993797a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,8 +8,6 @@ #include "TileTypes.h" #include "Maze.h" -static int score = 0; - static Texture ground; static Texture wall; static Texture out; @@ -19,9 +17,7 @@ static Model3D raptor_model; static Maze* maze; static constexpr float horizontal_speed = 0.15; -static constexpr int units_per_pixel = 2; -static constexpr int map_side = 32; -static constexpr int corner_pos = (map_side*units_per_pixel); +static int score = 0; void manage_inputs() { @@ -51,9 +47,9 @@ void manage_inputs() translation.x -= horizontal_speed; } - constrained_translation(translation,OGLE::camera,maze->map,units_per_pixel); + constrained_translation(translation,OGLE::camera,maze->map,maze->scaling_factor); - Vec3i map_colour = current_map_colour(OGLE::camera.get_eyepos(),maze->map, units_per_pixel); + Vec3i map_colour = current_map_colour(OGLE::camera.get_eyepos(),maze->map, maze->scaling_factor); if (map_colour == Tiles::end) { std::cout << "Success !" << std::endl; @@ -99,9 +95,11 @@ int main(int argc, char** argv) raptor_model.set_scaling(0.0025,0.0025,0.0025); raptor_model.set_rotation(-90,1,0,0); - OGLE::camera.set_position({corner_pos/2,1,corner_pos/2}); maze = new Maze("resources/Map.tga", 2, ground, wall, out, raptor_model); + OGLE::camera.set_position({static_cast(maze->map.width*maze->scaling_factor/2.0), + 1, + static_cast(maze->map.width*maze->scaling_factor/2.0)}); // Fill colour is sky blue. glClearColor(0.53,0.81,0.75,1);