Added the camera to the 05th excerscise.

This commit is contained in:
Relintai 2021-04-03 01:14:39 +02:00
parent 524b365901
commit 04e394a764
4 changed files with 49 additions and 2 deletions

View File

@ -0,0 +1,24 @@
#include "camera.h"
#include "renderer.h"
void Camera::bind() {
Renderer::get_singleton()->set_integer_scaling(integer_scaling);
Renderer::get_singleton()->set_scale(scale_w, scale_h);
Renderer::get_singleton()->set_viewport(viewport);
Renderer::get_singleton()->set_clip_rect(&clip_rect);
}
Camera::Camera() {
integer_scaling = false;
scale_w = 1;
scale_h = 1;
viewport = Renderer::get_singleton()->get_viewport();
clip_rect = Renderer::get_singleton()->get_clip_rect();
}
Camera::~Camera() {
}

View File

@ -0,0 +1,22 @@
#ifndef CAMERA_H
#define CAMERA_H
#include <SDL.h>
#include "rect2.h"
class Camera {
public:
void bind();
Camera();
virtual ~Camera();
bool integer_scaling;
float scale_w;
float scale_h;
Rect2 viewport;
Rect2 clip_rect;
};
#endif

View File

@ -22,8 +22,9 @@ g++ -Wall -g $(sdl2-config --cflags) -c renderer.cpp -o obj/renderer.o
g++ -Wall -g $(sdl2-config --cflags) -c image.cpp -o obj/image.o
g++ -Wall -g $(sdl2-config --cflags) -c texture.cpp -o obj/texture.o
g++ -Wall -g $(sdl2-config --cflags) -c sprite.cpp -o obj/sprite.o
g++ -Wall -g $(sdl2-config --cflags) -c camera.cpp -o obj/camera.o
g++ -Wall -g $(sdl2-config --cflags) -c main.cpp -o obj/main.o
g++ -o bin/program obj/math.o obj/rect2.o obj/color.o obj/string.o obj/renderer.o obj/image.o obj/texture.o obj/sprite.o obj/main.o $(sdl2-config --libs)
g++ -o bin/program obj/math.o obj/rect2.o obj/color.o obj/string.o obj/renderer.o obj/image.o obj/texture.o obj/sprite.o obj/camera.o obj/main.o $(sdl2-config --libs)

View File

@ -18,7 +18,7 @@ Camera::Camera() {
scale_h = 1;
viewport = Renderer::get_singleton()->get_viewport();
clip_rect = Renderer::get_singleton()->get_viewport();
clip_rect = Renderer::get_singleton()->get_clip_rect();
}
Camera::~Camera() {
}