Simple setup for grid debug rendering
This commit is contained in:
parent
1aea157aa1
commit
4dc9702747
11 changed files with 80 additions and 22 deletions
|
@ -34,7 +34,7 @@ set(SOURCES
|
||||||
src/primitives/circle_object.cpp
|
src/primitives/circle_object.cpp
|
||||||
src/primitives/circle_object.h
|
src/primitives/circle_object.h
|
||||||
src/game/game_factory.cpp
|
src/game/game_factory.cpp
|
||||||
src/game/game_factory.hpp src/config.h)
|
src/game/game_factory.hpp src/config.h src/debug/grid_debug_layer.cpp src/debug/grid_debug_layer.h)
|
||||||
|
|
||||||
set(PHYSICS_00_SOURCES
|
set(PHYSICS_00_SOURCES
|
||||||
src/prototypes/physics_00.cpp
|
src/prototypes/physics_00.cpp
|
||||||
|
|
|
@ -9,5 +9,6 @@
|
||||||
|
|
||||||
#define ANTIALIASINGLEVEL 8
|
#define ANTIALIASINGLEVEL 8
|
||||||
|
|
||||||
|
#define WOLRD_TO_ISO_SCALE 50.0f
|
||||||
|
|
||||||
#endif //HOLESOME_CONFIG_H
|
#endif //HOLESOME_CONFIG_H
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "coordinate_transformer.h"
|
#include "coordinate_transformer.h"
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
// Initialize matrix
|
// Initialize matrix
|
||||||
const Eigen::Matrix<float, 3, 3> CoordinateTransformer::worldToIsometricMatrix =
|
const Eigen::Matrix<float, 3, 3> CoordinateTransformer::worldToIsometricMatrix =
|
||||||
|
@ -11,7 +12,7 @@ IsometricCoordinates CoordinateTransformer::worldToIsometric(WorldCoordinates wo
|
||||||
Eigen::Vector3f worldCoordinatesVector;
|
Eigen::Vector3f worldCoordinatesVector;
|
||||||
worldCoordinatesVector << worldCoordinates.x, worldCoordinates.y, worldCoordinates.z;
|
worldCoordinatesVector << worldCoordinates.x, worldCoordinates.y, worldCoordinates.z;
|
||||||
|
|
||||||
Eigen::Vector3f isoCoordinatesVector = worldToIsometricMatrix * worldCoordinatesVector;
|
Eigen::Vector3f isoCoordinatesVector = worldToIsometricMatrix * worldCoordinatesVector * WOLRD_TO_ISO_SCALE;
|
||||||
|
|
||||||
return IsometricCoordinates(
|
return IsometricCoordinates(
|
||||||
isoCoordinatesVector.x(), // x
|
isoCoordinatesVector.x(), // x
|
||||||
|
|
|
@ -4,15 +4,15 @@
|
||||||
|
|
||||||
#include "translated_coordinates.h"
|
#include "translated_coordinates.h"
|
||||||
|
|
||||||
WorldCoordinates TranslatedCoordinates::getWorldCoordinates() const {
|
WorldCoordinates TranslatedCoordinates::world() const {
|
||||||
return worldCoordinates;
|
return worldCoordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
IsometricCoordinates TranslatedCoordinates::getScreenCoordinates() const {
|
IsometricCoordinates TranslatedCoordinates::isometric() const {
|
||||||
return isoCoordTransformer->worldToIsometric(worldCoordinates);
|
return isoCoordTransformer->worldToIsometric(worldCoordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
GridCoordinates TranslatedCoordinates::getGridCoordinates() const {
|
GridCoordinates TranslatedCoordinates::grid() const {
|
||||||
// Grid coords are just world coords without height, and scaled differently
|
// Grid coords are just world coords without height, and scaled differently
|
||||||
return {worldCoordinates.x * worldToGridFactor, worldCoordinates.y * worldToGridFactor};
|
return {worldCoordinates.x * worldToGridFactor, worldCoordinates.y * worldToGridFactor};
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,11 @@ class TranslatedCoordinates {
|
||||||
public:
|
public:
|
||||||
explicit TranslatedCoordinates(WorldCoordinates worldCoordinates);
|
explicit TranslatedCoordinates(WorldCoordinates worldCoordinates);
|
||||||
|
|
||||||
WorldCoordinates getWorldCoordinates() const;
|
WorldCoordinates world() const;
|
||||||
|
|
||||||
IsometricCoordinates getScreenCoordinates() const;
|
IsometricCoordinates isometric() const;
|
||||||
|
|
||||||
GridCoordinates getGridCoordinates() const;
|
GridCoordinates grid() const;
|
||||||
|
|
||||||
void set(WorldCoordinates newWorldCoordinates);
|
void set(WorldCoordinates newWorldCoordinates);
|
||||||
|
|
||||||
|
|
37
src/debug/grid_debug_layer.cpp
Normal file
37
src/debug/grid_debug_layer.cpp
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#include "grid_debug_layer.h"
|
||||||
|
#include "../primitives/circle_object.h"
|
||||||
|
|
||||||
|
GridDebugLayer::GridDebugLayer(int minX, int maxX, int minY, int maxY)
|
||||||
|
{
|
||||||
|
// Generate markers
|
||||||
|
for (int x = minX; x <= maxX; x++)
|
||||||
|
{
|
||||||
|
for (int y = minY; y <= maxY; y++)
|
||||||
|
{
|
||||||
|
auto *gameObject = new CircleObject(5, sf::Color::Red);
|
||||||
|
gameObject->coordinates.set(WorldCoordinates(x, y, 0));
|
||||||
|
marker.push_back(gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GridDebugLayer::~GridDebugLayer()
|
||||||
|
{
|
||||||
|
for (auto &gameObject: marker)
|
||||||
|
{
|
||||||
|
delete gameObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridDebugLayer::draw(sf::RenderWindow *window) const
|
||||||
|
{
|
||||||
|
for (auto &gameObject: marker)
|
||||||
|
{
|
||||||
|
gameObject->draw(window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridDebugLayer::update() const
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
21
src/debug/grid_debug_layer.h
Normal file
21
src/debug/grid_debug_layer.h
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef HOLESOME_GRID_DEBUG_LAYER_H
|
||||||
|
#define HOLESOME_GRID_DEBUG_LAYER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "../game/game_object.h"
|
||||||
|
|
||||||
|
class GridDebugLayer : public GameObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GridDebugLayer(int minX, int maxX, int minY, int maxY);
|
||||||
|
~GridDebugLayer();
|
||||||
|
|
||||||
|
void draw(sf::RenderWindow *window) const override;
|
||||||
|
void update() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<GameObject*> marker;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //HOLESOME_GRID_DEBUG_LAYER_H
|
|
@ -1,5 +1,6 @@
|
||||||
#include "game_object.h"
|
#include "game_object.h"
|
||||||
|
|
||||||
GameObject::GameObject() : coordinates(std::make_shared<TranslatedCoordinates>(WorldCoordinates(0, 0, 0))) {
|
GameObject::GameObject() : coordinates(WorldCoordinates(0, 0, 0))
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,7 @@ public:
|
||||||
virtual void draw(sf::RenderWindow *window) const = 0;
|
virtual void draw(sf::RenderWindow *window) const = 0;
|
||||||
virtual void update() const = 0;
|
virtual void update() const = 0;
|
||||||
|
|
||||||
protected:
|
TranslatedCoordinates coordinates;
|
||||||
std::shared_ptr<TranslatedCoordinates> coordinates;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //HOLESOME_GAME_OBJECT_H
|
#endif //HOLESOME_GAME_OBJECT_H
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "logging/easylogging++.h"
|
#include "logging/easylogging++.h"
|
||||||
#include "game/game.h"
|
|
||||||
#include "primitives/circle_object.h"
|
|
||||||
#include "game/game_factory.hpp"
|
#include "game/game_factory.hpp"
|
||||||
|
#include "debug/grid_debug_layer.h"
|
||||||
|
|
||||||
INITIALIZE_EASYLOGGINGPP
|
INITIALIZE_EASYLOGGINGPP
|
||||||
|
|
||||||
|
@ -13,7 +12,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
auto game = GameFactory::createFullscreen("Holesome");
|
auto game = GameFactory::createFullscreen("Holesome");
|
||||||
|
|
||||||
game->addGameObject(new CircleObject(50, sf::Color::Red));
|
game->addGameObject(new GridDebugLayer(0, 50, 0, 50));
|
||||||
|
|
||||||
game->run();
|
game->run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,22 @@
|
||||||
//
|
|
||||||
// Created by max on 27.04.23.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <SFML/Graphics/CircleShape.hpp>
|
#include <SFML/Graphics/CircleShape.hpp>
|
||||||
#include "circle_object.h"
|
#include "circle_object.h"
|
||||||
|
|
||||||
CircleObject::CircleObject(int radius, sf::Color color) : radius(radius), color(color) {
|
CircleObject::CircleObject(int radius, sf::Color color) : radius(radius), color(color)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircleObject::draw(sf::RenderWindow *window) const {
|
void CircleObject::draw(sf::RenderWindow *window) const
|
||||||
|
{
|
||||||
sf::CircleShape circle(radius);
|
sf::CircleShape circle(radius);
|
||||||
circle.setFillColor(color);
|
circle.setFillColor(color);
|
||||||
circle.setPosition(coordinates->getScreenCoordinates().x, coordinates->getScreenCoordinates().y);
|
circle.setPosition(coordinates.isometric().x - radius / 2, coordinates.isometric().y - radius / 2);
|
||||||
|
|
||||||
window->draw(circle);
|
window->draw(circle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircleObject::update() const {
|
void CircleObject::update() const
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue