refactor
parent
07ddceaa37
commit
423ad110c5
|
@ -66,8 +66,8 @@ add_executable(${CMAKE_PROJECT_NAME}
|
||||||
engine/io/Mouse.h
|
engine/io/Mouse.h
|
||||||
engine/io/SoundController.cpp
|
engine/io/SoundController.cpp
|
||||||
engine/io/SoundController.h
|
engine/io/SoundController.h
|
||||||
engine/utils/CameraController.cpp
|
engine/utils/ObjectController.cpp
|
||||||
engine/utils/CameraController.h
|
engine/utils/ObjectController.h
|
||||||
engine/animation/Animation.h
|
engine/animation/Animation.h
|
||||||
engine/animation/Timeline.cpp
|
engine/animation/Timeline.cpp
|
||||||
engine/animation/Timeline.h
|
engine/animation/Timeline.h
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
//
|
|
||||||
// Created by Иван Ильин on 22.01.2022.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "CameraController.h"
|
|
||||||
#include "Time.h"
|
|
||||||
#include "../math/Vec2D.h"
|
|
||||||
|
|
||||||
CameraController::CameraController(std::shared_ptr<Camera> camera,
|
|
||||||
std::shared_ptr<Keyboard> keyboard,
|
|
||||||
std::shared_ptr<Mouse> mouse) :
|
|
||||||
_camera(std::move(camera)),
|
|
||||||
_keyboard(std::move(keyboard)),
|
|
||||||
_mouse(std::move(mouse)){
|
|
||||||
}
|
|
||||||
|
|
||||||
void CameraController::update() {
|
|
||||||
// Left and right
|
|
||||||
if (Keyboard::isKeyPressed(sf::Keyboard::A))
|
|
||||||
_camera->translate(_camera->left()*Time::deltaTime()*5.0);
|
|
||||||
|
|
||||||
if (Keyboard::isKeyPressed(sf::Keyboard::D))
|
|
||||||
_camera->translate(-_camera->left()*Time::deltaTime()*5.0);
|
|
||||||
|
|
||||||
// Forward and backward
|
|
||||||
if (Keyboard::isKeyPressed(sf::Keyboard::W))
|
|
||||||
_camera->translate(_camera->lookAt()*Time::deltaTime()*5.0);
|
|
||||||
|
|
||||||
if (Keyboard::isKeyPressed(sf::Keyboard::S))
|
|
||||||
_camera->translate(-_camera->lookAt()*Time::deltaTime()*5.0);
|
|
||||||
|
|
||||||
if (Keyboard::isKeyPressed(sf::Keyboard::LShift))
|
|
||||||
_camera->translate(Vec3D{0.0, -Time::deltaTime()*5.0, 0});
|
|
||||||
|
|
||||||
if (Keyboard::isKeyPressed(sf::Keyboard::Space))
|
|
||||||
_camera->translate(Vec3D{0.0, Time::deltaTime()*5.0, 0});
|
|
||||||
|
|
||||||
// Mouse movement
|
|
||||||
Vec2D disp = _mouse->getMouseDisplacement();
|
|
||||||
|
|
||||||
_camera->rotate(Vec3D{0, -disp.x()/1000.0, 0});
|
|
||||||
_camera->rotateLeft(disp.y()/1000.0);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
//
|
|
||||||
// Created by Иван Ильин on 22.01.2022.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef SHOOTER_CAMERACONTROLLER_H
|
|
||||||
#define SHOOTER_CAMERACONTROLLER_H
|
|
||||||
|
|
||||||
#include "../Camera.h"
|
|
||||||
#include "../io/Keyboard.h"
|
|
||||||
#include "../io/Mouse.h"
|
|
||||||
|
|
||||||
class CameraController {
|
|
||||||
private:
|
|
||||||
std::shared_ptr<Camera> _camera;
|
|
||||||
std::shared_ptr<Keyboard> _keyboard;
|
|
||||||
std::shared_ptr<Mouse> _mouse;
|
|
||||||
|
|
||||||
public:
|
|
||||||
CameraController(std::shared_ptr<Camera> camera,
|
|
||||||
std::shared_ptr<Keyboard> keyboard,
|
|
||||||
std::shared_ptr<Mouse> mouse);
|
|
||||||
|
|
||||||
void update();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //SHOOTER_CAMERACONTROLLER_H
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
//
|
||||||
|
// Created by Иван Ильин on 22.01.2022.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "ObjectController.h"
|
||||||
|
#include "Time.h"
|
||||||
|
#include "../math/Vec2D.h"
|
||||||
|
|
||||||
|
ObjectController::ObjectController(std::shared_ptr<Object> object,
|
||||||
|
std::shared_ptr<Mouse> mouse) :
|
||||||
|
_object(std::move(object)),
|
||||||
|
_mouse(std::move(mouse)){
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectController::update() {
|
||||||
|
// Left and right
|
||||||
|
if (Keyboard::isKeyPressed(sf::Keyboard::A))
|
||||||
|
_object->translate(_object->left()*Time::deltaTime()*5.0);
|
||||||
|
|
||||||
|
if (Keyboard::isKeyPressed(sf::Keyboard::D))
|
||||||
|
_object->translate(-_object->left()*Time::deltaTime()*5.0);
|
||||||
|
|
||||||
|
// Forward and backward
|
||||||
|
if (Keyboard::isKeyPressed(sf::Keyboard::W))
|
||||||
|
_object->translate(_object->lookAt()*Time::deltaTime()*5.0);
|
||||||
|
|
||||||
|
if (Keyboard::isKeyPressed(sf::Keyboard::S))
|
||||||
|
_object->translate(-_object->lookAt()*Time::deltaTime()*5.0);
|
||||||
|
|
||||||
|
if (Keyboard::isKeyPressed(sf::Keyboard::LShift))
|
||||||
|
_object->translate(Vec3D{0.0, -Time::deltaTime()*5.0, 0});
|
||||||
|
|
||||||
|
if (Keyboard::isKeyPressed(sf::Keyboard::Space))
|
||||||
|
_object->translate(Vec3D{0.0, Time::deltaTime()*5.0, 0});
|
||||||
|
|
||||||
|
// Mouse movement
|
||||||
|
Vec2D disp = _mouse->getMouseDisplacement();
|
||||||
|
|
||||||
|
_object->rotate(Vec3D{0, -disp.x()/1000.0, 0});
|
||||||
|
_object->rotateLeft(disp.y()/1000.0);
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
//
|
||||||
|
// Created by Иван Ильин on 22.01.2022.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SHOOTER_OBJECTCONTROLLER_H
|
||||||
|
#define SHOOTER_OBJECTCONTROLLER_H
|
||||||
|
|
||||||
|
#include "../Object.h"
|
||||||
|
#include "../io/Keyboard.h"
|
||||||
|
#include "../io/Mouse.h"
|
||||||
|
|
||||||
|
class ObjectController {
|
||||||
|
private:
|
||||||
|
std::shared_ptr<Object> _object;
|
||||||
|
std::shared_ptr<Mouse> _mouse;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ObjectController(std::shared_ptr<Object> object,
|
||||||
|
std::shared_ptr<Mouse> mouse);
|
||||||
|
|
||||||
|
void update();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //SHOOTER_OBJECTCONTROLLER_H
|
Loading…
Reference in New Issue