Remove draw scale from Camera struct.
This commit is contained in:
parent
bce640219f
commit
33f673741b
1
camera.h
1
camera.h
@ -9,7 +9,6 @@ typedef struct
|
||||
float direction;
|
||||
unsigned int resolution;
|
||||
float fov;
|
||||
float drawScale;
|
||||
} Camera;
|
||||
|
||||
void camera_update(Camera* camera, float t);
|
||||
|
@ -45,6 +45,12 @@ float level_rayCastDistance(sf::Vector2f point, float direction)
|
||||
return castRay(point, direction);
|
||||
}
|
||||
|
||||
void level_getDimensions(unsigned int* width, unsigned int* height)
|
||||
{
|
||||
*width = WIDTH;
|
||||
*height = HEIGHT;
|
||||
}
|
||||
|
||||
static void drawGrid(sf::RenderTarget* renderTarget, unsigned int tileSize)
|
||||
{
|
||||
for (unsigned int x = 0; x < WIDTH; x++) {
|
||||
|
1
level.h
1
level.h
@ -7,5 +7,6 @@ int level_init();
|
||||
void level_update(sf::RenderTarget* renderTarget, unsigned int drawSize);
|
||||
void level_end();
|
||||
float level_rayCastDistance(sf::Vector2f point, float direction);
|
||||
void level_getDimensions(unsigned int* width, unsigned int* height);
|
||||
|
||||
#endif
|
||||
|
18
minimap.cpp
18
minimap.cpp
@ -10,19 +10,29 @@ static void drawLine(sf::RenderTarget* renderTarget, sf::Vector2f pos, float ang
|
||||
|
||||
static sf::RenderTexture minimap;
|
||||
|
||||
static bool init = false;
|
||||
static unsigned int minimapSize;
|
||||
static float drawScale;
|
||||
|
||||
int minimap_init(unsigned int size)
|
||||
{
|
||||
printf("minimap_init()\n");
|
||||
minimapSize = size;
|
||||
if (!minimap.create(size, size)) return 0;
|
||||
level_init();
|
||||
|
||||
unsigned int width, height;
|
||||
level_getDimensions(&width, &height);
|
||||
|
||||
minimapSize = size;
|
||||
drawScale = (float)size/(float)width;
|
||||
|
||||
init = true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void minimap_update(sf::RenderTarget* renderTarget, Camera* camera)
|
||||
{
|
||||
if (!init) return;
|
||||
if (!renderTarget || !camera) return;
|
||||
minimap.clear();
|
||||
level_update(&minimap, minimapSize);
|
||||
@ -35,7 +45,7 @@ void minimap_update(sf::RenderTarget* renderTarget, Camera* camera)
|
||||
|
||||
static void drawCamera(sf::RenderTarget* renderTarget, Camera* camera)
|
||||
{
|
||||
const sf::Vector2f scaledPos = camera->pos * camera->drawScale;
|
||||
const sf::Vector2f scaledPos = camera->pos * drawScale;
|
||||
const float circleRadius = 0.02f * minimapSize;
|
||||
sf::CircleShape circle(circleRadius);
|
||||
circle.setPosition(scaledPos);
|
||||
@ -49,7 +59,7 @@ static void drawCamera(sf::RenderTarget* renderTarget, Camera* camera)
|
||||
|
||||
static void drawRays(sf::RenderTarget* renderTarget, Camera* camera)
|
||||
{
|
||||
const sf::Vector2f scaledPos = camera->pos * camera->drawScale;
|
||||
const sf::Vector2f scaledPos = camera->pos * drawScale;
|
||||
|
||||
float rayDirection = 0;
|
||||
float rayDirectionStep = camera->fov / (float)camera->resolution;
|
||||
@ -64,7 +74,7 @@ static void drawRays(sf::RenderTarget* renderTarget, Camera* camera)
|
||||
else
|
||||
rayDirection = camera->direction + rayDirectionOffset;
|
||||
|
||||
float distance = level_rayCastDistance(camera->pos, rayDirection) * camera->drawScale;
|
||||
float distance = level_rayCastDistance(camera->pos, rayDirection) * drawScale;
|
||||
|
||||
drawLine(renderTarget, scaledPos, rayDirection, distance, sf::Color(150, 150, 100));
|
||||
|
||||
|
4
view.cpp
4
view.cpp
@ -6,13 +6,13 @@
|
||||
#include "camera.h"
|
||||
#include "minimap.h"
|
||||
|
||||
#define MINIMAP_SIZE 300
|
||||
#define MINIMAP_SIZE 250
|
||||
#define HALF_MINIMAP_SIZE MINIMAP_SIZE/2.f
|
||||
#define DRAW_SCALE MINIMAP_SIZE/5.f
|
||||
|
||||
static int handleKeyCode(sf::Keyboard::Key key);
|
||||
|
||||
static Camera camera = { sf::Vector2f(5.f/2.f, 5.f/2.f), 0.f, 300, 0.5f*PI, DRAW_SCALE };
|
||||
static Camera camera = { sf::Vector2f(5.f/2.f, 5.f/2.f), 0.f, 300, 0.5f*PI };
|
||||
|
||||
static sf::Uint32 style = sf::Style::Titlebar;
|
||||
static sf::RenderWindow window(sf::VideoMode(MINIMAP_SIZE + camera.resolution, MINIMAP_SIZE), "Raycasting", style);
|
||||
|
Loading…
Reference in New Issue
Block a user