Fixed occlusion
This commit is contained in:
parent
c49d937e20
commit
364f4c6423
5 changed files with 21 additions and 2 deletions
|
@ -32,6 +32,7 @@
|
||||||
#define MOVEMENT_SKEW sf::Vector2f(1.f, 1/ISOMETRIC_SKEW/2.f)
|
#define MOVEMENT_SKEW sf::Vector2f(1.f, 1/ISOMETRIC_SKEW/2.f)
|
||||||
#define WORLD_TO_ISO_SCALE 50.0f // 50.f, don't change. Rather adjust the zoom of the camera
|
#define WORLD_TO_ISO_SCALE 50.0f // 50.f, don't change. Rather adjust the zoom of the camera
|
||||||
#define MASKED_HOLE_BORDER_TRANSITION_SIZE 0.2f
|
#define MASKED_HOLE_BORDER_TRANSITION_SIZE 0.2f
|
||||||
|
#define MASKED_HOLE_DARKNESS_LIMIT 0.5f
|
||||||
|
|
||||||
// Tracking view defaults
|
// Tracking view defaults
|
||||||
#define DEF_TV_IS_ABSOLUTE_FREE_MOVE_THRESHOLD false
|
#define DEF_TV_IS_ABSOLUTE_FREE_MOVE_THRESHOLD false
|
||||||
|
|
|
@ -109,3 +109,8 @@ void TranslatedCoordinates::removeParent()
|
||||||
// this->worldCoordinates = globalWorldCoordinates;
|
// this->worldCoordinates = globalWorldCoordinates;
|
||||||
this->parent = nullptr;
|
this->parent = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TranslatedCoordinates::TranslatedCoordinates(IsometricCoordinates isometricCoordinates)
|
||||||
|
{
|
||||||
|
setIsometric(isometricCoordinates);
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ class TranslatedCoordinates
|
||||||
public:
|
public:
|
||||||
explicit TranslatedCoordinates(WorldCoordinates worldCoordinates);
|
explicit TranslatedCoordinates(WorldCoordinates worldCoordinates);
|
||||||
explicit TranslatedCoordinates(DiagonalWorldCoordinates diagonalWorldCoordinates);
|
explicit TranslatedCoordinates(DiagonalWorldCoordinates diagonalWorldCoordinates);
|
||||||
|
explicit TranslatedCoordinates(IsometricCoordinates isometricCoordinates);
|
||||||
explicit TranslatedCoordinates(GridCoordinates gridCoordinates);
|
explicit TranslatedCoordinates(GridCoordinates gridCoordinates);
|
||||||
|
|
||||||
[[nodiscard]] WorldCoordinates world() const;
|
[[nodiscard]] WorldCoordinates world() const;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "../game_object.h"
|
#include "../game_object.h"
|
||||||
|
#include "../player/player.hpp"
|
||||||
|
|
||||||
class Collectable : public GameObject
|
class Collectable : public GameObject
|
||||||
{
|
{
|
||||||
|
@ -23,6 +24,8 @@ public:
|
||||||
private:
|
private:
|
||||||
int collectableId = 0;
|
int collectableId = 0;
|
||||||
static inline int collectableCount = 0;
|
static inline int collectableCount = 0;
|
||||||
|
|
||||||
|
std::shared_ptr<Player> consumedBy = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,10 @@ void MaskedSprite::updateFreshMaskedSprite()
|
||||||
maskedImage->copy(*image, 0, 0);
|
maskedImage->copy(*image, 0, 0);
|
||||||
|
|
||||||
// Calculate world coordinates for each pixel
|
// Calculate world coordinates for each pixel
|
||||||
auto topLeftCorner = sf::Vector2f(coordinates->diagonalWorld().horizontal, coordinates->diagonalWorld().vertical);
|
auto coordinatesTopLeftCorner = TranslatedCoordinates(
|
||||||
|
IsometricCoordinates(renderPosition.x, renderPosition.y, coordinates->isometric().depth));
|
||||||
|
auto topLeftCorner = sf::Vector2f(coordinatesTopLeftCorner.diagonalWorld().horizontal,
|
||||||
|
coordinatesTopLeftCorner.diagonalWorld().vertical);
|
||||||
auto xAxis = rotateVectorByAngle(sf::Vector2f(1, 0), angle);
|
auto xAxis = rotateVectorByAngle(sf::Vector2f(1, 0), angle);
|
||||||
auto yAxis = rotateVectorByAngle(sf::Vector2f(0, -1), angle);
|
auto yAxis = rotateVectorByAngle(sf::Vector2f(0, -1), angle);
|
||||||
float xFactorPerPixel = sprite->getScale().x / WORLD_TO_ISO_SCALE;
|
float xFactorPerPixel = sprite->getScale().x / WORLD_TO_ISO_SCALE;
|
||||||
|
@ -124,7 +127,13 @@ sf::Color MaskedSprite::calculateNewPixelColor(sf::Color currentColor, sf::Vecto
|
||||||
return currentColor;
|
return currentColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change color based on height and hole
|
// Make darker the further below the ground
|
||||||
|
float remainigBrightnessFactor = exp(position.y) * (1 - MASKED_HOLE_DARKNESS_LIMIT) +
|
||||||
|
MASKED_HOLE_DARKNESS_LIMIT; // y is negative here already
|
||||||
|
currentColor.r *= remainigBrightnessFactor;
|
||||||
|
currentColor.g *= remainigBrightnessFactor;
|
||||||
|
currentColor.b *= remainigBrightnessFactor;
|
||||||
|
|
||||||
// Cut off pixels that are hidden in the ground, beyond the hole
|
// Cut off pixels that are hidden in the ground, beyond the hole
|
||||||
float depth = coordinates->diagonalWorld().depth;
|
float depth = coordinates->diagonalWorld().depth;
|
||||||
auto pixelCoordinates = TranslatedCoordinates(DiagonalWorldCoordinates(position.x, position.y, depth));
|
auto pixelCoordinates = TranslatedCoordinates(DiagonalWorldCoordinates(position.x, position.y, depth));
|
||||||
|
|
Loading…
Reference in a new issue