Fixed diagonal world coordinates
This commit is contained in:
parent
1c98c75cf9
commit
949412df8a
10 changed files with 57 additions and 26 deletions
|
@ -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)
|
||||
|
|
|
@ -6,8 +6,16 @@
|
|||
// Initialize matrix
|
||||
const Eigen::Matrix<float, 3, 3> CoordinateTransformer::worldToIsometricMatrix =
|
||||
(Eigen::Matrix<float, 3, 3>() <<
|
||||
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<float, 3, 3> CoordinateTransformer::worldToDiagonalMatrix =
|
||||
(Eigen::Matrix<float, 3, 3>() <<
|
||||
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
|
||||
};
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ class CoordinateTransformer
|
|||
{
|
||||
private:
|
||||
static const Eigen::Matrix<float, 3, 3> worldToIsometricMatrix;
|
||||
static const Eigen::Matrix<float, 3, 3> worldToDiagonalMatrix;
|
||||
|
||||
public:
|
||||
static IsometricCoordinates worldToIsometric(WorldCoordinates worldCoordinates);
|
||||
|
|
|
@ -23,9 +23,6 @@ public:
|
|||
private:
|
||||
int collectableId = 0;
|
||||
static inline int collectableCount = 0;
|
||||
|
||||
float angle = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
#include "collectable_sim_ground_segment.hpp"
|
14
src/game/physics/holes/collectable_sim_ground_segment.hpp
Normal file
14
src/game/physics/holes/collectable_sim_ground_segment.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef HOLESOME_COLLECTABLE_SIM_GROUND_SEGMENT_HPP
|
||||
#define HOLESOME_COLLECTABLE_SIM_GROUND_SEGMENT_HPP
|
||||
|
||||
#include <box2d/box2d.h>
|
||||
|
||||
class CollectableSimGroundSegment
|
||||
{
|
||||
public:
|
||||
int leftHoleId;
|
||||
int rightHoleId;
|
||||
b2Body *body;
|
||||
};
|
||||
|
||||
#endif //HOLESOME_COLLECTABLE_SIM_GROUND_SEGMENT_HPP
|
|
@ -55,11 +55,16 @@ std::shared_ptr<Collectable> 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);
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -43,5 +43,5 @@ DepthHoleLayout HoleLayout::atDepth(float depth) const
|
|||
{
|
||||
depthHoles.push_back(hole.atDepth(depth));
|
||||
}
|
||||
return DepthHoleLayout(depth, depthHoles);
|
||||
return {depth, depthHoles};
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
|
||||
void clear();
|
||||
|
||||
DepthHoleLayout atDepth(float depth) const;
|
||||
[[nodiscard]] DepthHoleLayout atDepth(float depth) const;
|
||||
|
||||
private:
|
||||
static inline std::shared_ptr<HoleLayout> singletonInstance = nullptr;
|
||||
|
|
Loading…
Reference in a new issue