mirror of
https://github.com/Relintai/programming_tutorials.git
synced 2025-04-21 21:51:22 +02:00
Camera class.
This commit is contained in:
parent
373b36664b
commit
524b365901
24
06_sdl_application/camera.cpp
Normal file
24
06_sdl_application/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_viewport();
|
||||
}
|
||||
Camera::~Camera() {
|
||||
}
|
22
06_sdl_application/camera.h
Normal file
22
06_sdl_application/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,6 +22,7 @@ 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 scene.cpp -o obj/scene.o
|
||||
g++ -Wall -g $(sdl2-config --cflags) -c application.cpp -o obj/application.o
|
||||
@ -29,5 +30,5 @@ g++ -Wall -g $(sdl2-config --cflags) -c main_scene.cpp -o obj/main_scene.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/scene.o obj/application.o obj/main_scene.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/scene.o obj/application.o obj/main_scene.o obj/main.o $(sdl2-config --libs)
|
||||
|
||||
|
@ -12,6 +12,13 @@ void MainScene::update(float delta) {
|
||||
void MainScene::render() {
|
||||
Renderer::get_singleton()->clear();
|
||||
|
||||
_camera->viewport.x -= 1;
|
||||
|
||||
if (_camera->viewport.x >= 300)
|
||||
_camera->viewport.x = 0;
|
||||
|
||||
_camera->bind();
|
||||
|
||||
_sprite->set_x(30);
|
||||
_sprite->set_y(30);
|
||||
|
||||
@ -19,6 +26,7 @@ void MainScene::render() {
|
||||
}
|
||||
|
||||
MainScene::MainScene() {
|
||||
_camera = new Camera();
|
||||
_image = new Image("ti.bmp");
|
||||
_texture = new Texture(_image);
|
||||
_sprite = new Sprite(_texture);
|
||||
@ -31,4 +39,5 @@ MainScene::~MainScene() {
|
||||
delete _sprite;
|
||||
delete _texture;
|
||||
delete _image;
|
||||
delete _camera;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "image.h"
|
||||
#include "texture.h"
|
||||
#include "sprite.h"
|
||||
#include "camera.h"
|
||||
|
||||
class MainScene : public Scene {
|
||||
public:
|
||||
@ -16,6 +17,7 @@ public:
|
||||
MainScene();
|
||||
~MainScene();
|
||||
|
||||
Camera *_camera;
|
||||
Image *_image;
|
||||
Texture *_texture;
|
||||
Sprite *_sprite;
|
||||
|
Loading…
Reference in New Issue
Block a user