diff --git a/CMakeLists.txt b/CMakeLists.txt index fec1ebb..32b424a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,7 +121,7 @@ set(SOURCES src/game/physics/holes/layouts/hole_layout.cpp src/game/physics/holes/layouts/hole_layout.hpp src/game/physics/holes/layouts/depth_hole_layout.hpp - src/game/physics/holes/layouts/depth_hole_description.hpp) + src/game/physics/holes/layouts/depth_hole_description.hpp src/game/physics/holes/collectable_sim_ground_segment.hpp src/game/physics/holes/collectable_sim_ground_segment.cpp) set(PHYSICS_00_SOURCES src/prototypes/physics_00.cpp) diff --git a/src/coordinates/coordinate_transformer.cpp b/src/coordinates/coordinate_transformer.cpp index 887a706..aac5248 100644 --- a/src/coordinates/coordinate_transformer.cpp +++ b/src/coordinates/coordinate_transformer.cpp @@ -6,8 +6,16 @@ // Initialize matrix const Eigen::Matrix CoordinateTransformer::worldToIsometricMatrix = (Eigen::Matrix() << - 1, -1, 0, - -ISOMETRIC_SKEW, -ISOMETRIC_SKEW, -1, + WORLD_TO_ISO_SCALE, -WORLD_TO_ISO_SCALE, 0, + -ISOMETRIC_SKEW * WORLD_TO_ISO_SCALE, -ISOMETRIC_SKEW * WORLD_TO_ISO_SCALE, -WORLD_TO_ISO_SCALE, + 1, 1, 0 + ).finished(); + +// Same as above, but with SKEW = 0 and height positive +const Eigen::Matrix CoordinateTransformer::worldToDiagonalMatrix = + (Eigen::Matrix() << + WORLD_TO_ISO_SCALE, -WORLD_TO_ISO_SCALE, 0, + 0, 0, 1, 1, 1, 0 ).finished(); @@ -19,8 +27,8 @@ IsometricCoordinates CoordinateTransformer::worldToIsometric(WorldCoordinates wo Eigen::Vector3f isoCoordinatesVector = worldToIsometricMatrix * worldCoordinatesVector; return { - isoCoordinatesVector.x() * WORLD_TO_ISO_SCALE, // x - isoCoordinatesVector.y() * WORLD_TO_ISO_SCALE, // y + isoCoordinatesVector.x(), // x + isoCoordinatesVector.y(), // y isoCoordinatesVector.z() // depth }; } @@ -28,8 +36,8 @@ IsometricCoordinates CoordinateTransformer::worldToIsometric(WorldCoordinates wo WorldCoordinates CoordinateTransformer::isometricToWorld(IsometricCoordinates isometricCoordinates) { Eigen::Vector3f isoCoordinatesVector; - isoCoordinatesVector << isometricCoordinates.x / WORLD_TO_ISO_SCALE, - isometricCoordinates.y / WORLD_TO_ISO_SCALE, + isoCoordinatesVector << isometricCoordinates.x, + isometricCoordinates.y, isometricCoordinates.depth; Eigen::Vector3f worldCoordinatesVector = worldToIsometricMatrix.inverse() * isoCoordinatesVector; @@ -56,25 +64,30 @@ sf::Vector2f CoordinateTransformer::closestWorldPointAtDepth(float depth, sf::Ve DiagonalWorldCoordinates CoordinateTransformer::worldToDiagonal(WorldCoordinates worldCoordinates) { - auto depth = CoordinateTransformer::worldToDepth(worldCoordinates.toGroundCoordinates()); + Eigen::Vector3f worldCoordinatesVector; + worldCoordinatesVector << worldCoordinates.x, worldCoordinates.y, worldCoordinates.z; - auto depthCenterCoordinates = CoordinateTransformer::closestWorldPointAtDepth(depth, {0, 0}); - auto horizontal = length(worldCoordinates.toGroundCoordinates() - depthCenterCoordinates); + Eigen::Vector3f diagonalCoordinateVector = worldToDiagonalMatrix * worldCoordinatesVector; - return {horizontal, worldCoordinates.z, depth}; + return { + diagonalCoordinateVector.x(), // horizontal + diagonalCoordinateVector.y(), // vertical + diagonalCoordinateVector.z() // depth + }; } WorldCoordinates CoordinateTransformer::diagonalToWorld(DiagonalWorldCoordinates diagonalWorldCoordinates) { - auto depthCenterCoordinates = CoordinateTransformer::closestWorldPointAtDepth(diagonalWorldCoordinates.depth, - {0, 0}); + Eigen::Vector3f diagonalCoordinateVector; + diagonalCoordinateVector << diagonalWorldCoordinates.horizontal, + diagonalWorldCoordinates.vertical, + diagonalWorldCoordinates.depth; - auto const horizontalAxis = sf::Vector2f(1, -1); - auto worldGroundCoordinates = depthCenterCoordinates + horizontalAxis * diagonalWorldCoordinates.horizontal; + Eigen::Vector3f worldCoordinatesVector = worldToDiagonalMatrix.inverse() * diagonalCoordinateVector; return { - worldGroundCoordinates.x, - worldGroundCoordinates.y, - diagonalWorldCoordinates.vertical + worldCoordinatesVector.x(), // x + worldCoordinatesVector.y(), // y + worldCoordinatesVector.z() // z }; } diff --git a/src/coordinates/coordinate_transformer.h b/src/coordinates/coordinate_transformer.h index 35508a6..487d58b 100644 --- a/src/coordinates/coordinate_transformer.h +++ b/src/coordinates/coordinate_transformer.h @@ -8,6 +8,7 @@ class CoordinateTransformer { private: static const Eigen::Matrix worldToIsometricMatrix; + static const Eigen::Matrix worldToDiagonalMatrix; public: static IsometricCoordinates worldToIsometric(WorldCoordinates worldCoordinates); diff --git a/src/game/collectables/collectable.hpp b/src/game/collectables/collectable.hpp index c9cf27b..98e6d10 100644 --- a/src/game/collectables/collectable.hpp +++ b/src/game/collectables/collectable.hpp @@ -23,9 +23,6 @@ public: private: int collectableId = 0; static inline int collectableCount = 0; - - float angle = 0; - }; diff --git a/src/game/physics/holes/collectable_sim_ground_segment.cpp b/src/game/physics/holes/collectable_sim_ground_segment.cpp new file mode 100644 index 0000000..91fbc67 --- /dev/null +++ b/src/game/physics/holes/collectable_sim_ground_segment.cpp @@ -0,0 +1 @@ +#include "collectable_sim_ground_segment.hpp" \ No newline at end of file diff --git a/src/game/physics/holes/collectable_sim_ground_segment.hpp b/src/game/physics/holes/collectable_sim_ground_segment.hpp new file mode 100644 index 0000000..39d5347 --- /dev/null +++ b/src/game/physics/holes/collectable_sim_ground_segment.hpp @@ -0,0 +1,14 @@ +#ifndef HOLESOME_COLLECTABLE_SIM_GROUND_SEGMENT_HPP +#define HOLESOME_COLLECTABLE_SIM_GROUND_SEGMENT_HPP + +#include + +class CollectableSimGroundSegment +{ +public: + int leftHoleId; + int rightHoleId; + b2Body *body; +}; + +#endif //HOLESOME_COLLECTABLE_SIM_GROUND_SEGMENT_HPP diff --git a/src/game/physics/holes/collectable_simulation.cpp b/src/game/physics/holes/collectable_simulation.cpp index 46ed060..127d565 100644 --- a/src/game/physics/holes/collectable_simulation.cpp +++ b/src/game/physics/holes/collectable_simulation.cpp @@ -55,11 +55,16 @@ std::shared_ptr CollectableSimulation::getCollectable() const void CollectableSimulation::updateGroundHole() { auto holeLayout = HoleLayout::getInstance()->atDepth(collectable->getDepth()); + + } void CollectableSimulation::updateCollectable() { auto bodyPosition = body->GetPosition(); collectable->coordinates->setDiagonal({bodyPosition.x, bodyPosition.y, collectable->getDepth()}); - collectable->setRotation(body->GetAngle()); + + // Convert radians to degrees + float angle = body->GetAngle() * 180 / M_PI; + collectable->setRotation(angle); } diff --git a/src/game/physics/holes/layouts/hole_description.hpp b/src/game/physics/holes/layouts/hole_description.hpp index fdbaa0e..62c550d 100644 --- a/src/game/physics/holes/layouts/hole_description.hpp +++ b/src/game/physics/holes/layouts/hole_description.hpp @@ -29,12 +29,12 @@ struct HoleDescription if (distance > radius) { // No hole at this depth - return DepthHoleDescription(playerId, 0.f, 0.f); + return {playerId, 0.f, 0.f}; } float chordLength = 2.f * std::sqrt(radius * radius - distance * distance); - return DepthHoleDescription(playerId, closestPointAtDepth.x, chordLength); + return {playerId, closestPointAtDepth.x, chordLength}; } }; diff --git a/src/game/physics/holes/layouts/hole_layout.cpp b/src/game/physics/holes/layouts/hole_layout.cpp index 3091621..cca3625 100644 --- a/src/game/physics/holes/layouts/hole_layout.cpp +++ b/src/game/physics/holes/layouts/hole_layout.cpp @@ -43,5 +43,5 @@ DepthHoleLayout HoleLayout::atDepth(float depth) const { depthHoles.push_back(hole.atDepth(depth)); } - return DepthHoleLayout(depth, depthHoles); + return {depth, depthHoles}; } diff --git a/src/game/physics/holes/layouts/hole_layout.hpp b/src/game/physics/holes/layouts/hole_layout.hpp index 450b09c..0d55f97 100644 --- a/src/game/physics/holes/layouts/hole_layout.hpp +++ b/src/game/physics/holes/layouts/hole_layout.hpp @@ -18,7 +18,7 @@ public: void clear(); - DepthHoleLayout atDepth(float depth) const; + [[nodiscard]] DepthHoleLayout atDepth(float depth) const; private: static inline std::shared_ptr singletonInstance = nullptr;