mirror of
https://github.com/Relintai/programming_tutorials.git
synced 2025-04-21 21:51:22 +02:00
Added the camera to the 05th excerscise.
This commit is contained in:
parent
524b365901
commit
04e394a764
24
05_sdl_software_renderer/camera.cpp
Normal file
24
05_sdl_software_renderer/camera.cpp
Normal 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() {
|
||||
}
|
22
05_sdl_software_renderer/camera.h
Normal file
22
05_sdl_software_renderer/camera.h
Normal 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
|
@ -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)
|
||||
|
||||
|
@ -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() {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user