diff --git a/CMakeLists.txt b/CMakeLists.txt index ffbc675..747f985 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,7 +91,7 @@ add_executable(shooter engine/network/UDPConnection.h engine/network/UDPSocket.cpp engine/network/UDPSocket.h - engine/SoundController.cpp engine/SoundController.h ShooterMsgType.h ShooterMsgType.cpp) + engine/SoundController.cpp engine/SoundController.h ShooterMsgType.h ShooterMsgType.cpp engine/animation/AAttractToPoint.h engine/animation/ARotateRelativePoint.h) if(APPLE OR UNIX) include_directories(/usr/local/include) diff --git a/Shooter.cpp b/Shooter.cpp index 6830080..2a1a662 100644 --- a/Shooter.cpp +++ b/Shooter.cpp @@ -11,6 +11,10 @@ #include "engine/animation/Timeline.h" #include "ShooterConsts.h" #include "engine/SoundController.h" +#include "engine/animation/AAttractToPoint.h" +#include "engine/animation/ARotateRelativePoint.h" +#include "engine/animation/ATranslateToPoint.h" +#include "engine/animation/AWait.h" using namespace std; diff --git a/ShooterClient.cpp b/ShooterClient.cpp index 695af6c..f1e4d7e 100644 --- a/ShooterClient.cpp +++ b/ShooterClient.cpp @@ -9,6 +9,12 @@ #include "engine/animation/Timeline.h" #include "ShooterMsgType.h" +#include "engine/animation/AAttractToPoint.h" +#include "engine/animation/ARotateRelativePoint.h" +#include "engine/animation/ATranslateToPoint.h" +#include "engine/animation/AWait.h" +#include "engine/animation/AFunction.h" + void ShooterClient::updatePacket() { sf::Packet packet; packet << MsgType::ClientUpdate << _player->position().x() << _player->position().y() << _player->position().z() @@ -109,12 +115,33 @@ void ShooterClient::processCustomPacket(sf::Packet &packet) { if (buffId[0] == _socket.ownId()) { _player->addDeath(); - // respawn - _player->translateToPoint( - Vec3D{50.0 * (-1 + 2.0 * (double) rand() / RAND_MAX), 30.0 * (double) rand() / RAND_MAX, - 50.0 * (-1 + 2.0 * (double) rand() / RAND_MAX)}); - _player->reInitWeapons(); - _player->setFullAbility(); + + auto camera = _player->attached(ObjectNameTag("Camera")); + _player->unattach(ObjectNameTag("Camera")); + _player->translateToPoint(Vec3D{10000}); + Vec2D cameraOrientation(camera->angleLeftUpLookAt().x(), _player->angle().y()); + camera->rotateLeft(-cameraOrientation.x()); + camera->transform(Matrix4x4::Rotation(Vec3D(-_player->angle()))); + + Timeline::animate(AnimationListTag("camera_anim"), std::make_shared(camera, Vec3D(-20, 30, -100))); + Timeline::animate(AnimationListTag("camera_anim"), std::make_shared(camera, Vec3D(0), Vec3D{0, Consts::PI, 0}, 5, Animation::LoopOut::None, Animation::InterpolationType::Linear)); + Timeline::animate(AnimationListTag("camera_anim"), std::make_shared(0)); + Timeline::animate(AnimationListTag("camera_anim"), std::make_shared([this, camera](){ + // respawn + _player->translateToPoint(Vec3D{50.0 * (-1 + 2.0 * (double) rand() / RAND_MAX), 30.0 * (double) rand() / RAND_MAX, + 50.0 * (-1 + 2.0 * (double) rand() / RAND_MAX)}); + _player->reInitWeapons(); + _player->setFullAbility(); + + camera->rotateToAngle(Vec3D(0)); + camera->transform(Matrix4x4::Rotation(Vec3D(_player->angle()))); + camera->rotateLeft(_player->headAngle()); + camera->translateToPoint(_player->position() + Vec3D{0, 1.8, 0}); + _player->attach(camera); + + }, 1, 0.1)); + + SoundController::playSound(SoundTag("death"), ShooterConsts::DEATH_SOUND); _lastEvent += _player->playerNickName(); } else { diff --git a/engine/Consts.h b/engine/Consts.h index e46237e..5224041 100644 --- a/engine/Consts.h +++ b/engine/Consts.h @@ -16,7 +16,7 @@ namespace Consts { const std::string PROJECT_NAME = "engine"; const bool USE_LOG_FILE = true; const bool USE_OPEN_GL = true; - const bool SHOW_DEBUG_INFO = false; + const bool SHOW_DEBUG_INFO = true; const bool SHOW_FPS_COUNTER = true; const double PI = 3.14159265358979323846264338327950288; diff --git a/engine/Object.cpp b/engine/Object.cpp index 67a8542..3594170 100644 --- a/engine/Object.cpp +++ b/engine/Object.cpp @@ -97,6 +97,11 @@ void Object::translateToPoint(const Vec3D &point) { translate(point - position()); } +void Object::attractToPoint(const Vec3D &point, double value) { + Vec3D v = (point - position()).normalized(); + translate(v*value); +} + void Object::rotateToAngle(const Vec3D &v) { rotate(v - _angle); } diff --git a/engine/Object.h b/engine/Object.h index 7ad3d33..d33ca85 100644 --- a/engine/Object.h +++ b/engine/Object.h @@ -63,6 +63,8 @@ public: void translateToPoint(const Vec3D &point); + void attractToPoint(const Vec3D &point, double value); + void scale(const Vec3D &s); void rotate(const Vec3D &r); diff --git a/engine/animation/AAttractToPoint.h b/engine/animation/AAttractToPoint.h new file mode 100644 index 0000000..1333160 --- /dev/null +++ b/engine/animation/AAttractToPoint.h @@ -0,0 +1,34 @@ +// +// Created by Иван Ильин on 01.11.2021. +// + +#ifndef SHOOTER_AATTRACTTOPOINT_H +#define SHOOTER_AATTRACTTOPOINT_H + +#include "Animation.h" +#include "../Object.h" + +class AAttractToPoint : public Animation { +private: + const std::weak_ptr _object; + const Vec3D _targetPoint; + const double _valueToAttract; + + void update() override { + if (_object.expired()) { + stop(); + return; + } + + _object.lock()->attractToPoint(_targetPoint, _valueToAttract * dprogress()); + } + +public: + AAttractToPoint(std::weak_ptr object, const Vec3D &targetPoint, double valueToAttract, double duration = 1, + Animation::LoopOut looped = LoopOut::None, + Animation::InterpolationType interpolationType = InterpolationType::Bezier) + : Animation(duration, looped, interpolationType), _object(object), _targetPoint(targetPoint), + _valueToAttract(valueToAttract) {} +}; + +#endif //SHOOTER_AATTRACTTOPOINT_H diff --git a/engine/animation/ARotate.h b/engine/animation/ARotate.h index 089a0f3..8c0c67f 100644 --- a/engine/animation/ARotate.h +++ b/engine/animation/ARotate.h @@ -27,7 +27,7 @@ private: public: ARotate(std::weak_ptr object, const Vec3D &r, double duration = 1, LoopOut looped = LoopOut::None, InterpolationType interpolationType = InterpolationType::Bezier) - : Animation(duration, looped, interpolationType), _object(std::move(object)), _rotationValue(r) { + : Animation(duration, looped, interpolationType), _object(object), _rotationValue(r) { } }; diff --git a/engine/animation/ARotateRelativePoint.h b/engine/animation/ARotateRelativePoint.h new file mode 100644 index 0000000..73f77ee --- /dev/null +++ b/engine/animation/ARotateRelativePoint.h @@ -0,0 +1,37 @@ +// +// Created by Иван Ильин on 01.11.2021. +// + +#ifndef SHOOTER_AROTATERELATIVEPOINT_H +#define SHOOTER_AROTATERELATIVEPOINT_H + +#include + +#include "Animation.h" +#include "../Object.h" + +class ARotateRelativePoint : public Animation { +private: + const std::weak_ptr _object; + const Vec3D _targetPoint; + const Vec3D _rotationValue; + + void update() override { + + if (_object.expired()) { + stop(); + return; + } + + _object.lock()->rotateRelativePoint(_targetPoint, _rotationValue * dprogress()); + } + +public: + ARotateRelativePoint(std::weak_ptr object, const Vec3D &targetPoint, const Vec3D &rotationValue, + double duration = 1, Animation::LoopOut looped = LoopOut::None, + Animation::InterpolationType interpolationType = InterpolationType::Bezier) + : Animation(duration, looped, interpolationType), _object(object), _targetPoint(targetPoint), + _rotationValue(rotationValue) {} +}; + +#endif //SHOOTER_AROTATERELATIVEPOINT_H diff --git a/shooter.vcxproj b/shooter.vcxproj index b399a95..d3317a7 100644 --- a/shooter.vcxproj +++ b/shooter.vcxproj @@ -206,6 +206,8 @@ + + diff --git a/shooter.vcxproj.filters b/shooter.vcxproj.filters index 8527692..e05e70c 100644 --- a/shooter.vcxproj.filters +++ b/shooter.vcxproj.filters @@ -215,6 +215,12 @@ Файлы заголовков\engine\animation + + Файлы заголовков\engine\animation + + + Файлы заголовков\engine\animation + Файлы заголовков\weapon