Compare commits
2 Commits
dd703c3221
...
73412b27f8
Author | SHA1 | Date | |
---|---|---|---|
73412b27f8 | |||
35ba580398 |
31
camera.cpp
Normal file
31
camera.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "camera.h"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <SFML/Graphics/Color.hpp>
|
||||||
|
|
||||||
|
#define PI 3.14159265
|
||||||
|
|
||||||
|
static void drawLine(sf::RenderWindow* window, sf::Vector2f pos, float angle, float length, sf::Color color);
|
||||||
|
|
||||||
|
void camera_update(Camera* camera, sf::RenderWindow* window)
|
||||||
|
{
|
||||||
|
if (!camera || !window) return;
|
||||||
|
|
||||||
|
drawLine(window, camera->pos, camera->direction, 100, sf::Color::Red);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void drawLine(sf::RenderWindow* window, sf::Vector2f pos, float angle, float length, sf::Color color)
|
||||||
|
{
|
||||||
|
if (!window) return;
|
||||||
|
|
||||||
|
sf::Vector2f endOffset(length * cos(angle * PI/180.f), length * sin(angle * PI/180.3));
|
||||||
|
sf::Vertex start(pos);
|
||||||
|
sf::Vertex end(pos + endOffset);
|
||||||
|
|
||||||
|
start.color = color;
|
||||||
|
end.color = color;
|
||||||
|
|
||||||
|
sf::Vertex line[] = { start, end };
|
||||||
|
|
||||||
|
window->draw(line, 2, sf::Lines);
|
||||||
|
}
|
17
camera.h
Normal file
17
camera.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef CAMERA_H
|
||||||
|
#define CAMERA_H
|
||||||
|
|
||||||
|
#include <SFML/Graphics/RenderWindow.hpp>
|
||||||
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
sf::Vector2f pos;
|
||||||
|
float direction;
|
||||||
|
float resolution;
|
||||||
|
float fov;
|
||||||
|
} Camera;
|
||||||
|
|
||||||
|
void camera_update(Camera* camera, sf::RenderWindow* window);
|
||||||
|
|
||||||
|
#endif
|
4
makefile
4
makefile
@ -11,7 +11,7 @@ LDFLAGS = -lsfml-graphics -lsfml-window -lsfml-system
|
|||||||
|
|
||||||
.PHONY: all run clean
|
.PHONY: all run clean
|
||||||
|
|
||||||
all: $(TARGET) $(OBJD)
|
all: $(TARGET)
|
||||||
|
|
||||||
$(TARGET): $(OBJS)
|
$(TARGET): $(OBJS)
|
||||||
$(CC) $^ -o $(TARGET) $(LDFLAGS) $(CCFLAGS)
|
$(CC) $^ -o $(TARGET) $(LDFLAGS) $(CCFLAGS)
|
||||||
@ -23,6 +23,6 @@ $(OBJS): $(OBJD)/%.o: %.cpp
|
|||||||
clean:
|
clean:
|
||||||
rm -r $(TARGET) $(OBJD)
|
rm -r $(TARGET) $(OBJD)
|
||||||
|
|
||||||
run:
|
run: main
|
||||||
./$(TARGET)
|
./$(TARGET)
|
||||||
|
|
||||||
|
4
view.cpp
4
view.cpp
@ -3,12 +3,15 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "level.h"
|
#include "level.h"
|
||||||
|
#include "camera.h"
|
||||||
|
|
||||||
static int handleKeyCode(sf::Keyboard::Key key);
|
static int handleKeyCode(sf::Keyboard::Key key);
|
||||||
|
|
||||||
static sf::Uint32 style = sf::Style::Titlebar;
|
static sf::Uint32 style = sf::Style::Titlebar;
|
||||||
static sf::RenderWindow window(sf::VideoMode(500, 500), "Raycasting", style);
|
static sf::RenderWindow window(sf::VideoMode(500, 500), "Raycasting", style);
|
||||||
|
|
||||||
|
static Camera camera = { sf::Vector2f(300.f, 250.f), 0.f, 1.f, 70.f };
|
||||||
|
|
||||||
int view_init()
|
int view_init()
|
||||||
{
|
{
|
||||||
printf("view_init()\n");
|
printf("view_init()\n");
|
||||||
@ -35,6 +38,7 @@ int view_update()
|
|||||||
|
|
||||||
window.clear();
|
window.clear();
|
||||||
if (!level_update()) return 0;
|
if (!level_update()) return 0;
|
||||||
|
camera_update(&camera, &window);
|
||||||
window.display();
|
window.display();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user