Fixed occlusion

This commit is contained in:
Maximilian Giller 2023-07-09 04:06:29 +02:00
parent c49d937e20
commit 364f4c6423
5 changed files with 21 additions and 2 deletions

View file

@ -32,6 +32,7 @@
#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 MASKED_HOLE_BORDER_TRANSITION_SIZE 0.2f
#define MASKED_HOLE_DARKNESS_LIMIT 0.5f
// Tracking view defaults
#define DEF_TV_IS_ABSOLUTE_FREE_MOVE_THRESHOLD false

View file

@ -109,3 +109,8 @@ void TranslatedCoordinates::removeParent()
// this->worldCoordinates = globalWorldCoordinates;
this->parent = nullptr;
}
TranslatedCoordinates::TranslatedCoordinates(IsometricCoordinates isometricCoordinates)
{
setIsometric(isometricCoordinates);
}

View file

@ -10,6 +10,7 @@ class TranslatedCoordinates
public:
explicit TranslatedCoordinates(WorldCoordinates worldCoordinates);
explicit TranslatedCoordinates(DiagonalWorldCoordinates diagonalWorldCoordinates);
explicit TranslatedCoordinates(IsometricCoordinates isometricCoordinates);
explicit TranslatedCoordinates(GridCoordinates gridCoordinates);
[[nodiscard]] WorldCoordinates world() const;

View file

@ -3,6 +3,7 @@
#include "../game_object.h"
#include "../player/player.hpp"
class Collectable : public GameObject
{
@ -23,6 +24,8 @@ public:
private:
int collectableId = 0;
static inline int collectableCount = 0;
std::shared_ptr<Player> consumedBy = nullptr;
};

View file

@ -58,7 +58,10 @@ void MaskedSprite::updateFreshMaskedSprite()
maskedImage->copy(*image, 0, 0);
// 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 yAxis = rotateVectorByAngle(sf::Vector2f(0, -1), angle);
float xFactorPerPixel = sprite->getScale().x / WORLD_TO_ISO_SCALE;
@ -124,7 +127,13 @@ sf::Color MaskedSprite::calculateNewPixelColor(sf::Color currentColor, sf::Vecto
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
float depth = coordinates->diagonalWorld().depth;
auto pixelCoordinates = TranslatedCoordinates(DiagonalWorldCoordinates(position.x, position.y, depth));